how to force gdb to stop right after the start of program execution?

后端 未结 3 1267
轮回少年
轮回少年 2021-01-01 02:17

I\'ve tried to set breakpoint on every function that makes any sense but program exit before reaching any of those. Is there a way to make program run in step-by-step mode f

相关标签:
3条回答
  • 2021-01-01 02:29

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

    One way to do this is to do info files which gives you for example "Entry point: 0x4045a4". Then do "break *0x4045a4". After run-ning program, it will immediately stop.

    From here on you can use single stepping instructions (like step or stepi) to proceed.

    You did not tell what system you are trying to debug. If code is in read-only memory you may need to use hardware breakpoints (hbreak) if they are supported by that system.

    0 讨论(0)
  • 2021-01-01 02:32

    You can type record full right after running the program. This will record all instructions and make them possible for replaying/going back.

    For main function, you'd need to type this before reaching the breakpoint so you can set an earlier one by break _start -> _start is a function always called before the standard main function. (apparently applies only to the gcc compiler or similar)

    Then continue to main breakpoint and do reverse-stepi to go exactly one instruction back

    For more info about recording look here: link

    0 讨论(0)
  • 2021-01-01 02:48

    Use start command

    The ‘start’ command does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking the ‘run’ command.

    e.g.

    a program with debug info main, and usage like this: main arg1 arg2

    gdb main
    (gdb) start arg1 arg2
    
    0 讨论(0)
提交回复
热议问题