Add section 3, remove duplicate abstract, add section numbers
[mudman.git] / md / debugging.md
1 % A Dynamic Debugging System For Muddle
2 % Joel Mayer Berez
3 % January 1978
4
5 MIT Technical Memo 94
6
7 Laboratory for Computer Science\
8 Massachusetts Institute of Technology\
9 545 Technology Square Cambridge, Massachusetts 02139
10
11 Copyright
12 =========
13
14 This research was supported by the Advanced Research Projects Agency
15 of the Department of Defense and was monitored by the Office of Naval
16 Research under Contract No. N00014-75-C-0661.
17
18 This report was originally published in the United States in January
19 1978 without a copyright notice and without subsequent registration
20 with the U.S. Copyright Office within 5 years. Doing at least one of
21 those was a requirement of United States copyright law at that time.
22 This report is therefore in the public domain in the United States for
23 failure to comply with the required formalities. This means you're
24 free to download, modify and redistribute this report. People outside
25 of the United States must check the copyright laws of their country
26 before downloading or redistributing.
27
28 Abstract
29 ========
30
31 Program debugging is a time consuming process. Conventional debugging
32 techniques and aids typically give the user a narrow view of the
33 program's operation, making debugging difficult. A debugging system
34 that would present a clear overall picture of a program's behavior and
35 would be both flexible and simple to operate would be a valuable tool.
36 Such a system was designed and implemented in for Muddle, a high-level
37 applicative programming language. This report discusses: the design
38 alternatives considered during the debugging system's design and
39 implementation phases, the reasons for the resulting design choices,
40 and the system attributes. A major attribute of the system (MEND) is
41 that it does not simulate the program being debugged but instead
42 monitors it from another process. This attribute results in a robust
43 and viable debugging system, because MEND not be modified in order to
44 handle each new extension to Muddle and/or each new user-defined
45 primitive.
46
47 This report reproduces a thesis of the same title submitted to the
48 Department of Electrical Engineering, Massachusetts Institute of
49 Technology, in partial fulfillment of the requirements for the Degree
50 of Bachelor of Science.
51
52 Acknowledgements
53 ================
54
55 I wish to thank Al Vezza, for supervising this work and guiding me
56 along the road to winnage; Stu Galley, for the original idea; Bruce
57 Daniels and Gerald Farrell, for laying some of the ground work I have
58 built upon; Brian Berkowitz and Chris Reeve, for patiently repairing
59 my ailing Muddles; Marc Blank and Tak To, for support work and for
60 providing me with company during all-night console sessions; and all
61 of the other ITS and DynaMod hackers who have built a system well
62 worth using.
63
64 I Introduction
65 ==============
66
67 I.1 Background
68 --------------
69
70 A time-consuming and frustrating aspect of computer programming is the
71 debugging of faulty programs. Current debugging techniques involve
72 tracing through the present operation of the program and mentally
73 comparing its action with one's concept of what should be happening.
74 With few exceptions, an understanding of where the program fails to
75 conform to "correct" operation must be made before the cause of the
76 failure can be determined and corrective action taken. This is where
77 much of the difficulty occurs.
78
79 In conventional debugging, it is rare for the programmer to have
80 available any more than the most basic aids. One usually has to
81 extrapolate from a bare minimum of information (such as machine
82 generated error messages) or one may be buried under a large excess of
83 information, most irrelevant (such as a core dump). Even with the more
84 advanced aids, the programmer typically gets but a small window in the
85 operation of the program through which, sooner or later, she or he
86 will locate the problem. A well-localized fault will be relatively
87 easy to spot compared to a global problem that the programmer may only
88 catch glimpses of through the debugging window.
89
90 In a compiler language, the programmer's best hope is to insert
91 statements to print intermediate results or to try to separate the
92 program into easier-to-handle modules. There are a few more advanced
93 aids available[^1], but their use is limited. One problem is that the
94 program is, in effect, first translated into a lower-level language
95 (generally "machine" language) and then executed interpretively in
96 that language. The original symbols and syntax of the source program
97 are lost, or saved only with great difficulty, making analysis and
98 manipulation of the executing program a very painful process.
99
100 If the programmer is using an interpretive language with facilities
101 for interaction, things are considerably easier. The common technique
102 is to stop execution at strategic points and examine the state of the
103 environment. Since this is done interactively, with the source program
104 still available in more or less its original form, the cause of the
105 problem can often be found in less time than it could otherwise. one
106 of the best example of this approach is the use of DDT (Dynamic
107 Debugging Tool/Technique)[^2][^3].
108
109 DDT basically works with machine-language programs. However, by freely
110 translating between numbers and symbols through the use of a table
111 generated by the assembler, DDT makes programs look to the programmer
112 like symbolic assembly-language programs. The user of DDT can operate
113 in free-run mode or in n-step (statement) mode, switching between them
114 at will. In either case one can set a breakpoint at any statement,
115 which will cause execution to stop just before the statement is
116 executed. Whenever stopped in DDT, the user can examine or change the
117 contents of any location. This can be done in several data modes
118 (e.g., unsigned octal, full ASCII, sixbit, etc.) including the use of
119 symbols to represent addresses. Arbitrary numeric expressions can also
120 be evaluated without affecting the program.
121
122 One main advantage of DDT is that the debugging environment is very
123 similar to the language environment the programmer used to write the
124 program. One has to learn only the DDT commands rather than an
125 entirely new language. Another advantage is the user's ability for
126 viewing the results of the changes. In addition, one can quickly see
127 the results of the changes and act accordingly.
128
129 The main deficiency of DDT is that, although is names include the word
130 "dynamic", its operation is really static. The application program can
131 run freely, but when the programmer wants to see what is taking place,
132 the program must be stopped. Although the real interest may be about
133 changes on a gross scale, perhaps thousands of program statements, if
134 one does not know exactly where the program is misbehaving, one may be
135 required to suspend execution of it every few instructions to examine
136 variable in order to obtain a true picture of the program's behavior.
137 This the programmers see *not what is taking place*, but *what has
138 taken place*, and through small windows at that. This is inefficient,
139 and the programmer can become bogged down in detail that hinders the
140 discovery of the true problem. The situation can be improved with the
141 use of breakpoints that allow the program is execute freely until a
142 breakpoint is reached, at which point the program halts. DDT is a
143 powerful tool but still leaves much to be desired in a debugging tool.
144
145 ESP[^4][^5] (Execution Simulator and Presenter) is one solution to the
146 static problem. It really is dynamic is that large amounts of data are
147 constantly being displayed for the programmer while the program is
148 being executed (actually, simulated). The information is presented in
149 graphic form to improve readability and reduce confusion. A user of
150 ESP may watch areas of the display where data of particular interest
151 are being presented. One also has many options including control over
152 the speed of execution, the type of quantity of data displayed, and
153 special (more flexible than just a breakpoint) conditions for halting
154 execution. In this way one can structure and control the picture
155 presented to more easily understand what the simulated program is
156 doing. And that is one key step in the process of debugging.
157
158 Like DDT, ESP has deficiencies also. These are mainly in the area of
159 editing and DDT-like examination of a faulty program. DDT is a
160 sophisticated language that ESP does not attempt to entirely replace.
161 The flaw in ESP is that it is not compatible with DDT. Ideally both
162 should be simultaneously available to the programmer, who can use
163 features of each as the need dictates.
164
165 DDT and ESP work with a low-level language whose operation can be
166 shown fairly simply. For example, ESP often shows flow of control by
167 just displaying the actual section of program being executed and
168 pointing to the current statement[^6]. It also draws lines to show
169 where branching has occurred and in some cases even indicates looping.
170 The display philosophy can be readily extended to higher level
171 languages that are line oriented, like BASIC, but it fails with
172 applicative ones, like LISP or Muddle. The latter type does not use a
173 linear control flow, but uses a complex depth-first tree structure.
174 Furthermore, quite complicated data structures can be built (or
175 themselves executed) that bear little relation to the appearance of
176 the program.
177
178 A good basic display for Muddle was used in MUMBLE[^7] (Gerald
179 Farrell's monitor and debugging aid). The code being executed is shown
180 in stack form. Each line shows a piece of code being evaluated. As
181 each object in the bottom line is evaluated, it is replaced by a
182 single downward-arrow symbol in this line and then printed on a new
183 line. In this way the evaluation can be followed from the top level
184 down to the current object being evaluated. Furthermore, after the
185 bottom is reached, the value returned by each line replaces its symbol
186 in the previous line. With this mechanism, the programmer can follow
187 execution in a natural and reasonably clear representation.
188
189 MUMBLE had some difficulties arising from the fact that it simulated
190 execution rather than just watching it and letting it proceed
191 naturally. This caused it to run slowly and to be complex yet fragile.
192 At the time MUMBLE was written, the Muddle compiler was not yet
193 perfected and the language itself lacked some of the multiprocessing
194 features that would have made simulation unnecessary. Later Farrell
195 replaced MUMBLE with a debugger utilizing new software related to
196 single-stepping a process, which eliminated the simulation but also
197 eliminated the feature reflecting results of an evaluation back into
198 the original code. Also, a mode was added that allowed the programmer
199 to attach conditions to parts of the program which would stop
200 execution when and if a condition was false. This is as far as MUMBLE
201 ever progressed, and it was not in use as of the time of the proposal
202 for the current work.
203
204 I.2 MEND
205 --------
206
207 After the Muddle compiler became operational and many additional new
208 software features became available, it appeared that it would be
209 possible to design and implement a debugging system that would be
210 comprehensive, easy to use, and reasonably fast. It was therefore
211 proposed that a debugging system for Muddle called MEND (Muddle
212 Executor , aNalyzer, and Debugger) be designed and implemented. It has
213 the following characteristics. (A glossary of special terms, those in
214 all capital letters, used here and throughout the rest of this memo
215 may be found in Appendix B.)
216
217 1.  MEND possesses a display similar to that of MUMBLE, including the
218     replacement of arguments in a FORM by their values as they are
219     evaluated.
220 2.  Execution is monitored from another process (as opposed to being
221     simulated as in ESP) using 1STEP and related features[^8].
222 3.  Execution speed is variable by the user including a static single
223     or multi-step mode where desired.
224 4.  MEND allows execution to run freely below a certain depth of
225     evaluation or between certain points in the program and to run
226     controlled elsewhere.
227 5.  Unconditional and conditional breakpoints are available that can
228     be attached to any object to halt execution before evaluation of
229     that object.
230 6.  The system is capable of keeping track of programmer specified
231     conditions and of changing modes or giving some visible indication
232     when the conditions are met (or not met).
233 7.  Information, such as the local value of programmer specified ATOMs
234     and the values of programer specified FORMs, is constantly
235     displayed beneath the main display.
236 8.  Each line in the main display area is &-printed (abbreviated
237     printing, see glossary) and can be viewed in full at any time.
238 9.  At any time, with execution stopped, the user can EVAL objects in
239     the ENVIRONMENT of the program. This means the user can examine
240     the state of the program or change it.
241
242 I.3 Possible Additional Characteristics
243 ---------------------------------------
244
245 Certain other characteristics were seen as desirable for MEND but
246 possibly beyond the scope of this project. If time permitted these
247 features were to be included in the system:
248
249 1.  The IMLAC multi-screen capability would be used to allow the user
250     to rapidly switch between the debugger display and the program's
251     own output. Other system output could also be put on additional
252     pages.
253 2.  The editor IMED (an editor for Muddle objects analogous to
254     IMEDIT[^9]) would be tied into the system to allow easy editing.
255     PRINTTYPE and READ-TABLEs would be used to allow breakpoints to be
256     easily set and removed in IMED as single symbols. Other control
257     codes and statements could also be inserted using this editor.
258 3.  At the applications programmer's option and within certain limits,
259     execution could be reversed either so that something different
260     could be tried or for purposes of reexamining the process for
261     something that may have been missed the first time. This feature
262     could come in two possible forms, the UNDO package[^10] to
263     actually reverse execution or a simulation displaying information
264     previously stored by the system.
265
266 I.4 Design and Implementation
267 -----------------------------
268
269 MEND was designed with the intent of providing the application
270 programmer with many options so that debugging could proceed in the
271 most suitable manner for each situation. In the normal running state,
272 MEND displays several kinds of information on the screen. Most
273 important is an area showing the execution of the application program
274 being debugged in stack form. The only other area that is always
275 present is a line or two of status information about the current
276 operation of MEND showing its current speed of execution (user
277 adjustable) and the state of each modifiable mode.
278
279 It was intended that the output of the application program be saved by
280 MEND for later reference. The user of MEND could then elect to have
281 the most recent output constantly displayed in a window on the main
282 screen (see section on future work). If multi-screening were
283 available, the output could be kept on another virtual screen. That
284 screen could be displayed or made invisible at the user's option
285 without stopping MEND.
286
287 Information such as programmer specified values of ATOMs, structured
288 objects, and, in general, the value of any Muddle expression may be
289 constantly displayed. MEND is also capable of displaying such
290 information on an exception basis according to some predescribed
291 condition. Such information is &-printed but is viewable in full when
292 desired.
293
294 It is important for a debugging system like MEND to be compatible with
295 and to take advantage of available software in related areas. One such
296 area is editing. There were two Muddle editors in use when the
297 proposal for this work was made, EDIT[^11] and IMED. The main
298 difference between them is that IMED uses the local editing features
299 of the IMLAC while EDIT does not. EDIT, however, has the advantage of
300 being the only one that possesses breakpoint capabilities. Whichever
301 proved to be most compatible with MEND (possibly both) would be
302 slightly modified to allow the setting and removing of certain MEND
303 codes including, in the case of IMED, breakpoints.
304
305 Muddle itself has many features that greatly aid the debugging
306 process. One of these is FRAMES. This function can be used to print
307 the stack of functional evaluations and applications when execution is
308 halted at any depth below the top level. At this point it is also
309 possible to get the values of objects in the current ENVIRONMENT and
310 to change them. One can even restart execution at a higher level after
311 making such changes. Because the Muddle debugging features are quite
312 powerful, MEND was designed to allow the user to stop execution (of
313 the application program) and to use these aids or any others built in
314 to Muddle with the MEND system itself transparent. Evaluation would
315 take place in the ENVIRONMENT of the application program.
316
317 MEND now includes the main features of all the debuggers that have
318 been mentioned and enough other features that it should prove to be
319 quit useful for the analysis and debugging of Muddle programs. It
320 should also serve as a good example of the type of debugging system
321 that can be built around an applicative type language.
322
323 II Terminal Display
324 ===================
325
326 II.1 IMLAC Console Program
327 --------------------------
328
329 One basic concern throughout the project was the display: how the
330 information made available by MEND would be presented to the user. To
331 a large extent the physical characteristics of Muddle, ITS[^12]
332 (Incompatible Timesharing System, the operating system used on the
333 Dynamic Modeling System computer), and the available terminals
334 dictated what was reasonably possible.
335
336 The terminal most commonly used by users of the Dynamic Modeling
337 System is the IMLAC PDS-1. This is a minicomputer capable of having
338 programs loaded into it from the PDP-10 host computer. One program
339 written for it by Dave Lebling is MSC, a multiple-screen terminal
340 program. Up to four virtual screens (or pages) can be created that
341 will individually operate like the actual screen area of the standard
342 terminal program (SSV[^13]). Output may be directed to any one of the
343 screens and any screen may be visible or invisible at any instant of
344 time, at the programmer's option. Selection of screen is controllable
345 either by program from the host or locally by the user.
346
347 It was originally Intended that MEND would use MSC for its normal
348 display. One page would constantly show MEND's representation of the
349 control stack of the application program. Output initiated by the
350 program being debugged would go to a second page. A third page would
351 be used for interaction with MEND and would show user typein along
352 with any output from MEND that one was interested in seeing. The
353 latter would include, by user request, full displays of both objects
354 printed in an abbreviated form on the page containing the control
355 stack of the application program and values being monitored or traced.
356 The user could switch back and forth among the pages at will during
357 the execution of the program. The application program would have a
358 full standard screen to write onto, and ample room would be available
359 for the information to be displayed by MEND.
360
361 After a fair amount of testing, this proposal was discarded for the
362 following reasons. First, MSC was supposed to look just like SSV for
363 individual virtual screens. Unfortunately new features added to SSV
364 had not also been added to MSC. A primary reason for this disparity
365 was that the new features encroached upon the IMLAC's character space.
366 An SSV with all current features can only hold about one and a half
367 full pages of text, where a page is the amount that can be visible at
368 one time. The overhead required for additional screens reduces it
369 still further. Therefore, with all features included, four virtual
370 screens could each only average about one-third full. Without many of
371 the current features, people were reluctant to use MSC.
372
373 The second and perhaps most devastating problem with MSC is that it is
374 not properly supported by ITS as is SSV. Ordinarily the operating
375 system will keep track of where on the page the terminal's cursor is
376 and will properly handle such updating as deletions even in the face
377 of random access performed (if done by request to the system). When
378 using MSC, ITS does not realize that information is being written onto
379 more than one screen and will therefore often move the cursor to the
380 wrong position.
381
382 MEND could completely control positioning for typeout and echoing on
383 typein but that would add the large overhead of having to run a
384 non-trivial routine for each character typed out on the display. Also,
385 because MSC is not the standard console program, requiring the user to
386 load it before using MEND might discourage the use of MEND. (It takes
387 between about 30 seconds and a couple of minutes, depending upon
388 system load, to load a new console program into the IMLAC.)
389
390 From the outset it was intended that MEND be used routinely by
391 programmers as debugging problems arose. Therefore it was decided that
392 the proper way for such a system to operate was to use, as far as
393 possible, the common environment so as to keep the overhead for
394 invoking MEND small. This philosophy, which had been seen to affect
395 the success of many earlier projects, decided between the alternatives
396 and in this case led to the final decision to use SSV instead of MSC.
397
398 II.2 Terminal Independence
399 --------------------------
400
401 The MEND terminal handling capabilities are actually quite general and
402 MEND does not depend exclusively on SSV. For the purpose of dividing
403 the screen area into several sections, horizontal lines are sometimes
404 drawn (see Appendix A showing sample display). With an IMLAC and SSV
405 these lines could be drawn quite simply using graphics mode. However,
406 for purposes of generality with regard to terminals, these lines are
407 instead formed by using underbar characters (on a line of their own).
408 By using no actual graphics MEND can be used with almost any display
409 terminal having random access. MEND outputs display commands, such as
410 clearing a line, as escape codes to ITS which then translates these
411 into the appropriate commands for the terminal in use. ITS currently
412 knows about several types of display terminals in use at the
413 Laboratory for Computer Science, and other types of terminals located
414 at foreign sites on the ARPA network may be handled by interface
415 software that simulates a known type. Naturally MEND can handle a
416 large range of possible line and screen lengths. (The current version
417 of SSV provides four possible character sizes.)
418
419 II.3 Control of Screen Sectioning
420 ---------------------------------
421
422 There still remained the question of how to handle the
423 multi-sectioning of the displayed information. Originally three
424 sections corresponding to the three virtual screens in the aborted MSC
425 implementation were planned. The bottom section would hold user typein
426 and application program output. Three possible methods of achieving
427 this involved having ITS, Muddle, or MEND do various amounts of the
428 work with increasing overhead and decreasing speed for those three,
429 respectively.
430
431 The most attractive solution utilized an ITS feature allowing the
432 specification of an echo area at the bottom of the screen where echoed
433 input would always be printed (with the echoing handled by the system,
434 which is the normal case) . After some experimentation this method of
435 handling the typein and application program output was rejected
436 because typeout and deletion are handled by Muddle which ignores the
437 echo area MEND would effectively have had to control all typeout and
438 monitor all typein, which would have made the echo area useless.
439
440 Experimentation with the second solution, an indirect method, involved
441 monitoring of special Muddle memory locations where information
442 concerning horizontal and vertical page positions is stored. It was
443 soon discovered that Muddle becomes confused quickly, contains several
444 bugs with respect to this position information, and generally has a
445 poor idea of where it is actually printing.
446
447 The third solution appeared to be the most painful from an
448 implementation and efficiency point of view. MEND would need to
449 control the printing of every character on output and certain
450 characters on input, constantly checking page positions by querying
451 the system. Not only did this slow output, but also MEND was forced to
452 constantly move the cursor to a safe position in case Muddle managed
453 to sneak some output past it, which it occasionally does.
454
455 Fortuitously the problem was neatly solved when a little known feature
456 of ITS was discovered. It Is possible to open a channel to the
457 terminal in a mode that would cause all output to appear in the echo
458 area. By creating this echo area and reopening Muddle's normal
459 terminal output channel in this mode, it is possible to cause Muddle
460 and the application program to think that the entire screen consists
461 of only the echo area. All output including application program
462 display escape commands is automatically routed by ITS to this echo
463 area. MEND sends its output to a second channel opened in the normal
464 mode, thereby allowing it to use an area of the screen unknown to and
465 left untouched by the application program. The physical cursor stays
466 where the last used logical cursor left it, thereby eliminating most
467 of the unnecessary cursor movement, resulting in a more pleasing
468 visual effect.
469
470 As a result of this solution, the screen is divided into only two main
471 sections. All typein appears in the lower section, whether it is to
472 the application program or to MEND. Application program output also
473 goes to the lower section, as does unstructured output produced by
474 interaction with MEND. The upper section, in general, contains only
475 those items that occupy one line of the display each. As will be
476 explained later, these items include all output automatically
477 displayed by MEND during execution of the application program.
478
479 III MSTACK: MEND's Representation of the Control Stack
480 ======================================================
481
482 III.1 Program Execution In Muddle
483 ---------------------------------
484
485 MEND's primary role is to allow the applications programmer to
486 visually monitor the execution of a program. In a language like
487 Muddle, this is most easily accomplished by showing the programmer a
488 picture of the control stack.
489
490 A Muddle program consists of the evaluation of a single object. The
491 object is usually structured in some manner and itself contains other
492 objects. The most common object is the FORM. This is a list of objects
493 in which the first is (or evaluates to) some function and the rest are
494 arguments to that function. A FORM is evaluated by applying the
495 function to its arguments, usually after the arguments are themselves
496 evaluated. This evaluation actually is initiated by the Muddle
497 interpreter by applying the function EVAL to the original object. EVAL
498 takes an object as its argument and returns the value to which it
499 evaluates.
500
501 Figure 1 shows a (simplified) static representation of the evaluation
502 of a Muddle object. Starting with the FORM (list of objects in
503 angle-brackets) to be evaluated, the flow of control/evaluation may be
504 described as a depth-first search through the tree pictured. The
505 arrows represent values being returned to previous levels. At the end
506 of this "search" the FORM returns the value shown at the top.
507
508     Figure 1:
509
510            31
511            â†‘
512     <+ .A .B .C 5>
513      â†‘  â†‘  â†‘  â†‘ â†‘
514      + .A .B .C 5
515         â†‘  â†‘  â†‘
516         6  8  12
517
518 Typically the control stack will start with one object on it, the FORM
519 to be evaluated. This evaluation will first require that the objects
520 in the FORM (possibly FORMs themselves) be added to the stack and
521 evaluated. EVAL recursively calls itself for this purpose. The stack
522 builds (downward, by convention) until some object is placed on it
523 which ls known by EVAL to need no further evaluation. This object is
524 returned as its own value to the previous level and values continue to
525 be returned upward until a level is reached where another object must
526 be evaluated. In this manner, the stack grows and shrinks until the
527 topmost (initial) object returns a value.
528
529 III.2 Monitoring Program Execution
530 ----------------------------------
531
532 The manner in which the stack builds, the objects are evaluated, and
533 the values are returned illustrate most of what the program is doing.
534 Other factors, including side effects and complied code, will be
535 discussed at the end of this chapter. MEND's main display therefore
536 shows a representation of the stack being continuously updated as
537 execution/evaluation proceeds.
538
539 There are essentially two ways that MEND could follow the flow of
540 control of the application program. The most direct way, as attempted
541 by MUMBLE[^14] and discussed in the last chapter, would be for MEND to
542 execute the application program by simulating the operation of Muddle.
543 This type of simulation has been shown to require a complex end all
544 too often fragile structure. The debugging program would need to be
545 constantly updated to match changes and additions to the Muddle
546 language , but more importantly it would fail to properly handle
547 programmer-defined primitives, several varieties of which are provided
548 for by Muddle.
549
550 A far more satisfactory method is to allow Muddle to execute the
551 application program in more or less its normal fashion but to stand
552 beck somewhere and watch. Fortunately Muddle contains a mechanism
553 ideal for this, called multiprocessing. Basically another control
554 stack , or process, may be created (independent of the first) that may
555 be used to execute a different function with its own set of variable
556 bindings. One such process, in this case MEND, may place another, the
557 application program, into a single step mode where the latter will be
558 stopped before each call to EVAL and again as each call returns. The
559 MEND process will at these points be restarted and given information
560 about what the application process is doing. MEND stores this
561 information in a multi-level structure it creates called an MSTACK.
562
563 Each level of an MSTACK corresponds to a level of the control stack
564 being monitored. Each level contains the original object (actually, a
565 pointer to it) being evaluated at that level and a new object, called
566 the "displayed object", that will or does contain the results of
567 evaluating each of the arguments or elements of the original. The
568 displayed object is initially the same as the original (in a real
569 sense, it is the original) but is systematically rebuilt as each
570 element is evaluated and replaced by what it returns. Thus MEND can
571 keep track of the relationship between the changing display and the
572 unchanging program. (Figure 2 shows the various stages that the
573 displayed object corresponding to the FORM being evaluated in Figure 1
574 goes through. Each stage would in fact be painted over the previous
575 one so that all of these stages represent only one line of the screen.
576 The down-arrow shown in some of the stages is a place-holder that
577 represents an object that is actually expanded on the next line of the
578 screen.) A pointer is also kept showing which element is currently
579 above this on the stack to be evaluated unless, of course, this is the
580 initial element of the stack.
581
582     Figure 2:
583
584     <+ .A .B .C 5>
585     <+  â†“ .B .C 5>
586     <+  6 .B .C 5>
587     <+  6  â†“ .C 5>
588     <+  6  8 .C 5>
589     <+  6  8  â†“ 5>
590     <+  6  8 12 5>
591
592         31
593
594 III.3 A Displayed Representation of Program Execution
595 -----------------------------------------------------
596
597 The printed representation of the stack occupies the top section of
598 the screen and is the most prominent and important characteristic of
599 MEND. Most often, in fact, it is only necessary to watch this display
600 as the application program is executed to ascertain where a bug is
601 located or to observe exactly how the program operates. Therefore
602 considerable time has been spent making the operation of the MSTACK
603 and associated display as natural and informative as possible.
604
605 Using the collected information described in the previous section, a
606 representation of the stack is displayed as a number of lines, each
607 corresponding to one level. Each line shows a level number and the
608 displayed object printed in "&-printing", named for the printing
609 function &[^15] created by Greg Pfister. Although strictly speaking
610 the stack builds upward (towards higher memory locations), it seams
611 more natural to display and speak of the stack as building from the
612 top downward, in the direction that printing normally occurs. As each
613 element of the bottom level (the bottom line on this section of the
614 screen) is placed on the stack for evaluation, a new line is added
615 beneath the previous bottom-level line showing that element, and the
616 element is replaced in the previous line by a pointer ("↓") marking
617 its location. When the element finally returns a value, the returned
618 value will replace the pointer in the displayed object.
619
620 To avoid visual distraction, a minimum of updating is done on the
621 screen. In most cases random access is used to replace only those
622 lines that have changed. In general the complete stack will not fit in
623 the display area allocated for it (whose size is user adjustable) so a
624 scrolling procedure has been devised. The complete display area is
625 rewritten whenever an attempt is made to write past the bottom or
626 erase upward past a certain level while some lines are invisible
627 because they have been scrolled off. The scrolling parameters have
628 been selected to optimize the number of lines visible on the average
629 vs. the frequency of scrolling. Level numbers allow the user to see
630 how much is hidden "above the screen" and how deep the evaluation is
631 nested.
632
633 III.4 MEND Program Steps Vs. Muddle Steps
634 -----------------------------------------
635
636 To make it easier for the programmer to follow what the application
637 program is doing, the speed of execution of the program must be
638 controllable. MEND does this by inserting a constant, user adjustable
639 delay between program "steps." One MEND step is not precisely the same
640 as one Muddle step. Remember that a Muddle step is one call to or
641 return from EVAL. Each MSTACK level, and therefore each displayed
642 line, will have two Muddle steps associated with it. At the first
643 step, MEND will create the level and add one line to the screen. At
644 the second step, MEND will erase that line and put the returned value
645 back into the previous line. For clarity MEND adds a third step
646 between these two which actually occurs at the second Muddle stop.
647 Before substituting into the previous line, the current one is first
648 replaced by the returned value, the normal delay occurs, and then the
649 "second" step occurs as described.
650
651 Some types of Muddle objects are self-evaluating; EVAL will simply
652 return the object it was given. Although nothing interesting has
653 happened, two steps have occurred. In this case MEND will avoid
654 clutter by pretending that no steps have occurred. (MEND only does
655 this with built-in types that MEND recognizes, and the programmer
656 should recognize, as being self-evaluating. Programmer-defined types
657 that are self-evaluating will generate the usual number of MEND
658 steps.)
659
660 Another case of disparity between Muddle and MEND stops is more
661 complex. First some further explanations about Muddle objects are
662 needed Generally the interesting objects, the ones that generate MEND
663 steps, are linear (usually list) structures containing a number of
664 other Muddle objects, as are the FORMs described earlier. Normally
665 during evaluation of such an object the elements will be evaluated one
666 at a time from first to last. However this sequence is not always
667 followed by Muddle. MEND cannot directly determine which element is
668 about to be evaluated at each call to EVAL. It is only given the
669 object to be evaluated itself and not its position in the parent
670 structure. It is normally sufficient to do a comparison of this object
671 with the elements of the parent, starting with the first element
672 believed to not yet have been evaluated. Naturally, if the elements
673 are evaluated out of order, this procedure may fail to find the
674 desired match, because a Muddle object may contain the same element in
675 two or more positions. Thus it is possible to match the
676 about-to-be-evaluated object to the wrong occurrence of it. Further
677 complications arise because some functions can sometimes back up and
678 re-evaluate their arguments.
679
680 A strong attempt was made to make MEND dependent only upon the general
681 characteristics of Muddle functions and not upon specific exceptions
682 and idiosyncrasies. It was felt to be desirable to make MEND
683 independent of both future changes to the language and
684 programmer-defined "primitives" that would not be known to MEND.
685 Besides, without actually simulating Muddle it is not possible to
686 always get the information MEND needs. It was felt that the "general
687 rule" approach would take care of a sufficiently large number of cases
688 without falling into the simulator problem.
689
690 It was determined after some experimentation, however, that MEND could
691 not be made to work properly without some specific knowledge about
692 several important cases in Muddle. Two functions, PROG and REPEAT,
693 allow for branching the flow of control. They are normally
694 first-to-last functions as described above but at times control may
695 jump backwards to re-evaluate some elements. MEND was implemented so
696 that if it cannot locate an element in its normal search path, it will
697 start looking again from the beginning of the structure. If it is then
698 found, the displayed object will be reinitialized to be as if
699 evaluation had not yet proceeded past that point. Evaluation will then
700 continue normally.
701
702 Another phenomenon of Muddle that we must discuss is what this author
703 labels the "clause" behavior. A clause is a list of objects given to a
704 function as a single argument. The list is not itself evaluated, but
705 some or all of its elements are evaluated. The most common function
706 illustrating this behavior is COND, a general purpose conditional
707 function. COND's arguments are all lists of objects. It sequences
708 through these lists, evaluating the first object in each, until an
709 evaluated object returns something considered "true." Then the rest of
710 the objects in that list are evaluated and COND returns what the last
711 object in the list returns. MEND's normal search path only looks at
712 top-level elements and would therefore never find the ones actually
713 being evaluated.
714
715 This phenomenon seemed to be more widespread than the PROG/REPEAT one
716 and could not be easily attributed to certain functions. The solution
717 chosen here was to in all cases do a nested search in elements that
718 looked as if they might be clauses. (The search actually goes one
719 extra level deep to allow for certain special cases.) When a match is
720 found in a clause, MEND will for clarity generate extra steps to make
721 it appear to the user as if first the clause and then its appropriate
722 element was put on the stack for evaluation. The clause will stay on
723 the stack until some element that is not above it in the evaluation
724 tree is evaluated. At that time the clause will be removed in an
725 orderly manner, and the new element or clause plus element will be put
726 onto the stack. To do this smoothly, up to six MEND steps may have to
727 be generated for the one Muddle step. (See the example in Appendix A.)
728
729 III.5 What the User Does Not See
730 --------------------------------
731
732 MEND, in its display of the MSTACK, attempts to show the user
733 everything of importance that is happening as the program is executed.
734 However certain features of Muddle cannot be captured in this sort of
735 representation.
736
737 One such feature is the existence of compiled code. Although Muddle
738 was originally intended to be a high-level interpretive language, an
739 assembler was written[^16], producing machine code that executes in
740 the Muddle environment, to allow programmers to create "primitives"
741 that perform functions not otherwise available in Muddle. Once the
742 assembler was written, it was natural that a compiler[^17] followed.
743 It translates normal Muddle code into Muddle assembly code which is
744 then assembled. Typically Muddle programs are tested interpretively
745 and, when fully debugged, complied in order to obtain a major increase
746 in speed of execution.
747
748 A call to a compiled (or assembled) function usually looks to the
749 programmer and to MEND like a call to a Muddle primitive. The
750 operation of the function is not seen except when it calls uncompiled
751 functions. This does not present a major problem to MEND since
752 generally only uncompiled functions are being debugged, and the
753 compiled ones encountered are hopefully performing known functions
754 properly.
755
756 One feature of Muddle that MEND is unable to cope with is the
757 interrupt system. The programmer may enable a large class of
758 interrupts and assign handling functions wherever desired. Examples
759 Include interrupts for characters being typed to a certain input
760 channel and notification that the system is about to be brought down.
761 (MEND uses interrupts to catch single character commands and to catch
762 errors.)
763
764 Recall that MEND monitors application program execution by placing its
765 process into a single-stepping mode. When Muddle passes control to an
766 interrupt handier, it temporarily causes the process to leave
767 single-stepping mode. This is necessary partially because such a
768 handler may be specified to run in a process other than the current
769 one at the time of the interrupt. It unfortunately makes the handler
770 invisible to MEND. it is therefore not currently possible to use MEND
771 to debug interrupt handlers.
772
773 There is a whole series of side-effects, such as printing by the
774 application program, that are not directly seen in the MSTACK
775 representation but are made visible by various other features of MEND.
776 These will be discussed where appropriate in later sections.
777
778 [^1]: G.A. Mann, "A Survey of Debug Systems", Honeywell Computer
779     Journal 1973, volume 7, number 3, pages 182-198
780
781 [^2]: Digital Equipment Corporation, "DDT-10 Programmer's Reference
782     Manual", Assembly Language Handbook, DEC-10-NRZA-D
783
784 [^3]: B. Bressler, DDT: A Debugging Aid, SYS.06.01, Programming
785     Technology Division Document, Laboratory for Computer Science,
786     M.I.T., November, 1971
787
788 [^4]: S.W. Galley, Debugging with ESP -- Execution Simulator and
789     Presenter, SYS.09.01, Programming Technology Division Document,
790     Laboratory for Computer Science, M.I.T., November, 1971
791
792 [^5]: S.W. Galley and R.P. Goldberg, "Software Debugging: The Virtual
793     Machine Approach", Proceedings of the Association for Computing
794     Machinery Annual Conference, November, 1974, volume 2, pages
795     395-401
796
797 [^6]: M.H. Liu, DETAIL: A Graphical Debugging Tool, S.B. Thesis,
798     Department of Electrical Engineering, M.I.T., February, 1972
799
800 [^7]: G.J. Farrell, A System for Muddle Programming, M.S. Thesis,
801     Department of Electrical Engineering, M.I.T., August, 1973
802
803 [^8]: S.W. Galley and G. Pfister, Muddle Programming Language Primer
804     and Manual, Laboratory for Computer Science, M.I.T., May, 1977
805
806 [^9]: J. Haverty, IMEDIT Editor Program for Use with the Imlac
807     Terminals, SYS.08.01.02, Programming Technology Division Document,
808     Laboratory for Computer Science, M.I.T., August, 1972
809
810 [^10]: B. Berkowitz, UNDO, Undergraduate Research Report, Programming
811     Technology Division, Laboratory for Computer Science, M.I.T.,
812     December, 1974
813
814 [^11]: N. Ryan, EDIT: The Muddle Editor, SYS.11.14, Programming
815     Technology Division Document, Laboratory for Computer Science,
816     M.I.T., August, 1974
817
818 [^12]: D. Eastlake, R. Greenblatt, J. Holloway, T. Knight, and S.
819     Nelson, ITS 1.5 Reference Manual, Memo No. 161A, Artificial
820     Intelligence Laboratory, M.I.T., July 1969
821
822 [^13]: P.D. Lebling, SSV User's Manual, SYS.52.07, Programming
823     Technology Division Document, Laboratory for Computer Science,
824     M.I.T., (in preparation)
825
826 [^14]: G.J. Farrell, A System for Muddle Programming, M.S. Thesis,
827     Department of Electrical Engineering, M.I.T., August, 1973
828
829 [^15]: S.W. Galley, Pre-loaded Pure MDL RSUBRs, SYS.11.28, Programming
830     Technology Division Document, Laboratory for Computer Science,
831     M.I.T., November 1975
832
833 [^16]: B. Daniels, The MDL Assembler, SYS.11.07, Programming
834     Technology Division Document, Laboratory for Computer Science,
835     M.I.T., (in preparation)
836
837 [^17]: C. Reeve, The MDL Compiler, SYS.11.25, Programming Technology
838     Division Document, Laboratory for Computer Science, M.I.T., (in
839     preparation)