如何在日志文件中包含GDB命令? [英] How to include GDB commands in logging file?

查看:147
本文介绍了如何在日志文件中包含GDB命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行的文件中有一些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.

我在名为gdb.in的文件中编写了以下gdb脚本.

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

但是,如果执行此gdb脚本,则只能看到记录到gdb.out的输出.我看不到执行的命令.

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

但是我无法回忆起我为获得这样的输出所做的事情.搜索网络也无济于事.我在如何将整个GDB会话转储到文件中(包括我键入的命令及其输出)遇到了这个问题?那里的答案不能捕获在日志文件中执行的命令.

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.

推荐答案

set trace-commands on:在执行命令之前先回显屏幕中的命令.将此与日志一起使用,以将命令写入文件.

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

这篇关于如何在日志文件中包含GDB命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