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,683
  • 2
  • 15
  • 17

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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
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
  • 22,324
  • 5
  • 59
  • 79
  • I wrote the opcode detection script: http://stackoverflow.com/a/31249378/895245 but for this specific case there is a more efficient solution with `rbreak .`: http://stackoverflow.com/a/31249717/895245 – Ciro Santilli OurBigBook.com Jul 06 '15 at 15:26