This article originally appeared in TidBITS on 1998-10-26 at 12:00 p.m.
The permanent URL for this article is: http://tidbits.com/article/5146
Include images: Off

MacsBug for the Merely Geeky, Part Three

by Geoff Duncan

Previous parts of this article explored MacsBug, Apple's free low-level debugger. First, we covered installing MacsBug and using it to recover from application crashes - we also established MacsBug as possibly the least friendly software you'll ever encounter on a Macintosh. Next, we discussed common MacsBug commands that reveal detailed information about your Mac, applications, and memory, and how to make logs of problems you encounter. Although MacsBug isn't for the faint of heart, it can be useful even for people who don't program for a living.

<http://db.tidbits.com/series/1057>

Now that you're familiar with MacsBug, you can put your knowledge to good use for automatically restarting crashed servers.

Poor Man's Server Restart -- You may have noticed the StdLog command discussed in the second part of this article contains output from several other MacsBug commands. That's because StdLog is actually a MacsBug macro, or a sequence of other commands separated by semicolons. You can use the help command to see what commands are in a macro: type "help stdlog" to see the full expansion of the StdLog macro.

Generally, non-programmers don't need to define macros. However, MacsBug has two reserved macro names - FirstTime and EveryTime - that can be useful for people running unattended servers. If they exist, the FirstTime macro is executed when MacsBug is loaded at startup, and the EveryTime macro is executed every other time MacsBug is invoked, whether by the user or as the result of a system error. Here are some common strategies for defining these macros:

Simple restart:
FirstTime: G
EveryTime: RS
Smarter restart:
FirstTime: DX OFF;G
EveryTime: STDLOG;RS

The first example tells MacsBug to resume execution when it's invoked at system startup, then has MacsBug restart the machine in the event of a system error. The second example is identical, except that it turns off user breaks in the FirstTime macro (see the DX command, in part two of this article), and tries to make a standard log and restart the machine in the event of a system error - that way there's a record that the machine is having problems. Note that commands are separated by semicolons.

<http://db.tidbits.com/article/05130>

You can use the RB command instead of RS in these macros, if you like. Be sure the last command in the FirstTime macro is G, or the Mac will never continue starting up. Also, don't end the EveryTime macro with G, or you'll never be able to get into MacsBug.

The FirstTime and EveryTime macros must be defined as permanent macros before you can use them to restart a machine. To do this, you use a resource editor like Apple's free ResEdit to define the macros and store them in a file.

<ftp://ftp.info.apple.com/Apple_Support_Area/ Apple_SW_Updates/US/Macintosh/Utilities/ ResEdit_2.1.3.sea.bin>

Although I can't give complete instructions about using ResEdit in this article, here are the steps for creating these macros:

Beyond Merely Geeky -- I still won't pretend that using MacsBug is for everyone. However, I hope you can see that its utility isn't limited to code-heads who drink too many carbonated beverages. Knowing the basics of using MacsBug can help you understand and troubleshoot software problems, which in turn makes your Mac more stable and using you Mac more productive. In the end, that's what everyone wants.