From: Daniel Jacobowitz <drow@false.org>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: tromey@redhat.com, gdb@sourceware.org
Subject: Re: container_of equivalent in gdb-python script
Date: Wed, 10 Jun 2009 20:42:00 -0000 [thread overview]
Message-ID: <20090610204201.GA17154@caradoc.them.org> (raw)
In-Reply-To: <4A30133F.9000909@web.de>
On Wed, Jun 10, 2009 at 10:10:39PM +0200, Jan Kiszka wrote:
> I want to automate 'add-symbol-file linux_module.ko 0xff...' that you
> have to run for loading the symbols of dynamically loaded kernel
> modules. Before that you also have to look up the module base address,
> typically by cat'ing /proc/modules on the target. With a proper python
> script, this will be trivial to do automatically. You just have to walk
> the module list of the kernel you are attached to, extract names and
> base addresses, search for the corresponding module binaries (also easy
> with python) and issue the proper add-symbol-file commands.
FYI, I am hoping to work on this soon (in the next month). The right
representation is not a set of add-symbol-file commands, which doesn't
play nicely with repeated unload/reload, but instead a synthetic list
of shared libraries. That calls for some extensions to the current
set of Python hooks and shared library infrastructure, though! And it
will require basically everything you're doing now :-)
> But now back to the core problems, starting with the exercise to
> implement offset_of(type, field):
>
> def offset_of(type, field):
> container_type = gdb.lookup_type(type)
> dummy_obj = gdb.selected_frame().read_var('modules')
> container_obj = dummy_obj.cast(container_type)
> field_obj = container_obj[field]
> return int(str(field_obj.address), 16) - \
> int(str(container_obj.address), 16)
>
> I meanwhile discovered (reading testcases and python-*.c)
> gdb.lookup_type() and Value.cast() to make this real. But you see, I
> still need an ugly synthetic Value object which must have a non-'None'
> address to do this calculation. Is there a cleaner, more generic way?
It's typical to do this the same way folks do in C: Create a null
pointer of the right type.
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2009-06-10 20:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-10 16:56 Jan Kiszka
2009-06-10 18:57 ` Tom Tromey
2009-06-10 20:10 ` Jan Kiszka
2009-06-10 20:37 ` Tom Tromey
2009-06-10 21:06 ` Jan Kiszka
2009-06-10 20:42 ` Daniel Jacobowitz [this message]
2009-06-10 21:33 ` Jan Kiszka
2009-06-10 21:42 ` Tom Tromey
2009-06-10 22:13 ` Jan Kiszka
2009-06-10 22:17 ` Tom Tromey
2009-06-11 9:51 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090610204201.GA17154@caradoc.them.org \
--to=drow@false.org \
--cc=gdb@sourceware.org \
--cc=jan.kiszka@web.de \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox