Most of my 30+ years as a Mac OS user, I had never bothered
myself with using MacsBug. "It's for developers". "Look at all
those cryptic commands" etc.

Well, I was wrong. Ever since co-admin Knezzen introduced me to
MacsBug, I've been tinkering with it. Suddenly crashing apps on
Mac OS weren't as intimidating. A little later, I've shared my
newfound knowledge in the Help! My Mac keeps freezing article
here on S7T.

This tutorial aims get a little deeper while still providing the
framework for total newcomers to MacsBug.
So what is MacsBug, you ask?
It's basically a debugger from Apple, intended for software
developers to chase errors in their code. It's widely available
in various versions. I recommend using at least 6.5.4a6 - older
versions miss out on some features.

Installation is nice and easy - just drag & drop the MacsBug
extension into your System Folder and reboot. The familiar
"Welcome to Macintosh" screen should feature a "Debugger
installed" info if done correctly. Other than that, MacsBug
doesn't get in your way. That is, until an application crashes
and would normally freeze your Mac.

Recover from a crashing application
We touched this subject in the help! My Mac keeps freezing
article. Here's a little more flesh to the bone.

Whenever MacsBug kicks in, it presents you with a shell-style
environment and a debug message as well as the location (in
memory). At this point, by entering ES (exit to shell) you can
quit the active (!) program and return to the Finder. You can
then save whatever you have running and safely reboot.

There's cases where the crash is so severe, that an exit to shell
is not possible. In that case, you can try a reset by typing RS
(restart) or RB (reboot). What's the difference, you ask? RS
tries to unmount all volumes, RB does the same, but just with the
boot volume.

So far, that's what we had covered in the previous article. But
there's literally dozens of other commands available. When I
tested beta quality software for archival on the Mac Garden, I've
had "user break" appear in the debug message. Referring to a
breakpoint set by the developer, which he/she had missed to
delete. By typing in G (Go) you can just try to continue. If you
type DX OFF, you can even teach MacsBug to ignore user breaks
altogether.

Rescue data from memory
Since MacsBug allows you to directly access what's in your RAM,
you can use that to your advantage. Let's assume I'm using my
System 7 Mac for writing a novel distraction free. Such things
supposedly happen. Let's also assume my favorite writing software
just crashed and MacsBug kicked in. Normally I'd have to reboot
and cry about losing all my unsaved progress. With MacsBug I can
recover my work.

First, I need to remember a word from my novel, ideally something
from right at the beginning, e.g. the heading. Typing in the
command RAMF (RAM Find) will search for the text string in your
RAM and return its location. Something like RAMF "MacsBug" might
give you an answer like

0187B7C5   4372 6173 682D 4V75 7273 2069 6E20 4D61  MacsBug 101 o

The first sequence gives the location (in hexadecimal). From here
on I set out to find the location of the beginning of my text. So
go ahead and search the RAM address in descending order (e.g.
0187b700, 0187b000, ...). Take small steps until you find the the
location where your text starts.

If you're unfamiliar with hexadecimal values, you can click to
copy them to the command line of MacsBug and convert them by
simply pressing return. A possible answer might look like:

0187B7C5 = $0187B7C5      #25671621       #25671621 ...

The first number with the leading # is the converted decimal. Now
take small steps from here. In order to check an address, use the
DMA {address} command. In our example, I'd try my luck with DMA
0187B7C5. Or in decimal: DMA #25671000. (make sure to include the
# to indicate it's a decimal)

Found the start of your document? Time to save it. Use the
following commands:

LOG anyfilename (hit return)
DMA {memory address of starting point} (hit return until the end
of text)
LOG (to close, hit return)

Now the contents of the RAM should be saved in a file on your
desktop. The only downside I found is that each line contains the
memory location, which will require some manual editing to get
rid of.

Screenshot with MacsBug
Another useful function many people are unaware of. If you're
using at least v. 6.5.4a6 of MacsBug, you can invoke the
screenshot FKEY from within MacsBug by using FKEY 3.

Older versions will complain about "FKEY not recognized". If
there's something on your desktop you're afraid to lose, a
screenshot might help to recover it later.

Crashing app due to low memory
Might be interesting to know if the application causing the crash
simply had too few memory and if manual allocation of more RAM
might help. Start the process by typing HZ. This returns a list
of all active applications with leading number.

To check a specific program, now type HX #NumberOfCrashedApp and
hit return. Then type HT (Heap Total). It returns you a table of
the allocated resources. If the column free (free memory) shows a
low value, it might be a good idea to simply try to increase
memory allocation via Get Info.

Helpful MacsBug commands
G                       Go              Continues the active application
RS                      Restart         Unmounts all volumes and restarts the Mac
RB                      Reboot          Unmounts the start volume and restarts the Mac
DM {address}            Display         Memory  Show memory content at address
DMA {address}           Display         Memory in ASCII Show memory content in ASCII
RAMF "Text"             RAM Find        Searches RAM for the string and returns location
HT                      Heap Total      Summary about current heap
HC {All}                Heap Check      Checks the Heap for errors
LOG {filename}          Logging         Writes RAM contents to a file
STDLOG                  Standard Log    Writes an error log
STOPAS                  Stop AppleTalk  Ends all sessions with AppleShare servers
STAT                    Statistics      Displays system info, ROM version etc.
GESTALT {selector}      Gestalt Info    Displays current value for a selector


MacsBug is a true beast within and I firmly believe no Mac OS
user should miss out on it. Once you learn handling it, one of
Mac OS critics argument (crashy applications) loses a lot of its
power. Granted, things are not perfect, but using MacsBug brings
us one step closer to perfection.