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

Cal*_*ius 2 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
Run Code Online (Sandbox Code Playgroud)

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

$ 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]
Run Code Online (Sandbox Code Playgroud)

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

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

Emp*_*ian 6

丑陋的美元符号的东西......我想让gdb这样做

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

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

(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0
Run Code Online (Sandbox Code Playgroud)