MacsBug for Modula-2
Volume Number: 1
Issue Number: 13
Column Tag: Modula Mods
Using Macsbug to debug Modula-2 Programs
By Tom Taylor, Modula Corp., Provo, Ut., MacTutor Contributing Editor
Developing a Mac application is not an exercise in trivial programming. With
four or five hundred toolbox routines at the programmer's disposal, writing a
Mac-like program can be somewhat frustrating. With no debugger available, the
MacModula-2 programmer is usually baffled and angry when his program bombs with
ID=02 or some other bomb box.
Although MacModula-2 does not come with a debugger, a machine-language level
debugger by Apple can be used by the Modula-2 programmer. MacModula-2 traps
most runtime errors such as range violation, integer, cardinal, real, and storage
overflow, among others. The toolbox, however, may not be so forgiving. Passing bad
parameters or calling routines in the wrong order can cause the infamous bomb box to
appear. Fortunately, Apple's debugger can be very useful when debugging a Modula-2
program riddled with toolbox calls.
In order to debug a program at the machine-code level, it is necessary to obtain a
debugger. Apple supplies a number of debuggers with its Macintosh 68000
Development System package:
• Maxbug - a full-screen debugger for 512k Macs.
• Macsbug or Midibug - an 8-line debugger for 128k Macs.
• Termbug A and Termbug B - debuggers that display their information on an
external terminal plugged into the modem or printer port.
I use Maxbug because of its 40-line display and the fact that it is the only
debugger (of the ones mentioned) that actually displays the toolbox trap names during
operation. The terminal-based debuggers come in handy once in a while because they
allow the user to print the heap on the ImageWriter. This article and its examples will
use Maxbug. Any one of the debuggers mentioned can be found in the following places:
• From Apple's Macintosh 68000 Development System package.
• From Compuserve. The debuggers have been uploaded to the Macintosh
Developer's section.
• From someone who has Apple's Software Supplement.
It would also be extremely helpful to obtain and read a copy of the documentation
that describes the MacsBug debuggers. Before installing the debugger, you should
install the "Programmer's Switch" that came with your Mac. This switch installs in
the lower-left-hand side of the Mac. The button closest to the front reboots the Mac
and the rear button generates a non-maskable interrupt. Pushing this button without
the debugger installed generates a bomb box with ID=13. With the debugger installed,
it simply places you in control of the debugger. Regardless of which debugger you wish
to use, you must copy it to your boot disk and name it Macsbug. Whenever you boot
with this disk, the debugger will automatically be installed (note: this means that after
copying the debugger to the boot disk and renaming it, you must shutdown and re-boot
in order to install the debugger). If you have not installed your own startup screen on
your boot disk, you'll see a "MacsBug Installed." message under the "Welcome to
Macintosh" bootup message (see figure 1). If you have installed your own startup
screen, no message will be displayed but the debugger will still be installed.
Figure 1. The startup screen with MacsBug on the boot disk.
If this is your first experience with the debugger, wait till the Finder has come
up and the disk drives have stopped spinning and hit the debug button on the side of the
Mac. If you are using Maxbug, the screen should clear and display something like
figure 2. If you are using Midibug, you'll see figure 2 on the bottom part of the screen.
Finally, if you are using one of the terminal debuggers, you'll see figure 2 on the
external terminal. Generally, whenever you enter the debugger, all of the registers
are displayed and the next line to be executed is disassembled. The debugger, à la
conventional (i.e. pre-Mac) programs, displays a ">" prompt and waits for the user to
enter a debug command. There are many commands that can be entered here. For
starters, though, enter a "G" (in these debug examples, the bold type highlights the
commands that should be typed by you, the user). The screen will display the desktop
again and the Mac will resume normal operation.
Figure 2. 1-Disassembled listing of next line to be executed, 2-Current stack pointer,