5

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 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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!
@mayasky: It should be possible to directly convert the address to some ctypes or NumPy array, but I don't know exactly how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.