How to make gdb stop immediately after starting the program?

I tried to set a breakpoint for each function that makes some sense, but will exit the program before reaching any of them. Is there a way to make the program step by step from the very beginning so that I can see what is happening?

I am trying to debug / usr / bin / id if it is important (we have a custom plugin for it and it behaves badly)

PS The Start command does not work for me here (it should be a comment, but I do not have enough reputation)

+4
source share
3 answers

Get the address of the program entry point and insert a breakpoint at this address.

One way to do this is to make information files that give you, for example, "Entry Point: 0x4045a4". Then do "break * 0x4045a4". After starting, the program will stop immediately.

Here you can use single step instructions (e.g. step or stepi).

You did not say which system you are trying to debug. If the code is in read-only memory, you may need to use hardware breakpoints (hbreak) if supported by this system.

+2
source

Use start command

The start command executes the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then calls the run command.

eg.

program with debugging information main and its use: main arg1 arg2

gdb main (gdb) start arg1 arg2 
+3
source

You can enter record full immediately after run in the program. This will record all instructions and make them possible for repeat play / return.

For the main function, you need to enter this before reaching the breakpoint so that you can set an earlier version break _start _start -> _start is a function always called before the standard main function. (obviously only applies to gcc compiler or similar)

Then continue to the main breakpoint and execute reverse-stepi to go back one command

Read more about the recording here: link

+2
source

Source: https://habr.com/ru/post/1501260/


All Articles