Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let GDB continue until the program enters another function?

Tags:

c++

c

debugging

gdb

Say I am in A() and A() calls B(). I just entered A() and I want the program to run until I am in B(). It doesn't have to be a specific function B(). I just want my program to pause whenever it enters a new function. Is there a way to do that?

like image 277
user1861088 Avatar asked Feb 04 '13 19:02

user1861088


People also ask

How do I continue GDB?

If you want gdb to resume normal execution, type "continue" or "c". gdb will run until your program ends, your program crashes, or gdb encounters a breakpoint.

Which command is used to continue the program until the next breakpoint occurs?

If you do accidentally step into a function, you can use the finish command to finish the function immediately and go back to the next line after the function. This will continue running the program until the next breakpoint or until the program ends.

What is until in GDB?

This command continues the debuggee past the current line until the specified source line in the current stack frame. Use this command to avoid single stepping through a loop more than once, or to skip over the execution of uninteresting code.

Why is GDB not stopping at breakpoint?

GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped.


1 Answers

For calls, as mentioned at: List of all function calls made in an application :

set confirm off
rbreak .

rbreak sets a breakpoint for every function that matches a given regular expression, . matches all functions.

This command might take a while to run for a large executable with lots of functions. But once it finishes, runtime will be efficient.

The exit is trickier, since we can't know at compile time where we will land: How to set a breakpoint in GDB where the function returns?

At How to break on instruction with a specific opcode in GDB? I also provided a script that single steps until a desired instruction is found, which you could use to find callq. That one has the advantage of not making you wait on a large executable, but execution will be very slow, so the target can't be very far away.