所以,我最近做了大量的装配工作,我发现不得不继续输入x / d $ eax,x / d $ ecx,x / t ......等等。我编辑了我的.gdbinit:
define showall
printf "Value:\n"
print $arg0
printf "Hex:\n"
x/x $arg0
printf "Decimal:\n"
x/d $arg0
print "Character:\n"
x/c $arg0
... and so on.
我遇到的问题是,当打印x / d或其他格式失败时,脚本将停止并且不会执行其余的语句以显示其他格式(如果能够这样做)。
问题的一个例子:
gdb someFile
showall $eax
...
:Value can't be converted to an integer.
*stops and doesn't continue to display x/c*
有没有办法告诉脚本继续,即使它无法显示格式?
答案 0 :(得分:2)
我认为没有办法让GDB命令文件解释不会在第一个错误时停止,但您可以使用Python脚本来执行您想要的操作。
将其保存到 examine-all-formats.py :
def examine_all(v):
gdb.write('Value:\n%s\n' % v)
try:
v0 = int(v)
except ValueError:
pass
else:
gdb.write('Hex:\n0x%x\n'
'Decimal:\n%d\n'
% (v0, v0))
try:
c = chr(v)
except ValueError:
pass
else:
gdb.write('Character:\n'
'%r\n' % (c,))
class ExamineAll(gdb.Command):
def __init__(self):
super(ExamineAll, self).__init__('examine-all', gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL)
def invoke(self, args, from_tty):
for i in gdb.string_to_argv(args):
examine_all(gdb.parse_and_eval(i))
ExamineAll()
然后运行:
$ gdb -q -x examine-all-formats.py
(gdb) file /bin/true
Reading symbols from /usr/bin/true...Reading symbols from /usr/lib/debug/usr/bin/true.debug...done.
done.
(gdb) start
Temporary breakpoint 1 at 0x4014c0: file true.c, line 59.
Starting program: /usr/bin/true
(gdb) examine-all argc
Value:
1
Hex:
0x1
Decimal:
1
Character:
'\x01'
(gdb) examine-all $eax
Value:
1532708112
Hex:
0x5b5b4510
Decimal:
1532708112