python interface gdb.execute() to_string is useless

Emiliano Testa
Wed Jul 1 12:26:39 GMT 2020


I'm using the gdb APIs to implement a command and I want to control when 
the output of a certain command is sent to the console.

To this end I'm using

s = gdb.execute(cmd, to_string=True)

unfortunately it doesn't seem to do what is says it would:

I can see s is not None when to_string=True BUT it doesn't contain the 
output that it should. It went to the console instead.

I think this is a bug.

Many thanks


The output I get (gdb version is "GNU gdb (Ubuntu 8.1-0ubuntu3.2)"):

(gdb) python
 >print ("Before")
 >s = gdb.execute("continue", to_string=True)
 >print ("After")
 >print (s)
loop_then_segv.c: i=0
loop_then_segv.c: i=1
loop_then_segv.c: i=2
loop_then_segv.c: i=3
loop_then_segv.c: i=4
loop_then_segv.c: i=5
loop_then_segv.c: i=6
loop_then_segv.c: i=7
loop_then_segv.c: i=8
loop_then_segv.c: i=9
causing deliberate segv pid=11290.

Program received signal SIGSEGV, Segmentation fault.
0x0804855c in main () at tests/test/generic/loop_then_segv.c:26
26          *(volatile int*)NULL = 0;

(gdb) python
 >print ("Before")
 >s = gdb.execute("continue", to_string=False)
 >print ("After")
 >print (s)

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.


Emiliano Testa | Software Engineer | Direct: (+44)7512468305 |

Undo <> | Accelerate software defect resolution by 
eliminating the guesswork in failure diagnosis

CI Best Practice: Go Green, Stay Green 

More information about the Gdb mailing list