2

I know how to set breakpoints at specific lines (so I could set a break at line 1) or i can also do :

break main (to set a break point at the entering of the main program)

but how do you set a break point BEFORE it enters a certain function or the main program?

also if anyone has the time. how do you start execution of a gdb program at a specific breakpoint (say if i set a breakpoint at line 7).

harekuin
  • 45
  • 1
  • 8

1 Answers1

0

There is no command (AFAIK) to put a breakpoint on all calls of some specific function (there could be multiple places from where a function is called, including virtual functions, function pointers, which gdb can't even discover).

How to start before main has been explained multiple times, including here. You can then step up to main.

In general why would you care to stop before function is entered? The difference is only in argument setup/stack. You put a breakpoint on function startup, then you move to the frame above ("up" command) and examine it as if function has not been called yet.

Similarly, it does not make much sense* to resume execution at some random point in your code, without having local variables / registers / arguments properly set up. You can execute a function (using "call" command). This does make sense.

(*) It is possible, though, but if you don't set up context appropriately, you will crash. Do "info break". This will give you an address at which breakpoint has been inserted (let's say it's 0x00000000004005ea. Then set your PC to that address (on x86-64 that would be "set $rip = 0x00000000004005ea"), set up your stack, registers, etc and then "continue".

Community
  • 1
  • 1
dbrank0
  • 9,026
  • 2
  • 37
  • 55
  • I'm currently studying for an exam and it was the word by word question from a past exam set. i know the question was a bit odd. none of the study material i had covered putting a break point BEFORE entering the main program (or function.. etc) so I was wondering if I was missing something. Thank you! – harekuin Jul 23 '16 at 06:13