user1661781
user1661781

Reputation: 327

How to generate all backtraces of a function using gdb?

I have a function that I am trying to examine. I want to find all callers of this function, but there are a few issues:

There is a stack trace of 10+ function calls until you get to actual code that is not in the STL that caused this function to be invoked. But those STL entry points vary, as it is a compare function and calls for is_equal go through a different sequence than those that go through not_equal, etc. I will need to do this for at least 10+ different functions, and I want to streamline this as much as possible.

I want a tool that can dump each unique, full backtrace each time the function is called. Does anybody know a tool that can do this?

I am using gdb and c++ on Ubuntu 14.04.

Upvotes: 0

Views: 866

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54455

You can make gdb execute a series of commands each time a given breakpoint is executed, e.g.,

break someFunction
commands
bt
continue
end

The feature is mentioned in gdb scripting: execute commands at selected breakpoint, which has a link to the online documentation for gdb 5.1.7 Breakpoint Command Lists

Upvotes: 2

Related Questions