0

所以,我最近一直在做很多组装工作,我发现不得不继续输入 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*

有没有办法告诉脚本继续,即使它无法显示格式?

4

1 回答 1

2

我认为没有办法让 GDB 命令文件解释不会在第一个错误时停止,但您可以使用 Python 脚本来执行您想要的操作。

将此保存到检查所有格式.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
于 2013-05-04T02:17:44.943 回答