How to Set Breakpoint at the Very Beginning of Program Execution

How to set breakpoint at the very beginning of program execution

You can do this by adding a registry key to "Image File Execution Options" with the name of your exe. Add a value of type string named "Debugger" and set it to vsjitdebugger.exe to launch the just-in-time debugger dialog. Which then lets you pick one of the available debuggers, including Visual Studio. This dialog is triggered right after Windows has loaded the EXE, before any code starts running.

Here's is a sample .reg file that triggers the dialog when you start notepad.exe. Modify the key name to your .exe:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="vsjitdebugger.exe"

How to set breakpoint at the very beginning of program execution

You can do this by adding a registry key to "Image File Execution Options" with the name of your exe. Add a value of type string named "Debugger" and set it to vsjitdebugger.exe to launch the just-in-time debugger dialog. Which then lets you pick one of the available debuggers, including Visual Studio. This dialog is triggered right after Windows has loaded the EXE, before any code starts running.

Here's is a sample .reg file that triggers the dialog when you start notepad.exe. Modify the key name to your .exe:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="vsjitdebugger.exe"

Stopping at the first machine code instruction in GDB

Starting with GDB 8.1, there's a special command for this: starti. Example GDB session:

$ gdb /bin/true
Reading symbols from /bin/true...(no debugging symbols found)...done.
(gdb) starti
Starting program: /bin/true

Program stopped.
0xf7fdd800 in _start () from /lib/ld-linux.so.2
(gdb) x/5i $pc
=> 0xf7fdd800 <_start>: mov eax,esp
0xf7fdd802 <_start+2>: call 0xf7fe2160 <_dl_start>
0xf7fdd807 <_dl_start_user>: mov edi,eax
0xf7fdd809 <_dl_start_user+2>: call 0xf7fdd7f0
0xf7fdd80e <_dl_start_user+7>: add ebx,0x1f7e6

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

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.

GDB put breakpoint at very first instruction

Is it possible

Sure. Here is one way to do it:

$ echo "int main() { return 0; }" | gcc -xc -
$ gdb -q ./a.out
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) x/i &main
0x5fa <main>: push %rbp

Note that this is a PIE binary, and it has not been relocated yet (no code will ever execute at address 0x5fa on a Linux system).

(gdb) set stop-on-solib-events 1
(gdb) run
Starting program: /tmp/a.out
Stopped due to shared library event (no libraries added or removed)
(gdb) x/i &main
0x5555555545fa <main>: push %rbp

You can now see that the binary has been relocated, and can set a breakpoint on main.

(gdb) b main
Breakpoint 1 at 0x5555555545fe
(gdb) c
Continuing.
Stopped due to shared library event:
Inferior loaded /lib/x86_64-linux-gnu/libc.so.6
(gdb) c
Continuing.

Breakpoint 1, 0x00005555555545fe in main ()

Voilà.

How to see the execution steps of a java program

Look for the little green bug at the top.
If you run it by pressing this icon, your application will run in a new perspective and stop at your breakpoints.

Sample Image

Enter breakpoints by clicking the area where you see the blue dot in this picture.

Sample Image

Navigate inside of the debugger with:

Sample Image

Green arrow is for running till next breakpoint.
Red square is for terminating the process.
The 90degree arrow goes into methods you invoke showing each step IN the method. The last arrow executes them without showing the steps.

If you're done with debugging you can switch perspective here.(upper right corner)
Sample Image

How to set a JavaScript breakpoint from code in Chrome?

You can use debugger; within your code. If the developer console is open, execution will break. It works in firebug as well.



Related Topics



Leave a reply



Submit