Analysis of VC debugging

Source: Internet
Author: User

Every time a project is created in VC, VC automatically creates two versions: release version and debug version, the release version is the version used for compilation when the program is ready for release, while the debug version is used for debugging during development.

You must use the debug version when debugging the program. You can set debugging options on the C/C ++ page of the Project Setting dialog box.

 

Fig 4.2

The meanings of each option are as follows:

  • Program database indicates a data file (. PDB) that generates information about a stored program. It contains type information and symbolic debugging information;
  • Line numbers only indicates that the. OBJ or. EXE file generated by the program after compilation and link only contains global and external symbols and row number information;
  • C7 compatible indicates the generation of A. OBJ or. EXE file line number information and symbolic debugging information;
  • None indicates that no debugging information is generated.

2. General debugging process

Debugging means to observe the state of the program at a certain stage of the program running process. In general, the program runs continuously, so we must stop the program at a certain location. So the first task we do is to set up a breakpoint. Second, run the program again. When the program stops at the set breakpoint, use various tools to observe the program status. After the program stops at the breakpoint, sometimes we need to control the program running as required to further observe the program flow. So next we will introduce the breakpoint settings in sequence, how to control program running and use of various observation tools.

1.3 How to set breakpoints

In VC, you can set multiple types of breakpoints. We can divide these breakpoints into three types based on the method in which they work: 1. Location-related breakpoints; 2. breakpoint related to logical conditions 3. breakpoint related to Windows messages Below we will introduce these three types of breakpoints respectively.

First, we will introduce the location-related breakpoints.

  1. The simplest is to set a general position breakpoint. You only need to move the cursor to the position where you want to set the breakpoint. Of course, this line must contain a valid statement; then press the Add/Remove breakpoint button on the toolbar or press the shortcut key F9; at this time, you will see a red dot on the left of the line on the screen, indicating that the two have set a breakpoint.

Fig 4.3

2. Sometimes, you may not need to stop the program every time it runs here, but to stop it only when certain conditions are met, in this case, you need to set a location-related logical breakpoint. To set this breakpoint, you only need to select the breakpoint command from the edit menu. Then, the breakpoint dialog box will appear on the screen. Select the location tag in the breakpoint dialog box to bring up the location page, 4.4

 

Fig 4.4

Click the condition button to bring up the breakpoint dialog box. In the expression editing box, write your logical expression, for example, x> = 3 or a + B> 25. Then press OK to return the result.

Fig 4.5

 

This type of breakpoint mainly works based on its location, but it also integrates logical conditions to make it more flexible.

3. Sometimes we need to debug the program more deeply. We need to enter the assembly code of the program, so we need to set a breakpoint on the assembly code: to set this breakpoint, we only need to select the debug window command from the View menu,

 

Fig 4.6

Then select the disassembly sub-command, and the Assembly window will appear on the screen.

Fig 4.7

In the Assembly window shown in Figure 4.7, you will see the assembly code corresponding to the source program. The source program is displayed in italic. The following shows the corresponding assembly code. To set a breakpoint, move the cursor to the position where you want to set the breakpoint and click Insert/remove breakpoints on the toolbar, then you will see a red dot on the right of the assembly code.

 

 

Fig 4.8

The breakpoint mentioned above is mainly due to its position, that is, when the program runs to the place where the breakpoint is set, the program will stop. But sometimes we set up a breakpoint that is only related to the logical condition, but not the location. The following describes the breakpoints related to logical conditions.

(1) set the breakpoint triggered by logical conditions:

    • Select the breakpoint command from the edit menu. the breakpoint dialog box appears on the screen.

Fig 4.9

 

    • Select the data label in the breakpoint dialog box. The corresponding page will pop up.

 

Fig 4.10

    • Write your logical expression in the expression edit box on the data page in Figure 4.10, for example (x = 3 );

Fig 4.11

    • Finally, press OK to return.

The methods for setting other breakpoints are similar. We will describe them one by one.

(2) monitoring Expression Change breakpoint:

    • Select the breakpoint command from the edit menu. the breakpoint dialog box appears on the screen.
    • Select the data label in the breakpoint dialog box. The corresponding page will pop up.
    • Write the expression you want to monitor in the expression editing box.
    • Press OK.

(3) breakpoint for monitoring array changes:

    • Select the breakpoint command from the edit menu. the breakpoint dialog box appears on the screen.
    • Select the data label in the breakpoint dialog box. The corresponding page will pop up.
    • Write the name of the array to be monitored in the expression editing box;
    • In the number of elements edit box, enter the number of elements in the array to be monitored;
    • Press OK.

(4) monitoring the breakpoint that changes the array pointed to by the pointer:

    • Select the breakpoint command from the edit menu. the breakpoint dialog box appears on the screen.
    • Select the data label in the breakpoint dialog box;
    • In the expression editing box, enter * pointname, where * pointname is the pointer variable name;
    • In the number of elements edit box, enter the number of elements in the array to be monitored;
    • Press OK.

(5) breakpoint for monitoring changes to external variables:

    • Select the breakpoint command from the edit menu. the breakpoint dialog box is displayed on the screen;
    • Select the data label in the breakpoint dialog box;
    • Enter the variable name in the expression editing box;
    • Click the drop-down key on the right of the expression editing box;
    • Select the advanced option. The advanced breakpoint dialog box appears;
    • Enter the corresponding function name (if needed) in the context box;
    • Press OK to close the advanced breakpoint dialog box.
    • Press OK to close the breakpoints dialog box.

(6) After talking about the location breakpoint and logical breakpoint, let's talk about the breakpoint related to Windows messages.

Note: Such breakpoints can only work on x86 or Pentium systems.

    • Select the breakpoint command from the edit menu. the breakpoint dialog box is displayed on the screen;
    • Select the message tag in the breakpoint dialog box. The corresponding page will pop up;
    • In the break at wndproc edit box, enter the name of the Windows function;
    • In the set one breakpoint from each message to watch drop-down list box, select the corresponding message;
    • Press OK to return.

 

The debug version contains debugging information in Microsoft format without any code optimization. In the release version, the binary code of the executable program is optimized, however, this does not contain any debugging information.

In the new project, you can see the debug version. To select the release version, you can select the setting command in the menu project. The project setteing dialog box is displayed on the screen, select release from the setting for drop-down list, and press OK to exit, 4.1.

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.