3

I have a system developed in C++ on Linux platform. I am doing some debugging of this system. I want to look for the complete sequence of function calls to a function. Lets assume the functions are called in the following sequence

function_1 -> function_2 -> function_3 -> function_4

If I put a break point at function_4, the execution will be holded at that point. I want to see that functions_1, function_2 and function_3 are called before function_4. If there any gdb command to trace these function calls?

Thanks, Ankur

3
  • Does function_1 get called and then return - or does function_1 call function_2() et al Commented Feb 8, 2012 at 4:39
  • RTFM: it's something like "bt" or "st" (back trace or stack trace). Commented Feb 8, 2012 at 4:39
  • 1
    bt gets the backtrace, but it relies on the stack frame, so unless all those function calls are nested (1 calls 2 calls 3 calls 4), that's not going to work for you. Commented Feb 8, 2012 at 4:41

3 Answers 3

8

You want a backtrace. The gdb command bt will show exactly what you are interested in.

Sign up to request clarification or add additional context in comments.

3 Comments

bt utility is not available on the Linux server. Is that not possible to find function calls using gdb?
Also, to examine call-stack use the command "frame" or f. More info here : ofb.net/gnu/gdb/gdb_43.html#SEC43
Thanks buddy, bt works. This is exactly I was looking for. Thanks.
2

bt: backtrace http://sourceware.org/gdb/onlinedocs/gdb/Backtrace.html

Comments

1

If function_1() calls function_2() which calls function_3() etc

You can set your breakpoint in function_4() and you use the command

where

To print a backtrace of the stack

Another tool that may be useful is valgrind with the callgrind tool

1 Comment

Thanks Adrian, this works. It is exactly similar to bt. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.