Use boundschecker to detect memory leakage 2

Source: Internet
Author: User

Recently I found myProgramThe leak is serious and cannot be found manually. Pointer out of order. So I just got a boundchecker version 6.0.

I saw its usage on the Internet, and it feels pretty good.

Boundschecker usage

Http://blog.sina.com.cn/u/53d9f7e9010007fz

Boundschecker is a run-time error detection tool that mainly locates various errors that occur during running of a program. Boundschecker can detect the following errors:

1)) 1,Pointer operation, memory, and resource leakage errors, such:

Memory leakage;

Resource leakage;

Incorrect operation on Pointer variables.

22. Memory Operation errors, such:

Memory read/write overflow;

Use uninitialized memory.

33. API function usage Error

After the boundschecker is successfully installed, a menu named boundschecker is displayed in your VC ++ integrated development environment, as shown below:


Figure 3-1 boundscheckerVC ++ integrated development environmentMenu

Boundschecker has been fully integrated into the VC ++ integrated development environment.

UseBoundschecker can detect program running errors in two usage modes. One mode is activecheck, And the other mode is finalcheck.. The following is an introduction.

 

3.1 activecheck

Activecheck is a convenient and fast error detection mode provided by boundschecker. It can detect a limited number of error types, including memory leakage errors, resource leakage errors, and API function usage errors.

To detect program running errors in activecheck mode, you only need to enable the boundschecker function in the VC ++ integrated development environment, and then run the program from the debugging status. In this case, activecheck runs automatically in the background and checks whether an error occurs in the program at any time. The following describes the procedure.

3.1.1 use activecheck to detect errors

Follow these steps to use activecheck:

first, open it in the integrated development environment of VC ++. test program, and ensure that the project is in the debug Compiling state.

In the VC ++ integrated development environment, make sure that the [boundschecker/Integrated debugging] menu items and [boundschecker/report errors and events] menu items are in the selected status. Only when these two items are selected will the boundschecker play a role in the running process.

Finally, select the [Build/start debug/go] menu command in the integrated development environment of VC ++, run the program in the debug state, and activecheck starts running in the background.

In this case, you can operate the program according to the developed test cases. Any program that has been executedCodeIf an error exists, activecheck records the error.

There is a [report errors immediately] in the [boundschecker] menu, as shown in:


Figure 3-2 about[Boundschecker/report errors immediately] menu item

This menu itemActivecheck mode, and the finalcheck mode described below have the same effect: If this option is not selected, the boundschecker records various errors found during the program running, the report will be reported after the program ends. When this menu item is selected, the following dialog box will pop up immediately when the boundschecker finds an error during the program running:


 

Figure 3-3 Error Report Dialog Box

The buttons in the dialog box are described as follows:

Button1: ClickIf this button is used, the program will be executed temporarily.

Button 2:ClickThis button will jump to the problematic code line immediately. After the problem is solved, click[Build/start debug/go] menu item,You can continue to execute the program for detection.

Button 3:ClickThis button adds the error to the ignored Error List. When this problem occurs again,Boundschecker will not report.

Button 4:ClickTo terminate the program execution immediately.

Button 5:ClickThis button will display the current memory application and usage.

Button 6:ClickThis button will get the help information for the current error.

Buttons 7 and 8: The two buttons and [Boundschecker \ report errors immediately] And [Boundschecker \ report errors and event] Menu commands have the same functions,I will not go into details here.

Button 9:ClickThis button will show/hide the function call stack related to the error and the location of the specific error code line.

Whether to select the [boundschecker/report errors immediately] menu item depends on your own preferences and the specific conditions during the test. If you wantBoundschecker reports errors to you during the program running in real time. You can select this menu item. If you want to wait until the operation is complete, in addition, you do not have to select this menu item if you analyze the errors detected by the boundschecker during the operation. In general, I prefer the latter one.

3.1.2 Analysis Error

After you finish all the operations and exit the program,

The boundschecker displays a list of detected errors. We need to analyze the errors listed in the List to determine the cause and location of the errors.

In the error detection result list, all memory leaks, resource leaks, and API function usage errors detected by activecheck during program execution are listed. As shown in:

 


 

