【发布时间】:2015-06-18 08:54:50
【问题描述】:
我需要print addresses of all local variables in C,为此我正在尝试使用 GDB 脚本。
我正在使用以下 gdb 脚本。首先,我在 main 处设置断点,一旦遇到,我在下一行设置断点,然后在程序的每一行 step 进入它。
甚至可以使用 next 代替 step 执行到下一行。但是我需要使用 step 来进入函数,因为 next 不会这样做。
b main
commands 1
while 1
info locals //some code needed to print addresses
b
step
end
end
run
但是,“step”命令也可以进入库函数。有没有办法有条件地运行“step”命令,使其不会进入库函数?我将有一个程序中使用的函数和变量的列表,因为它由我的GCC Plugin 返回。我可以使用 if 语句,仅在遇到用户定义的函数时执行 step,否则执行 next?
commands 1
while 1
info locals
b
if //function name belongs to a predefined set
step
else
next
end
end
end
我想了解有关 GDB 脚本语言的更多信息,但找不到足够的资料。我还需要知道我们是否可以声明数组、字符串并对其进行比较和其他操作。
【问题讨论】:
-
skip命令可以做你想做的事。 Skipping over functions and files
标签: c debugging scripting gdb memory-address