2012-07-30 20 views

回答

1

我假設你想要運行的宏是一個gdb宏。爲了解決這個問題,我建議你在gdb中使用Python支持來包含這個。把下面的forallindir.py

import gdb 
import os 

class ForAllInDir (gdb.Command): 
    "Executes a gdb-macro for all files in a directory." 

def __init__ (self): 
    super (ForAllInDir, self).__init__ ("forallindir", 
             gdb.COMMAND_SUPPORT, 
             gdb.COMPLETE_NONE, True) 

def invoke(self, arg, from_tty): 
    arg_list = gdb.string_to_argv(arg) 
    path = arg_list[0] 
    macro = arg_list[1] 
    for filename in os.listdir(path): 
    gdb.execute(macro + ' ' + os.path.join(path, filename)) 

ForAllInDir() 

然後在gdb來source forallindir.py,它應該工作。例如,定義一個宏進行測試,像

define testit 
    print "i got called with $arg0" 
end 

forallindir /tmp/xx testit與在該目錄中的兩個樣本文件會給我們

$1 = "i got called with /tmp/xx/ape" 
$2 = "i got called with /tmp/xx/bear" 

希望有所幫助。

相關問題