About how to use Codeguard in BCB
First, why writing this thing
I need to check a lot of things when using BCB5 to write some programs, such as memory leaks, resource is released, etc. After using a lot of tools, I found that the tools of BCB5 itself comes with --codeguard, very good, very convenient However, it took a long time (and overturned some information, including Help). The purpose of writing this article hopes that there is a friend of this issue can learn from each other, and everyone will learn together and make progress together. My contact method: email: szbug@szbug.com, I hope that the like-minded friend will communicate with each other. The following article is a piece of article that is patching, some information is found on the book, some are seen on Help.
Second, what is codeguard
CodeGuard is a tool that appears in C Builder5. CodeGuard is a program in C Builder in runtime inspector for checking memory or resource usage, and verification of function calls.
CodeGuard can detect the following program running period error:
l illegal memory release.
l Invalid handle or file stream.
l illegally pointed.
l Use the pointer that has been released.
l Memory leakage.
l Assign but finally there is no memory variable.
l Pass the incorrect parameters of the function (including VCL and Win32 functions).
l Function Return the error. (Including VCL and Win32 functions).
For example, attempting to release the same resource multiple times in the application (or have released resources), trying to access memory that has been released.
Third, how to use codeguard in BCB5 - Configure Codeguard
If you want to use Codeguard, some code must be compiled into your application, so after changing the following settings. You must recompile all (remember to remember !!!). First, open the Codeguard page box of the application's engineering option, and tick the CodeGuard Validation in front of the project option, there are other three options. The first option allows the CodeGuard to check the invalid pointer and data overflow to the local, global and static variable. The second option allows CodeGuard to detect calls for methods of illegal (invalid, deleted) objects. The third option allows the CodeGuard to verify access to the inline pointer (in some information, open this option will cause the program execution speed to be very slow, I tested, if the project is not big, it is not very obvious, you can accept .) General debugging is to open all options (default selection is all open).
With the Codeguard configuration tool, you can configure some options for CodeGuard to perform CGConfig.exe in the command line. You can see a dialog
Preferences tab is used to set global options for CODEGUARD. Enable options can be used in the case where the application does not recompile or does not use Codeguard, which is generally enabled. If you use CODEGUARD, it is recommended to set the project option to disable or use Codeguard. The Stack Fill Frequency fill stack is to detect invalid access to the running stack. The Report and Error Message Box options are how to set up the Codeguard report error. In Report, the Stiatistics option opens the CODEGUARD output allocation and release memory statistics, the Win32API call, the usage of resources, and add a module list in the log file to check errors. The Resource Leaks option is to tell CodeGuard to report the resource leak after the application ends. After the Error Message Box option is selected, when the application is not running in the IDE, if the CodeGuard detects an error message, the user will tell the user using a dialog box. Other options are generally unused, you can see the online HELP of C Builder. The Resource Options and Function Options page in the CodeGuard Configuration Tool allows users to set various tracking options for the application's resources, files, and function calls. Unless special reasons need to change the default configuration, you will use the default settings. There is a relatively common option on the Function Options page that is a record of a specific function.
The Ignored Modules page box allows you to tell CodeGuard that some running periods can be ignored when detecting (some DLLs or packages) are ignored. This option is generally not commonly used.
Fourth, use codeguard
Using Codeguard is actually very simple, just configured CodeGuard as before, then runs your application, whether your application is running in the IDE, CodeGuard will monitor your application according to the options configured in the Codeguard. At the same time, he will also output all information in a log file (file storage in the directory of your project, the file name and engineering name, the extension is .cgl). For example, your project is called C: /word/test.prg, then the Codeguard log file is C: /word/test.cgl, which is a text file that can be edited with any text editor.
In the IDE, you can view the codeguard log file (or use shortcut Ctrl ATL O) via