This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: unexpected output from print
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: Markus Teich <markus dot teich at stusta dot mhn dot de>
- Cc: <gdb at sourceware dot org>
- Date: Mon, 25 Mar 2013 22:09:13 -0300
- Subject: Re: unexpected output from print
- References: <4dbff288e0c76a516273ba1cb19694b4 at mail dot fs dot tum dot de>
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