2

I have a structure that describes a bitmap. It looks like this

struct bitmap {
    int XSize;
    int YSize;
    unsigned char *pData;
};

When an instances of this structure is initialized pData points to thousands of random-like but non-zero bytes. When I print the instance of the structure GDB shows a lot of meaningless bytes. That very time consuming. When the disp of such a variable is active I get the output for each step what delays debugging.

Is there a GDB option that limits the output length?

When the bytes are meaningless I could change the type of pData to void *. But since the structure is used in a precompiled library the type can't be changed. Can the type that GDB uses for print and disp be "overridden"?

harper
  • 13,345
  • 8
  • 56
  • 105

2 Answers2

2

As Paul has pointed out the answer in this question gives the correct command to allow unlimited length.

To limit the length you need the command

set print elements n

where n is the maximum number of elements. Setting n to 0 gives the unlimited length.

Community
  • 1
  • 1
harper
  • 13,345
  • 8
  • 56
  • 105
0

Setting print elements 4 will limit the number of pData characters to 4, but it will also limit all other strings and arrays, which could be quite annoying (e.g. print filename would produce /tmp... when the actual value is /tmp/foobar.

A possibly better approach is to write a Python pretty-printer for struct bitmap (assuming you have sufficiently recent GDB). See this answer on how to do that.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362