Finish Appendix B; fix footnote references.
[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
23 for failure to comply with the required formalities. This means
24 you're free to download, modify and redistribute this report. People
25 outside of the United States must check the copyright laws of their
26 country 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
35 and would be both flexible and simple to operate would be a valuable
36 tool. Such a system was designed and implemented in for Muddle, a
37 high-level applicative programming language. This report discusses:
38 the design alternatives considered during the debugging system's
39 design and implementation phases, the reasons for the resulting
40 design choices, and the system attributes. A major attribute of the
41 system (MEND) is that it does not simulate the program being debugged
42 but instead monitors it from another process. This attribute results
43 in a robust and viable debugging system, because MEND not be modified
44 in order to handle each new extension to Muddle and/or each new
45 user-defined 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
71 the debugging of faulty programs. Current debugging techniques
72 involve tracing through the present operation of the program and
73 mentally comparing its action with one's concept of what should be
74 happening. With few exceptions, an understanding of where the program
75 fails to conform to "correct" operation must be made before the cause
76 of the failure can be determined and corrective action taken. This is
77 where 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
83 of information, most irrelevant (such as a core dump). Even with the
84 more advanced aids, the programmer typically gets but a small window
85 in the operation of the program through which, sooner or later, she
86 or he will locate the problem. A well-localized fault will be
87 relatively easy to spot compared to a global problem that the
88 programmer may only 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
104 program still available in more or less its original form, the cause
105 of the problem can often be found in less time than it could
106 otherwise. one of the best example of this approach is the use of DDT
107 (Dynamic Debugging Tool/Technique)[^2][^3].
108
109 DDT basically works with machine-language programs. However, by
110 freely translating between numbers and symbols through the use of a
111 table generated by the assembler, DDT makes programs look to the
112 programmer like symbolic assembly-language programs. The user of DDT
113 can operate in free-run mode or in n-step (statement) mode, switching
114 between them at will. In either case one can set a breakpoint at any
115 statement, which will cause execution to stop just before the
116 statement is executed. Whenever stopped in DDT, the user can examine
117 or change the contents of any location. This can be done in several
118 data modes (e.g., unsigned octal, full ASCII, sixbit, etc.) including
119 the use of symbols to represent addresses. Arbitrary numeric
120 expressions can also 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
130 word "dynamic", its operation is really static. The application
131 program can run freely, but when the programmer wants to see what is
132 taking place, the program must be stopped. Although the real interest
133 may be about changes on a gross scale, perhaps thousands of program
134 statements, if one does not know exactly where the program is
135 misbehaving, one may be required to suspend execution of it every few
136 instructions to examine variable in order to obtain a true picture of
137 the program's behavior. This the programmers see *not what is taking
138 place*, but *what has taken place*, and through small windows at
139 that. This is inefficient, and the programmer can become bogged down
140 in detail that hinders the discovery of the true problem. The
141 situation can be improved with the use of breakpoints that allow the
142 program is execute freely until a breakpoint is reached, at which
143 point the program halts. DDT is a powerful tool but still leaves much
144 to be desired in a debugging tool.
145
146 ESP[^4][^5] (Execution Simulator and Presenter) is one solution to
147 the static problem. It really is dynamic is that large amounts of
148 data are constantly being displayed for the programmer while the
149 program is being executed (actually, simulated). The information is
150 presented in graphic form to improve readability and reduce
151 confusion. A user of ESP may watch areas of the display where data of
152 particular interest are being presented. One also has many options
153 including control over the speed of execution, the type of quantity
154 of data displayed, and special (more flexible than just a breakpoint)
155 conditions for halting execution. In this way one can structure and
156 control the picture presented to more easily understand what the
157 simulated program is doing. And that is one key step in the process
158 of debugging.
159
160 Like DDT, ESP has deficiencies also. These are mainly in the area of
161 editing and DDT-like examination of a faulty program. DDT is a
162 sophisticated language that ESP does not attempt to entirely replace.
163 The flaw in ESP is that it is not compatible with DDT. Ideally both
164 should be simultaneously available to the programmer, who can use
165 features of each as the need dictates.
166
167 DDT and ESP work with a low-level language whose operation can be
168 shown fairly simply. For example, ESP often shows flow of control by
169 just displaying the actual section of program being executed and
170 pointing to the current statement[^6]. It also draws lines to show
171 where branching has occurred and in some cases even indicates
172 looping. The display philosophy can be readily extended to higher
173 level languages that are line oriented, like BASIC, but it fails with
174 applicative ones, like LISP or Muddle. The latter type does not use a
175 linear control flow, but uses a complex depth-first tree structure.
176 Furthermore, quite complicated data structures can be built (or
177 themselves executed) that bear little relation to the appearance of
178 the program.
179
180 A good basic display for Muddle was used in MUMBLE[^7] (Gerald
181 Farrell's monitor and debugging aid). The code being executed is
182 shown in stack form. Each line shows a piece of code being evaluated.
183 As each object in the bottom line is evaluated, it is replaced by a
184 single downward-arrow symbol in this line and then printed on a new
185 line. In this way the evaluation can be followed from the top level
186 down to the current object being evaluated. Furthermore, after the
187 bottom is reached, the value returned by each line replaces its
188 symbol in the previous line. With this mechanism, the programmer can
189 follow execution in a natural and reasonably clear representation.
190
191 MUMBLE had some difficulties arising from the fact that it simulated
192 execution rather than just watching it and letting it proceed
193 naturally. This caused it to run slowly and to be complex yet
194 fragile. At the time MUMBLE was written, the Muddle compiler was not
195 yet perfected and the language itself lacked some of the
196 multiprocessing features that would have made simulation unnecessary.
197 Later Farrell replaced MUMBLE with a debugger utilizing new software
198 related to single-stepping a process, which eliminated the simulation
199 but also eliminated the feature reflecting results of an evaluation
200 back into the original code. Also, a mode was added that allowed the
201 programmer to attach conditions to parts of the program which would
202 stop execution when and if a condition was false. This is as far as
203 MUMBLE ever progressed, and it was not in use as of the time of the
204 proposal for the current work.
205
206 I.2 MEND
207 --------
208
209 After the Muddle compiler became operational and many additional new
210 software features became available, it appeared that it would be
211 possible to design and implement a debugging system that would be
212 comprehensive, easy to use, and reasonably fast. It was therefore
213 proposed that a debugging system for Muddle called MEND (Muddle
214 Executor , aNalyzer, and Debugger) be designed and implemented. It
215 has the following characteristics. (A glossary of special terms,
216 those in all capital letters, used here and throughout the rest of
217 this memo may be found in Appendix B.)
218
219 1.  MEND possesses a display similar to that of MUMBLE, including the
220     replacement of arguments in a FORM by their values as they are
221     evaluated.
222 2.  Execution is monitored from another process (as opposed to being
223     simulated as in ESP) using 1STEP and related features[^8].
224 3.  Execution speed is variable by the user including a static single
225     or multi-step mode where desired.
226 4.  MEND allows execution to run freely below a certain depth of
227     evaluation or between certain points in the program and to run
228     controlled elsewhere.
229 5.  Unconditional and conditional breakpoints are available that can
230     be attached to any object to halt execution before evaluation of
231     that object.
232 6.  The system is capable of keeping track of programmer specified
233     conditions and of changing modes or giving some visible
234     indication when the conditions are met (or not met).
235 7.  Information, such as the local value of programmer specified
236     ATOMs and the values of programer specified FORMs, is constantly
237     displayed beneath the main display.
238 8.  Each line in the main display area is &-printed (abbreviated
239     printing, see glossary) and can be viewed in full at any time.
240 9.  At any time, with execution stopped, the user can EVAL objects in
241     the ENVIRONMENT of the program. This means the user can examine
242     the state of the program or change it.
243
244 I.3 Possible Additional Characteristics
245 ---------------------------------------
246
247 Certain other characteristics were seen as desirable for MEND but
248 possibly beyond the scope of this project. If time permitted these
249 features were to be included in the system:
250
251 1.  The IMLAC (see section II.1) multi-screen capability would be
252     used to allow the user to rapidly switch between the debugger
253     display and the program's own output. Other system output could
254     also be put on additional pages.
255 2.  The editor IMED (an editor for Muddle objects analogous to
256     IMEDIT[^9]) would be tied into the system to allow easy editing.
257     PRINTTYPE and READ-TABLEs would be used to allow breakpoints to
258     be easily set and removed in IMED as single symbols. Other
259     control codes and statements could also be inserted using this
260     editor.
261 3.  At the applications programmer's option and within certain
262     limits, execution could be reversed either so that something
263     different could be tried or for purposes of reexamining the
264     process for something that may have been missed the first time.
265     This feature could come in two possible forms, the UNDO
266     package[^10] to actually reverse execution or a simulation
267     displaying information previously stored by the system.
268
269 I.4 Design and Implementation
270 -----------------------------
271
272 MEND was designed with the intent of providing the application
273 programmer with many options so that debugging could proceed in the
274 most suitable manner for each situation. In the normal running state,
275 MEND displays several kinds of information on the screen. Most
276 important is an area showing the execution of the application program
277 being debugged in stack form. The only other area that is always
278 present is a line or two of status information about the current
279 operation of MEND showing its current speed of execution (user
280 adjustable) and the state of each modifiable mode.
281
282 It was intended that the output of the application program be saved
283 by MEND for later reference. The user of MEND could then elect to
284 have the most recent output constantly displayed in a window on the
285 main screen (see section on future work). If multi-screening were
286 available, the output could be kept on another virtual screen. That
287 screen could be displayed or made invisible at the user's option
288 without stopping MEND.
289
290 Information such as programmer specified values of ATOMs, structured
291 objects, and, in general, the value of any Muddle expression may be
292 constantly displayed. MEND is also capable of displaying such
293 information on an exception basis according to some predescribed
294 condition. Such information is &-printed but is viewable in full when
295 desired.
296
297 It is important for a debugging system like MEND to be compatible
298 with and to take advantage of available software in related areas.
299 One such area is editing. There were two Muddle editors in use when
300 the proposal for this work was made, EDIT[^11] and IMED. The main
301 difference between them is that IMED uses the local editing features
302 of the IMLAC while EDIT does not. EDIT, however, has the advantage of
303 being the only one that possesses breakpoint capabilities. Whichever
304 proved to be most compatible with MEND (possibly both) would be
305 slightly modified to allow the setting and removing of certain MEND
306 codes including, in the case of IMED, breakpoints.
307
308 Muddle itself has many features that greatly aid the debugging
309 process. One of these is FRAMES. This function can be used to print
310 the stack of functional evaluations and applications when execution
311 is halted at any depth below the top level. At this point it is also
312 possible to get the values of objects in the current ENVIRONMENT and
313 to change them. One can even restart execution at a higher level
314 after making such changes. Because the Muddle debugging features are
315 quite powerful, MEND was designed to allow the user to stop execution
316 (of the application program) and to use these aids or any others
317 built in to Muddle with the MEND system itself transparent.
318 Evaluation would take place in the ENVIRONMENT of the application
319 program.
320
321 MEND now includes the main features of all the debuggers that have
322 been mentioned and enough other features that it should prove to be
323 quit useful for the analysis and debugging of Muddle programs. It
324 should also serve as a good example of the type of debugging system
325 that can be built around an applicative type language.
326
327 II Terminal Display
328 ===================
329
330 II.1 IMLAC Console Program
331 --------------------------
332
333 One basic concern throughout the project was the display: how the
334 information made available by MEND would be presented to the user. To
335 a large extent the physical characteristics of Muddle, ITS[^12]
336 (Incompatible Timesharing System, the operating system used on the
337 Dynamic Modeling System computer), and the available terminals
338 dictated what was reasonably possible.
339
340 The terminal most commonly used by users of the Dynamic Modeling
341 System is the IMLAC PDS-1. This is a minicomputer capable of having
342 programs loaded into it from the PDP-10 host computer. One program
343 written for it by Dave Lebling is MSC, a multiple-screen terminal
344 program. Up to four virtual screens (or pages) can be created that
345 will individually operate like the actual screen area of the standard
346 terminal program (SSV[^13]). Output may be directed to any one of the
347 screens and any screen may be visible or invisible at any instant of
348 time, at the programmer's option. Selection of screen is controllable
349 either by program from the host or locally by the user.
350
351 It was originally Intended that MEND would use MSC for its normal
352 display. One page would constantly show MEND's representation of the
353 control stack of the application program. Output initiated by the
354 program being debugged would go to a second page. A third page would
355 be used for interaction with MEND and would show user typein along
356 with any output from MEND that one was interested in seeing. The
357 latter would include, by user request, full displays of both objects
358 printed in an abbreviated form on the page containing the control
359 stack of the application program and values being monitored or
360 traced. The user could switch back and forth among the pages at will
361 during the execution of the program. The application program would
362 have a full standard screen to write onto, and ample room would be
363 available for the information to be displayed by MEND.
364
365 After a fair amount of testing, this proposal was discarded for the
366 following reasons. First, MSC was supposed to look just like SSV for
367 individual virtual screens. Unfortunately new features added to SSV
368 had not also been added to MSC. A primary reason for this disparity
369 was that the new features encroached upon the IMLAC's character
370 space. An SSV with all current features can only hold about one and a
371 half full pages of text, where a page is the amount that can be
372 visible at one time. The overhead required for additional screens
373 reduces it still further. Therefore, with all features included, four
374 virtual screens could each only average about one-third full. Without
375 many of the current features, people were reluctant to use MSC.
376
377 The second and perhaps most devastating problem with MSC is that it
378 is not properly supported by ITS as is SSV. Ordinarily the operating
379 system will keep track of where on the page the terminal's cursor is
380 and will properly handle such updating as deletions even in the face
381 of random access performed (if done by request to the system). When
382 using MSC, ITS does not realize that information is being written
383 onto more than one screen and will therefore often move the cursor to
384 the wrong position.
385
386 MEND could completely control positioning for typeout and echoing on
387 typein but that would add the large overhead of having to run a
388 non-trivial routine for each character typed out on the display.
389 Also, because MSC is not the standard console program, requiring the
390 user to load it before using MEND might discourage the use of MEND.
391 (It takes between about 30 seconds and a couple of minutes, depending
392 upon system load, to load a new console program into the IMLAC.)
393
394 From the outset it was intended that MEND be used routinely by
395 programmers as debugging problems arose. Therefore it was decided
396 that the proper way for such a system to operate was to use, as far
397 as possible, the common environment so as to keep the overhead for
398 invoking MEND small. This philosophy, which had been seen to affect
399 the success of many earlier projects, decided between the
400 alternatives and in this case led to the final decision to use SSV
401 instead of MSC.
402
403 II.2 Terminal Independence
404 --------------------------
405
406 The MEND terminal handling capabilities are actually quite general
407 and MEND does not depend exclusively on SSV. For the purpose of
408 dividing the screen area into several sections, horizontal lines are
409 sometimes drawn (see Appendix A showing sample display). With an
410 IMLAC and SSV these lines could be drawn quite simply using graphics
411 mode. However, for purposes of generality with regard to terminals,
412 these lines are instead formed by using underbar characters (on a
413 line of their own). By using no actual graphics MEND can be used with
414 almost any display terminal having random access. MEND outputs
415 display commands, such as clearing a line, as escape codes to ITS
416 which then translates these into the appropriate commands for the
417 terminal in use. ITS currently knows about several types of display
418 terminals in use at the Laboratory for Computer Science, and other
419 types of terminals located at foreign sites on the ARPA network may
420 be handled by interface software that simulates a known type.
421 Naturally MEND can handle a large range of possible line and screen
422 lengths. (The current version of SSV provides four possible character
423 sizes.)
424
425 II.3 Control of Screen Sectioning
426 ---------------------------------
427
428 There still remained the question of how to handle the
429 multi-sectioning of the displayed information. Originally three
430 sections corresponding to the three virtual screens in the aborted
431 MSC implementation were planned. The bottom section would hold user
432 typein and application program output. Three possible methods of
433 achieving this involved having ITS, Muddle, or MEND do various
434 amounts of the work with increasing overhead and decreasing speed for
435 those three, respectively.
436
437 The most attractive solution utilized an ITS feature allowing the
438 specification of an echo area at the bottom of the screen where
439 echoed input would always be printed (with the echoing handled by the
440 system, which is the normal case) . After some experimentation this
441 method of handling the typein and application program output was
442 rejected because typeout and deletion are handled by Muddle which
443 ignores the echo area MEND would effectively have had to control all
444 typeout and monitor all typein, which would have made the echo area
445 useless.
446
447 Experimentation with the second solution, an indirect method,
448 involved monitoring of special Muddle memory locations where
449 information concerning horizontal and vertical page positions is
450 stored. It was soon discovered that Muddle becomes confused quickly,
451 contains several bugs with respect to this position information, and
452 generally has a poor idea of where it is actually printing.
453
454 The third solution appeared to be the most painful from an
455 implementation and efficiency point of view. MEND would need to
456 control the printing of every character on output and certain
457 characters on input, constantly checking page positions by querying
458 the system. Not only did this slow output, but also MEND was forced
459 to constantly move the cursor to a safe position in case Muddle
460 managed to sneak some output past it, which it occasionally does.
461
462 Fortuitously the problem was neatly solved when a little known
463 feature of ITS was discovered. It Is possible to open a channel to
464 the terminal in a mode that would cause all output to appear in the
465 echo area. By creating this echo area and reopening Muddle's normal
466 terminal output channel in this mode, it is possible to cause Muddle
467 and the application program to think that the entire screen consists
468 of only the echo area. All output including application program
469 display escape commands is automatically routed by ITS to this echo
470 area. MEND sends its output to a second channel opened in the normal
471 mode, thereby allowing it to use an area of the screen unknown to and
472 left untouched by the application program. The physical cursor stays
473 where the last used logical cursor left it, thereby eliminating most
474 of the unnecessary cursor movement, resulting in a more pleasing
475 visual effect.
476
477 As a result of this solution, the screen is divided into only two
478 main sections. All typein appears in the lower section, whether it is
479 to the application program or to MEND. Application program output
480 also goes to the lower section, as does unstructured output produced
481 by interaction with MEND. The upper section, in general, contains
482 only those items that occupy one line of the display each. As will be
483 explained later, these items include all output automatically
484 displayed by MEND during execution of the application program.
485
486 III MSTACK: MEND's Representation of the Control Stack
487 ======================================================
488
489 III.1 Program Execution In Muddle
490 ---------------------------------
491
492 MEND's primary role is to allow the applications programmer to
493 visually monitor the execution of a program. In a language like
494 Muddle, this is most easily accomplished by showing the programmer a
495 picture of the control stack.
496
497 A Muddle program consists of the evaluation of a single object. The
498 object is usually structured in some manner and itself contains other
499 objects. The most common object is the FORM. This is a list of
500 objects in which the first is (or evaluates to) some function and the
501 rest are arguments to that function. A FORM is evaluated by applying
502 the function to its arguments, usually after the arguments are
503 themselves evaluated. This evaluation actually is initiated by the
504 Muddle interpreter by applying the function EVAL to the original
505 object. EVAL takes an object as its argument and returns the value to
506 which it evaluates.
507
508 Figure 1 shows a (simplified) static representation of the evaluation
509 of a Muddle object. Starting with the FORM (list of objects in
510 angle-brackets) to be evaluated, the flow of control/evaluation may
511 be described as a depth-first search through the tree pictured. The
512 arrows represent values being returned to previous levels. At the end
513 of this "search" the FORM returns the value shown at the top.
514
515     Figure 1:
516
517            31
518            ↑
519     <+ .A .B .C 5>
520      ↑  ↑  ↑  ↑ ↑
521      + .A .B .C 5
522         ↑  ↑  ↑
523         6  8  12
524
525 Typically the control stack will start with one object on it, the
526 FORM to be evaluated. This evaluation will first require that the
527 objects in the FORM (possibly FORMs themselves) be added to the stack
528 and evaluated. EVAL recursively calls itself for this purpose. The
529 stack builds (downward, by convention) until some object is placed on
530 it which ls known by EVAL to need no further evaluation. This object
531 is returned as its own value to the previous level and values
532 continue to be returned upward until a level is reached where another
533 object must be evaluated. In this manner, the stack grows and shrinks
534 until the topmost (initial) object returns a value.
535
536 III.2 Monitoring Program Execution
537 ----------------------------------
538
539 The manner in which the stack builds, the objects are evaluated, and
540 the values are returned illustrate most of what the program is doing.
541 Other factors, including side effects and complied code, will be
542 discussed at the end of this chapter. MEND's main display therefore
543 shows a representation of the stack being continuously updated as
544 execution/evaluation proceeds.
545
546 There are essentially two ways that MEND could follow the flow of
547 control of the application program. The most direct way, as attempted
548 by MUMBLE[^7] and discussed in the last chapter, would be for MEND to
549 execute the application program by simulating the operation of
550 Muddle. This type of simulation has been shown to require a complex
551 end all too often fragile structure. The debugging program would need
552 to be constantly updated to match changes and additions to the Muddle
553 language , but more importantly it would fail to properly handle
554 programmer-defined primitives, several varieties of which are
555 provided for by Muddle.
556
557 A far more satisfactory method is to allow Muddle to execute the
558 application program in more or less its normal fashion but to stand
559 beck somewhere and watch. Fortunately Muddle contains a mechanism
560 ideal for this, called multiprocessing. Basically another control
561 stack , or process, may be created (independent of the first) that
562 may be used to execute a different function with its own set of
563 variable bindings. One such process, in this case MEND, may place
564 another, the application program, into a single step mode where the
565 latter will be stopped before each call to EVAL and again as each
566 call returns. The MEND process will at these points be restarted and
567 given information about what the application process is doing. MEND
568 stores this information in a multi-level structure it creates called
569 an MSTACK.
570
571 Each level of an MSTACK corresponds to a level of the control stack
572 being monitored. Each level contains the original object (actually, a
573 pointer to it) being evaluated at that level and a new object, called
574 the "displayed object", that will or does contain the results of
575 evaluating each of the arguments or elements of the original. The
576 displayed object is initially the same as the original (in a real
577 sense, it is the original) but is systematically rebuilt as each
578 element is evaluated and replaced by what it returns. Thus MEND can
579 keep track of the relationship between the changing display and the
580 unchanging program. (Figure 2 shows the various stages that the
581 displayed object corresponding to the FORM being evaluated in Figure
582 1 goes through. Each stage would in fact be painted over the previous
583 one so that all of these stages represent only one line of the
584 screen. The down-arrow shown in some of the stages is a place-holder
585 that represents an object that is actually expanded on the next line
586 of the screen.) A pointer is also kept showing which element is
587 currently above this on the stack to be evaluated unless, of course,
588 this is the initial element of the stack.
589
590     Figure 2:
591
592     <+ .A .B .C 5>
593     <+  ↓ .B .C 5>
594     <+  6 .B .C 5>
595     <+  6  ↓ .C 5>
596     <+  6  8 .C 5>
597     <+  6  8  ↓ 5>
598     <+  6  8 12 5>
599
600         31
601
602 III.3 A Displayed Representation of Program Execution
603 -----------------------------------------------------
604
605 The printed representation of the stack occupies the top section of
606 the screen and is the most prominent and important characteristic of
607 MEND. Most often, in fact, it is only necessary to watch this display
608 as the application program is executed to ascertain where a bug is
609 located or to observe exactly how the program operates. Therefore
610 considerable time has been spent making the operation of the MSTACK
611 and associated display as natural and informative as possible.
612
613 Using the collected information described in the previous section, a
614 representation of the stack is displayed as a number of lines, each
615 corresponding to one level. Each line shows a level number and the
616 displayed object printed in "&-printing", named for the printing
617 function &[^14] created by Greg Pfister. Although strictly speaking
618 the stack builds upward (towards higher memory locations), it seams
619 more natural to display and speak of the stack as building from the
620 top downward, in the direction that printing normally occurs. As each
621 element of the bottom level (the bottom line on this section of the
622 screen) is placed on the stack for evaluation, a new line is added
623 beneath the previous bottom-level line showing that element, and the
624 element is replaced in the previous line by a pointer ("↓") marking
625 its location. When the element finally returns a value, the returned
626 value will replace the pointer in the displayed object.
627
628 To avoid visual distraction, a minimum of updating is done on the
629 screen. In most cases random access is used to replace only those
630 lines that have changed. In general the complete stack will not fit
631 in the display area allocated for it (whose size is user adjustable)
632 so a scrolling procedure has been devised. The complete display area
633 is rewritten whenever an attempt is made to write past the bottom or
634 erase upward past a certain level while some lines are invisible
635 because they have been scrolled off. The scrolling parameters have
636 been selected to optimize the number of lines visible on the average
637 vs. the frequency of scrolling. Level numbers allow the user to see
638 how much is hidden "above the screen" and how deep the evaluation is
639 nested.
640
641 III.4 MEND Program Steps Vs. Muddle Steps
642 -----------------------------------------
643
644 To make it easier for the programmer to follow what the application
645 program is doing, the speed of execution of the program must be
646 controllable. MEND does this by inserting a constant, user adjustable
647 delay between program "steps." One MEND step is not precisely the
648 same as one Muddle step. Remember that a Muddle step is one call to
649 or return from EVAL. Each MSTACK level, and therefore each displayed
650 line, will have two Muddle steps associated with it. At the first
651 step, MEND will create the level and add one line to the screen. At
652 the second step, MEND will erase that line and put the returned value
653 back into the previous line. For clarity MEND adds a third step
654 between these two which actually occurs at the second Muddle stop.
655 Before substituting into the previous line, the current one is first
656 replaced by the returned value, the normal delay occurs, and then the
657 "second" step occurs as described.
658
659 Some types of Muddle objects are self-evaluating; EVAL will simply
660 return the object it was given. Although nothing interesting has
661 happened, two steps have occurred. In this case MEND will avoid
662 clutter by pretending that no steps have occurred. (MEND only does
663 this with built-in types that MEND recognizes, and the programmer
664 should recognize, as being self-evaluating. Programmer-defined types
665 that are self-evaluating will generate the usual number of MEND
666 steps.)
667
668 Another case of disparity between Muddle and MEND stops is more
669 complex. First some further explanations about Muddle objects are
670 needed Generally the interesting objects, the ones that generate MEND
671 steps, are linear (usually list) structures containing a number of
672 other Muddle objects, as are the FORMs described earlier. Normally
673 during evaluation of such an object the elements will be evaluated
674 one at a time from first to last. However this sequence is not always
675 followed by Muddle. MEND cannot directly determine which element is
676 about to be evaluated at each call to EVAL. It is only given the
677 object to be evaluated itself and not its position in the parent
678 structure. It is normally sufficient to do a comparison of this
679 object with the elements of the parent, starting with the first
680 element believed to not yet have been evaluated. Naturally, if the
681 elements are evaluated out of order, this procedure may fail to find
682 the desired match, because a Muddle object may contain the same
683 element in two or more positions. Thus it is possible to match the
684 about-to-be-evaluated object to the wrong occurrence of it. Further
685 complications arise because some functions can sometimes back up and
686 re-evaluate their arguments.
687
688 A strong attempt was made to make MEND dependent only upon the
689 general characteristics of Muddle functions and not upon specific
690 exceptions and idiosyncrasies. It was felt to be desirable to make
691 MEND independent of both future changes to the language and
692 programmer-defined "primitives" that would not be known to MEND.
693 Besides, without actually simulating Muddle it is not possible to
694 always get the information MEND needs. It was felt that the "general
695 rule" approach would take care of a sufficiently large number of
696 cases without falling into the simulator problem.
697
698 It was determined after some experimentation, however, that MEND
699 could not be made to work properly without some specific knowledge
700 about several important cases in Muddle. Two functions, PROG and
701 REPEAT, allow for branching the flow of control. They are normally
702 first-to-last functions as described above but at times control may
703 jump backwards to re-evaluate some elements. MEND was implemented so
704 that if it cannot locate an element in its normal search path, it
705 will start looking again from the beginning of the structure. If it
706 is then found, the displayed object will be reinitialized to be as if
707 evaluation had not yet proceeded past that point. Evaluation will
708 then continue normally.
709
710 Another phenomenon of Muddle that we must discuss is what this author
711 labels the "clause" behavior. A clause is a list of objects given to
712 a function as a single argument. The list is not itself evaluated,
713 but some or all of its elements are evaluated. The most common
714 function illustrating this behavior is COND, a general purpose
715 conditional function. COND's arguments are all lists of objects. It
716 sequences through these lists, evaluating the first object in each,
717 until an evaluated object returns something considered "true." Then
718 the rest of the objects in that list are evaluated and COND returns
719 what the last object in the list returns. MEND's normal search path
720 only looks at top-level elements and would therefore never find the
721 ones actually being evaluated.
722
723 This phenomenon seemed to be more widespread than the PROG/REPEAT one
724 and could not be easily attributed to certain functions. The solution
725 chosen here was to in all cases do a nested search in elements that
726 looked as if they might be clauses. (The search actually goes one
727 extra level deep to allow for certain special cases.) When a match is
728 found in a clause, MEND will for clarity generate extra steps to make
729 it appear to the user as if first the clause and then its appropriate
730 element was put on the stack for evaluation. The clause will stay on
731 the stack until some element that is not above it in the evaluation
732 tree is evaluated. At that time the clause will be removed in an
733 orderly manner, and the new element or clause plus element will be
734 put onto the stack. To do this smoothly, up to six MEND steps may
735 have to be generated for the one Muddle step. (See the example in
736 Appendix A.)
737
738 III.5 What the User Does Not See
739 --------------------------------
740
741 MEND, in its display of the MSTACK, attempts to show the user
742 everything of importance that is happening as the program is
743 executed. However certain features of Muddle cannot be captured in
744 this sort of representation.
745
746 One such feature is the existence of compiled code. Although Muddle
747 was originally intended to be a high-level interpretive language, an
748 assembler was written[^15], producing machine code that executes in
749 the Muddle environment, to allow programmers to create "primitives"
750 that perform functions not otherwise available in Muddle. Once the
751 assembler was written, it was natural that a compiler[^16] followed.
752 It translates normal Muddle code into Muddle assembly code which is
753 then assembled. Typically Muddle programs are tested interpretively
754 and, when fully debugged, complied in order to obtain a major
755 increase in speed of execution.
756
757 A call to a compiled (or assembled) function usually looks to the
758 programmer and to MEND like a call to a Muddle primitive. The
759 operation of the function is not seen except when it calls uncompiled
760 functions. This does not present a major problem to MEND since
761 generally only uncompiled functions are being debugged, and the
762 compiled ones encountered are hopefully performing known functions
763 properly.
764
765 One feature of Muddle that MEND is unable to cope with is the
766 interrupt system. The programmer may enable a large class of
767 interrupts and assign handling functions wherever desired. Examples
768 Include interrupts for characters being typed to a certain input
769 channel and notification that the system is about to be brought down.
770 (MEND uses interrupts to catch single character commands and to catch
771 errors.)
772
773 Recall that MEND monitors application program execution by placing
774 its process into a single-stepping mode. When Muddle passes control
775 to an interrupt handier, it temporarily causes the process to leave
776 single-stepping mode. This is necessary partially because such a
777 handler may be specified to run in a process other than the current
778 one at the time of the interrupt. It unfortunately makes the handler
779 invisible to MEND. it is therefore not currently possible to use MEND
780 to debug interrupt handlers.
781
782 There is a whole series of side-effects, such as printing by the
783 application program, that are not directly seen in the MSTACK
784 representation but are made visible by various other features of
785 MEND. These will be discussed where appropriate in later sections.
786
787 IV Issuing Commands to MEND
788 ===========================
789
790 IV.1 Types of Commands
791 ----------------------
792
793 There is a need in debugging systems similar to MEND for two types of
794 commands for controlling operation. One type is a set of short,
795 immediate-action commands that the user of the debugging system may
796 issue at any time, such as a command to completely stop all
797 activities of the debugging system and to exit. The other type is the
798 set of all commands not belonging to the first set. This includes
799 commands that take arguments and those that can only be given while
800 the application program is suspended from execution.
801
802 IV.2 Immediate Interrupt-Level Commands
803 ---------------------------------------
804
805 In MEND's normal mode, various actions occur automatically. Most
806 importantly, the application program is executing and the displayed
807 representation of the MSTACK is being updated correspondingly. During
808 this time the programmer may type ahead to the application program,
809 but, since there is only one physical cursor that is used by both
810 MEND's display and typein echoing that must therefore jump back and
811 forth between the two text entry positions, a large amount of typein
812 is awkward. Therefore, all immediate action commands that the user
813 can issue while MEND is in automatic mode are single characters. To
814 minimize the chance of conflict with typein that the executing
815 application program might read, MEND immediate action commands are
816 invoked by typing certain ASCII control characters. Furthermore
817 typing one of these control characters causes an interrupt to occur
818 which is handled by MEND and allows immediate response.
819
820 Note that this arrangement requires that there be certain reserved
821 characters, as listed below, that cannot be used to communicate with
822 the application program. Normally this presents no difficulty. An
823 alternative method was considered that required the reservation of
824 only one control character. However, the user would be required to
825 type an additional character as an argument signifying what function
826 is intended. There did not seem to be a great advantage to this
827 scheme and it was considered after the first scheme had been
828 implemented. For this and other reasons stated later in this section,
829 the alternative scheme was discarded.
830
831 From the user's viewpoint, the currently implemented interrupt-level
832 commands are as follows. (ASCII control characters are represented by
833 "↑" followed by the corresponding letter.)
834
835   ---- ------------------------------------------------
836   ↑L   clear screen, reprint stack and input
837   ↑Q   Quit from current MEND
838   ↑E   End automatic mode
839   ↑B   Begin automatic mode
840   ↑U   Unprint (stop displaying stack)
841   ↑P   Print (start displaying stack)
842   ↑O   skip Over (completely evaluate) current object
843   ↑N   Next step (used when not in automatic mode)
844   ---- ------------------------------------------------
845
846 The command invoked by typing ↑L is for housekeeping purposes. It
847 causes extraneous information (e.g., old program output) to be
848 cleared from the screen and all MEND-related constantly-displayed
849 information to be reprinted. Unread input is also reprinted.
850
851 The command invoked by typing ↑Q is used to exit from an invocation
852 of MEND. It has the effect of stopping all actions related to
853 monitoring the application program and allowing the program to
854 continue normally. In this way a programmer may discard MEND and
855 continue running the application program without the need for
856 restarting it at the beginning.
857
858 The two commands invoked by typing ↑E and ↑B switch MEND between
859 automatic mode, the only one described thus far, and non-automatic
860 (command) mode. Command mode will be described in the next section.
861
862 Sometimes it is desirable for the sake of saving both computer time
863 and the application programmer's time to turn off printing of the
864 MSTACK. MEND will continue to monitor program execution and store the
865 appropriate information but it does not display it. Nor does it pause
866 between steps in the normal manner. This is mainly useful when
867 breakpoints are present to turn on printing or switch to command
868 mode. At that time MEND will know how it got to the current level and
869 will be able to display the MSTACK as usual. Two commands invoked by
870 typing ↑U and ↑P toggle the state of printing.
871
872 Whenever the programmer is satisfied that a particular call of a
873 function is working properly or for some reason he or she is not
874 interested in seeing the details of evaluation of some object, typing
875 ↑O just before the object's evaluation invokes a command that causes
876 MEND to skip over that evaluation and continue normal monitoring and
877 display immediately after a value is returned. Unlike turning off the
878 printing, no monitoring is performed here at all so the evaluation
879 proceeds as fast as it would without MEND. This is actually handled
880 by causing Muddle to leave single-stepping mode during the evaluation
881 of the object.
882
883 The last command, invoked by typing ↑N, is special in that it is
884 ignored in automatic mode. Its actions in command mode will be
885 described in the next section. It is an interrupt-level command
886 mainly for convenience and compatibility with DEBUGR.
887
888 Bruce Daniels' DEBUGR is the prototype Muddle multiprocessing
889 debugging system. It provides a simple user interface to Muddle's
890 single-stepping functions that makes single-stepping through a Muddle
891 program appear similar to single-stepping through an
892 assembly-language program with DDT[^2][^3]. The choices of characters
893 for invoking many of the MEND functions were based upon the
894 characters used to invoke similar functions in DEBUGR. Many of
895 DEBUGR's command invocation characters were in turn based upon those
896 in DDT. The object of all of this is to build character/command
897 associations in the user's mind that may be carried over from one
898 system to the next.
899
900 Several other control-character commands are handled by MEND
901 invisibly. That is, the user may not be aware that they are being
902 handled. Most of these are commands that are already being handled by
903 other subsystems but must be intercepted by MEND to maintain
904 consistency in its environment. Two of this type, invoked by typing
905 ↑S and ↑G, are already set up in an initial Muddle and a third,
906 invoked by typing ↑F , is set up by the subsystem EDIT, which is
907 called by MEND as described in the next section. All three of these
908 are used to escape to various command levels. MEND has its own
909 command level (see next section) and must in many cases escape to
910 that one instead to maintain control. Until a method was discovered
911 for having ITS section the screen, it was necessary to also interrupt
912 on carriage-returns (↑M, the new-line character) on input to insure
913 that typein was kept in the proper section.
914
915 IV.3 MEND's Command Level
916 -------------------------
917
918 Sometimes the user may wish to stop the application program at some
919 point to examine it in more detail or to alter it or its environment
920 in some way. Alternatively the user may want to issue commands to
921 MEND that require arguments. A command level is provided for both of
922 these activities.
923
924 The command level differs from the automatic mode described in the
925 last section in two ways. First, the application program is not
926 continually executing. It runs one step at a time under the direct
927 control of the user rather than automatically. Second, in
928 non-automatic mode typein is normally passed to MEND instead of the
929 application program, even that class of typein which does not produce
930 immediate action.
931
932 When the application program is stopped, the user may either request
933 a service from the debugging system or examine and/or modify the
934 program and/or its environment. Since editing functions form a large
935 part of the latter class of actions, it was decided that instead of
936 requiring the user to "import" an editor, MEND should provide an
937 editor by making one available at command level.
938
939 It is generally believed and empirical evidence indicates, that
940 creating a new editor is "the kiss of death" for a Muddle subsystem.
941 A number of Muddle editors have been tried over the years and the
942 only one that finally became generally accepted (and is now
943 pre-loaded in Muddle) is EDIT[^11] . Members of the Muddle community
944 will tolerate minor changes to EDIT, but they will not accept a new
945 editing system. The situation is analogous to one of the major
946 obstacles blocking the acceptance of ESP. Programmers were accustomed
947 to using DDT to examine and modify their machine-language programs.
948 ESP was not compatible with DDT and therefore did not provide the
949 familiar interface desired.
950
951 In view of the situation, it seemed desirable to incorporate EDIT
952 into the command level, essentially unaltered. EDIT uses a special
953 reader that either interprets input as a command to it or passes
954 input on to the normal Muddle reader. At first the task of
955 superimposing a MEND reader on top of both of these appeared
956 difficult. After much discussion with the current maintainer of EDIT,
957 a very satisfactory solution was arrived at.
958
959 A general capability was added to EDIT allowing the specification at
960 runtime of a table of EDIT-like commands to be handled by
961 programmer-defined functions. This table is searched before EDIT's
962 command table and thereby provides a capability to override standard
963 EDIT commands. MEND basically uses an invocation of EDIT as its
964 command level with all MEND commands included in a table as
965 described. EDIT-format commands are all one or two letters and may
966 take suffix arguments. Currently the MEND table includes the
967 following commands. (FIX here means a Muddle object of type FIX,
968 i.e., a fixed-point number. FLOAT means a floating-point number.
969 PPRINT[^14] is a function that prints a Muddle object in a format
970 which indicates the positions of its elements and sub-elements in the
971 tree hierarchy.)
972
973   NAME   ARG TYPE   MEANING
974   ------ ---------- -------------------------------------------------
975   ?      none       type out short summary of MEND commands
976   ??     none       type out complete summary of all commands
977   O      any        Open object or MCSTACK level n (if arg n is FIX)
978   V      none       toggle Verbosity
979   N      FIX        do Next n steps (like ↑N)
980   OV     none       skip OVer current object (like ↑O)
981   Q      none       Quit EDIT & return to automatic mode (like ↑B)
982   QM     none       Quit MEND (like ↑Q)
983   SN     FIX        Set number of lines used for stack display
984   SV     FIX        Set leVel below which MEND will not 1STEP
985   SD     number     Set Delay time (FIX or FLOAT) between steps
986   PD     FIX        Pprint Displayed object in level n
987   PO     FIX        Pprint Original (actual) object in level n
988   AI     any        Add an Item to the list being monitored
989   DI     FIX        Delete Item number n from the list
990   PI     FIX        Pprint Item number n
991
992 What the user types to the command level is inspected by EDIT. If it
993 looks like an EDIT command, it is looked-up in the MEND command table
994 or the EDIT one and handled as appropriate. Otherwise it is passed to
995 the Muddle reader. In general any interesting (useful) input that
996 Muddle should read and evaluate will not look like an EDIT command,
997 so there is no confusion.
998
999 As can be seen from the table, the MEND commands include general
1000 information retrieval ones (? and ??), system tailoring ones (V, SN,
1001 SV, and SD), and commends that allow objects to be accessed in
1002 special MEND locations (O, PD, PO, AI, DI, and PI. The O command is
1003 special in that it allows an object known only by its location in the
1004 MSTACK to be opened for examination and alteration by the normal EDIT
1005 commands. The remaining commands duplicate control-character commands
1006 except that they are read at normal input level rather than at
1007 interrupt level.
1008
1009 The most powerful feature of this command level is seen when Muddle
1010 objects are evaluated. This level, and therefore the evaluation, uses
1011 stack space below the application program and in the same process.
1012 All bindings and pending evaluations of the program are above the
1013 command level where they may be examined and modified at will. Most
1014 of what constitutes MEND is in another process safely removed and
1015 hidden from the user. Even the small amount of overhead constituting
1016 the command level function is hidden from functions such as
1017 FRAMES[^13], which may be used to view the levels of the application
1018 program's current control stack. The effect is much the same as that
1019 of Muddle's listening loop which is invoked at the current bottom of
1020 the stack in case of error, to allow the programmer to run any
1021 program (evaluate any object) to find and correct the problem.
1022
1023 Note that for critical examination of the program, the user may
1024 request that it be continued for a limited number of steps (usually
1025 one) with control then being returned to him or her at the command
1026 level. One normally would employ such a feature when the program is
1027 executing statements near the area of suspected trouble but it is not
1028 entirely clear how or why the program is misbehaving.
1029
1030 IV.4 Breakpoints
1031 ----------------
1032
1033 Normally MEND operates in automatic mode where the application
1034 program is running continuously. If one is aware of a particular area
1035 of concern, one cannot and should not have to see that area as it is
1036 reached and quickly type ↑E in order to stop the program. One may
1037 have the program running with a very small delay time or have the
1038 printing turned off.
1039
1040 In their simplest form, MEND breakpoints stop the program when
1041 evaluated, putting the user in command mode if she or he was not
1042 already in it. This is the Muddle equivalent of DDT breakpoints,
1043 which stop a program at a certain instruction. The breakpoints can
1044 also be conditional, where the evaluation of an arbitrary object
1045 determines whether or not to actually break at that point.
1046
1047 The breakpoints as so far described are very much like the
1048 breakpoints that can be set by EDIT. As a matter of fact, EDIT is
1049 used to set and clear these breakpoints just as it would be in the
1050 absence of MEND. The only real difference is that, when MEND is
1051 present, a MEND function is called to handle the break instead of an
1052 EDIT function.
1053
1054 MEND breakpoints would be useful even if they only did what was just
1055 described. However they are more powerful. A standard EDIT-style
1056 breakpoint is a call to the break function with a number of
1057 arguments. The first of these is the object at which the breakpoint
1058 is set, which will be evaluated when the user returns from the
1059 breakpoint and whose value will be returned by the break function to
1060 the application program. The next is the conditional object and the
1061 rest are objects to be evaluated and printed at each break. MEND's
1062 break function handles these as EDIT's does but also looks for a
1063 recognized ATOM (variable name), which may come after or replace the
1064 conditional. If such an ATOM is found, it will cause a special action
1065 to occur instead of stopping the program:
1066
1067   ------- ---------------------------------------
1068   ON      printing will be turned on (like ↑P)
1069   OFF     printing will be turned off (like ↑U)
1070   GO      free-run the object (like ↑O)
1071   PRINT   just print arguments & continue
1072   ------- ---------------------------------------
1073
1074 Other arguments will still be printed and all actions are still
1075 predicated upon the value of the conditional.
1076
1077 The first two special ATOMs (ON and OFF), perhaps coupled with manual
1078 control, are used to allow the MSTACK to be viewed only during areas
1079 of interest while maintaining maximum speed in other places. The next
1080 one (GO) is used to avoid wasting time examining the details of a
1081 functional call that is known to be working and is probably evaluated
1082 repeatedly. When the break function returns, single-stepping resumes
1083 as before the break. The last special ATOM (PRINT) is used to give
1084 information at key places that might not otherwise be seen.
1085
1086 One thing that was considered extremely important was to make MEND's
1087 breakpoints compatible with those of EDIT. The problem is that a
1088 breakpoint inserted outside of MEND might still be present when MEND
1089 is started and vice versa. As has been stated EDIT breakpoints work
1090 almost exactly as usual when handled by MEND's break function. The
1091 converse is not quite true. EDITs break function will ignore the
1092 significance of a special ATOM end simply print it as a normal
1093 argument. Fortunately, an ATOM evaluates to itself. If it is in the
1094 conditional position it will always be considered "true" and no harm
1095 will be done.
1096
1097 It would be easy to extend this arrangement to other special ATOMs if
1098 other functions were considered useful. The above seem to form a
1099 basic set in this system. At least they are useful and no one has yet
1100 suggested another type of breakpoint that would also prove useful.
1101
1102 V Final Thoughts about MEND
1103 ===========================
1104
1105 V.1 Monitoring of Values
1106 ------------------------
1107
1108 A feature that was originally considered to be important, and is
1109 present in ESP[^4][^5], is the constant monitoring of values. This
1110 feature has not been too happily received in MEND, but that may be
1111 due more to the current implementation than to an inherent lack of
1112 utility.
1113
1114 Ideally one should not have to see the object being monitored or its
1115 value if one does not want to. The debugging system should be capable
1116 of performing certain actions upon, for example, a change in value.
1117 This would be analogous to conditional breakpoints except that the
1118 test would be performed after each step of execution of the
1119 application program rather than at certain arbitrary times.
1120
1121 One problem with the above scheme is the difficulty of testing for a
1122 change in value (the basic test). For example, the value of an object
1123 being monitored may be some sort of structure. During execution the
1124 application program may not explicitly change the value of the object
1125 but may change an element of the structure that the object evaluates
1126 to. Assuming MEND had saved a pointer to the structure, if it now
1127 evaluated the object being monitored, it would again find that
1128 structure and assume that the value had not changed. However since an
1129 element of the structure had changed, the programmer would probably
1130 want to be notified.
1131
1132 The only solution to the above dilemma is to at each step save a
1133 complete representation to all levels of the value of the object in
1134 some form that cannot be affected by the application program. This
1135 can be done by, at each step, unparsing the value to be saved for
1136 future tests into its printed (string) representation. Then the
1137 comparison of current and previous values will simply be a string
1138 comparison, not subject to sharing by the values. Unfortunately this
1139 may create incredible amounts of "garbage." In fact, a circular list
1140 (quite legal) will produce a string of infinite length!
1141
1142 The solution finally chosen was to print the values of the objects
1143 being monitored at each step and to let the user visually compare
1144 versions. The values are &-printed as usual but may be examined in
1145 full at will.
1146
1147 When tested it became immediately obvious that the constant
1148 reprinting wasted time and was distracting. A feature was added to
1149 cause printing to occur only at controllable intervals, but that
1150 produced other problems. Primarily the user might not see a change
1151 that had occurred at one step until some later step when valuable
1152 information had already been lost. One would also not have the
1153 opportunity to take immediate action.
1154
1155 What needs to be done at this point is to reduce the emphasis on such
1156 pathological cases as described above. Printing should only occur at
1157 well defined moments (i.e., when requested or when some recognizable
1158 condition occurs). Only gross and easily testable changes in value
1159 should be watched for (i.e., the value is a new object, entirely).
1160 Conditional monitoring should be installed analogous to the
1161 conditions of breakpoints. With all of this testing, a variety of
1162 indications should be available as with breakpoints.
1163
1164 V.2 Control Stack Display
1165 -------------------------
1166
1167 MEND's display of the application program's control stack has proven
1168 to be by itself a highly useful debugging aid. This display can be
1169 and often is used without any of MEND's other features to debug a
1170 faulty program. It should also be emphasized that a valid use of this
1171 display is to monitor a working program in order to understand its
1172 operation. In this case, where the user of MEND is completely
1173 unfamiliar with the operation of the application program, MEND's
1174 step-by-step display of program execution is even more useful than in
1175 the normal debugging situation.
1176
1177 One of the unique features of MEND's "trace" of the application
1178 program is that MEND shows both the code being executed and the
1179 results of that execution. Since Muddle is an applicative language,
1180 most of the results consist of values returned by evaluated objects.
1181 By reflecting the returned values back into the original code, MEND
1182 shows intermediate results in an intuitive manner for the user.
1183
1184 Other programming languages could also benefit from this sort of
1185 display. Too often a trace routine provided for debugging in a
1186 language shows only results of execution, such as value assignments,
1187 without showing the corresponding program steps, or it shows program
1188 steps but leaves it to the programmer to insert instructions to show
1189 intermediate results. What the programmer really needs to see is a
1190 well-integrated display of both program instructions and results,
1191 such as MEND provides.
1192
1193 Muddle is an exceptional language in that the MEND display was
1194 implemented fairly cleanly with just a package of Muddle functions
1195 and without changes to the interpreter itself. With suitable language
1196 enhancements, however, a similar display could be provided for LISP
1197 or any other LISP-like language. Although major compiler
1198 modifications would be required, a stack-oriented display might also
1199 be suitable for a block structured language like ALGOL.
1200
1201 Especially in a block structured language, where instructions might
1202 be treated in groups rather than individually, but also in
1203 applicative languages, it would be useful to be shown variable
1204 bindings as they occur. Muddle does not provide any information about
1205 the occurrence of bindings, so the programmer is not informed of such
1206 occurrences by MEND. However when major modifications are made in a
1207 language to provide a display similar to MEND's, it would probably be
1208 a mistake not to include a provision for notifying the programmer of
1209 variable bindings and unbindings as they occur.
1210
1211 V.3 Simulation Vs. Multiprocessing
1212 ----------------------------------
1213
1214 Besides its control stack display, MEND's other major feature, and
1215 its major difference from debugging systems like EEP or the first
1216 version of MUMBLE, is its use of multiprocessing rather than
1217 simulation to follow application program execution. (Even debugging
1218 aids that use multiprocessing often do not work the way MEND does.
1219 While MEND is a program written in the same language and running
1220 concurrently in the same interpreter as the application program, some
1221 debuggers , such a DDT, are machine language programs running near
1222 the application program, and others are simply complied into the
1223 language itself.) This feature is perhaps the key to MEND's success
1224 as a debugger. The choice to avoid simulation certainly reduced the
1225 size and complexity of MEND by two or three times and similarly
1226 affected run time. What remains to be discussed are the tradeoffs
1227 involved in the choice. The advantages just mentioned heavily favor
1228 the multiprocessing solution but there are other considerations.
1229
1230 If MEND had been implemented using simulation, it would for the
1231 evaluation of each object determine which elements need evaluation;
1232 evaluate those elements by recursively calling MEND's own evaluation
1233 simulator; determine whether some function should be applied;
1234 determine the effects of the required functional application, if any;
1235 and cause those effects while displaying some representation of them
1236 for the programmer. In short, MEND would duplicate the actions of
1237 Muddle while maintaining and updating its own information about those
1238 actions. Therefore MEND would at all times know exactly what the
1239 application program was doing and could never miss some important
1240 effects of execution or be fooled by an unusual program. In the
1241 previous section it was stated that it is desirable to show the
1242 occurrence of variable bindings to the programmer. This feature would
1243 be easy to implement in a debugging system that simulated execution
1244 of the application program.
1245
1246 But what about a debugging system using multiprocessing? A
1247 multiprocessing debugger, such as MEND, allow s the application
1248 program to execute more-or-less freely in its own process while
1249 monitoring it from another process. Since MEND id not in direct
1250 control of the application program, it must rely for its information
1251 on whatever data it is given by the multiprocessing mechanism built
1252 into Muddle and on inferences based on examination of the application
1253 program's environment, its knowledge of the general behavior of
1254 Muddle programs, and some specific knowledge of special cases. The
1255 occurrence of variable bindings is not decipherable from the
1256 information that MEND can gather. Fortunately, as has been previously
1257 shown, MEND does have the information essential to the creation of
1258 its display and the display is a sufficient debugging tool.
1259
1260 Monitoring execution of the application program from another process
1261 provides sufficient information for a useful debugging system while
1262 simulation of the application program provides enough information for
1263 a more comprehensive system. Therefore if speed and size of the
1264 debugger were not important factors, then, although not a necessary
1265 choice, simulation would be the favored choice for a debugging system
1266 except for one other factor.
1267
1268 The simulator needs much more knowledge of specific details of the
1269 behavior of program functions than does the monitor. In fact the
1270 simulator must know exactly the effects of each function that might
1271 be used in the application program. Uncompiled user-defined functions
1272 are no problem. They consist merely of one or more applications of
1273 other functions to given arguments. Complied user-defined functions
1274 cannot be dealt with at all without actually creating a simulator for
1275 machine language programs, a project comparable in magnitude to the
1276 design and implementation of all of the other parts of the simulator
1277 combined! The remaining functions are Muddle's built-in primitives.
1278 They are well defined but frequently change (usually upward
1279 compatibly). Furthermore new primitives are constantly being added. A
1280 simulator for Muddle programs would therefore quickly become
1281 outdated.
1282
1283 Given the problems of a simulator and the relatively few drawbacks of
1284 a monitor, it is clear now why MEND was implemented as the latter.
1285 The same arguments apply to debugging systems for other languages.
1286 Whenever the appropriate multiprocessing features exist, with
1287 sufficient information available about execution in another process,
1288 a debugging system based upon simulation of the application program
1289 should be rejected in favor of a monitor-type system. MEND has proven
1290 to be an effective debugging aid and should serve as a good example
1291 of the latter type of system.
1292
1293 VI Suggestions for Future Work
1294 ==============================
1295
1296 VI.1 Monitoring of Access
1297 -------------------------
1298
1299 Because of the problems described in Section V.1 concerning the
1300 monitoring of values, there was not enough time to work on a related
1301 but more interesting feature for MEND. Frequently the main piece of
1302 information that is available about a bug Ii a program is that at
1303 some point a certain data area (variable value, list slot, etc.) is
1304 being "clobbered" by function(s) unknown.
1305
1306 Rather than watching the program execution in detail to find the
1307 culprit, it would be far more useful to set a break point on access
1308 to the location in question. This could be done by having MEND
1309 redefine all data access functions to watch for certain locations.
1310 Not only would that be messy, but it goes against one of the basic
1311 philosophies of MEND. With good reason, as described earlier, MEND
1312 tries to alter its environment as little as possible. (For example,
1313 what if the application program redefined one of the functions also?)
1314
1315 Muddle again provides the answer. The code already exists for
1316 monitoring read or write access to any standard data location. It is
1317 only necessary to set up the proper type of interrupt handler with a
1318 pointer to the location to be watched. Each time the specified type
1319 of access occur, the handier will be called with all of the
1320 particulars.
1321
1322 MEND should have commands installed for creating and destroying such
1323 handlers. For consistency and to facilitate remembering for the user,
1324 the possible actions of this handler upon being called should be
1325 similar to those of breakpoints and of monitoring of values.
1326
1327 VI.2 Other Unimplemented Features
1328 ---------------------------------
1329
1330 Three other proposed features were not implemented due to an acquired
1331 belief that the value of each of these features in relation to the
1332 goals of this work was not worth the time required to properly
1333 implement it. However each of these features has merit and may be
1334 desirable in some future, more comprehensive debugging system.
1335
1336 The first such feature involves saving all output of the application
1337 program for the programmer to refer back to. This has the
1338 implementation difficulty that there is no easy way to separate
1339 application program output from much of the MEND output. All
1340 application program output and certain MEND output goes to the lower
1341 section of the screen utilizing the same output mechanism (i.e.,
1342 standard Muddle output to the primary terminal output channel). No
1343 distinction is made between the two kinds of output. A distinction
1344 could be made, by having MEND do all of its output through yet
1345 another terminal output channel (a second channel is currently used
1346 for the upper screen section), but another consideration made the
1347 effort seem not worthwhile. In practice, programs that produce a lot
1348 of output usually send it to a file and not to the terminal. Since
1349 only small amounts of output are usually sent to the terminal, a
1350 short output history, such as that which is present on the screen
1351 itself, is generally sufficient.
1352
1353 The second unimplemented feature would have allowed the setting of
1354 MEND breakpoints using the editor IMED. This would have meant sending
1355 a function out to the IMLAC where, local editing would have been used
1356 to create, or delete such breakpoints. PRINTTYPE and READ-TABLEs
1357 would have been used to allow for setting normal breakpoints and the
1358 special MEND types (ON, OFF, etc.) using one or two mnemonic
1359 characters.
1360
1361 The primary reason that this feature was not implemented was that
1362 EDIT wad chosen to be the MEND editor instead of IMED. That choice
1363 was made partly because EDIT is in many respects the more powerful of
1364 the two, but mostly because EDIT is the editor now used almost
1365 exclusively by Muddle programmers. In fact, EDIT is now pre-loaded in
1366 Muddle while IMED is not. Another reason for rejection of this
1367 feature was that it would have made MEND, or at least this part of
1368 it, terminal dependent.
1369
1370 In a different environment a similar feature might be quite useful.
1371 IMED still has the large advantage over EDIT that by constantly
1372 displaying the entire function while the programmer moves the cursor
1373 around in it, creating and deleting MEND "command symbols" at will,
1374 the user is provided with a much better feel for the debugging
1375 environment being set up than with EDIT.
1376
1377 The third feature would allow the user to reverse execution of the
1378 application program or to simply back up to some previous point. This
1379 was suggested in two varieties, an actual undoing of all effects of
1380 the program on a step-by-step basis or simply showing previous states
1381 of the MSTACK. The first version would have used UNDO[^10], a package
1382 of functions to actually back up a program to some previous state.
1383 UNDO however violates a primary design goal of MEND. It works by
1384 redefining every Muddle function that has a side-effect, thereby
1385 causing most of the negative effects of simulation that were
1386 previously discussed. Unfortunately the way UNDO works is really the
1387 only reasonable way such a package could work, short of modifying
1388 Muddle Itself, and even UNDO is not foolproof.
1389
1390 The only practical way this feature could be implemented is in its
1391 second variety. It would be possible to store (in a file, probably)
1392 information specifying the state of the MSTACK (at each step and to
1393 allow the programmer to view previous steps in some comfortable
1394 manner. The time required to implement this feature, though, put it
1395 outside the scope of this work.
1396
1397 VI.3 Immediate Action Commands
1398 ------------------------------
1399
1400 Empirical evidence suggests that one more interrupt -level immediate
1401 action command would be highly useful. Currently the user may skip
1402 over the complete execution of a single object by typing ↑O just
1403 after the object is placed on the stack for evaluation. The user may
1404 also want to rapidly complete the evaluation of some object that is
1405 already executing. For example, one may have watched the first few
1406 objects in a REPEAT loop being evaluated and now wants to free-run
1407 the application program until the looping is finished. For such a
1408 case, a command should be available to skip over the evaluation of
1409 the current object and all others at the same level (i.e., finish
1410 evaluation of the object on the previous level).
1411
1412 Further use of MEND may indicate a need for other interrupt-level
1413 commands. (Perhaps certain interrupt-level commands should somehow be
1414 able to take arguments?)
1415
1416 VI.4 Terminal Handling
1417 ----------------------
1418
1419 The MSC implementation of MEND was discarded because of problems
1420 specific to the current operating environment. In a suitable
1421 environment, multi-screening is still seen to be a useful feature for
1422 a similar debugging system. It has even been suggested that something
1423 of the sort could be implemented using two separate terminals. One
1424 terminal would look to the application program just like the terminal
1425 it would have seen in the absence of MEND. The other terminal would
1426 be used for communications with MEND. Not only would this eliminate
1427 output conflicts between the application program and MEND, but with
1428 two keyboards there would be no need to have a reserved character set
1429 for MEND interrupt -level commands. Of course, it might be difficult
1430 for the user of such a system to coordinate activities between the
1431 two terminals.
1432
1433 Another area where MEND might be improved is its knowledge of the
1434 terminal being used. As has been previously discussed, it currently
1435 assumes certain basic display functions and relies upon ITS to
1436 understand the requirements of the terminal. Although ITS handles the
1437 job well, it is not the only operating system that Muddle may run
1438 under. This author, in fact, actively uses Muddle under TENEX, an
1439 operating system that lacks the terminal code to support MEND. To
1440 properly work under most operating systems, MEND would have to be
1441 tailorable to individual terminal codes and requirements and would
1442 have to do much more of the work than under ITS.
1443
1444 It has been proposed that MEND could be made to work in some fashion
1445 with the basic ASCII printing terminal, something that nearly all
1446 terminals and operating systems can simulate. However it is the
1447 opinion of this author that MEND would lose much of its value under
1448 such conditions. Watching the stack grow and shrink, and seeing
1449 objects replaced by their values, gives the user more of a feel for
1450 what the application program is doing than a long stream of
1451 sequentially printed lines ever could.
1452
1453 Appendix B: Glossary of Terms
1454 =============================
1455
1456 &: A function pre-loaded in Muddle that prints objects in an
1457 abbreviated form to fit in a programmer-specified number of character
1458 positions.
1459
1460 1STEP: A built-in Muddle function used by one program to single-step
1461 another for debugging purposes.
1462
1463 ATOM: A Muddle variable.
1464
1465 COND: A built-in Muddle function providing a general conditional
1466 capability. The arguments to CONO are lists. Muddle evaluates the
1467 first element of each list in turn until an element returns a
1468 non-false value. Then the rest of the elements in the current list
1469 are evaluated and COND returns what the last element in the list
1470 returns.
1471
1472 DDT: A program used to debug assembly language programs.
1473
1474 DEBUGR: A program utilizing Muddle's single-stepping functions to
1475 show a programmer the step-by-step execution of a program. DEBUGR is
1476 an attempt to provide a DDT-like debugger for Muddle programs.
1477
1478 EDIT: A pre-loaded editor for Muddle objects. EDIT works within
1479 Muddle by restructuring the object being EDITed according to the
1480 specifications of the programmer. EDIT allows one to define one's own
1481 commands or to redefine those of EDIT.
1482
1483 ENVIRONMENT: A Muddle object which specifies a particular set of
1484 variable bindings. An ENVIRONMENT is normally cumulatively built up
1485 as the control stack of a program builds and ATOMs are bound. The
1486 ENVIRONMENT actually corresponds to a particular point on the control
1487 stack. A program may have an object evaluated in an ENVIRONMENT
1488 specifying the current state of another running program. The effect
1489 is as if the latter program had evaluated the object.
1490
1491 ESP: A debugging system for assembly-language programs.
1492
1493 EVAL: A build-in Muddle function that evaluated an object and returns
1494 the value of that object
1495
1496 FIX: A Muddle object that is an integer.
1497
1498 FLOAT: A Muddle object that is a floating-point number.
1499
1500 FORM: A list of Muddle objects which is evaluated by applying the
1501 first element (some function) to the rest of the elements (its
1502 arguments). "Execution" in Muddle generally refers to the evaluation
1503 of a FORM. The evaluation of that FORM will often require the
1504 evaluation of other FORMs (the arguments to the function or FORMs in
1505 the body of the function ).
1506
1507 FRAMES: A pre-loaded function that shows the programmer a printed
1508 representation of the control stack of the current program.
1509
1510 IMED: An editor for Muddle objects that works by outputting an object
1511 to the IMLAC where the local editing functions are used.
1512
1513 IMLAC: A minicomputer with a keyboard and CRT display used as an
1514 intelligent terminal.
1515
1516 ITS: A general-purpose time-sharing operating system developed by the
1517 Artificial Intelligence Laboratory at M.I.T.
1518
1519 LVAL: A built-in Muddle function that returns the local value of a
1520 given ATOM. The local value is that which was last bound to the ATOM
1521 In the current ENVIRONMENT.
1522
1523 Muddle: An applicative programming language used to inclement MEND.
1524
1525 MEND: Muddle Executor, aNalyzer, and Debugger. The subject of this
1526 report.
1527
1528 MSC: Multi-Screen Console program for an IMLAC. This gives the IMLAC
1529 used as a terminal a capability for having several virtual screens
1530 that may be accessed and displayed independently.
1531
1532 MSTACK: A structure that MEND builds to contain a representation of
1533 the control stack of the application program.
1534
1535 MUMBLE: An early debugging aid for Muddle programs providing a
1536 display of the application program's control stack.
1537
1538 PPRINT: A pre-loaded Muddle function that "Pretty-PRINTs" an object
1539 in a format which indicates the positions of its elements and
1540 sub-elements in the tree hierarchy.
1541
1542 PRINTTYPE: A built-in Muddle function allowing the programmer to
1543 specify exactly how any particular type of object should be printed.
1544 May be used to output characters that will be interpreted as special
1545 commands on input. See READ-TABLE.
1546
1547 PROG: A built-in Muddle function used for sequential execution of
1548 Muddle objects (generally FORMs). This function provides for binding
1549 of ATOMs to be used within the PROG's scope and then evaluates each
1550 of the objects in its body, usually in order. It is possible,
1551 however, to alter the flow of control by branching forward or
1552 backward to another part of the PROG body. See REPEAT.
1553
1554 READ-TABLE: A table that may be set up in Muddle to specify how any
1555 character should be treated on input. See PRINTTYPE.
1556
1557 REPEAT: Like PROG except that when the end of the body of objects is
1558 reached, control returns to the beginning.
1559
1560 SSV: The normally used IMLAC console program. See MSC.
1561
1562 UNDO: A Muddle program that stores information about the execution of
1563 an application program so that the execution may be backed up to some
1564 previous point at any time.
1565
1566 [^1]: G.A. Mann, "A Survey of Debug Systems", Honeywell Computer
1567     Journal 1973, volume 7, number 3, pages 182-198
1568
1569 [^2]: Digital Equipment Corporation, "DDT-10 Programmer's Reference
1570     Manual", Assembly Language Handbook, DEC-10-NRZA-D
1571
1572 [^3]: B. Bressler, DDT: A Debugging Aid, SYS.06.01, Programming
1573     Technology Division Document, Laboratory for Computer Science,
1574     M.I.T., November, 1971
1575
1576 [^4]: S.W. Galley, Debugging with ESP -- Execution Simulator and
1577     Presenter, SYS.09.01, Programming Technology Division Document,
1578     Laboratory for Computer Science, M.I.T., November, 1971
1579
1580 [^5]: S.W. Galley and R.P. Goldberg, "Software Debugging: The Virtual
1581     Machine Approach", Proceedings of the Association for Computing
1582     Machinery Annual Conference, November, 1974, volume 2, pages
1583     395-401
1584
1585 [^6]: M.H. Liu, DETAIL: A Graphical Debugging Tool, S.B. Thesis,
1586     Department of Electrical Engineering, M.I.T., February, 1972
1587
1588 [^7]: G.J. Farrell, A System for Muddle Programming, M.S. Thesis,
1589     Department of Electrical Engineering, M.I.T., August, 1973
1590
1591 [^8]: S.W. Galley and G. Pfister, Muddle Programming Language Primer
1592     and Manual, Laboratory for Computer Science, M.I.T., May, 1977
1593
1594 [^9]: J. Haverty, IMEDIT Editor Program for Use with the Imlac
1595     Terminals, SYS.08.01.02, Programming Technology Division
1596     Document, Laboratory for Computer Science, M.I.T., August, 1972
1597
1598 [^10]: B. Berkowitz, UNDO, Undergraduate Research Report, Programming
1599     Technology Division, Laboratory for Computer Science, M.I.T.,
1600     December, 1974
1601
1602 [^11]: N. Ryan, EDIT: The Muddle Editor, SYS.11.14, Programming
1603     Technology Division Document, Laboratory for Computer Science,
1604     M.I.T., August, 1974
1605
1606 [^12]: D. Eastlake, R. Greenblatt, J. Holloway, T. Knight, and S.
1607     Nelson, ITS 1.5 Reference Manual, Memo No. 161A, Artificial
1608     Intelligence Laboratory, M.I.T., July 1969
1609
1610 [^13]: P.D. Lebling, SSV User's Manual, SYS.52.07, Programming
1611     Technology Division Document, Laboratory for Computer Science,
1612     M.I.T., (in preparation)
1613
1614 [^14]: S.W. Galley, Pre-loaded Pure Muddle RSUBRs, SYS.11.28,
1615     Programming Technology Division Document, Laboratory for
1616     Computer Science, M.I.T., November 1975
1617
1618 [^15]: B. Daniels, The Muddle Assembler, SYS.11.07, Programming
1619     Technology Division Document, Laboratory for Computer Science,
1620     M.I.T., (in preparation)
1621
1622 [^16]:  C. Reeve, The Muddle Compiler, SYS.11.25, Programming
1623     Technology Division Document, Laboratory for Computer Science,
1624     M.I.T., (in preparation)