6

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?

user1861088
  • 1,573
  • 2
  • 14
  • 16

2 Answers2

3

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.

1

There would be a nice solution in form of setting a breakpoint on call instruction, but as this answer states there is no way to do that.

I think, the easiest solution would be to set that breakpoints manually or try to write a script in Python which finds function calls in the currect function listing and sets desired breakpoints.

Community
  • 1
  • 1
Rafał Rawicki
  • 21,626
  • 3
  • 57
  • 77