📄 ape.htm
字号:
<TD ALIGN="LEFT">Default level (all reasonable warnings) </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Level 4 </TD> <TD ALIGN="LEFT">Very sensitive (good for perfectionists) </TD> </TR></TABLE><H3><A NAME="Heading4"></A>Table E.2. Debug info settings.</H3><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Setting</I></TD> <TD ALIGN="LEFT"><I>Debugging Information Generated</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">None </TD> <TD ALIGN="LEFT">Produces no debugging information--usually reserved for Release modes. </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Line Numbers Only </TD> <TD ALIGN="LEFT">This generates only line numbers that refer to the source code for functions and global variables. However, compile time and executable size are reduced. </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">C 7.0-Compatible </TD> <TD ALIGN="LEFT">This generates debugging information that is compatible with Microsoft C 7.0. It places all the debugging information into the executable files and increases their size, but allows full symbolic debugging. </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Program Database </TD> <TD ALIGN="LEFT">This setting produces a file with a .pdb extension that holds the maximum level of debugging information, but doesn't create the Edit and Continue information. </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Program Database for Edit and Continue </TD> <TD ALIGN="LEFT">This is the default and usual debug setting. It produces a .pdb file with the highest level of debugging and creates the information required for the new Edit and Continue feature. </TD> </TR></TABLE><H3><A NAME="Heading5"></A>Creating and Using Browse Information</H3><P>You can use the Source Browser tool to inspect your source code in detail. Thistool can be invaluable if you are examining someone else's code or coming back toyour own code after you haven't viewed it for awhile.</P><P>To use the Source Browser, you must compile the application with the GenerateBrowse Info setting checked, in the C/C++ tab of the Project Settings dialog box.To run the tool, press Alt+F12 or click the Tools menu and select the Source Browseroption. (The first time you run the tool, it will ask you to compile the browserinformation.)</P><P>The first dialog box the Source Browser presents requests an Identifier to browsefor (as shown in Figure E.2). This identifier can be a class name, structure name,function name, or global or local variable name in your application. After you haveentered an identifier, the OK button is enabled, and you can browse for details aboutthat identifier.</P><P><A HREF="javascript:popUp('30fig02.gif')"><B>FIGURE E.2.</B></A><B> </B><I>TheBrowse dialog box requesting a symbol to browse.</I></P><P>Select Query offers various options for details pertaining to your chosen symbol.You can choose from any of the following:</P><P><UL> <LI>Definitions and References. This option shows you all the files that have refer-ences to the specified identifier and whether they are references to the identifier (places where it is used in the code) or definitions (places where the identifier is defined), as shown in Figure E.3. The line numbers are listed along with the filenames in each file. By double-clicking one of the references or definitions, the code to which it refers will be loaded and shown in the Developer Studio editor at that specific position. This is very useful for tracking all the places that a specific variable or function is used.</UL><P><A HREF="javascript:popUp('30fig03.gif')"><B>FIGURE E.3.</B></A><B> </B><I>SourceBrowser showing definitions and references.</I></P><P><I></I><UL> <LI>File Outline. This option shows you all the classes, data, functions, macros, and types that are defined in the specified filename (identifier), as shown in Figure E.4. You can filter each type in or out by pressing relevant buttons along the top of the browser window.</UL><P><A HREF="javascript:popUp('30fig04.gif')"><B>FIGURE E.4.</B></A><B> </B><I>Thefile outline display of the source browser.</I></P><P><I></I><UL> <LI>Base Classes and Members. This arguably is one of the most useful options of the source browser. By specifying a class as the identifier, all the classes' hierarchy and member functions and variables at each hierarchy level are displayed (see Figure E.5). You can also set the filter options to show only certain types of member functions and variables.</UL><P><A HREF="javascript:popUp('30fig05.gif')"><B>FIGURE E.5.</B></A><B> </B><I>TheBase Classes and Members view of the source browser.</I></P><P><I></I><UL> <LI>Derived Classes and Members. This view is also very useful and shows all the classes that are derived from the specified class, along with their own member functions and variables. You can also use the browser with the MFC classes to gain more insight into the MFC implementation, as shown with the MFC CWnd class in Figure E.6.</UL><P><A HREF="javascript:popUp('30fig06.gif')"><B>FIGURE E.6.</B></A><B> </B><I>TheDerived Classes and Members view of the Source Browser showing CWnd-derived classes.</I></P><P><I></I><UL> <LI>Call Graph. The Call Graph option shows you all the functions that are called by a specified identifier and the files in which they are defined and implemented. This lets you quickly track the potential flow of a program. <P> <LI>Callers Graph. The corresponding Callers Graph option shows you all the functions that call the specified identifier. You can use this to track the possible callers of your specified function.</UL><H3><A NAME="Heading6"></A>Using Remote and Just-in-Time Debugging</H3><P>The debugger includes tools that let you debug a program running on a remote machine(even over the Internet via TCP/IP). This can be useful if you want to test yourapplication in a different environment other than your development machine. To dothis, you must have exactly the same versions of the .dll and .exe files on bothmachines. After loading the project, you can debug it via a shared directory fromthe remote machine by changing the Executable for Debug Session edit box to the pathand filename of your local .exe file (located in the Project Settings dialog boxunder the Debug tab).</P><P>You must also add a path to the .exe file in the Remote Executable Path and FileName edit box at the bottom of the Debug tab, leaving the Working Directory blank.You can then start the remote debugger monitor on the remote computer by runningthe MSVCMON.EXE program and connecting to it by clicking the Build menu and selectingthe Debugger Remote Connection option.</P><P>From the Remote Connection dialog box you can choose Local for a shared directorydebug session or Remote to debug via a TCP/IP connection. (You can set the addressby clicking Settings.) This will connect to the remote monitor that will start theremote debugging session.</P><H3><A NAME="Heading7"></A>Installing the Remote Debugger Files</H3><P>You will also need the following files to run the remote debugger monitor on theremote machine: MSVCMON.EXE, MSVCRT.DLL, TLN0T.DLL, DM.DLL, MSVCP5O.DLL, and MSDIS100.DLL.These files can be found in your installed ...\Microsoft Visual Studio\Common\MSDev98\binsubdirectory.</P><P>Just-in-time debugging lets you debug a program that was run normally (not throughthe debugger) and then developed a problem. If you have Visual C++ installed on amachine and this option is enabled, any program that develops a fault will be loadedinto a new Developer Studio session ready for debugging and show the code that causedthe crash.</P><P>This often raises a chuckle when Developer Studio itself crashes and then proceedsto load another session of itself, offering you an assembly code view of where thecrash took place in the original for you to debug. It can be very useful to debugyour own applications when they crash unexpectedly (usually in a demonstration toyour boss). You can enable this option by clicking the Tools menu and selecting Optionsto display the Options dialog box. Then select the Debug tab and ensure that theJust-in-Time debugging check box is checked.</P><P>The OLE RPC debugging option on this tab is also very useful when developing COMand DCOM applications because it lets the debugger traverse a function call intoanother out-of-process program or .dll and lets another debugger take over for theother process. It then hands control back when returning from the remote functionand works across networks and different computers.</P><P><H2><A NAME="Heading8"></A>Tracing and Single Stepping</H2><P>One of the most useful features of the Visual C++ debugging environment is theinteractive single stepping. This feature lets you step through the code one lineat a time and examine the contents of variables as you go. You can also set breakpointsso that the program runs until it reaches a breakpoint and then stops at that point,letting you step from that point until you want to continue running.</P><P>Trace statements and assertions are also very useful tools for finding programfaults. Trace statements let you display messages and variables from your programin the output window as it runs through trace statements. You can use assertionsto cause the program to stop if a condition isn't TRUE when you assert that it shouldbe.</P><P><H3><A NAME="Heading9"></A>Using the TRACE Macro</H3><P>You can add TRACE macros to your program at various places to indicate that variousparts of the code have been run or to display the contents of variables at thosepositions. The TRACE macros are compiled into your code in the debug configurationand displayed in the Output window on the Debug tab, when you run your program throughthe debugger.</P><P>You can safely leave in the TRACE macros when you perform a release build becausethese macros are automatically excluded from the destination object.</P><P>You can display simple messages or output variable contents by passing a formatstring as the first parameter to the TRACE macro. This format string is exactly thesame as you would pass to a printf() or CString::Format() function. You can specifyvarious special formatting codes such as %d to display a number in decimal, %x todisplay a number in hexadecimal, or %s to display a string. The following parametersshould then correspond to the order of the formatting codes. For example, the code</P><P><PRE>int nMyNum = 60;char* szMyString = "This is my String";TRACE("Number = %d, or %x in hex and my string is: %s\n", nMyNum, szMyString);</PRE><P>will result in this output trace line:</P><P><PRE>Number = 60, or 3c in hex and my string is ÂThis is my String</PRE><P>Listing E.1 shows the TRACE macro used to display the contents of an array beforeand after sorting by a very inefficient but simple sort algorithm.</P><P>If you want to try the code shown in Listing E.1, you can use the AppWizard tobuild a simple SDI framework. Simply add the code above the OnNewDocument() memberfunction of your document class and then call it by adding a DoSort() call into yourOnNewDocument() function.</P><P>You can run the application through the debugger (click Build, select Start Debug,and choose Go from the pop-up menu) to see the output trace.</P><P>You must ensure that the output window is visible (click the View menu and selectOutput) when the tabbed output window is shown (same as the compiler output). Ensurethat the Debug tab is selected.</P><P><H4>LISTING E.1. LSTE_1.CPP--A SIMPLE SORT ROUTINE TO DEMONSTRATE DEBUGGINGTECHNIQUES.</H4><PRE>1: void Swap(CUIntArray* pdwNumbers,int i)2: {3: UINT uVal = pdwNumbers->GetAt(i);4: pdwNumbers->SetAt(i, pdwNumbers->GetAt(i+1));5: pdwNumbers->SetAt(i+1,uVal);6: }7:8: void DoSort()9: {10: CUIntArray arNumbers;11: for(int i=0;i<10;i++) arNumbers.Add(1+rand()%100);12:13: TRACE("Before Sort\n");14: for(i=0;i<arNumbers.GetSize();i++)15: TRACE("[%d] = %d\n",i+1,arNumbers[i]);16: 17: BOOL bSorted;18: do19: {20: bSorted = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -