Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the setting of breakpoint in Visual Studio debugging

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to analyze the setting of Visual Studio debugging breakpoints. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.

I have asked a lot of people, how do you usually debug your program?

F9, F5, F11, F.

There are many books and articles about how to use Visual Studio to write programs like WinForm, ASP.NET, and so on; it's important to know how to write, but I think programmers may only spend 30% of their time writing code, and spend most of the rest of their time debugging programs. I've seen a lot of people introduce the use of Windbg on the Internet, but I haven't seen a few articles on debugging with Visual Studio. Windbg is powerful, but the problem is that its learning curve is too steep, and a lot of debugging doesn't need to be debugged with Windbg (of course, it doesn't mean I can't debug Windbg-that's what I'll talk about in a future debugging series), so why not use Visual Studio, which we're most familiar with?

Debugging is nothing more than looking at the internal state of the program when it is running, such as the value of some variables, taking a look at the path of the program call, and so on. Of course, the most direct way is to directly interrupt the execution of the program and use the debugger to check the situation of the program. So F9, F5, F10, F11.

So let's talk about what is a breakpoint and what is a breakpoint?

Not F9, not that little red ball, in the CPU of the Intel series (including the CPU produced by AMD), it is actually a special instruction-INT 3. When CPU executes the instruction set of the program, whenever it encounters this instruction, it will interrupt the execution of the program (of course, CPU will notify the operating system, and then... And then. And then. I will explain the implementation mechanism of breakpoints in a future article, but now we just need to know that that INT 3 instruction will interrupt the execution of the program, okay? ).

Of course, we need to prove what I said above with facts, so compile and execute the following program, click "Yes", click "Break", yes, the program is interrupted, I believe you can see it:

# include void main () {printf ("Before breakpoint" n "); _ _ asm {int 3} printf (" Before breakpoint "n");}

Compilation method:

1. Open Visual Studio 2008 [2005] Command Prompt (Visual Studio 2008 [2005] command line) in the start menu.

two。 Enter the path to the folder where the above C source code (int3.c) is saved.

3. Execute the compilation command (because my machine is Windows 7 RC + Visual Studio 2008 + x64 CPU, there is a problem with direct compilation. If your machine is not my configuration above, you can try to execute cl / Zi int3.c)

Cl / Zi / c int3.c

4. Execute the link command (you can skip this step if you directly executed the command cl / Zi int3.c).

Link / libpath: "C:" Program Files "Microsoft SDKs" Windows "v6.0A" Lib "int3.obj

5. Run the output int3.exe.

At this point you should see Visual Studio pop up and break on the int3 on the source line, indicating that we have successfully asked CPU to interrupt the execution of the int3.exe program.

Tip: if you do not find the Visual Studio window popping up when you are performing int3.exe, click "Tools"-"Options" in the Visual Studio menu item, then select "Debugging"-"Just-In-Time" in the "Options" window, and then check the "Native" option. As shown in the following figure:

"to sum up, the breakpoint is

Int 3 is triggered by this instruction! (the mathematical proof problem of childhood) ".

What functions are derived from the instruction int 3 (on the CPU of the intel series, of course):

Language / tools

Name

Description

C++

DebugBreak

Hard-code a breakpoint in C++ code.

C#

Debugger.Break

Hard-coding a breakpoint in .NET code

Visual Studio

Breakpoint

Set a breakpoint

The above is how to analyze the setting of breakpoints in Visual Studio debugging. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report