Recently I came across with surprise the the current version of GDB support python scrippting, which very likely means I can plot variables while debugging the program -- something I dreamed about a long time ago. However, I quickly get stuck because I can't get a variable's value "out of" GDB and assign it to a python variable. The method should be inside the gdb module, but I don't know which function to call. Anybody knows? Tell me please :) Thank you!
1 Answer
To access the variable x in the currently selected gdb frame, you can use
x = gdb.selected_frame().read_var("x")
This will assign a gdb.Value instance to x.
2 Comments
mayasky
Thank you! Your answer is very helpful, and the link is informative. Just another question: I have a Fortran array assigned to a python variable "x" in this way, and I'd like to convert this gdb.Value type to a python list -- I have to do this element by element, right ? Because there doesn't seem to be a single function to achieve this. Thanks!
Sven Marnach
@mayasky: It should be possible to directly convert the address to some
ctypes or NumPy array, but I don't know exactly how.