Discussion:
Converting function pointers to PC values in Python (was: [patch] Add libstdc++ type printers for class templates)
(too old to reply)
Samuel Bronson
2014-08-05 06:23:06 UTC
Permalink
Raw Message
One part of the patch I wasn't sure about was this, where 'mgr' is a
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!
Loading...