2012-07-30 57 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" 

希望有所帮助。