Podstrony
- Strona startowa
- VB.NET Module 4 Object Oriented Design for Visual Basic .NET
- eBook A Programmers Introduction To Visual Basic .NET.ShareReactor
- (ebook computers) Visual C .NET DeveloperÂ’s Guide
- Sams' Teach Yourself Linux In 24 Hours
- SAMS Teach Yourself PHP4 in 24 Hours
- Teach Yourself DirectX 7 in 24 Hours (2)
- Rice Anne Krzyk w niebiosa
- Philip K. Dick Czas poza czasem
- Microsoft Office 2003 Super Bible
- Rodrigues dos Santos Jose Kodeks 632
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- alpha1982.htw.pl
[ Pobierz całość w formacie PDF ]
.Trace statements let you display messages and variables from your program in the outputwindow as it runs through trace statements.You can use assertions to cause the programto stop if a condition isn t TRUE when you assert that it should be.Using the TRACE MacroYou 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 those positions.The TRACE macros are compiled into your code in the debug configuration and displayedin the Output window on the Debug tab, when you run your program through thedebugger.You can safely leave in the TRACE macros when you perform a release build becauseEthese macros are automatically excluded from the destination object.You can display simple messages or output variable contents by passing a format stringas the first parameter to the TRACE macro.This format string is exactly the same as youwould pass to a printf() or CString::Format() function.You can specify various spe-cial formatting codes such as %d to display a number in decimal, %x to display a numberin hexadecimal, or %s to display a string.The following parameters should then corre-spond to the order of the formatting codes.For example, the codeint nMyNum = 60;char* szMyString = This is my String ;TRACE( Number = %d, or %x in hex and my string is: %s\n ,nMyNum, szMyString);will result in this output trace line:Number = 60, or 3c in hex and my string is¥'This is my String033 31240-9 APP E 4/27/00 1:11 PM Page 686686 Appendix EListing E.1 shows the TRACE macro used to display the contents of an array before andafter sorting by a very inefficient but simple sort algorithm.If you want to try the code shown in Listing E.1, you can use the AppWizard to build asimple SDI framework.Simply add the code above the OnNewDocument() member func-tion of your document class and then call it by adding a DoSort() call into yourOnNewDocument() function.You can run the application through the debugger (click Build, select Start Debug, andchoose Go from the pop-up menu) to see the output trace.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.LISTING E.1.LSTE_1.CPP A SIMPLE SORT ROUTINE TO DEMONSTRATE DEBUGGING TECHNIQUES.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 0);EYou are more likely to use VERIFY to check return codes from functions:VERIFY(MyFunc() != FALSE);Using Breakpoints and Single Stepping the ProgramThe use of single stepping and breakpoints is probably the most effective debugging toolfor tracking down the majority of problems.The support for various types of breakpointsand the single-stepping information available is very sophisticated in Visual C++; I canonly hope to give you a taste of the power of this debugging tool.The key to single stepping is breakpoints.You can set a breakpoint anywhere in yourcode and then run your program through the debugger.When the breakpoint is reached,the code will be displayed in the editor window at the breakpoint position, ready for youto single step or continue running.033 31240-9 APP E 4/27/00 1:11 PM Page 690690 Appendix EYou can add a breakpoint by selecting the specific code line (clicking the editor cursoronto the line in the editor window) and then either clicking the Breakpoint icon in theBuild minibar (see Figure E.8) or by pressing F9.Alternatively, most sophisticatedbreakpoints can be added or removed by clicking the Edit menu and selecting theBreakpoints option to display the Breakpoints dialog box (see Figure E.9).When youadd a breakpoint, it s displayed as a small red circle next to the line you have specified.Breakpoints can be set only against valid code lines, so sometimes the Developer Studiowill move one of your breakpoints to the closest valid code line for you.FIGURE E.8.Adding a breakpoint toyour code via the Buildminibar toolbar or theF9 key.FIGURE E.9.Adding a breakpointusing the Breakpointsdialog box.You can toggle the breakpoint on or off by clicking the Breakpoint (hand shaped) icon orremove it by clicking the Remove or Remove All buttons on the Breakpoints dialog box.You can leave them in position but disable them by clicking the check mark to the left ofeach breakpoint listed in the Breakpoints dialog box.Clicking there again will show thecheck and re-enable the breakpoint.When you have set your breakpoint(s), you can run the code through the debugger bychoosing Build, Start Debug, Go.Alternatively, you can use the shortcut by clicking theGo icon (to the left of the Breakpoint icon on the Build minibar toolbar refer to FigureE.8) or by pressing the F5 key.The program will run as normal until it reaches the breakpoint, where it will stop anddisplay an arrow against the line with the breakpoint.At that point, you can use theDebug toolbar to control the single stepping process, as shown in Figure E.10.033 31240-9 APP E 4/27/00 1:11 PM Page 691Using the Debugger and Profiler 691FIGURE E.10.The debugger stoppedat a breakpoint readyfor single steppingwith the Debugtoolbar.When stopped in the debugger, you can see the contents of most variables merely bymoving the cursor over them in the editor window.Their contents are then displayed in aToolTip at the cursor position.More detailed contents are shown by dragging the vari-ables into the Watch window, as discussed in detail in the next section.You can single step through the code using the four curly brace icons shown on theDebug toolbar or by clicking the Debug menu and choosing one of the step options.Theavailable step options are shown in Table E.4
[ Pobierz całość w formacie PDF ]