I have this script of GDB commands:
$ 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
If I run it in GDB I get this:
$ 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]
So there is that ugly dollar sign thing. I can sed
it out, but I would like to have GDB to do that. Is it possible?
(The reason I'm use GDB like this is because we are writing an emulator and want to test if it behaves correctly.)
ugly dollar sign thing ... I would like to have gdb to do that
You can control GDB's output precisely with printf
command:
(gdb) print/x $rax
$1 = 0x7ffff7ffe2a0
(gdb) printf "0x%lx\n", $rax
0x7ffff7ffe2a0
There is a command that does exactly that:
(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
prints the variables without the $1 =
and the newline.
User contributions licensed under CC BY-SA 3.0