Instant debugging (Just-in-timedebugging) Visual Studio debugging breakpoint interrupt program execution (breakpoint command)

Source: Internet
Author: User

Just-in-time debugging in VC, which is applied in this debugging modeProgramYou can run it outside of the Visual C ++ development environment to know that an error has occurred. when a program error occurs, just-in-time debugging automatically loads visual c ++ debugger. to enable just-in-time debugging, you only need to modify the tools-> options-> just-in-time debugging option (in fact, the operation of this option is to write a registry, this section describes how to handle exceptions thrown by other programs)

Set the instant debugging breakpoint, and add a breakpoint exception to the compiled debug version program.CodeHard-coded a breakpoint (equivalent to making a program error), allowing the program to load the debugger with open source code when reaching the position where the programmer wants to stop to debug the position.(Of course, debugging can be done without the source code, :--). If you want to debug the compilation .)

How to set the breakpoint for instant debugging in VC: dbgbreakpoint orDebugbreak

How to set the breakpoint for instant debugging in C #: debugger. Break

How to Set breakpoint for instant debugging in JS: Debugger

In ASP (vbs), the instant debugging breakpoint setting method is stop.

Visual Studio debug the execution of the breakpoint interrupt program (breakpoint command)

Breakpoint command
So what is a breakpoint and a breakpoint? It's not F9, nor the little ball. In intel series CPUs (including AMD-produced CPUs), it is actually a special command-INT 3. When the CPU executes the instruction set of a program, it will interrupt the execution of the program as long as it encounters the instruction set.

Reference example
Of course, we need to use facts to prove the above, so compile and execute the following program, click "yes", click "break", and the program will be interrupted.
Reference content is as follows:
# Include <stdio. h>
Void main ()
{
Printf ("before breakpoint" N ");
_ ASM

{

INT 3

}
Printf ("before breakpoint" N ");
}

The breakpoint is triggered by the INT 3 command.

Functions derived from the INT 3 command (of course on Intel series CPUs:

Language/tool Name Description
C ++ Debugbreak Hardcoded a breakpoint in the C ++ code.
C # Debugger. Break Hard-coding a breakpoint in. Net code
Visual Studio Breakpoint Set a breakpoint

Excerpt:

The ability to connect a debug program to any process at any time is called Instant debugging (Just-in-timedebugging ).

Here we will explain how it works: When a programmer clicks the cancel button, it will tell the unhandledexceptionfilter function to debug the process. Internally, unhandledexceptionfilter calls the debugging program. You need to view the following subkeywords in the registry:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ AeDebug
In this subkeyword, a value named debugger is set to the following value when Visual Studio is installed:
"C: \ Program Files \ Microsoft Visual Studio \ common \ msdev98 \ bin \ msdev.exe"-P % LD-E % LD
In Windows 98, these values are not stored in the registry, but in the win. ini file.
This line of code is the Program (msdev.exe) to be run by the worker system as a debug program. You can also select other debugging programs. Unhandledexceptionfilter also transmits two parameters to the debugging program in this command line. The first parameter is the ID of the debugged process. The second parameter specifies an inherited manual reset event, which is created by unhandledexceptionfilter In the stateless state. Vendors must implement their debugging programs so that they can understand the-P and-e options for the specified process ID and event handle.
After the process ID and event handle are merged into this string, unhandledexceptionfilter calls CreateProcess to execute the debugging program. At this time, the program debugging process starts to run and check its command line parameters. If the-P option exists, the debugger obtains the process ID and calls debugactiveprocess to connect itself to the process.
Bool debugactiveprocess (DWORD dwprocessid );
Once the debugging program completes its own mounting, the operating system reports the status of the debuggable (debuggee) to the debugging program.
After the debugging program is fully initialized, it needs to check its command line and find the-e option. If this option exists, the debug program obtains the corresponding event handle and calls setevent. The debug program can directly use the event handle value because the event handle has the inheritance that can be created, and the call by the debug process to the unhandledexceptionfilter function also makes the debug program process a sub-process.
Setting this event will wake up the thread of the debugged process. The awakened thread transmits information about the unprocessed exception to the debugging program. The debugger receives these notifications and loads the corresponding Source code File, and then place itself in the Command location that causes exceptions.
Also, you do not have to wait for exceptions before debugging the process. You can connect a debugging program to any process at any time. You only need to run "msdev-ppid", where PID is the ID of the process to be debugged. In fact, it is easy to use Windows2000 taskmanager to do these tasks. When you observe the process tag bar, you can select a process, right-click the process, and select the Debug menu option. This will cause taskmanager to view the subkeyword of the Registry discussed earlier, call CreateProcess, and pass the ID of the selected process as the parameter. In this case, TASKMANAGER transfers 0 values for the event handle.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.