-1

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.

user567879
  • 5,139
  • 20
  • 71
  • 105

2 Answers2

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:

http://pymotw.com/2/subprocess/

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.

Community
  • 1
  • 1
peter
  • 84
  • 2