Visual Studio Debugger Guide --- control execution

Visual Studio debugger provides powerful commands to control the execution of applications. The following describes the control command execution with a debugger executable tasks:

  • Begin (or continue) to perform

  • Break execution

  • Stop execution

  • Step through the application

  • Run to the specified location

  • Set point of execution

Begin execution

It started one of the most basic debugging function.

  1. Select "Start", "Step Into" or "Step Over" on the "Debug" menu.

    - or -

  2. In the source window, right in a row of executable code, and then select "Run to the cursor."

If you select "Start", the application starts and runs until the breakpoint. You can break execution at any time, to check the values, modify variables, or check program status.

If the "Step Into" or "Step Over" is selected, the application will launch and execute, then interrupted in the first row. If "Run to Cursor", the application is started and runs until the breakpoint or the cursor position, particularly to see the previous or cursor breakpoint former. The cursor may be provided in the source window. In some cases, interrupt does not occur. This means that the execution has not reach the set-up code at the cursor.

Solutions may contain more than one project. This time can be selected by the "Debug" menu command to start the implementation of the project started. Alternatively, you can launch the selected item from the "Solution Explorer." You can use the "Debug" "started (not debug)" command on the menu, at the beginning of the implementation of the project without a debugger.

 

 

Break execution

When using the Visual Studio debugger to debug an application, or application program running (execution) or in break mode. Most debugging functions (such as calculation ** "monitoring" ** window expression) is available only in break mode. When execution reaches a breakpoint or exception occurs, the debugger will break execution of the program. You can always manually break execution. If there is no interruption in the implementation of the corresponding source code, you will be able to "disassemble" in the debug window.

Manual interrupt program execution

  • On the "Debug" menu, click "Break All."

    The debugger will stop executing all running under the debugger program. The program does not quit, you can resume execution at any time. Debugger and the application is now in break mode.

If you are debugging more than one program, by default, break or "break all" command will affect all the program being debugged. If you only want to interrupt the current program, you can change the default value.

Interruption when changing behavior debug multiple programs

  1. On the "Tools" menu, click "Options."

  2. In the "Options" dialog box, select "Debug" folder and click on the "General" category.

  3. Switching "all processes is interrupted when a process is interrupted."

  4. Click "OK."

 

 

Stop Debugging or stop execution

Stop debugging means terminating the debugging session. Stop execution means that termination being debugged process and end the debugging session. Not to be confused with the break execution, which means the suspension of the execution process being debugged but debugging session is still active.

Stop Debugging

  • On the "Debug" menu, choose "Stop Debugging."

If the program is started from Visual Studio, then ** "Stop Debugging" to terminate the process being debugged. If the program is attached to the process, rather than start from Visual Studio, then the process continues to run. If you want to terminate the additional process, through the "process window" to terminate a single process, or terminate all attached process by "phasing out" ** command.

Termination of all additional processes are being debugged

  • On the "Debug" menu select "All termination."

If you want to stop running currently being debugged and immediately start a new run, you can use ** "restart" ** command.

Stop debugging and restart

  • On the "Debug" menu, select "Restart."

"Restart" ** Stop session currently being debugged, and restarts the project.

If you exit the application being debugged, the debugger will stop automatically. If you are debugging multiple programs, debugging will continue until the last out of the program. If the commissioning of the project is hosted by other applications (such as Microsoft Internet Explorer Web project consists hosted) Exiting the host application (such as Microsoft Internet Explorer), the debugger will stop.

In Visual Basic and C #, if you are debugging a Web service, and use the service client application is terminated, the debugging Web services will stop.

Single-step execution

"Single step" is one of the most common debugging process. "Single step" that the first performance line of code.

"Debug" menu provides three commands to step through the code:

  • Step Into

  • Step Over

  • Bounce

"Step Into" differences and "Step Over" is that they only way to deal with different function calls. Both commands instructs the debugger to execute the next line of code. If a line contains a function call, "by the statement" calling itself only, then stop at the first line of code in the function. The "by-process" to perform the entire function, and then stops at the first row at the outer function. If you want to view the contents of a function call, use "by the statement." To avoid a single-step execution function, use "Step Over."

In the nested function calls, "Step Into" will step into the implementation of the most deeply nested functions. If you call using the "Step Into" for similar Func1 (Func2 ()), the debugger will step into the execution of the function Func2. If you want to step into the implementation of specific nested function, use the "single-step execution of certain" shortcut menu command. It is located inside a function call and want to return to the calling function, use the "jump" **. "Bounce" will always execute the code until the function returns, then return at the point of interruption in the calling function.

Run to the specified location

Sometimes, during debugging, you want to perform a certain point in the code, and then interrupted. If you set a breakpoint where you want to interrupt, you can achieve the above purpose.

Run to breakpoint specified location has been set

  • On the "Debug" menu, click "start" or "continue."

    You really do not need to have set a breakpoint in any case. Visual Studio debugger to run the specific command provided to the cursor position to the specified function or operation.

Set Next Statement

In the Visual Studio debugger, you can move the execution point to set the next statement to execute the code. Source window or "disassemble" blank area of ​​the window yellow arrows marked for the lower position of a statement. By moving the arrow to be skipped to return to the line code or part of previously executed. In some cases this method may be used, e.g., skip code segment containing a known bug. Note: Setting the next statement will cause the program counter to jump directly to the new location. Be careful when using the following command:

  • Instruction execution point between the old and the new execution point is not executed.

  • If the execution point rearward movement, the insertion instruction is not undone.

  • The next statement is moved to another function or range typically results in damage to the call stack, resulting in a runtime error or exception. If you try to move to the next statement to another range, the debugger will open a dialog box containing a warning, and provide an opportunity to cancel the operation. In Visual Basic, the next statement can not be moved to another range or function.

  • In the native C ++, when you run checking is enabled, the next statement will lead to the setting raises an exception when execution reaches the end of the method.

  • When you enable the "Edit and Continue", if you make the "Edit and Continue" Edit not immediately remapped, the "Set Next Statement" will fail. For example, if you edit the code in the catch block, it will happen. When this happens, you will see an error message similar to the following: "Can not set the next statement to this location does not support operating Unknown error: error number"

In managed code, the next statement can not be moved under the following conditions:

  • The next statement and current statement not in the same method.

  • Use real-time debugging start debugging.

  • Unfolding a call stack.

  • It has triggered a System.StackOverflowException System.Threading.ThreadAbortException or abnormal.

The next statement can not be set when the application is active operational state. To set the next statement, the debugger must be in break mode.

Setting the next statement to be executed

  • In the Source window, click the yellow arrow, next to which you want to set a position statement, it will drag the arrow to the position, which should be in the same source file

    - or -

  • In the source window, right-click on the next statement to be executed, and then select "Set Next Statement."

  • In the "disassembly" window, right-click to perform a next assembly language instructions, and then select "Set Next Statement."

Guess you like

Origin www.cnblogs.com/yilang/p/12456174.html