Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include GDB commands in logging file?

Tags:

logging

gdb

I have some gdb commands in a file that I want to execute. I also want the commands run and the output to be logged to a file.

I wrote the following gdb script in a file named gdb.in.

set logging file gdb.out
set logging on
echo hi\n
printf "bye\n"
quit

However, if I execute this gdb script, I can only see the output logged to gdb.out. I don't see the commands executed.

$ gdb -x gdb.in
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
hi
bye
$ cat gdb.out
hi
bye

As far as I can remember, a few years ago, I found a way to log the commands. Each command used to appear in the log file with a +-sign as a prefix. For example, I was able to get an output like this a few years ago.

+ echo hi\n
hi
+ printf "bye\n"
bye
+ quit

But I am unable to recall what I did to get such an output. Searching the web also didn't help me. I came across this question at How to dump the entire GDB session to a file, including commands I type and their output? but the answers there don't capture the commands executed in the log file.

like image 365
Lone Learner Avatar asked May 30 '16 16:05

Lone Learner


2 Answers

set trace-commands on: echos the command in screen before executing it. Use this along with logging to get the command written to file.

like image 151
prasannatsm Avatar answered Nov 14 '22 09:11

prasannatsm


This is the subject of GDB feature request, which is at least 12 years old :-(

There is currently no way to achieve this. You may use script to record the entire GDB session, but that has a distinct disadvantage of also recording various screen control "garbage" characters.

like image 20
Employed Russian Avatar answered Nov 14 '22 08:11

Employed Russian