This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: unexpected output from print


On Saturday, March 23 2013, Markus Teich wrote:

> Yesterday i stumbled upon an unexpected case, where gdb would output a
> single value without the attribute name in a struct:
> __in6_u = {__u6_addr8 = "325243A2", '\000' <repeats 11 times>,
> __u6_addr16 = {41941, 12865, 0, 0, 0, 0, 0, 0}, __u6_addr32 =
> {843162581, 0, 0, 0}}

This is because GDB is telling you what's the value of every byte of
this union according to the interpretation each field's type.  `uint8_t'
is actually `unsigned char' on most architectures, so it is treating the
`__u6_addr8' field as an array of characters.

If you use pretty-printing, you will see things more organized.  Try
`set print pretty on', and print the struct again.  Then you will
understand that the output is actually something like:

    __in6_u = {
      __u6_addr8 = "325243A2", '\000' <repeats 11 times>,
      __u6_addr16 = {41941, 12865, 0, 0, 0, 0, 0, 0},
      __u6_addr32 = {843162581, 0, 0, 0}
    }

I.e., the `'\000' <repeats 11 times>' part refers to the first field,
and is not a second-field-without-a-name as you guessed.

In short: if you want GDB to stop printing the '\000' part, try using
`set print null-stop on'.

-- 
Sergio


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]