I am looking for a way to access results from gdb from python. I need to debug a c program using gdb and access the results from python. It is like calling gdb from python to debug c program.
Asked
Active
Viewed 462 times
2 Answers
0
Use subprocess to call gdb
on the compiled binary (e.g. a.out
):
import subprocess
# if you have arguments to gdb, you can supply then in the list itself.
proc = subprocess.Popen(['gdb', 'a.out'],
stdin=subprocess.PIPE,
)
proc.communicate('\tGDB Output:\n')
Reference:

jrd1
- 10,358
- 4
- 34
- 51
0
I think you should invert the problem and instead add support what you need by extending gdb: https://sourceware.org/gdb/onlinedocs/gdb/Extending-GDB.html. When python runs within gdb it has access to gdb API. See How to import 'GDB' in python for some extra details.