I. Differences between the debug version and the release version
Debug is usually called a debug version. It contains debugging information without any optimization, so that programmers can debug programs easily. Release is called a release version. It is often optimized to optimize the code size and running speed, so that users can use it well.
Only debug programs can set breakpoint, single-step execution, and debug output statements using trace/assert. The release version does not contain any debugging information, so it is small in size and runs fast.
Generally, the debug version is more *. ilk and *. PDB files than the release version.
1. *. ilk File
All ilk suffixes are called "incremental linking", meaning incremental links.
In vc6, the "Project setting-> Link (Category: General)" check "link incrementally" by default. In the corresponding vc2005, "project properties-> Configuration properties-> linker-> General-> enable incremental link" the default option is "Yes (/Incremental )".
When the incremental compilation link is selected, the linker automatically generates the ilk file to record the link information, that is, each re-compilation does not compile all the source files, only compile the modified files. But how does the compiler know which ones have been compiled and not compiled? Besides checking the modification time, this ilk file is also very important information.
In vs2005, the breakpoint is changed to an exclamation point circle. If the prompt "the breakpoint is not hit currently. The executable code has not been loaded at this location. "The/Zi switch that generates debugging information may not be enabled. Select "program database (/Zi)" in "Project Properties> Configuration Properties> C/C ++> General> debugging information format )". Select "Yes (/debug)" in "Project Properties"> "configuration properties"> "linker"> "debug"> "generate debugging information )". If the message "the current breakpoint is not hit, the source code is different from the original version .", In tool> Options> debugging, remove the check box before "requires matching the source file with the original version" and delete the DEBUG directory to generate a solution.
/C7 |
C 7.0-compatible |
The target file or executable file contains the line number and all symbol debugging information, including the variable name and type, function and prototype. |
/Zi |
Program database |
Create a library (PDB), including type information and symbol debugging information. |
The breakpoint set in a source file is always invalid, prompting "the current breakpoint is not hit. The source code is different from the original version. Clearing the project, re-editing the project, and re-copying the original file will not solve the problem. "Tools-> options-> debugging" removes the check box before "requires matching of source files and original versions.
Reference: vs2005 does not hit breakpoints currently, and no symbols have been loaded for this document
2. *. PDB File
The PDB suffix is called "program debug Database", meaning the program database file.
In vc6, the "Project setting-> Link (Category: General)" check "Generate debug info" and "project setting-> Link (Category: mimize)" by default) "Use Program database is selected by default. In the corresponding vc2005," Project properties-> Configuration properties-> linker-> debugging ", the default "generate debugging information" option is "Yes (/debug)", and the default "generate program database file" field is ". \ debug \*. PDB ". The compilation switch corresponding to this option is/PDB.
A symbolic file is a data information file that contains debugging information for application binary files (such as EXE and DLL). It is used for debugging, the final executable file does not need this symbol file at runtime, but all the variable information in your program is recorded in this file. Therefore, this file is very important when you debug the application. This file is used when debugging programs using VC and windbg.
For more information about symbol files, see PDB files (C ++), symbol files-Windows
Essential for application debugging.
Ii. Common VC debugging operations
Shortcut Key |
Function |
F5 |
Start debugging and breakpoint-based debugging |
F9 |
Set (cancel) breakpoint |
CTRL + F10 |
Debug to the cursor location |
F10 |
One-step debugging, skipped when a sub-function is encountered |
F11 |
One-step debugging, when a sub-function tracking enters the internal |
Shift + F11 |
Jump out of the current function |
Shift + F5 |
Stop debugging |
Generally, F9 sets a breakpoint. After F5 is started, F11, F11, and shift + F11 are used in turn to debug multiple breakpoints.
Iii. Source Code tracking and debugging
We set a breakpoint at the printf function call in vc2005. F11 will open the source code file c: \ ProgramFiles \ Microsoft Visual Studio 8 \ Vc \ CRT \ SRC \ printf of the printf function. c enters the printf function. In fact, "tool-> Option-> project and solution-> VC ++ directory-> source file" contains the CRT source code path: $ (vcinstalldir) CRT \ SRC.
In vc6, c: \ ProgramFiles \ Microsoft Visual Studio \ vc98 \ CRT \ SRC does not exist, so the "Find source" dialog box will pop up when you try to enter the printf of F11, the prompt "Please enter the path for printf. c.
When debugging VC, the compiler can trace the C library function because the compiler itself provides the debug version of the CRT library.
The MSVCRTD.DLL-MSVCRTD.LIB-MSVCRTD.PDB in vc6 (corresponding to msvcr80d. dll-msvcrtd.lib in vc2005) is the debug version of C Runtime Library, which contains the debugging information of C Runtime Library.
The MSVCP60D.DLL-MSVCPRTD.LIB-MSVCP60D.PDB in vc6 (corresponding to msvcp80d. dll-msvcprtd. Lib in vc2005) is the debug version of C ++ Runtime Library, which contains the debugging information of C ++ Runtime Library.
In view of the debugging information record of the debug version and the DLL-> lib (*. OBJ ,*. lib)-> SRC (*. C ,*. in VC, we can set the breakpoint tracking and debugging code.
Iv. Disassembly
In vc2005, "file properties-> C/C ++-> output file-> Assembly output" is "no list" by default. The options are as follows:
(1) "only list the Assembly (/FA) ": Generate fa. ASM with a line number without source code.
(2) "assembly with source code (/Fas) ": Generate Fas. ASM with line numbers and source code.
(3) "assembly with machine code (/Fac) ": Generate FAC. COD, and list the machine code based on fa. ASM.
(4) "assembly, machine code, and source code (/FACS) ": Generate FACS. COD, and list the source code based on FAC. COD.
In the debug status, "debug-> window-> disassembly (Alt + 8)", where "Alt + 8" disassembly shows the/Fas result. During the debugging process, you can call out the "Alt + 5" register window to view the data registers (eax/EBX/ECx/EDX) and address change registers (ESI/EDI) real-time status values of control registers (EFL/EIP) and pointer registers (ESP/EBP.
You can enter"Cl/?" View the "-output files-" section in the help documentation. For details, see the description in msdn:/FA,/FA (listingfile),/FA,/FA (list file).
5. Joint debugging of the Link Library (Lib, DLL) project and application (exe) project
For a Linked Library Project, you must import a test program that can call it to debug the project.
For debugging purposes, of course, the static or dynamic link library project should generate a debug version with debugging information. In vc6, "Project setting-> Link (Category: General)" is checked by default by "generate
Debug info. the default option "Yes (/debug)" is "Project Properties"> "configuration properties"> "linker"> "debugging"> "generate debugging information" in the corresponding vc2005 )".
1. *. OBJ file and *. Lib File
OBJ: Intermediate file. The binary code format corresponding to CPP is not relocated!
Lib: Object file library, a collection of several OBJ, essentially the same as OBJ!
In use, there is no essential difference between OBJ and Lib. Lib is obj. You can use OBJ wherever you use Lib.
For static variables or functions in the *. cpp file, both symbolic information and entity definitions are available in *. OBJ or *. Lib.
For *. the extern variable or function in the CPP file, in *. OBJ or *. lib usually contains symbolic information. objects can be defined in this file or in other files. For extern variables or functions, objects are searched in all *. OBJ or *. Lib links.
2. Coordinate lib and exe
Create Solution d: \ libdemo (. DSW ,. SLN), under which to create a static library (Win32 static library) Project mylib (. DSP ,. vcproj) and static library test project (Win32
Consoleapplication) mylibdemo (. DSP,. vcproj ). First, you must add header file inclusion and link library inclusion for the mylibdemo project.
(1) If you set mylibdemo as the startup project and run the F5 debugging command, the breakpoint in mylib and mylibdemo will be paused. In mylibdemo, F11 can be used to enter the function definition in mylib.
(2) If you set mylib as the startup project, configure the external EXE Caller:
In vc6, set "executable for debugsession" in "project setting-> debug (Category: General)" to the EXE path, for example, D: \ libdemo \ mylibdemo \ debug \ mylibdemo.exe. In the corresponding vc2005, enter the EXE path in "project properties-> Configuration properties-> debugging-> commands.
If you run the F5 debugging command, the breakpoint in mylib and mylibdemo will be paused. The effect is the same as (1 ).
For lib projects and exe projects under different solutions (. DSW,. sln), the collaborative debugging method is the same as above.
3. Coordinate DLL and exe
DLL projects usually generate a corresponding Lib, which is the DLL export function and symbolic link information. It is a little different from the Lib generated by the Lib project. Only the prototype information is available here, and the entity code is in the DLL. DLL is a binary code that can be run, including the locating code.
Create Solution d: \ dlldemo (. DSW ,. SLN), under which the new dynamic library (Win32 dynamic-Link Library) Project mydll (. DSP ,. vcproj) and dynamic library test project (Win32
Console Application) mydlldemo (. DSP,. vcproj ).
Like lib and exe coordination, you must first include the header file (. h) and the Link Library (. Lib) for the EXE project.
(1) If mydlldemo is set as the startup project, in order to make mydll. dll visible to the debug EXE, set the debug working directory (Working
Directory) is .. \ mydll \ debug.
If you run the F5 debugging command, the breakpoint in mydll and mydlldemo will be paused. In mydlldemo, F11 can be used to enter the function definition in mydll.
(2) If you set mydll to a startup project (for example, Def explicit dynamic link library debugging), configure the external EXE Caller:
In vc6, set "executable for debugsession" in "project setting-> debug (Category: General)" to the EXE path, for example, D: \ dlldemo \ mydlldemo \ debug \ mydlldemo.exe. In the corresponding vc2005, enter the EXE path in "project properties-> Configuration properties-> debugging-> commands.
To make mydll. dll visible to the debug EXE, set the working directory to. \ debug.
If you run the F5 debugging command, the breakpoint in mydll and mydlldemo will be paused. The effect is the same as (1 ).
For DLL projects and exe projects under different solutions (. DSW,. sln), the collaborative debugging method is the same as above.
4. event processing after generation
In (1) and (2), in addition to specifying the debugging working directory, you can also process post-generated events and copy the generated link library file directly to the application DEBUG directory. Specifically, in vc6, "Project
Setting-> post-builtstep "or" project properties-> Configure properties-> Generate events-> Generate post-event "in vc2005, enter the post-generate processing command: Copy. \ debug \ mydll. DLL .. \ mydlldemo \ debug \ mydll. DLL (sometimes xcopy is required to automatically generate Directories ). Of course, you can direct the output directory of mylib (mydll) to the DEBUG directory of mylibdemo (mydlldemo.
Refer:
Visual c ++ 6.0 graphic debugging function tutorial