Powerful VC6 Debugger

Source: Internet
Author: User

To be an excellent software engineer, the ability to debug is essential. This article will describe in more detail the main uses of the VC6 debugger.

The debugger for the Windows platform is divided into two main categories:

1 user mode (User-mode) debugger: They are all based on the Win32 debugging API, have a user-friendly interface, primarily for debugging user-mode applications. Such debuggers include the Visual C + + debugger, WinDBG, Boundchecker, Borland C + + Builder debugger, NTSD, and so on.

2 kernel mode (kernel-mode) debugger: The kernel debugger is located between the CPU and the operating system, and once started, the operating system is aborted, primarily for debugging drivers or programs that are not easily debugged by the user-mode debugger. This type of debugger includes WDEB386, WinDbg, and SoftICE. Where WinDbg and SoftICE can also debug user-mode code.

A foreign debugging master has said that he 70% debugging time is in the use of VC + +, the rest of the time is the use of WinDbg and SoftICE. After all, debugging user-mode code, the VC6 debugger is highly efficient. Therefore, I will first introduce the main usage of the VC6 debugger in this article, the use of other debuggers, and some debugging skills to be elaborated in subsequent articles.

One location breakpoint (Location breakpoint)

The most common breakpoint is a normal location breakpoint, and a location breakpoint is set by pressing F9 on one line of the source program. But for many problems, this simple breakpoint has limited effect. For example, the following code:

void CForDebugDlg::OnOK()   
{
   for (int i = 0; i < 1000; i++)  //A
   {
     int k = i * 10 - 2;   //B
     SendTo(k);    //C
     int tmp = DoSome(i);   //D
     int j = i / tmp;  //E
   }
}

Execution of this function, the program crashed in line E, found at this time TMP is 0, assuming that TMP should not be 0, how this time for 0? So it's best to keep track of how the Dosome function works when the loop is running, but because it's in the loop, if you set a breakpoint on line E, you might need to press F5 (GO) many times. So the hands to keep pressing, very painful. You can easily fix this problem by using the VC6 breakpoint to decorate the condition. The steps are as follows.

1 Ctrl+b Open the Breakpoint Settings box, as shown below:

Figure 1 Set advanced location breakpoint

2 then select the breakpoint on line D, then click the Condition button, enter a large number in the bottom of the pop-up dialog box, depending on the application, here 1000 is enough.

3 Press F5 to re-run the program, the program interrupted. Ctrl+b Opens the breakpoint box, finds this breakpoint followed by a series of instructions: ... 487 Times remaining. It means that there are 487 times left without execution, that is to say, 513 (1000-487) times the error occurred. So, in step 2, we change the number of times this breakpoint is skip, and 1000 to 513.

4 rerun the program again, the program performs 513 cycles, and then automatically stops at the breakpoint. At this point, we can look at how Dosome returns 0. In this way, you avoid the pain of the fingers and save time.

Then look at the position breakpoint other cosmetic conditions. As shown in Figure 1, under "Enter the expression to be evaluated:", you can enter conditions that the breakpoint will start when these conditions are met. For example, just the program, we need I for 100 when the program stops, we can enter in the edit box to enter "i==100."

In addition, if you enter only the variable name in this edit box, the breakpoint is started when the variable changes. This is convenient for detecting when a variable is modified, especially for some large programs.

With the modification of the position breakpoint, it is very convenient to solve some problems.

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.