container_of equivalent in gdb-python script

Jan Kiszka jan.kiszka@web.de
Wed Jun 10 22:13:00 GMT 2009


Tom Tromey wrote:
>>>>>> "Jan" == Jan Kiszka <jan.kiszka@web.de> writes:
> 
> Daniel> It's typical to do this the same way folks do in C: Create a null
> Daniel> pointer of the right type.
> 
> Jan> You can't do that with the current upstream python interface, but the
> Jan> parse_and_eval solves this nicely.
> 
> Actually, for constants you can:
> 
> (gdb) python print gdb.Value(0)
> 0
> (gdb) python print type(gdb.Value(0))
> <type 'gdb.Value'>
> (gdb) python print gdb.Value(0).cast(gdb.lookup_type('char').pointer())
> 0x0

Yeah, seen this (in the testsuite). But such objects neither have
addresses, nor do they help with non-constant objects I'm interested in.

> 
> Whoops, this seems to be undocumented.

Not the only piece... :)

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/gdb/attachments/20090610/1b2fa27a/attachment.sig>


More information about the Gdb mailing list