in many cases, the debug version of the Program runs normally. However, once the release version is released, an error occurs, it is depressing. As you know, the release version in VC ++ cannot debug the Source Code . The general practice is to insert the MessageBox function before and after the Code that is suspected to have an error, and display the variable values that may cause the error in the function. Or insert the statement to write the file, and output the variable values that may cause errors to a record file. In fact, in addition to the above method, there are other ways to debug the release version. The following describes two methods for debugging the release version based on your experience and online search materials:
Method 1: debug the release version using the *. PDB symbol file.
There is a reference in the online magazine of vckbase.Article: Symbol file -- Windows application debugging essential (http://www.vckbase.com/document/viewdoc? Id = 1710). This article describes how to generate the PDB file corresponding to the release binary file. With the PDB file, you can debug the release:
1. In Project Settings, select settings for all deployments.
2. In the C/C ++ label, debug info selects program database.
3. In the link label, select debug for category and check the debug info check box and Microsoft format.
After the above settings, we can set the breakpoint for testing as in the debugging version. Due to code optimization, some variables cannot be observed, and the running sequence of the rows may be different.
Note that the assert macro does not work in the release version. In the release version, verify should be used instead of assert for debugging. If there is a problem with running the release version, you can disable all code optimization before debugging.
Method 2: Add the following Assembly statement where a breakpoint needs to be added:
_ Asm int 3
However, the C program cannot be displayed during debugging. Only the ASM code is displayed.
INT 3 is used to set breakpoints, which is defined by the CPU. Most debuggers in windows and DOS use this method.
Articles on related topics can also be found on the Internet, but some details are always unclear. For more information, see the following.
First, the complete release version (VC default) cannot be used for source code-level debugging, even if the PDB file is copied from other places.
If you want to debug the source code, you need to build some debugging information into the DLL/EXE/OCX when generating the release version (DLL, EXE, OCX, compile the program to generate the corresponding PDB file to save detailed debugging information. With such EXE/DLL, PDB, and source files, you can debug the program. The procedure is as follows:
1. Control the compilation process. VC-> Project Settings-> C/C ++ tab, general category, debug info combo box, select program database. this setting will add the/Zi switch to your compiles. do not select program database for edit and continue (/Zi), which is generally unavailable. In addition, the/z7 option can also be used. The difference between it and/Zi is that/z7Generate debugging information in codeview format and save it in the OBJ file;/Zi generate debugging information in the program database format and save it in the. PDB file.
2. Control the link process. VC-> Project Settings-> link tab, general category, check Generate debug info. this setting turns on the/debug switch to the linker. as optional, you can also type/OPT: ref in the Link option. This option tells the linker not to generate debugging information for functions that are not called. but in fact this option is not necessary, because for DLL, we cannot know which will be called during the link. in addition, even if this option is not added, the compiled EXE/DLL is only larger, which is not a problem in general.
With debugging information, the main difference between the release version and the debug version is whether it has been optimized. due to optimization, the source code cannot be in the current execution status during debugging of the release version, but it is always better than that without debugging. for a commercial application, especially when a problem occurs on the client side, debugging is required on the client side. In particular, the release version also contains debugging information. the cost for debugging convenience is that the generated EXE/DLL is large, and this price is worthwhile. debugging is required. Copy the PDB file and source code to get started.