| 1 | <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN"> |
| 2 | |
| 3 | <html> |
| 4 | <head> |
| 5 | <title> Pep/8: Debugging Programs Documentation </title> |
| 6 | <style type="text/css" media="all"> |
| 7 | code { font-family:Courier, 'Courier New', monospace; font-size:11pt } |
| 8 | img { vertical-align:text-top; } |
| 9 | h4 { margin-bottom: 0; border-bottom-width: 0; padding-bottom: 0; } |
| 10 | </style> |
| 11 | </head> |
| 12 | <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#000033" alink="#0066FF"> |
| 13 | <table bgcolor="#FB9F14" width="100%" cellpadding="2" cellspacing="0" border="0"> |
| 14 | <tr><td> |
| 15 | <p style="text-align:center; font-family:helvetica, arial, sans-serif; font-size:14pt; font-weight:bold; color: #29315E"> |
| 16 | Debugging Programs |
| 17 | </p> |
| 18 | </td></tr> |
| 19 | </table> |
| 20 | <p> |
| 21 | The Pep/8 system provides debugging tools to help you locate errors in the programs you write. |
| 22 | The tools include a memory dump, break points, and a symbolic trace feature. |
| 23 | If you are debugging a machine language program that you wrote you can use the memory dump feature |
| 24 | but you cannot set break points or use the symbolic trace feature. |
| 25 | You can use all the debugging features if you are debugging an assembly language program. |
| 26 | An additional debugging tool is the byte converter, which is available any time the application is running. |
| 27 | <p> |
| 28 | <a name = "Topics">Topics:</a> |
| 29 | <a href="#Memory">The memory dump</a>, |
| 30 | <a href="#Break">Break points</a>, |
| 31 | <a href="#Symbolic">Symbolic trace</a>, |
| 32 | <a href="#Byte">Byte converter</a>. |
| 33 | |
| 34 | <h3><a name="Memory">The memory dump</a></h3> |
| 35 | |
| 36 | View the Memory Dump pane by selecting View->Code/CPU/Memory from the menu or by clicking the corresponding icon in the tool bar. |
| 37 | <p> |
| 38 | <img src="images/codecpumemory.png" alt="codecpumemory" hspace=10 vspace=10> |
| 39 | <img src="images/codecpumemoryicon.png" alt="codecpumemoryicon" hspace=10 vspace=10> |
| 40 | <p> |
| 41 | The Pep/8 application may run noticibly slower when the Memory Dump pane is visible. |
| 42 | You can click either of the other two view icons to hide the Memory Dump pane. |
| 43 | <p> |
| 44 | <img src="images/codecodememory.png" alt="codecodememory" hspace=10 vspace=10> |
| 45 | <p> |
| 46 | You can scroll to any location in memory using the scroll bar on the right. |
| 47 | To scroll to a specific memory location enter the address in hexadecimal |
| 48 | in the input field at the bottom of the pane. |
| 49 | Click the SP button to scroll to the run-time stack. |
| 50 | Click the PC button to scroll to the region of memory pointed to by the program counter. |
| 51 | <p> |
| 52 | <img src="qrc:/help/images/scrollto.png" alt="fig0434" hspace=10 vspace=10> |
| 53 | |
| 54 | <h4>Switching to debug mode</h4> |
| 55 | To use the Memory Dump pane you must first switch to the debug mode. |
| 56 | If you are debugging a machine language program that you wrote, the first step is to enter the program in hexadecimal in the Object Code pane. |
| 57 | The following figure shows the object program from Figure 4.34 of the text. |
| 58 | <p> |
| 59 | <img src="qrc:/help/images/fig0434.png" alt="fig0434" hspace=10 vspace=10> |
| 60 | <p> |
| 61 | Then select Build->Start Debugging Object from the menu, which puts you in the debugging mode. |
| 62 | <p> |
| 63 | <img src="qrc:/help/images/startdebuggingobject.png" alt="startdebuggingobject" hspace=10 vspace=10> |
| 64 | <p> |
| 65 | If you are debugging an assembly language program that you wrote, enter the program in the Source Code pane. |
| 66 | Assemble it by selecting Build->Assemble from the menu or clicking on the hammer icon in the tool bar. |
| 67 | <p> |
| 68 | <img src="qrc:/help/images/assemble.png" alt="assemble" hspace=10 vspace=10> |
| 69 | <img src="qrc:/help/images/assembleicon.png" alt="assembleicon" hspace=10 vspace=10> |
| 70 | <p> |
| 71 | Then select Build->Start Debugging Source from the menu, or click on the icon with the bug in the toolbar, which puts you in the debugging mode. |
| 72 | <p> |
| 73 | <img src="qrc:/help/images/startdebuggingsource.png" alt="startdebuggingsource" hspace=10 vspace=10> |
| 74 | <img src="qrc:/help/images/startdebuggingicon.png" alt="startdebuggingicon" hspace=10 vspace=10> |
| 75 | <p> |
| 76 | <h4>Tracing in debug mode</h4> |
| 77 | While you are in the debugging mode, you can click the Single Step button in the CPU pane, |
| 78 | which will execute one von Neumann cycle of the CPU. |
| 79 | <p> |
| 80 | <img src="qrc:/help/images/singlestep.png" alt="singlestep" hspace=10 vspace=10> |
| 81 | <p> |
| 82 | The CPU pane shows you the values of the NZVC bits and of each register in the CPU. |
| 83 | The following screenshot shows the CPU pane after one click of the Single Step button for the object program from Figure 4.34. |
| 84 | <p> |
| 85 | <img src="qrc:/help/images/fig0434cpu.png" alt="fig0434cpupane" hspace=10 vspace=10> |
| 86 | <p> |
| 87 | The CPU pane displays the content of the accumulator, index register, stack pointer, and program counter first in hexadecimal and |
| 88 | then in decimal. |
| 89 | It displays the instruction specifier first in binary, and then as a mnemonic. |
| 90 | If the instruction is nonunary, it decodes the addressing mode field and shows the corresponding letter for the addressing mode |
| 91 | after the mnemonic, and displays the operand specifier. |
| 92 | <p> |
| 93 | The operand is not part of the CPU, except for the case of immediate addressing when the operand <i>is</i> the operand specifier. |
| 94 | However, for the convenience of the programmer, the CPU pane computes the value of the operand from the addressing mode |
| 95 | and displays it as well. |
| 96 | The Operand field in the CPU pane is enclosed in parentheses to emphasize the fact that it is <i>not</i> part of the CPU. |
| 97 | <p> |
| 98 | <img src="qrc:/help/images/operand.png" alt="operand" hspace=10 vspace=10> |
| 99 | <p> |
| 100 | The values in the CPU pane are the values <i>after</i> the instruction in the instruction specifier has executed. |
| 101 | For example, the values in the above screenshots are the values after the first <code>CHARI</code> executes. |
| 102 | In the von Neumann cycle, the program counter increments before the instruction executes. |
| 103 | So, the value of the program counter is the address of the <i>next</i> instruction to execute. |
| 104 | In the above screenshot, the program counter is 3, which is the address of the <i>next</i> instruction to execute, |
| 105 | while the instruction that just executed is the instruction at address 0. |
| 106 | <p> |
| 107 | As you single step through the program, the Memory Dump pane highlights in red the bytes that have changed, |
| 108 | and highlights in blue the bytes of the instruction as specified by the program counter. |
| 109 | The following screenshot shows the Memory Dump pane after the first click of the Single Step button. |
| 110 | <p> |
| 111 | <img src="qrc:/help/images/fig0434memorydump.png" alt="fig0434memorydump" hspace=10 vspace=10> |
| 112 | <p> |
| 113 | Each line of the Memory Dump pane displays eight bytes, each byte represented as two hexadecimal digits. |
| 114 | The address in the first column is the address of the first byte. |
| 115 | The rightmost column shows the value of the bytes in the row displayed as ASCII characters. |
| 116 | If the byte is a control character that cannot be displayed, the column depicts the value as a period. |
| 117 | <p> |
| 118 | The above screenshot highlights the byte at address 000D in red because the first <code>CHARI</code> instruction |
| 119 | input the letter <code>u</code> at that address. |
| 120 | It hightlights the bytes starting at address 0003 in blue because that is the value of the program counter, |
| 121 | and those bytes are the instruction that will execute <i>next</i>. |
| 122 | <p> |
| 123 | The Memory Dump pane also highlights the top byte of the stack in magenta. |
| 124 | The following screenshot from Figure 6.1 shows the stack starting at address FBCE just before the <code>ADDSP</code> executes. |
| 125 | <p> |
| 126 | <img src="qrc:/help/images/fig0601.png" alt="fig0601" hspace=10 vspace=10> |
| 127 | <p> |
| 128 | <h4>Switching out of debug mode</h4> |
| 129 | If you want the program to run to completion, click the Resume button. |
| 130 | The program will run to completion and exit the debug mode. |
| 131 | <p> |
| 132 | <img src="qrc:/help/images/resume.png" alt="resume" hspace=10 vspace=10> |
| 133 | <p> |
| 134 | If you want to terminate the debugging session without running the program to completion, select Build->Stop Debugging |
| 135 | from the menu or click the stop sign icon in the menu bar. |
| 136 | <p> |
| 137 | <img src="qrc:/help/images/stopdebugging.png" alt="stopdebugging" hspace=10 vspace=10> |
| 138 | <img src="qrc:/help/images/stopdebuggingicon.png" alt="stopdebuggingicon" hspace=10 vspace=10> |
| 139 | <p> |
| 140 | <a href="#Topics">Scroll to topics</a>. |
| 141 | <p> |
| 142 | <h3><a name="Break">Break points</a></h3> |
| 143 | To use break points for an assembly language program enter the debugging mode as described in the previous section. |
| 144 | Pep/8 will switch from the Code pane to the Trace pane and display the source program for tracing. |
| 145 | The following screenshot shows the Trace pane for the program in Figure 5.15 of the text. |
| 146 | <p> |
| 147 | <img src="qrc:/help/images/fig0515listingtrace.png" alt="fig0515listingtrace" hspace=10 vspace=10> |
| 148 | <p> |
| 149 | As you single step through the program, the CPU shows the content of the registers as described in the previous section. |
| 150 | Remember that the CPU pane shows the values of the registers <i>after</i> the instruction in the instruction specifier |
| 151 | has executed. |
| 152 | In addition, the Trace pane highlights the instruction specified by the program counter, which is the <i>next</i> instruction |
| 153 | to be executed. |
| 154 | The following screenshot shows the Trace pane after five clicks of the Single Step button. |
| 155 | The <code>LDA</code> instruction has just executed, and the <code>ADDA</code> instruction will execute next. |
| 156 | <p> |
| 157 | <img src="qrc:/help/images/fig0515listingadda.png" alt="fig0515listingadda" hspace=10 vspace=10> |
| 158 | <img src="qrc:/help/images/fig0515cpu.png" alt="fig0515cpu" hspace=10 vspace=10> |
| 159 | |
| 160 | <p> |
| 161 | <h4>Setting break points</h4> |
| 162 | Each executable instruction in the Trace pane has a checkbox for setting a break point. |
| 163 | The following screenshot shows the Trace pane for the program in Figure 5.15 before any statement has been executed. |
| 164 | The programmer has set a breakpoint at the <code>STA</code> instruction. |
| 165 | <p> |
| 166 | <img src="qrc:/help/images/fig0515breakpoint.png" alt="fig0515breakpoint" hspace=10 vspace=10> |
| 167 | <p> |
| 168 | When the programmer clicks the Resume button, the program resumes executing until it gets to an instruction with a breakpoint |
| 169 | or until completion if no breakpoint is encountered. |
| 170 | The following screenshots show what happens when the Resume button is clicked. |
| 171 | Note that the <code>STA</code> instruction will execute next if the programmer clicks the Single Step button at this point. |
| 172 | <p> |
| 173 | <img src="qrc:/help/images/resume.png" alt="resume" hspace=10 vspace=10> |
| 174 | <img src="qrc:/help/images/fig0515resumed.png" alt="fig0515resumed" hspace=10 vspace=10> |
| 175 | <p> |
| 176 | <h4>Tracing traps</h4> |
| 177 | If you want to trace the operating system's execution of a trap instruction, click the Trace Traps checkbox in the CPU pane before |
| 178 | entering the debugging mode. |
| 179 | <p> |
| 180 | <img src="qrc:/help/images/tracetraps.png" alt="tracetraps" hspace=10 vspace=10> |
| 181 | <p> |
| 182 | As you single step through your program, if you execute a trap instruction the Trace pane will show the individual instructions |
| 183 | in the trap handler of the operating system. |
| 184 | The following screenshot shows the <code>DECI</code> instruction about to be executed. |
| 185 | <p> |
| 186 | <img src="qrc:/help/images/fig0515deci.png" alt="fig0515deci" hspace=10 vspace=10> |
| 187 | <p> |
| 188 | Clicking the Single Step button at this point causes the Trace pane to switch to the trap handler in the operating system. |
| 189 | The screenshot below shows the Trace pane after clicking the Single Step button. |
| 190 | It highlights the first instruction in the trap handler of the operating system. |
| 191 | <p> |
| 192 | <img src="qrc:/help/images/fig0515trap.png" alt="fig0515trap" hspace=10 vspace=10> |
| 193 | <p> |
| 194 | When you are tracing an operating system trap, you can set breakpoints and click Single Step or Resume as you would |
| 195 | with the source program. |
| 196 | If you resume within the operating system and encounter no further breakpoints, Pep/8 will continue after the return |
| 197 | from trap instruction <code>RETTR</code> |
| 198 | to the source program until it encounters a break point there. |
| 199 | <p> |
| 200 | <a href="#Topics">Scroll to topics</a>. |
| 201 | |
| 202 | <h3><a name="Symbolic">Symbolic trace</a></h3> |
| 203 | |
| 204 | The symbolic trace feature is controlled by the trace tags described in the text. |
| 205 | Trace tags are contained in assembly language comments and have no effect on generated object code. |
| 206 | Each trace tag begins with the <code>#</code> character and supplies information to the symbol tracer on how to format |
| 207 | and label the memory cell in the trace window. |
| 208 | <p> |
| 209 | If your program does not include trace tags, the memory trace pane will not be visible when you run your program. |
| 210 | You can still use the debugger to single-step through your program and set break points. |
| 211 | If it does include trace tags, but errors are detected in the tags, a blue warning will be issued. |
| 212 | You can still run your program and use the debugger, but the memory trace pane will not be visible. |
| 213 | The screenshot below shows what happens if you make an error in one of the trace tags in the program from Figure 5.26. |
| 214 | <p> |
| 215 | <img src="qrc:/help/images/fig518tracetagwarning.png" alt="fig518tracetagwarning" hspace=10 vspace=10> |
| 216 | <p> |
| 217 | If your program does include trace tags and they have no errors, the memory trace will automatically become visible |
| 218 | below the listing trace pane. |
| 219 | As you single-step through the program, you can see the global variables on the left, and the run-time stack on the right. |
| 220 | The only user interface control that affects the symbolic trace display is the magnification input at the bottom left of the pane. |
| 221 | Here is a screenshot of the memory trace pane from the program in Figure 6.21. |
| 222 | The memory cell for <code>k</code> on top of the run-time stack is colored red because the <code>STA</code> |
| 223 | instruction has just changed its value. |
| 224 | <p> |
| 225 | <img src="qrc:/help/images/memorytrace.png" alt="memorytrace" hspace=10 vspace=10> |
| 226 | <p> |
| 227 | The sybolic trace feature displays global variables allocated with the <code>.BLOCK</code> dot command, |
| 228 | parameters and local variables allocated with the <code>SUBSP</code> instruction, the fields of a global <code>struct</code>, |
| 229 | and storage from the heap allocated with the <code>new</code> operator. |
| 230 | See the text for information on how to use trace tags in your programs. |
| 231 | <p> |
| 232 | <a href="#Topics">Scroll to topics</a>. |
| 233 | |
| 234 | <h3><a name="Byte">Byte converter</a></h3> |
| 235 | |
| 236 | Any time the Pep/8 application is running, the byte converter is available in the tool bar. |
| 237 | The four input fields represent the value of a single byte as displayed from left to right in decimal, hexadecimal, binary, and ASCII. |
| 238 | Simply enter any value in any input field and the other fields will show the same value in the corresponding format. |
| 239 | Here is the result of entering the letter <code>P</code> in the ASCII field. |
| 240 | <p> |
| 241 | <img src="qrc:/help/images/byteconverter.png" alt="byteconverter" hspace=10 vspace=10> |
| 242 | <p> |
| 243 | An instruction specifier decoder is to the right of the four input fields. |
| 244 | It displays the instruction mnemonic and possibly the addressing mode assuming you interpret the byte value as an instruction specifier. |
| 245 | <p> |
| 246 | <a href="#Topics">Scroll to topics</a>. |
| 247 | <p> |
| 248 | |
| 249 | </body> |
| 250 | </html> |