Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* unexpected output from print
@ 2013-03-23 10:01 Markus Teich
  2013-03-26 18:12 ` Tom Tromey
       [not found] ` <m3sj3jvufa.fsf@redhat.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Markus Teich @ 2013-03-23 10:01 UTC (permalink / raw)
  To: gdb

Hi,

i am trying to parse the output of the print command on structs and 
arrays.
To distinguish between this two possibilities i look at the first 
element. If it contains a '=' (not in parantheses) i interpret the 
output as struct, else i interpret it as array.

Example:
{a = 'b', c = 5, d = 0x123456}
would be a struct.

{"this = does not confuse me", "hello", "world"}
would be an array.

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}}

So i interpreted the __in6_u as struct but my parser noticed the 
missing name of the second element and returned NULL as expected.
I looked up the declaration of the struct in netinet/in.h and found 
there is a union in this struct:

struct in6_addr
{
   union
   {
     uint8_t __u6_addr8[16];
     #if defined __USE_MISC || defined __USE_GNU
     uint16_t __u6_addr16[8];
     uint32_t __u6_addr32[4];
     #endif
   } __in6_u;
   #define s6_addr         __in6_u.__u6_addr8
   #if defined __USE_MISC || defined __USE_GNU
   # define s6_addr16      __in6_u.__u6_addr16
   # define s6_addr32      __in6_u.__u6_addr32
   #endif¬
};

However i could not figure out the meaning of this unexpected result.
what does this single element
'\000' <repeats 11 times>
in the output tell me?

I am using
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04

Thanks for any hints.

Regards
Markus


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unexpected output from print
  2013-03-23 10:01 unexpected output from print Markus Teich
@ 2013-03-26 18:12 ` Tom Tromey
       [not found] ` <m3sj3jvufa.fsf@redhat.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2013-03-26 18:12 UTC (permalink / raw)
  To: Markus Teich; +Cc: gdb

>>>>> "Markus" == Markus Teich <markus.teich@stusta.mhn.de> writes:

Markus> i am trying to parse the output of the print command on structs and
Markus> arrays.

In addition to what Sergio said, it is better to use MI than to try to
parse gdb's output.

Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unexpected output from print
       [not found] ` <m3sj3jvufa.fsf@redhat.com>
@ 2013-03-26 22:30   ` Markus Teich
  2013-03-27 13:31     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Teich @ 2013-03-26 22:30 UTC (permalink / raw)
  To: gdb

Thanks,

that helped a lot.
@Tom: I am already using the machine interface, but unfortunately the
functions for symbol querying are not implemented in gdbmi (the C
library), therefore i parse the output of -data-evaluate-expression
manually.
Since gdbmi is not developed actively anymore: Is there a better way to
use the gdb machine interface from a C program?

--Markus


Am 26.03.2013 02:09, schrieb Sergio Durigan Junior:
> 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'.
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unexpected output from print
  2013-03-26 22:30   ` Markus Teich
@ 2013-03-27 13:31     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2013-03-27 13:31 UTC (permalink / raw)
  To: Markus Teich; +Cc: gdb

>>>>> "Markus" == Markus Teich <markus.teich@stusta.mhn.de> writes:

Markus> @Tom: I am already using the machine interface, but unfortunately the
Markus> functions for symbol querying are not implemented in gdbmi (the C
Markus> library), therefore i parse the output of -data-evaluate-expression
Markus> manually.

You can create a temporary varobj for this.
Or maybe I am misunderstanding.

Markus> Since gdbmi is not developed actively anymore: Is there a better way to
Markus> use the gdb machine interface from a C program?

Enhancements are made from time to time.  You can speed this along by
writing them yourself... :-)
There's also Python, for some things.

Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-27 13:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-23 10:01 unexpected output from print Markus Teich
2013-03-26 18:12 ` Tom Tromey
     [not found] ` <m3sj3jvufa.fsf@redhat.com>
2013-03-26 22:30   ` Markus Teich
2013-03-27 13:31     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox