📄 ch10.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</head>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//--> </SCRIPT><link rel="stylesheet" href="/includes/stylesheets/ebooks.css"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"> <TITLE>Teach Yourself Borland Delphi 4 in 21 Days -- Ch 10 -- Debugging Your Applications</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"></H1></CENTER><CENTER><H1><BR>Teach Yourself Borland Delphi 4 in 21 Days</H1></CENTER><CENTER><P><A HREF="../ch09/ch09.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch11/ch11.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1>- 10 -</H1></CENTER><CENTER><H1>Debugging Your Applications</H1></CENTER><UL> <LI><A HREF="#Heading1">Why Use the Debugger?</A> <LI><A HREF="#Heading2">The Debugging Menu Items</A> <LI><A HREF="#Heading3">Using Breakpoints</A> <UL> <LI><A HREF="#Heading4">Setting and Clearing Breakpoints</A> <LI><A HREF="#Heading5">The Breakpoint List Window</A> <LI><A HREF="#Heading6">Simple Breakpoints</A> <LI><A HREF="#Heading7">Conditional Breakpoints</A> <LI><A HREF="#Heading8">The Run to Cursor Command</A> <LI><A HREF="#Heading9">Tooltip Expression Evaluation</A> <LI><A HREF="#Heading10">The Watch List Context Menu</A> </UL> <LI><A HREF="#Heading11">Using the Watch Properties Dialog Box</A> <UL> <LI><A HREF="#Heading12">Enabling and Disabling Watch Items</A> <LI><A HREF="#Heading13">Adding Variables to the Watch List</A> <LI><A HREF="#Heading14">Using the Watch List</A> </UL> <LI><A HREF="#Heading15">The Debug Inspector</A> <UL> <LI><A HREF="#Heading16">Debug Inspector Pages</A> <LI><A HREF="#Heading17">Debug Inspector Context Menus</A> </UL> <LI><A HREF="#Heading18">Other Debugging Tools</A> <UL> <LI><A HREF="#Heading19">The Evaluate/Modify Dialog Box</A> <LI><A HREF="#Heading20">The Call Stack Window</A> <LI><A HREF="#Heading21">The CPU Window</A> <LI><A HREF="#Heading22">The Go to Address Command</A> </UL> <LI><A HREF="#Heading23">Stepping Through Your Code</A> <UL> <LI><A HREF="#Heading24">Debugging Gutter Symbols</A> <LI><A HREF="#Heading25">Step Over and Trace Into</A> </UL> <LI><A HREF="#Heading26">Debugging a DLL</A> <LI><A HREF="#Heading27">The Event Log Window</A> <LI><A HREF="#Heading28">The Module Window</A> <LI><A HREF="#Heading29">Debugging Techniques</A> <UL> <LI><A HREF="#Heading30">The OutputDebugString Function</A> <LI><A HREF="#Heading31">Tracking Down Access Violations</A> <LI><A HREF="#Heading32">Debug Quick Tips</A> </UL> <LI><A HREF="#Heading33">Debugger Options</A> <UL> <LI><A HREF="#Heading34">The General Page</A> <LI><A HREF="#Heading35">The Event Log Page</A> <LI><A HREF="#Heading36">The Language Exceptions Page</A> <LI><A HREF="#Heading37">The OS Exceptions Page</A> </UL> <LI><A HREF="#Heading38">Summary</A> <LI><A HREF="#Heading39">Workshop</A> <UL> <LI><A HREF="#Heading40">Q&A</A> <LI><A HREF="#Heading41">Quiz</A> <LI><A HREF="#Heading42">Exercises</A> </UL></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>A major feature of the Delphi IDE is the integrated debugger. The debugger enablesyou to easily set breakpoints, watch variables, inspect objects, and do much more.Using the debugger, you can quickly find out what is happening (or not happening)with your program as it runs. A good debugger is vital to efficient program development.</P><P>Debugging is easy to overlook. Don't tell anyone, but when I first started Windowsprogramming, I ignored the debugger for a long time because I had my hands full justlearning how to do Windows programming. When I found out how valuable a good debuggeris, I felt a little silly for cheating myself out of the use of that tool for solong. Oh well, live and learn. You have the luxury of learning from my mistakes.Today, you learn about what the debugger can do for you.</P><P>The IDE debugger provides several features and tools to help you in your debuggingchores. The following are discussed today:</P><UL> <LI>Debugger menu items <P> <LI>Using breakpoints <P> <LI>Inspecting variables with the Watch List <P> <LI>Inspecting objects with the Debug Inspector <P> <LI>Other debugging tools <P> <LI>Stepping through code <P> <LI>Debugging techniques</UL><H2><A NAME="Heading1"></A>Why Use the Debugger?</H2><P>The quick answer is that the debugger helps you find bugs in your program. Butthe debugging process isn't just for finding and fixing bugs--it is a developmenttool as well. As important as debugging is, many programmers don't take the timeto learn how to use all the features of the IDE debugger. As a result, they costthemselves time and money, not to mention the frustration caused by a bug that isdifficult to find.</P><P>You begin a debugging session by starting up the program under the debugger. Youautomatically use the debugger when you click the Run button on the toolbar. Youcan also choose Run|Run from the main menu or press F9 on the keyboard.</P><P><H2><A NAME="Heading2"></A>The Debugging Menu Items</H2><P>Before getting into the details of the debugger, let's review the menu items thatpertain to the debugger. Some of these menu items are on the main menu under Run,and others are on the Code Editor context menu. Table 10.1 lists the Code Editorcontext menu items specific to the debugger along with their descriptions.</P><P><H4>TABLE 10.1. CODE EDITOR CONTEXT MENU DEBUGGING ITEMS.</H4><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Item</I></TD> <TD ALIGN="LEFT"><I>Shortcut</I></TD> <TD ALIGN="LEFT"><I>Description</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Toggle Breakpoint</TD> <TD ALIGN="LEFT">F5</TD> <TD ALIGN="LEFT">Toggles a breakpoint on or off for the current line in the Code Editor.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Run to Cursor</TD> <TD ALIGN="LEFT">F4</TD> <TD ALIGN="LEFT">Starts the program (if necessary) and runs it until the line in the editor window containing the cursor is reached.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Item</I></TD> <TD ALIGN="LEFT"><I>Shortcut</I></TD> <TD ALIGN="LEFT"><I>Description</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Inspect</TD> <TD ALIGN="LEFT">Alt+F5</TD> <TD ALIGN="LEFT">Opens the Debug Inspect window for the object under the cursor.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Goto Address</TD> <TD ALIGN="LEFT">Ctrl+Alt+G</TD> <TD ALIGN="LEFT">Enables you to specify an address in the program at which program execution will resume.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Evaluate/Modify</TD> <TD ALIGN="LEFT">Ctrl+F7</TD> <TD ALIGN="LEFT">Enables you to view and/or modify a variable at runtime.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Add Watch at Cursor</TD> <TD ALIGN="LEFT">Ctrl+F5</TD> <TD ALIGN="LEFT">Adds the variable under the cursor to the Watch List.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">View CPU</TD> <TD ALIGN="LEFT">Ctrl+Alt+C</TD> <TD ALIGN="LEFT">Displays the CPU window.</TD> </TR></TABLE></P><P>The Run item on the main menu has several selections that pertain to running programsunder the debugger. The Run menu items enable you to start a program under the debugger,to terminate a program running under the debugger, and to specify command-line parametersfor your program, to name just a few functions. Some items found here are duplicatedon the Code Editor context menu. Table 10.2 shows the Run menu items that controldebugging operations.</P><P><H4>TABLE 10.2. THE RUN MENU'S DEBUGGING ITEMS.</H4><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Item</I></TD> <TD ALIGN="LEFT"><I>Shortcut</I></TD> <TD ALIGN="LEFT"><I>Description</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Run</TD> <TD ALIGN="LEFT">F9</TD> <TD ALIGN="LEFT">Compiles the program (if needed) and then runs the program under the control of the IDE debugger. Same as the Run toolbar button.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Parameters</TD> <TD ALIGN="LEFT">None</TD> <TD ALIGN="LEFT">Enables you to enter command-line parameters for your program and to assign a host application when debugging a DLL.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Step Over</TD> <TD ALIGN="LEFT">F8</TD> <TD ALIGN="LEFT">Executes the source code line at the execution point and pauses at the next source code line.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Trace Into</TD> <TD ALIGN="LEFT">F7</TD> <TD ALIGN="LEFT">Traces into the method at the execution point.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Trace to Next Source Line</TD> <TD ALIGN="LEFT">Shift+F7</TD> <TD ALIGN="LEFT">Causes the execution point to move to the next line in the program's source code.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Run to Cursor</TD> <TD ALIGN="LEFT">F4</TD> <TD ALIGN="LEFT">Runs the program and pauses when program execution reaches the current line in the source code.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Show Execution Point</TD> <TD ALIGN="LEFT">None</TD> <TD ALIGN="LEFT">Displays the program execution point in the Code Editor. Scrolls the source code window if necessary. Works only when program execution is paused.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Program Pause</TD> <TD ALIGN="LEFT">None</TD> <TD ALIGN="LEFT">Pauses program execution as soon as the execution point enters the program's source code.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Program Reset</TD> <TD ALIGN="LEFT">Ctrl+F2</TD> <TD ALIGN="LEFT">Unconditionally terminates the program and returns to the Delphi IDE.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">Inspect</TD> <TD ALIGN="LEFT">None</TD> <TD ALIGN="LEFT">Displays the Inspect dialog box so that you can enter the name of an object to inspect.</TD> </TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -