Powerful vc6 Debugger

Source: Internet
Author: User

 

Powerful vc6 Debugger
Author: yy2better

To become an excellent software engineer, debugging capability is essential. This article will introduce the main usage of the vc6 Debugger in detail.

Windows debuggers mainly fall into two categories:

1 user-mode Debugger: both are based on Win32 debugging
API, easy to use interface, mainly used to debug applications in user modeProgram. This type of Debugger includes visual
C ++ debugger, windbg, boundchecker, Borland C ++ builder debugger, ntsd, etc.
2
Kernel-mode Debugger: the kernel debugger is located between the CPU and the operating system. Once started, the operating system stops running. It is mainly used to debug the driver or user mode.
Programs that are not easy to debug. Such debuggers include wdeb386, windbg, and SoftICE. Windbg and SoftICE can also debug the user mode.Code.
A foreign debugging expert once said that he spent 70% of the debugging time using VC ++ and the rest of the time using windbg and SoftICE. After all, the efficiency of debugging user-mode code and vc6 Debugger
Is very high. Therefore, I will first introduce the main usage of the vc6 Debugger in this article.Article.
Location breakpoint)

The most common breakpoint is a normal position breakpoint. A position breakpoint is set in a line of the source program by pressing F9. However, for many problems, this simple breakpoint has limited function. For example, the following code:

 void cfordebugdlg: onok () 
{< br> for (INT I = 0; I <1000; I ++) // A
{< br> int K = I * 10-2; // B
sendto (k ); // C
int TMP = dosome (I); // d
Int J = I/tmp; // E
}< BR >}< br>

when this function is executed, the program crashes in line E and finds that TMP is 0 at this time. If TMP is not supposed to be 0, why is it 0 at this time? Therefore, it is best to track how the dosome function runs in this loop. However, because it is in the loop body, if you set a breakpoint in line E, you may need to press F5 (GO) many times. In this way, it is very painful to keep pressing. You can easily solve this problem by using the vc6 breakpoint Modification Conditions.
. The procedure is as follows.
1 Ctrl + B Open the breakpoint setting box, for example:
Figure 1 sets an advanced position breakpoint
2. Select the breakpoint of Row D and click the condition button, enter a large number in the bottom edit box of the pop-up dialog box, depending on the application. Here 1000 is enough.
3. Press F5 to run the program again, and the program is interrupted. CTRL + B Open the breakpoint box and find the breakpoint followed by a series of instructions:... 487 Times
remaining. It means that the remaining 487 times are not executed, that is to say, an error occurs when the execution reaches 513 (1000-487. Therefore, as described in step 2, change the number of
skips for this breakpoint to 1000.
4. Run the program again. The program executes 513 cycles and stops at the breakpoint automatically. In this case, we can carefully check how dosome returns 0. In this way, you can avoid finger pain and save time.
check other Modification Conditions of the position breakpoint. As shown in Figure 1 , under "Enter the expression to be evaluated:", you can enter some conditions. When these conditions are met, the breakpoint starts. For example, if we need to stop the program when I is 100, we can enter "I = 100" in the editing box ".
In addition, if you enter only the variable name in the edit box, the breakpoint starts when the variable changes. This is convenient for detecting when a variable is modified, especially for some large programs.
using the Modification Conditions of the position breakpoint can greatly solve some problems.

Data breakpoint)

During software debugging, some data may be inexplicably modified (for example, some arrays may overwrite other variables ), it is tricky to find out where code causes this memory to be changed
(Without the help of the debugger ). The proper use of data breakpoints can help you quickly locate when and where the data is modified. For example, the following program:

 
# Include "stdafx. H"
# Include

Int main (INT argc, char * argv [])
{
Char szname1 [10];
Char szname2 [4];
Strcpy (szname1, "Shenzhen ");
Printf ("% s/n", szname1); //

Strcpy (szname2, "vckbase"); // B
Printf ("% s/n", szname1 );
Printf ("% s/n", szname2 );

Return 0;
}

The output of this program is

 
Szname1: Shenzhen
Szname1: ase
Szname2: vckbase

When Will szname1 be modified? Because szname1 code is not significantly modified. We can first set a normal breakpoint in line A, F5 runs the program, and the program stops in line. Then we set another data breakpoint. Example:
Figure 2 data breakpoint
F5 continues to run. The program stops at line B, indicating that szname1 has been modified in code B. Why didn't I modify szname1 at location B? However, the debugger specifies that this line is normal, so it is still quiet
let's look at the program. Oh, you found that szname2 has only four bytes, strcpy contains 7 bytes, so szname1 is overwritten.
data breakpoint is not only valid for variable changes, but can also be used to set whether the variable is equal to a certain value. For example, you can change the Red Circle in Figure 2 to the condition "szname2 [0] = '''y' '''", when the first character of szname2 is Y, the breakpoint starts.
it can be seen that a big difference between the data breakpoint and the position breakpoint is that you do not need to specify which line of code to set the breakpoint.

III others

1. Set a breakpoint in the call Stack window, select a function, and press F9 to set a breakpoint. In this way, the required functions can be quickly returned from in-depth function calls.

2 set next statement command (in the debug process, right-click the command in the menu)

This command points the EIP of the program to different code lines. For example, you are debugging the above Code and running it in line A, but you are not willing to run line B and line C code
In this case, you can right-click Row D and then "set next statement ". The debugger does not execute lines B and C. As long as it is in the same function, this command can be executed before or after the jump.
Line. Flexible use of this function can greatly save debugging time.

3 Watch window

The Watch window supports a wide range of data formatting functions. If you enter 0x65, U, 101 is displayed in the right column.

Real-time display of Windows API call errors: Enter @ err, HR in the left column.

Call the function in the watch window. Remind you to clear the function immediately after calling it in the watch window. Otherwise, the debugger calls this function at each step during one-step debugging.

4. The messages breakpoint is not very practical. It can basically be replaced by the breakpoint described above.

Summary

The most important part of debugging is to think about where your program may go wrong, and then use your debugger to confirm your guess. These skills will undoubtedly speed up the process. Finally, if you have any questions about debugging, I would like to participate in the discussion.

Http://www.vckbase.com/document/viewdoc? Id = 1262

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.