3

我有这个 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 的原因是因为我们正在编写一个模拟器并想测试它是否行为正确。)

4

2 回答 2

9

丑陋的美元符号……我想让 gdb 来做那件事

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

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

(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0
于 2013-09-05T04:28:37.433 回答
1

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

(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打印不带 the$1 = 和换行符的变量。

于 2020-10-30T03:25:35.383 回答