How to convert a gdb Value to a python numeral object while debugging C program -
i'm using python2.6's gdb module while debugging c program, , convert gdb.value instance python numeral object (variable) based off instance's '.type'.
e.g. turn c program's somestruct->some_float_val = 1./6;
python gdb.value via sfv=gdb.parse_and_eval('somestruct->some_double_val')
, turn double precision floating point python variable -- knowing str(sfv.type.strip_typedefs())=='double'
, size 8b -- without converting through string using dbl=float(str(sfv))
or value.string()
rather unpacking bytes using struct
correct double value.
every link returned searches points https://sourceware.org/gdb/onlinedocs/gdb/values-from-inferior.html#values-from-inferior, can't see how convert value instance python variable cleanly, value wasn't in c memory represented gdb.value.address (so can't use inferior.read_memory()
), how 1 turn python int without casting string values?
you can convert directly value
using int
or float
:
(gdb) python print int(gdb.value(0)) 0 (gdb) python print float(gdb.value(0.0)) 0.0
there seems @ least 1 glitch in system, though, float(gdb.value(0))
not work.
Comments
Post a Comment