2013-05-03 167 views
0

因此,最近我一直在做大量的彙編工作,並且我發現它不得不繼續輸入x/d $ eax,x/d $ ecx,x/t ...等上。我編輯我的.gdbinit有:GDB腳本問題

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* 

有沒有辦法告訴腳本繼續,即便是無法顯示的格式?

回答

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