Finishing section 1, adding initial footnotes, restyling markdown text
[mudman.git] / md / debugging.md
1 ---
2 title: 'A Dynamic Debugging System For Muddle'
3 author: Joel Mayer Berez
4 date: January 1978
5 abstract: Program debugging is a time consuming process. Conventional
6   debugging techniques and aids typically give the user a narrow view
7   of the program's operation, making debugging difficult. A debugging
8   system that would present a clear overall picture of a program's
9   behavior and would be both flexible and simple to operate would be a
10   valuable tool. Such a system was designed and implemented in and for
11   Muddle, a high-level applicative programming language. This report
12   discusses the design alternatives considered during the debugging
13   system's design and implementation phases, the reasons for the
14   resulting design choices, and the system attributes. A major
15   attribute of the system (MEND) is that it does not simulate the
16   program being debugged but instead monitors it from another
17   process. This attribute results in a robust and viable debugging
18   system, because MEND need not be modified in order to handle each
19   new extension to Muddle and/or each new user-defined primitive.
20 ---
21
22 MIT Technical Memo 94
23
24 Laboratory for Computer Science
25 Massachusetts Institute of Technology
26 545 Technology Square Cambridge, Massachusetts 02139
27
28 Copyright
29 =========
30
31 This research was supported by the Advanced Research Projects Agency
32 of the Department of Defense and was monitored by the Office of Naval
33 Research under Contract No. N00014-75-C-0661.
34
35 This report was originally published in the United States in January
36 1978 without a copyright notice and without subsequent registration
37 with the U.S. Copyright Office within 5 years. Doing at least one of
38 those was a requirement of United States copyright law at that time.
39 This report is therefore in the public domain in the United States for
40 failure to comply with the required formalities. This means you're
41 free to download, modify and redistribute this report. People outside
42 of the United States must check the copyright laws of their country
43 before downloading or redistributing.
44
45 Abstract
46 ========
47
48 Program debugging is a time consuming process. Conventional debugging
49 techniques and aids typically give the user a narrow view of the
50 program's operation, making debugging difficult. A debugging system
51 that would present a clear overall picture of a program's behavior and
52 would be both flexible and simple to operate would be a valuable tool.
53 Such a system was designed and implemented in for Muddle, a high-level
54 applicative programming language. This report discusses: the design
55 alternatives considered during the debugging system's design and
56 implementation phases, the reasons for the resulting design choices,
57 and the system attributes. A major attribute of the system (MEND) is
58 that it does not simulate the program being debugged but instead
59 monitors it from another process. This attribute results in a robust
60 and viable debugging system, because MEND not be modified in order to
61 handle each new extension to Muddle and/or each new user-defined
62 primitive.
63
64 This report reproduces a thesis of the same title submitted to the
65 Department of Electrical Engineering, Massachusetts Institute of
66 Technology, in partial fulfillment of the requirements for the Degree
67 of Bachelor of Science.
68
69 Acknowledgements
70 ================
71
72 I wish to thank Al Vezza, for supervising this work and guiding me
73 along the road to winnage; Stu Galley, for the original idea; Bruce
74 Daniels and Gerald Farrell, for laying some of the ground work I have
75 built upon; Brian Berkowitz and Chris Reeve, for patiently repairing
76 my ailing Muddles; Marc Blank and Tak To, for support work and for
77 providing me with company during all-night console sessions; and all
78 of the other ITS and DynaMod hackers who have built a system well
79 worth using.
80
81 This research was supported by the Advanced Research Projects Agency
82 of the Department of Defense and was monitored by the Office of Naval
83 Research under Contract No. N00014-75-C-0661.
84
85 Introduction
86 ============
87
88 Background
89 ----------
90
91 A time-consuming and frustrating aspect of computer programming is the
92 debugging of faulty programs. Current debugging techniques involve
93 tracing through the present operation of the program and mentally
94 comparing its action with one's concept of what should be happening.
95 With few exceptions, an understanding of where the program fails to
96 conform to "correct" operation must be made before the cause of the
97 failure can be determined and corrective action taken. This is where
98 much of the difficulty occurs.
99
100 In conventional debugging, it is rare for the programmer to have
101 available any more than the most basic aids. One usually has to
102 extrapolate from a bare minimum of information (such as machine
103 generated error messages) or one may be buried under a large excess of
104 information, most irrelevant (such as a core dump). Even with the more
105 advanced aids, the programmer typically gets but a small window in the
106 operation of the program through which, sooner or later, she or he
107 will locate the problem. A well-localized fault will be relatively
108 easy to spot compared to a global problem that the programmer may only
109 catch glimpses of through the debugging window.
110
111 In a compiler language, the programmer's best hope is to insert
112 statements to print intermediate results or to try to separate the
113 program into easier-to-handle modules. There are a few more advanced
114 aids available[^1], but their use is limited. One problem is that the
115 program is, in effect, first translated into a lower-level language
116 (generally "machine" language) and then executed interpretively in
117 that language. The original symbols and syntax of the source program
118 are lost, or saved only with great difficulty, making analysis and
119 manipulation of the executing program a very painful process.
120
121 If the programmer is using an interpretive language with facilities
122 for interaction, things are considerably easier. The common technique
123 is to stop execution at strategic points and examine the state of the
124 environment. Since this is done interactively, with the source program
125 still available in more or less its original form, the cause of the
126 problem can often be found in less time than it could otherwise. one
127 of the best example of this approach is the use of DDT (Dynamic
128 Debugging Tool/Technique)[^2][^3].
129
130 DDT basically works with machine-language programs. However, by freely
131 translating between numbers and symbols through the use of a table
132 generated by the assembler, DDT makes programs look to the programmer
133 like symbolic assembly-language programs. The user of DDT can operate
134 in free-run mode or in n-step (statement) mode, switching between them
135 at will. In either case one can set a breakpoint at any statement,
136 which will cause execution to stop just before the statement is
137 executed. Whenever stopped in DDT, the user can examine or change the
138 contents of any location. This can be done in several data modes
139 (e.g., unsigned octal, full ASCII, sixbit, etc.) including the use of
140 symbols to represent addresses. Arbitrary numeric expressions can also
141 be evaluated without affecting the program.
142
143 One main advantage of DDT is that the debugging environment is very
144 similar to the language environment the programmer used to write the
145 program. One has to learn only the DDT commands rather than an
146 entirely new language. Another advantage is the user's ability for
147 viewing the results of the changes. In addition, one can quickly see
148 the results of the changes and act accordingly.
149
150 The main deficiency of DDT is that, although is names include the word
151 "dynamic", its operation is really static. The application program can
152 run freely, but when the programmer wants to see what is taking place,
153 the program must be stopped. Although the real interest may be about
154 changes on a gross scale, perhaps thousands of program statements, if
155 one does not know exactly where the program is misbehaving, one may be
156 required to suspend execution of it every few instructions to examine
157 variable in order to obtain a true picture of the program's behavior.
158 This the programmers see *not what is taking place*, but *what has
159 taken place*, and through small windows at that. This is inefficient,
160 and the programmer can become bogged down in detail that hinders the
161 discovery of the true problem. The situation can be improved with the
162 use of breakpoints that allow the program is execute freely until a
163 breakpoint is reached, at which point the program halts. DDT is a
164 powerful tool but still leaves much to be desired in a debugging tool.
165
166 ESP[^4][^5] (Execution Simulator and Presenter) is one solution to the
167 static problem. It really is dynamic is that large amounts of data are
168 constantly being displayed for the programmer while the program is
169 being executed (actually, simulated). The information is presented in
170 graphic form to improve readability and reduce confusion. A user of
171 ESP may watch areas of the display where data of particular interest
172 are being presented. One also has many options including control over
173 the speed of execution, the type of quantity of data displayed, and
174 special (more flexible than just a breakpoint) conditions for halting
175 execution. In this way one can structure and control the picture
176 presented to more easily understand what the simulated program is
177 doing. And that is one key step in the process of debugging.
178
179 Like DDT, ESP has deficiencies also. These are mainly in the area of
180 editing and DDT-like examination of a faulty program. DDT is a
181 sophisticated language that ESP does not attempt to entirely replace.
182 The flaw in ESP is that it is not compatible with DDT. Ideally both
183 should be simultaneously available to the programmer, who can use
184 features of each as the need dictates.
185
186 DDT and ESP work with a low-level language whose operation can be
187 shown fairly simply. For example, ESP often shows flow of control by
188 just displaying the actual section of program being executed and
189 pointing to the current statement[^6]. It also draws lines to show
190 where branching has occurred and in some cases even indicates looping.
191 The display philosophy can be readily extended to higher level
192 languages that are line oriented, like BASIC, but it fails with
193 applicative ones, like LISP or Muddle. The latter type does not use a
194 linear control flow, but uses a complex depth-first tree structure.
195 Furthermore, quite complicated data structures can be built (or
196 themselves executed) that bear little relation to the appearance of
197 the program.
198
199 A good basic display for Muddle was used in MUMBLE[^7] (Gerald
200 Farrell's monitor and debugging aid). The code being executed is shown
201 in stack form. Each line shows a piece of code being evaluated. As
202 each object in the bottom line is evaluated, it is replaced by a
203 single downward-arrow symbol in this line and then printed on a new
204 line. In this way the evaluation can be followed from the top level
205 down to the current object being evaluated. Furthermore, after the
206 bottom is reached, the value returned by each line replaces its symbol
207 in the previous line. With this mechanism, the programmer can follow
208 execution in a natural and reasonably clear representation.
209
210 MUMBLE had some difficulties arising from the fact that it simulated
211 execution rather than just watching it and letting it proceed
212 naturally. This caused it to run slowly and to be complex yet fragile.
213 At the time MUMBLE was written, the Muddle compiler was not yet
214 perfected and the language itself lacked some of the multiprocessing
215 features that would have made simulation unnecessary. Later Farrell
216 replaced MUMBLE with a debugger utilizing new software related to
217 single-stepping a process, which eliminated the simulation but also
218 eliminated the feature reflecting results of an evaluation back into
219 the original code. Also, a mode was added that allowed the programmer
220 to attach conditions to parts of the program which would stop
221 execution when and if a condition was false. This is as far as MUMBLE
222 ever progressed, and it was not in use as of the time of the proposal
223 for the current work.
224
225 MEND
226 ----
227
228 After the Muddle compiler became operational and many additional new
229 software features became available, it appeared that it would be
230 possible to design and implement a debugging system that would be
231 comprehensive, easy to use, and reasonably fast. It was therefore
232 proposed that a debugging system for Muddle called MEND (Muddle
233 Executor , aNalyzer, and Debugger) be designed and implemented. It has
234 the following characteristics. (A glossary of special terms, those in
235 all capital letters, used here and throughout the rest of this memo
236 may be found in Appendix B.)
237
238 1.  MEND possesses a display similar to that of MUMBLE, including the
239     replacement of arguments in a FORM by their values as they are
240     evaluated.
241 2.  Execution is monitored from another process (as opposed to being
242     simulated as in ESP) using 1STEP and related features[^8].
243 3.  Execution speed is variable by the user including a static single
244     or multi-step mode where desired.
245 4.  MEND allows execution to run freely below a certain depth of
246     evaluation or between certain points in the program and to run
247     controlled elsewhere.
248 5.  Unconditional and conditional breakpoints are available that can
249     be attached to any object to halt execution before evaluation of
250     that object.
251 6.  The system is capable of keeping track of programmer specified
252     conditions and of changing modes or giving some visible indication
253     when the conditions are met (or not met).
254 7.  Information, such as the local value of programmer specified ATOMs
255     and the values of programer specified FORMs, is constantly
256     displayed beneath the main display.
257 8.  Each line in the main display area is &-printed (abbreviated
258     printing, see glossary) and can be viewed in full at any time.
259 9.  At any time, with execution stopped, the user can EVAL objects in
260     the ENVIRONMENT of the program. This means the user can examine
261     the state of the program or change it.
262
263 Possible Additional Characteristics
264 -----------------------------------
265
266 Certain other characteristics were seen as desirable for MEND but
267 possibly beyond the scope of this project. If time permitted these
268 features were to be included in the system:
269
270 1.  The IMLAC multi-screen capability would be used to allow the user
271     to rapidly switch between the debugger display and the program's
272     own output. Other system output could also be put on additional
273     pages.
274 2.  The editor IMED (an editor for Muddle objects analogous to
275     IMEDIT[^9]) would be tied into the system to allow easy editing.
276     PRINTTYPE and READ-TABLEs would be used to allow breakpoints to be
277     easily set and removed in IMED as single symbols. Other control
278     codes and statements could also be inserted using this editor.
279 3.  At the applications programmer's option and within certain limits,
280     execution could be reversed either so that something different
281     could be tried or for purposes of reexamining the process for
282     something that may have been missed the first time. This feature
283     could come in two possible forms, the UNDO package[^10] to
284     actually reverse execution or a simulation displaying information
285     previously stored by the system.
286
287 Design and Implementation
288 -------------------------
289
290 MEND was designed with the intent of providing the application
291 programmer with many options so that debugging could proceed in the
292 most suitable manner for each situation. In the normal running state,
293 MEND displays several kinds of information on the screen. Most
294 important is an area showing the execution of the application program
295 being debugged in stack form. The only other area that is always
296 present is a line or two of status information about the current
297 operation of MEND showing its current speed of execution (user
298 adjustable) and the state of each modifiable mode.
299
300 It was intended that the output of the application program be saved by
301 MEND for later reference. The user of MEND could then elect to have
302 the most recent output constantly displayed in a window on the main
303 screen (see section on future work). If multi-screening were
304 available, the output could be kept on another virtual screen. That
305 screen could be displayed or made invisible at the user's option
306 without stopping MEND.
307
308 Information such as programmer specified values of ATOMs, structured
309 objects, and, in general, the value of any Muddle expression may be
310 constantly displayed. MEND is also capable of displaying such
311 information on an exception basis according to some predescribed
312 condition. Such information is &-printed but is viewable in full when
313 desired.
314
315 It is important for a debugging system like MEND to be compatible with
316 and to take advantage of available software in related areas. One such
317 area is editing. There were two Muddle editors in use when the
318 proposal for this work was made, EDIT[^11] and IMED. The main
319 difference between them is that IMED uses the local editing features
320 of the IMLAC while EDIT does not. EDIT, however, has the advantage of
321 being the only one that possesses breakpoint capabilities. Whichever
322 proved to be most compatible with MEND (possibly both) would be
323 slightly modified to allow the setting and removing of certain MEND
324 codes including, in the case of IMED, breakpoints.
325
326 Muddle itself has many features that greatly aid the debugging
327 process. One of these is FRAMES. This function can be used to print
328 the stack of functional evaluations and applications when execution is
329 halted at any depth below the top level. At this point it is also
330 possible to get the values of objects in the current ENVIRONMENT and
331 to change them. One can even restart execution at a higher level after
332 making such changes. Because the Muddle debugging features are quite
333 powerful, MEND was designed to allow the user to stop execution (of
334 the application program) and to use these aids or any others built in
335 to Muddle with the MEND system itself transparent. Evaluation would
336 take place in the ENVIRONMENT of the application program.
337
338 MEND now includes the main features of all the debuggers that have
339 been mentioned and enough other features that it should prove to be
340 quit useful for the analysis and debugging of Muddle programs. It
341 should also serve as a good example of the type of debugging system
342 that can be built around an applicative type language.
343
344 [^1]: G.A. Mann, "A Survey of Debug Systems", Honeywell Computer
345     Journal 1973, volume 7, number 3, pages 182-198
346
347 [^2]: Digital Equipment Corporation, "DDT-10 Programmer's Reference
348     Manual", Assembly Language Handbook, DEC-10-NRZA-D
349
350 [^3]: B. Bressler, DDT: A Debugging Aid, SYS.06.01, Programming
351     Technology Division Document, Laboratory for Computer Science,
352     M.I.T., November, 1971
353
354 [^4]: S.W. Galley, Debugging with ESP -- Execution Simulator and
355     Presenter, SYS.09.01, Programming Technology Division Document,
356     Laboratory for Computer Science, M.I.T., November, 1971
357
358 [^5]: S.W. Galley and R.P. Goldberg, "Software Debugging: The Virtual
359     Machine Approach", Proceedings of the Association for Computing
360     Machinery Annual Conference, November, 1974, volume 2, pages
361     395-401
362
363 [^6]: M.H. Liu, DETAIL: A Graphical Debugging Tool, S.B. Thesis,
364     Department of Electrical Engineering, M.I.T., February, 1972
365
366 [^7]: G.J. Farrell, A System for Muddle Programming, M.S. Thesis,
367     Department of Electrical Engineering, M.I.T., August, 1973
368
369 [^8]: S.W. Galley and G. Pfister, Muddle Programming Language Primer
370     and Manual, Laboratory for Computer Science, M.I.T., May, 1977
371
372 [^9]: J. Haverty, IMEDIT Editor Program for Use with the Imlac
373     Terminals, SYS.08.01.02, Programming Technology Division Document,
374     Laboratory for Computer Science, M.I.T., August, 1972
375
376 [^10]: B. Berkowitz, UNDO, Undergraduate Research Report, Programming
377     Technology Division, Laboratory for Computer Science, M.I.T.,
378     December, 1974
379
380 [^11]: N. Ryan, EDIT: The Muddle Editor, SYS.11.14, Programming
381     Technology Division Document, Laboratory for Computer Science,
382     M.I.T., August, 1974