如何只在gdb中打印变量的值?

时间:2013-09-04 17:04:25

标签: gdb

所以我有这个gdb命令的脚本:

$ cat gdb_commands.txt
set pagination off
set logging file output.txt
set logging on
file stuff
b *0x80000014
run
echo ***DIFF THIS***\n
echo eax:  
print $eax
echo ebx:
print $ebx
echo ecx:
print $ecx
echo edx:
print $edx
echo ***DIFF THIS END***\n
quit

如果我运行它,我得到这个:

$ gdb -q -x gdb_commands.txt 
Breakpoint 1 at 0x80000014

Breakpoint 1, 0x80000014 in _start ()
***DIFF THIS***
eax:$1 = 1
ebx:$2 = 2
ecx:$3 = 3
edx:$4 = 4
***DIFF THIS END***
A debugging session is active.

    Inferior 1 [process 8947] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]

所以有一个丑陋的美元符号的东西。我可以sed它,但我想让gdb这样做。有可能吗?

(我之所以使用gdb是因为我们正在编写模拟器,并且想测试它是否正常运行。)

2 个答案:

答案 0 :(得分:6)

  丑陋的美元符号......我想让gdb做到这一点

您可以使用printf命令精确控制GDB的输出:

(gdb) print/x $rax
$1 = 0x7ffff7ffe2a0

(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0

答案 1 :(得分:0)

有一个命令可以做到这一点:

(gdb) help output
Like "print" but don't put in value history and don't print newline.
This is useful in user-defined commands.

output显示不包含$1 = 和换行符的变量。

相关问题