Debug multiple C Projects in

Source: Internet
Author: User

I. Differences between the debug version and the release version

Debug is usually called a debug version. It contains debugging information and is not optimized.ProgramDebugging program. Release is called a release version. It is often optimized to make the programCodeBoth the size and running speed are optimal, so that users can use them 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, the default option "Yes (/Incremental)" is "Project Properties", "configuration properties", "linker", and "enable incremental link )".

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.

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 property configuration property "is" yes "(/debug) is selected by default) by default, ". \ 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 symbol files-Windows application debugging prerequisites.

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. Joint debugging 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) "Generate debug info is selected by default. In the corresponding vc2005, the default option" Yes (/debug) "is" Project Properties "," configuration properties "," linker ", and" debugging information generated )".

*. OBJ and *. Lib files

OBJ: intermediate file. The binary code format corresponding to CPP is not relocated!

Lib: object file library, a collection of several obj. It is 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.

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 console application) 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, fill in the EXE path in "executable for debug session" in "project setting à debug (Category: General)", for example, D: \ libdemo \ mylibdemo \ debug \ mylibdemo.exe. In the corresponding vc2005, fill in the EXE path in "project property configuration property debugging command.

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.

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 of mydlldemo to .. \ 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 as the startup project, you need to configure the external EXE Caller:

In vc6, fill in the EXE path in "executable for debug session" in "project setting à debug (Category: General)", for example, D: \ dlldemo \ mydlldemo \ debug \ mydlldemo.exe. In the corresponding vc2005, fill in the EXE path in "project property configuration property debugging command.

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.

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 "project setting à post-built step" in vc6 or in vc2005, "Project property à configuration property à generate event", enter the post-production command: Copy. \ debug \ mydll. DLL .. \ mydlldemo \ debug \ mydll. DLL. Of course, you can direct the output directory of mylib (mydll) to the DEBUG directory of mylibdemo (mydlldemo.

Iv. VC debugging Summary

We set a breakpoint at the printf function call in vc2005. F11 will open the source code file c: \ Program Files \ Microsoft Visual Studio 8 \ Vc \ CRT \ SRC \ printf of the printf function. c enters the printf function. In fact, "Tool & Option & Solution & VC ++ directory & file" contains the CRTSource codePath: $ (vcinstalldir) CRT \ SRC.

In vc6, c: \ Program Files \ 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.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/phunxm/archive/2010/01/17/5203931.aspx

Related Article

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.