我有这个 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 中运行它,我会得到:
$ 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 的原因是因为我们正在编写一个模拟器并想测试它是否运行正常。)
最佳答案
ugly dollar sign thing ... I would like to have gdb to do that
您可以使用printf
命令精确控制GDB的输出:
(gdb) print/x $rax
$1 = 0x7ffff7ffe2a0
(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0
关于gdb - 如何在 GDB 中只打印变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18619818/