0

I have a long C function that can return at different lines. Is it possible to have GDB run through the function and print out on what line the function returned? So far I have been going through one line at a time (using n), and this is becoming tedious.

Can I dynamically call a function with GDB and know on which line it returned?

Randomblue
  • 112,777
  • 145
  • 353
  • 547
  • Try adding breakpoints on all return statements. I usually try to follow the one return statement per function rule exactly for the purpose of debugging issues like the one you describe. – Ivaylo Strandjev Apr 30 '12 at 10:10
  • Exact duplicate of this: http://stackoverflow.com/questions/3649468/setting-breakpoint-in-gdb-where-the-function-returns and that question has a good answer: http://stackoverflow.com/a/3649698/16509 – jjrv Apr 30 '12 at 10:11
  • @jjrv: Thanks, but I don't have `reverse-step` since I'm working with an embedded device. – Randomblue Apr 30 '12 at 10:24

1 Answers1

3

One nasty trick if you're compiling with GCC and can edit the code would be to do a macro and search+replace all the returns in your editor...

int global_return_lineno;
#define return2(x) {global_return_lineno=__LINE__;return(x);}

Then call the function and inspect the global variable.

jjrv
  • 4,211
  • 2
  • 40
  • 54