我想创建一个宏,为其提供目录路径。宏还必须为目录中的所有文件运行另一个宏。这可能在gdb中吗?
答案 0 :(得分: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"
希望有所帮助。