Breakpoint basics for Visual Studio debugging

Source: Internet
Author: User

I have asked many people how you debug yourProgram?

F9, F5, F11, F......

many books and articles describe how to use Visual Studio compile winform and , Asp.. Net and other programs. It is important to know how to compile them, however, I think programmers may only spend 30% writing code , most of the time is spent debugging the program. On the Internet, I have seen many people introduce the usage of windbg , however, I have not seen several articles on Visual Studio debugging. windbg although it is powerful, the problem is that its learning curve is too steep, in addition, you do not need to use windbg for debugging (of course, it doesn't mean that I won't debug windbg - This will be discussed in a series of debugging articles in the future.) Why not use the most familiar Visual Studio for debugging?

Debugging is nothing more than checking the internal status of the program when it is running, such as the value of some variables and the path of the program call. Of course, the most direct way is to directly interrupt the execution of the program. Use the debugger to check the program. ThereforeF9, F5, F10, F11......

So what is a breakpoint and a breakpoint? NoF9It's not the little red ball.IntelSeriesCPU(IncludingAMDProducedCPU), It is actually a special command-INT 3.CPUWhen you run the instruction set of a program, the execution of the program will be interrupted (of course,CPUWill notify the operating system, and then ...... Then ...... Then ......, I will explain the breakpoint implementation mechanism in a later article. Now we only need to knowINT 3Will the command interrupt the execution of the program ?).

Of course, we need to use facts to prove what I mentioned above, so compile and execute the following program, click"Yes", Click"Break", Right, the program is interrupted. I believe you can see it:

# Include <Stdio. h>

 

VoidMain ()

{

Printf ("Before breakpoint" N");

_ ASM

{

Int3

}

Printf ("Before breakpoint" N");

}

 

Compilation Method:

1.OpenVisual Studio 2008 [2005] command prompt(Visual Studio 2008 [2005]Command Line ).

2.Go to save the aboveCSource code(Int3.c.

3.Execute the compilation command (because my machine isWindows 7 RC + Visual Studio 2008 + x64 CPU, Directly compile a little problem. If your machine is not configured above, you can try to executeCL/Zi int3.c)

CL/Zi/C int3.c

4.Run the link command (if you directly execute the commandCL/Zi int3.cYou can skip this step ).

Link/libpath: "C:" Program Files "Microsoft sdks" Windows "v6.0a" lib "int3.obj

5.Run the outputInt3.exe.

you should see Visual Studio popped up, then, it is interrupted on INT 3 in the source code line, we have successfully interrupted CPU int3.exe Program is executed.

Prompt: If you executeInt3.exeNoVisual StudioClickVisual Studio"Tools(Tool )"-"Options(Option), and thenOptionsSelect "Debugging(Debugging )"-"Just-in-time(Instant debugging) ", and then select"Native(Native program) option. As shown in:

"In conclusion, the breakpoint is INT 3.This command is triggered! (Mathematical Proof of childhood )".

ByINT 3This command (of course inIntelSeriesCPU(Above) What functions are derived from the extension:

Language/Tools

Name

Description

C ++

Debugbreak

InC ++A breakpoint is hardcoded in the code.

C #

Debugger. Break

In. NetHard coding of a breakpoint in the code

Visual Studio

Breakpoint

Set a breakpoint

 

To be continued ......

 

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.