and I would like to know if there is any way to stop a program when is using a function from a certain file. Ideally what I am looking for is something like:
Step 1: construct a list of all functions defined in foo.cpp
The simplest way I can think of (assuming you have binutils
and GNU grep
):
nm a.out | grep ' T ' | addr2line -fe a.out |
grep -B1 'foo\.cpp' | grep -v 'foo\.cpp' > funclist
Step 2: construct a GDB script which will set a break point on each of the above functions:
sed 's/^/break /' funclist > stop-in-foo.gdb
[Obviously, steps 1 and 2 could be combined ;-]
Step 3: actually set the breakpoints:
gdb a.out
(gdb) source stop-in-foo.gdb
Looking at this answer, an even simpler (if you are on Fedora Linux) way to find out which foo.cpp functions are called:
ftrace -sym='foo.cpp#*' ./a.out
Too bad ftrace man page says this isn't implemented yet.