Sandeep Singh
Sandeep Singh

Reputation: 5181

How To Stop at the End of a Function (Without Exiting it) In GDB?

Please consider the following Code:

main()
{
    ....
    retval = func();
}

Suppose I put a breakpoint on a given function:

gdb$ b func

Now, this breakpoint gets hit & I do 'finish' in function func():

gdb$ fin

My Problem is:

Doing 'finish' brings me back to main(), here:

retval = func();

I want to stop at the END of func() without Exiting func().

Can somebody please suggest some generic way (independent of the no. of lines of code in func()) to achieve this?

Thanks.

Upvotes: 8

Views: 1635

Answers (2)

Karol Dabrowski
Karol Dabrowski

Reputation: 1

You can type two commands 's' and 'finish'.

s - step in to func() function

finish - finish function and go back to the outside func(). In this case to the main()

Upvotes: -1

Tom Tromey
Tom Tromey

Reputation: 22519

There is no way to do it. Compilers generally don't emit the needed bit of debuginfo (there's a GCC bug open about this); and even if they did, gdb wouldn't read it; and even if it did it would need new syntax for you to be able to specify it as a breakpoint location.

I don't remember offhand if there is a gdb bug for this, but there ought to be.

Upvotes: 5

Related Questions