Figure 3-4Error Detection Result

In the left-side window, the program's memory, resources, and API function usage problems are listed one by one, including: the type of the problem, the number of times the problem occurs, and if the problem is caused by memory leakage, how much memory is lost and the code location where the problem occurs. When you click and select a record, the function call stack corresponding to the error record is displayed in the window on the right. When you double-click an error record with the mouse,Source code.

Now, how to use boundschecker in activecheck mode is complete. Is it easy?

When detecting a program in activecheck mode, the running speed of the program is basically not affected, but the disadvantage is that the types of errors detected are limited, that is, onlyMemory leakage error, resource leakage error, and API function usage error.Boundschecker provides another mode for detecting errors-finalcheck, that is, the second mode of boundschecker we mentioned earlier. Finalcheck can detect more errors in the program. Next we will introduce it.

3.2 use finalcheck to detect more errors

Finalcheck hasAll error checking functions provided by boundschecker.Finalcheck is a superset of activecheck. In addition to detecting errors that can be detected by activecheck, it can also discover many errors that cannot be detected by activecheck, including:Pointer operation errors, memory overflow, use of uninitialized memory, and so on.Activecheck can detect errors. finalcheck can provide more detailed information about errors. Therefore, we can regard finalcheck as the enhanced feature version of activecheck. The price we pay is that the program runs slowly, sometimes even slowly.

To test a program in finalcheck mode, you must use the compile connector provided by the integrated development environment of VC ++ to construct the program. Instead, you must use the compile connector provided by boundschecker to compile the Connection Program. When the boundschecker compilation connector compiles the Connection Program, it inserts some error detection code into the program, which is the reason why finalcheck can find more errors than activecheck.

Next

This section describes how to test a program in finalcheck mode:

1. Open the project you want to test in the VC ++ integrated development environment.

2. To use the compilation connector of boundschecker to re-compile the Connection Program, we construct a folder for boundschecker. In the integrated development environment of VC ++, the specific operation method is as follows:

A) Click the [Build/deployments...] menu command.

B) Click the Add button in the pop-up dialog box. Add the name of the folder you created for the boundschecker in the configuration editing box. This name is arbitrary. For example, we can name it boundchecker.

C) In the copy settings from combo box, select XXX-Win32 debug itemClick OK, and then click Close.

Now, we have constructed a folder for finalcheck.

3. Click [Build/set Active configuration…]. Menu command, select the folder you just created for boundschecker, and click OK. In this way, the intermediate files and executable programs generated when the boundschecker compiles the Connection Program will be put in this folder.

4. Select the [boundschecker/rebuild all with boundschecker] menu command to recompile and connect the program. That is, the boundschecker adds an error detection code to the code of the program under test. After the compilation connection is complete, the boundschecker will generate an executable file in the folder you constructed for the boundschecker.

In finalcheck mode, all the preparations for detecting the program are ready. At this time, you can start the program to start testing,

ProcedureThere is no difference in activechecker mode. DetailsThe procedure is as follows:

  1. Make sure that the [boundschecker/Integrated debugging] menu items and [boundschecker/report errors and events] menu items are selected in the VC ++ integrated development environment.
  2. Click[Build \ Start debug] menu, and select the "go" menu item. The program starts to run in the debug state.
  3. Operate the program according to the test cases you have developed.
  4. WhenWhen the boundschecker detects an error, a window will pop up to report it to you. You can handle it at that time, or wait until all your operations are completed, after exiting the program, analyze the listed errors. It depends entirely on whether you have selected[Boundschecker/report errors immediately] menu item.
  5. After exiting the program,BoundscheckerThe error detection result list is displayed. The error list is the same as that shown in activechecker. However, the information reported in this list is more and more detailed.

okay, boundschecker the finalcheck mode is also described. activechecker, the finalcheck modes have different lengths in comparison. activechecker is easy to use. You only need to run the program directly in the debug state, and the program runs quickly, but the types of detected errors are limited. In finalcheck mode, you must use the compilation connector of boundschecker to re-compile the connection to generate executable programs, and the program runs slowly, however, more error types and error-related information are provided than activechecker. Therefore, when to use the mode should be determined based on the specific circumstances at that time.

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.