I need to print addresses of all local variables in C, and for that I am trying to use a GDB script.
I am using the following gdb script. First I set a breakpoint at main, and once that is encountered, I set a breakpoint at the next line and then step into it at each line of the program.
Even next can be used instead of step to execute till the next line. But I need to use step to step into functions as next does not do that.
b main
commands 1
while 1
info locals //some code needed to print addresses
b
step
end
end
run
However, the command "step", steps into library functions too. Is there a way to run "step" command conditionally such that it does not step into library functions? I will have a list of functions and variables used in the program as it is returned by my GCC Plugin. Can I use an if statement which executes step only if a user defined function is encountered, and next otherwise?
commands 1
while 1
info locals
b
if //function name belongs to a predefined set
step
else
next
end
end
end
I want to learn more about the GDB Scripting Language but I am not able to find sufficient material about it. I also need to know if we can declare arrays,strings and perform comparisons and other operations on them.
As you have a list of function names you have declared, in the start of script add breakpoint on each function in your list, now run it, and after each break run your logic to print addresses, then continue.
For example:
prog:
gdb transcript: