Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get output from gdb.execute in PythonGDB (GDB 7.1)?

I'm currently writing a Python GDB script. The problem is that it has to be compatible with GDB 7.1. So I first wrote the script for GDB 7.3.1 and used the following function to receive the output of an gdb command (GDB 7.3.1):

myvar = gdb.execute("info target", False, True)

The last parameter of this function is that it should return the result as a string (which makes perfectly sense; why else would I execute such a command ;) )

In GDB Version 7.1 though it seems that the last parameter isn't available thus this line(GDB 7.1):

myvar = gdb.execute("info target", False)

returns None.

Is there any chance to retrieve the output of this command? I already tried to redirect the standard output of my python script into a file, then loading this file but apparently the standard input and output of my python script is overwritten by the gdb environment so the output from the gdb.execute command is not be written to my file.

The only thing I could think of now is to wrap my script up with a bash script that first opens gdb with a python script that executes various commands and then pipe that into a file. Then open gdb again but with another python script that loads the file, parses it and then executes other commands based on the input from the file and so on. But this is a really the ugliest solution I can think of.

So is there a way to receive the output of an gdb.execute in GDB 7.1?

like image 532
Uhlo Avatar asked Jan 24 '12 12:01

Uhlo


1 Answers

So is there a way to receive the output of an gdb.execute in GDB 7.1?

No.

Your best bet is to arrange for GDB-7.3 to be available. Since GDB doesn't usually use shared libraries (beyond libc and perhaps libpython), you can just copy gdb binary with your script. That will be much easier and more maintainable solution than the alternative you proposed.

like image 118
Employed Russian Avatar answered Nov 10 '22 23:11

Employed Russian