我要执行的文件中有一些 gdb 命令。我还希望运行命令并将输出记录到文件中。
我在名为 .gdb 的文件中编写了以下 gdb 脚本gdb.in。
set logging file gdb.out
set logging on
echo hi\n
printf "bye\n"
quit
Run Code Online (Sandbox Code Playgroud)
但是,如果我执行这个 gdb 脚本,我只能看到输出记录到gdb.out. 我没有看到执行的命令。
$ 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
Run Code Online (Sandbox Code Playgroud)
据我所知,几年前,我找到了一种记录命令的方法。每个命令过去都以 - 符号+作为前缀出现在日志文件中。例如,几年前我能够得到这样的输出。
+ echo hi\n
hi
+ printf "bye\n"
bye
+ quit
Run Code Online (Sandbox Code Playgroud)
但我不记得我做了什么来获得这样的输出。搜索网络也没有帮助我。我在如何将整个 GDB 会话转储到文件,包括我键入的命令及其输出?但是那里的答案没有捕获日志文件中执行的命令。
我不知道它是什么时候引入的,但@prasannatsm 在这里提出了解决方案): set trace-commands on。
我想补充一下并展示完整的过程。以下是我现在开始记录的方式:
set logging file ~/temp/gdb.txt
set logging on
set trace-commands on
show logging
flush
Run Code Online (Sandbox Code Playgroud)
show logging最后只是验证一切都在记录并按预期工作。
请注意,这set trace-commands on会导致您输入的每个命令现在都会回显给您(如果日志记录已打开,也会被记录),并在其+前面显示它是回显的命令输入,而不是响应。
这可以在此处的输出中看到,例如:
Run Code Online (Sandbox Code Playgroud)+show logging Currently logging to "/home/gabriel.staples/temp/gdb.txt". Logs will be appended to the log file. Output will be logged and displayed. +flush Register cache flushed.
我已经在我的git 和 Linux cmd、帮助、提示和技巧 - eRCaGuy_dotfiles存储库中的 Gabriel.txt 文件中写下了上面的 gdb 日志记录注释。在该文档中搜索“GDB LOGGING”。
| 归档时间: |
|
| 查看次数: |
1081 次 |
| 最近记录: |