This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Converting function pointers to PC values in Python (was: [patch] Add libstdc++ type printers for class templates)
- From: Samuel Bronson <naesten at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>, gdb at sourceware dot org
- Cc: Tom Tromey <tromey at redhat dot com>, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, pmuldoon at redhat dot com
- Date: Tue, 05 Aug 2014 02:23:06 -0400
- Subject: Converting function pointers to PC values in Python (was: [patch] Add libstdc++ type printers for class templates)
- Authentication-results: sourceware.org; auth=none
- References: <20140714142159 dot GF4871 at redhat dot com> <20140714192206 dot GG4871 at redhat dot com> <87y4vv1z0s dot fsf at fleche dot redhat dot com> <20140714235047 dot GK4871 at redhat dot com>
Jonathan Wakely <jwakely@redhat.com> writes:
> One part of the patch I wasn't sure about was this, where 'mgr' is a
> function pointer:
>
> func = gdb.block_for_pc(int(mgr.cast(gdb.lookup_type('intptr_t'))))
>
> Is there a better way to get a pc from the function pointer?
> I tried simply int(mgr) but it didn't work.
Well, long() WFM; e.g. with Python 2 and gdb 7.8.50.20140706-cvs I can do:
(gdb) python print(long(gdb.parse_and_eval("(void(*)())-1")))
4294967295
The fact that int() does not work the same way may indicate a
shortcoming in gdb.Value.__int__(); I'm told that in recent 2.x
versions, int() is perfectly happy returning a long instead of an int.
Of course, this still presumably won't work on architectures where
function pointers don't point straight to the code, e.g. most PowerPC,
where as I understand things it actually points at a "function
descriptor", which in turn references the actual code.
So it seems we're missing an API for this.
--
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!