Skip to content
Thoughtful, detailed coverage of everything Apple for 34 years
and the TidBITS Content Network for Apple professionals

MacsBug for the Merely Geeky, Part Three

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.

<https://tidbits.com/getbits.acgi?tbser=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.

<https://tidbits.com/getbits.acgi?tbart=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:


  • Make a copy of MacsBug. (You can throw it away later.)

  • Using ResEdit, create a new, empty file, naming it clearly. (Mine is called "MacsBug Cheapo Restart".)

  • Leaving your new file open, use ResEdit to open the copy of MacsBug. Find and open the TMPL resources, select the mxbm resource (it should be the first one listed), then choose Copy from the Edit menu.

  • Paste the mxbm template into your empty file, then close the copy of MacsBug. The only file ResEdit should have open now is your new file.

  • Choose Create New Resource from the Resource menu. You can either type mxbm (all lowercase) or select mxbm from the scrolling list, then click OK. ResEdit creates the new resource and immediately opens it for editing.

  • Click the resource entry, 1) *****, then choose Insert New Field(s) from the Resource menu.

  • In the Macro name box, type FirstTime. In the Expansion box, type your FirstTime macro. (You can just type the letter G for now – you can always edit this later with ResEdit.)

  • Click the second entry, 2) *****, and choose Insert New Field(s) from the Resource menu.

  • In the Macro name box, type EveryTime. In the Expansion box, type your EveryTime macro. (Again, you can just type RS for now, and change it later if you like.)

  • Choose Save from the File menu, and quit ResEdit.

  • Move the file to the MacsBug Preferences folder inside your System Folder’s Preferences folder. It will probably be the only file in that folder.

  • You’re done! The macros will start working when you restart the machine. If you want to disable them, move the file out of the MacsBug Preferences folder and restart.


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.


Subscribe today so you don’t miss any TidBITS articles!

Every week you’ll get tech tips, in-depth reviews, and insightful news analysis for discerning Apple users. For over 33 years, we’ve published professional, member-supported tech journalism that makes you smarter.

Registration confirmation will be emailed to you.

This site is protected by reCAPTCHA. The Google Privacy Policy and Terms of Service apply.