如何仅打印GDB中变量的值?
我有以下GDB命令脚本:如何仅打印GDB中变量的值?,gdb,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 THI
$ 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
out,但我想让GDB来做这件事。可能吗
(我之所以这样使用GDB,是因为我们正在编写一个模拟器,并希望测试它的行为是否正确。)
丑陋的美元符号。。。我希望gdb能做到这一点
您可以使用printf
命令精确控制GDB的输出:
(gdb) print/x $rax
$1 = 0x7ffff7ffe2a0
(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0
有一个命令正好执行以下操作:
(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=
和换行符的变量