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

I am currently writing a Python GDB script. The problem is that it must be compatible with GDB 7.1. Therefore, I first wrote a script for GDB 7.3.1 and used the following function to get the output of the 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 sense, why else should I execute such a command;))

In GDB version 7.1, although it seems that the last parameter is unavailable , so this line (GDB 7.1):

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

returns None .

Is there a chance to get the result of this team? I already tried to redirect the standard output of my python script to a file and then load this file, but apparently the standard input and output of my python script was overwritten by the gdb environment , so the output from the gdb.execute command is not written to my file.

The only thing I could think of was to wrap my script with a bash script, which first opens gdb with a python script that executes various commands and then transfers this to a file. Then open gdb again, but with a different python script that downloads the file, parses it, and then executes other commands based on input from the file and so on. But this is really the ugliest decision I can think of.

So, is there a way to get gdb.execute output in GDB 7.1?

+6
source share
2 answers

So, is there a way to get gdb.execute output in GDB 7.1?

Not.

It’s best to organize GDB-7.3. Since GDB usually does not use shared libraries (other than libc and possibly libpython), you can simply copy the gdb binary with a script. It will be much easier and more convenient than the alternative you are proposing.

+5
source

You can write to a file, then read the file, for example:

 os.system("rm tmp.txt") gdb.execute("set logging file tmp.txt") gdb.execute("set logging on") mainsec=gdb.execute("info proc mappings") gdb.execute("set logging off") mainsec = open("tmp.txt").read() 

The old version of gdb.execute was much higher.

+2
source

Source: https://habr.com/ru/post/906754/


All Articles