tags:

views:

333

answers:

2

Sometimes,I would need to get the gdb output.In the shell,I could use script command to extract text.Whats the equivalent in gdb?

ps: I tried shell script,but after hitted return, I was in the shell and lost the shell prompt and could not run command any more,moreover I could not use ctrl+c or ctrl+\ to exit.I'll need to force kill the /bin/login tty2 to exit!

thanks.

A: 

Have a look at the GDB documentation. Search for "Canned Sequences of Commands". There is a way to save GDB commands in a file and run them with the source command and you can use some GDB commands in these scripts to print information available to GDB (like echo, output and printf).

If you want that output in a file, use set logging file FILE.

Aaron Digulla
+2  A: 

If you want to log GDB's output, you can use the GDB logging output commands, eg.

set logging file mylog.txt
set logging on

If you want to redirect your program's output to a file, you can use a redirect, eg.

run myprog > mylog.txt

see the chapter on program IO in the GDB manual for more information

Hasturkun
the link is broken and it should be http://sourceware.org/gdb/current/onlinedocs/gdb/Logging-Output.html#Logging-Output.
Jichao