TweetFollow Us on Twitter

TMON Debugging
Volume Number:1
Issue Number:10
Column Tag:Assembly Language Lab

Debugging Techniques and TMON Review"

By Paul Snively, Columbus, IN., MacTutor Contributing Editor

I was just reading my Volume 1, No. 4 MacTutor and came across William Gladnick's letter asking about tips, utilities, and debugging techniques. OK, I'll bite!

MacsBug Snoops the ROMS

As far as useful utilities go, first, get a 512K system. Then get MacNOSY and TMON (the latter is from TMQ software). These, plus a good assembler (MacASM, in other words) are all that you really need to do serious Mac hacking.

As for tips, here's one: the Mac ROMs are buggy, and nearly everyone knows it. What's not so obvious is how to use MacsBug to trace through the ROMs step by step (rather than treating the A-traps as a single instruction). Wouldn't it be nice to be able to trace one instruction at a time while in a ROM routine? OK, here's how: write your application (I assume that you are using one assembler or another). The first instruction should be:

 LABEL   BRA   LABEL

followed by your program. Assemble the program in the usual way. Install MacsBug in your system. Double-click your program's icon. The system will seem to hang, since you told it to BRanch Always to LABEL, which is where the branch is. In other words, your program is in an infinite loop. Press the interrupt button on your Mac. MacsBug will be entered with the PC pointing to your BRA instruction. Bump the PC by two to point past the BRA. Now start tracing your program.

How to Trace the ROM Routines

As you are tracing or stepping through your code with MacsBug, the disassembly will eventually say something along the lines of "OSTRAP A219" or "TOOLBOX A912" or what have you. STOP! DO NOT TRACE OR STEP! Now, change the value in A7 downward by six bytes. In other words, if A7 is now 00123AC7, change it to 00123AC1. This is to simulate the stack setup caused by the 68000 during exception processing.

Now, look at the current PC value. Let's say it's 00004E56. Store this address at A7+2 using the SM command, like this:

SM 00123AC3 00 00 4E 56 

Now type PC 401018. You may now continue tracing or what have you. Essentially, you have done manually what the 68000 would have done automatically upon encountering the A-trap. 401018 is the address of the Macintosh A-trap dispatch routine. Observe the code as you trace through it; it's quite interesting. For example, the main difference between OSTRAPs and TOOLBOX traps is that for OSTRAPs, which require an I/O buffer address in A0 and return a status code in D0, A0 and D0 must not be saved on the stack across the actual code. Apple accomplished this by setting bit 11 in all of the TOOLBOX instructions (in other words, the second hexadecimal digit of a TOOLBOX trap will always be at least 8). The dispatch code at 401018 examines that bit to determine whether or not to save A0 and D0 (and possibly some other registers) on the stack.

More important, you can watch as the dispatch code determines via a lookup table where to go in the ROMs, and you can trace through those high-power ROM routines that we've all come to know and love. Now you can see for yourself exactly how a window is opened, or what have you.

The ability to trace through the ROMs, coupled with MacNOSY's capability of outputting labels, as opposed to addresses, makes for a relatively simple way of learning how the Mac works right down at the nuts and bolts level - which is right up MacTutor's alley, right, guys?

May all of your hacking - er, excuse me, I mean programming - be bug free!

TMON Thoughts

Some of you may have seen TMQ Software's ad in MacTutor lately. They're pushing a product called TMON, which at first made me laugh - TMON was the name of the first machine language monitor I ever actually laid my mits upon; it was for my (at the time) tape based Model I TRS-80. You can see why I laughed.

Nevertheless, TMQ promised some interesting things, like tracing ROM and setting up to seven breakpoints. Also, they claimed that TMON was a multiple-window monitor/debugger. Just the idea that a debugger could be multiple window boggled me. The thing must be huge. Especially if it can disassemble, do hex dumps, heap displays, register displays, and so on simultaneously.

The price looked pretty reasonable for all of this: the ad asked for $100.00, which is less than I paid for MacASM, my assembler of choice. I finally broke down and ordered TMON from TMQ. It arrived a few days after I ordered it; if you're willing to pay for it, TMQ will ship UPS blue label, which is how I prefer to work.

After using TMON and configuring it and reconfiguring it and debugging some of my own code and tinkering around with some code that I didn't write, I can make the following observations.

Love at First Byte

First, if you don't already own a copy of TMON, run, don't walk, to get your checkbook and order it now. If you are a serious developer (and if you are reading this, chances are pretty good that you are) you should be using TMON. Use TMON once and you'll never boot MacsBug again. I promise.

The ads really don't do it justice. They don't tell you about the interactive assembler/disassembler; they don't tell you about the fact that dump and disassembly windows can be "anchored" to registers and are continually updated; they don't tell you that TMON allows access to any online resource file; they don't tell you about the customizable user area; they don't tell you about the sophisticated label support, or the screen buffering, or the rich implementation of interrupt button functions... The list goes on.

Think of TMON as MacsBug and MacNosy combined, with some things thrown in that neither MacsBug nor MacNosy was intended to do. To be fair about it, since MacNosy is a disassembler and not a debugger, there are some features that MacNosy has that TMON doesn't. I recommend both of them if you are serious about Mac programming.

TMON's fast window system will impress you, as will its implementation of menus. It takes a little getting used to; both windows and the menubar are handled a little differently from "normal" Mac windows and menus.

Mouse Unfreeze

The menus are Dump, Asmbly, Brkpnts, Regs, Heap, File, Exit, GoSub, Step, Trace, Options, Num, User, and Print. Another feature that TMON implements via a command keystroke is called Mouse Unfreeze. Yes, you read right - if your program crashes and your mouse freezes up but the keyboard is still listening, you can unfreeze the mouse. Wild stuff.

Dump opens a window which is initially a dump starting at address 000000. There is a blinking cursor on the first line. As long as the cursor is on the first line, the address can be changed. You can type in any expression, label, or register to anchor to (as well as a special virtual register called V). The window will be instantaneously updated to show the new dump. More importantly, if you anchor to a register (say A0), whenever the contents of A0 changes the window will be updated to reflect the change. You won't believe how useful this is until you see it.

Disassembler Anchored to the PC Counter

'Asmbly' is the interactive assembler / disassembler. When you open this window, you get a disassembly starting at 000000, which doesn't make much sense, since there is no valid code there. You'll probably want to anchor the disassembly window to the PC. Like the dump window, when you anchor the disassembly window to a register it gets updated every time the register changes. Anchoring the disassembly window to the PC causes the window to be updated every time you step, trace, gosub, or exit to the program (actually, since exit actually transfers control to the program, the window will not be updated unless control returns to the monitor).

TMON normally displays A-traps as labels, not numbers, although this can be changed in order to conserve space. TMON also supports user-defined label tables. The TMON master disk includes a file called System.MAP which is a label file of all of the low memory equates on the Macintosh. This MAP file can be loaded into TMON so that features of TMON that support labels (nearly all of them, in other words) can now refer to low RAM areas (with labels like CurApName and so on) by name instead of address. This aspect of TMON, unfortunately, requires 512K.

TMON includes sophisticated customization support that allows you to fine tune TMON to your needs. TMON is quite capable of running on a 128K machine, and contrary to what you might think, it does not have to be hopelessly crippled in order to do so. I can use A-trap names and, with a compressed screen buffer of 4K, do some meaningful debugging. A 512K Mac sure would help, though.

TMON has an alternate register save area. This is interesting. You can come close to a routine that you think will crash, save the registers, execute the routine, and if it crashes (an exception lands you back in TMON), you can reload the registers and try again, and so forth. Kind of like being in suspended animation.

We all know that the interrupt button on the Mac is good for something. TMON knows it, too. Pressing the button from an application will get you into TMON, just like it does with MacsBug. However, there are several special-purpose keystroke-interrupt combinations that TMON has over MacsBug.

Pressing interrupt while holding down the command key restarts the monitor. This is considered a drastic step to be taken only when all else fails. This often has the effect of mulching part of TMON. The nice thing is that TMON is constantly checking itself, and if it thinks it's been damaged, it will say so.

Cmd-Option-Interrupt!

If that doesn't work, try command - option - interrupt. This does a really total monitor reset, which makes it definitely last-resort material.

Now for the interesting one. The user area supplied with TMON contains a function called Trap Signal. The manual calls the Trap Signal function a "smart interrupt," which is a pretty apt description. Trap Signal allows you to specify a trap or range of traps to apply this function to, as well as an optional address or address range. Once you've done that, go ahead and execute your program.

Nothing happened, right? You're program should be whizzing merrily along. Now press interrupt while holding down the option key. This activates the trap signal, which won't go into effect until your trap and address range criteria are met. That's why it's called a smart interrupt: it doesn't stop until it hits the right trap/PC location. This allows you to interrupt your program at a specific place rather than going into it blind. A good trap to put a smart interrupt on would be _GetNextEvent, since it tends to be at the main loop of any Mac application.

Trace uses the Trace bit

TMON's trace, step, and GoSub features are very nice and very powerful. TMQ Software saw fit to do what no one else did: they use the trace bit of the status register to force a trace interrupt, which the monitor traps. This is the essence of tracing under TMON. The trace function even allows you to watch as the A-trap dispatcher finds the address of the A-trap's code and executes it. This means that my little note concerning tracing the ROMs under MacsBug doesn't apply here; TMON's trace does it automatically. Step in TMON is exactly like trace except that A-traps are treated as a single instruction. GoSub is like step except that subroutines (executed by JSR or BSR) are executed in full without tracing.

The heap windows are something else. Not only do they show what blocks exist and whether the block is locked, purgable, relocatable, and what have you; they also show what is in the block (to the best of TMON's ability). You can see at a glance which block contains CODE segment number one of your program, which block contains the font that is currently in use, which blocks contain resources pertinent to the application, and so on. You can also examine the system heap in the same manner. A heap window can be made to switch from appplication heap to system or vice-versa by hitting the TAB key (which puts the cursor at the top of the window) and hitting the RETURN or ENTER key.

The file window is extremely useful. It shows the contents of all currently open resource files. For those resources that are in memory, their handle is given. For those that haven't been loaded from disk yet, "Nowhere" is displayed. Resources of any type and ID can be loaded using the standard user area LoadRes utility.

If a window is too limited to show you as much as you would like of what it is you're looking at, you can probably print it with the user area print utility. You can specify dump printing, disassembly printing, file printing, or heap printing. For dumps and disassemblies you must specify an address range. For files TMON needs the resource file number, and for heap prints it needs 0 for the system heap and a non-zero value for the application heap.

There are lots of other handy features, too, such as block moves, block compares, block fills, checksumming of memory, label table support, a very efficient heap scramble, a find utility, the ability to show the application's screen, and the ability to completely reset the system.

User Extensible via MDS

To make matters even better, the author includes the source code to the entire default user area on the TMON disk. The point is that sophisticated Mac programmers can write their own user area utilities that can either replace or augment the ones included with TMON. The source is in MDS format, and a link file is included to link the resulting object code into TMON. Obviously, you must have MDS for this to be of any use. Frankly, I think it'll be a long time before anyone comes up with a way to improve upon TMON's already fantastic user area routines.

That about wraps it up. My idea of an ideal Mac debugging setup is a 512K Mac running TMON. Use the normal default user area, then add in the System.MAP file. This will allow TMON to refer to low memory areas by name (which is handy if you're doing ROM disassemblies in particular). Now you can really debug! Goodbye, MacsBug; hello, TMON!

 
AAPL
$119.00
Apple Inc.
+1.40
MSFT
$47.75
Microsoft Corpora
+0.28
GOOG
$540.37
Google Inc.
-0.71

MacTech Search:
Community Search:

Software Updates via MacUpdate

HoudahSpot 3.9.6 - Advanced file search...
HoudahSpot is a powerful file search tool built upon MacOS X Spotlight. Spotlight unleashed Create detailed queries to locate the exact file you need Narrow down searches. Zero in on files Save... Read more
RapidWeaver 6.0.3 - Create template-base...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
iPhoto Library Manager 4.1.10 - Manage m...
iPhoto Library Manager lets you organize your photos into multiple iPhoto libraries. Separate your high school and college photos from your latest summer vacation pictures. Or keep some photo... Read more
iExplorer 3.5.1.9 - View and transfer al...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
MacUpdate Desktop 6.0.3 - Discover and i...
MacUpdate Desktop 6 brings seamless 1-click installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on macupdate.... Read more
SteerMouse 4.2.2 - Powerful third-party...
SteerMouse is an advanced driver for USB and Bluetooth mice. It also supports Apple Mighty Mouse very well. SteerMouse can assign various functions to buttons that Apple's software does not allow,... Read more
iMazing 1.1 - Complete iOS device manage...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
PopChar X 7.0 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more
Carbon Copy Cloner 4.0.3 - Easy-to-use b...
Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more
ForeverSave 2.1.3 - Universal auto-save...
ForeverSave auto-saves all documents you're working on while simultaneously doing backup versioning in the background. Lost data can be quickly restored at any time. Losing data, caused by... Read more

Latest Forum Discussions

See All

Bounce On Back (Games)
Bounce On Back 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »
Make Way for Fat Chicken, from the Maker...
Make Way for Fat Chicken, from the Makers of Scrap Squad Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Relevant Games has announced they will be releasing their reverse tower defense game, | Read more »
Tripnary Review
Tripnary Review By Jennifer Allen on November 26th, 2014 Our Rating: :: TRAVEL BUCKET LISTiPhone App - Designed for the iPhone, compatible with the iPad Want to create a travel bucket list? Tripnary is a fun way to do exactly that... | Read more »
Ossian Studios’ RPG, The Shadow Sun, is...
Ossian Studios’ RPG, The Shadow Sun, is Now Available for $4.99 Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Mmmm, Tasty – Having the Angry Birds for...
The very first Angry Birds debuted on iOS back in 2009. When you sit back and tally up the number of Angry Birds games out there and the impact they’ve had on pop culture as a whole, you just need to ask yourself: “How would the birds taste... | Read more »
Rescue Quest Review
Rescue Quest Review By Jennifer Allen on November 26th, 2014 Our Rating: :: PATH BASED MATCH-3Universal App - Designed for iPhone and iPad Guide a wizard to safety by matching gems. Rescue Quest might not be an entirely original... | Read more »
You Can Play the Final Chapter of Lone W...
You Can Play the Final Chapter of Lone Wolf: Dawn Over V’taag Right Now Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swords of Anima (Games)
Swords of Anima 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: A new tactical turn-based RPG experience. Command the Savior Rex Squad in an epic journey of courage and deception. Can you... | Read more »
Audio Defence: Zombie Arena
Audio Defence: Zombie Arena By Lee Hamlet on November 26th, 2014 Our Rating: :: DRAGS ITS FEETUniversal App - Designed for iPhone and iPad From the makers of Papa Sangre comes a defense game that forces players to listen carefully... | Read more »
Tales from the Borderland​s Will be Comi...
Tales from the Borderland​s Will be Coming to iOS by the End of the Year Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Telltale Games has announced | Read more »

Price Scanner via MacPrices.net

2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has the new 1.4GHz Mac mini on sale for $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new model. Adorama... Read more
Early Black Friday pricing on 27-inch 5K iMac...
 B&H Photo continues to offer Black Friday sale prices on the 27″ 3.5GHz 5K iMac, in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP... Read more
Early Black Friday sale prices on iPad Air 2,...
 MacMall is discounting iPad Air 2s by up to $75 off MSRP as part of their Black Friday sale. Shipping is free: - 16GB iPad Air WiFi: $459 $40 off - 64GB iPad Air WiFi: $559 $40 off - 128GB iPad Air... Read more
Early Black Friday MacBook Air sale prices, $...
 MacMall has posted early Black Friday MacBook Air sale prices. Save $101 on all models for a limited time: - 11″ 1.4GHz/128GB MacBook Air: $798 - 11″ 1.4GHz/256GB MacBook Air: $998 - 13″ 1.4GHz/... Read more
Why iPhone 6 Tablet/Laptop Cannibalization Is...
247wallst.com blogger Douglas A. McIntyre noted last week that according to research posted on the Applovin blog site the iPhone 6 is outselling the iPhone 6 Plus by a wide margin . Hardly a surprise... Read more
Worldwide Tablet Growth Expected to Slow to 7...
The global tablet market is expected to record massive deceleration in 2014 with year-over-year growth slowing to 7.2%, down from 52.5% in 2013, according to a new forecast from International Data... Read more
Touchscreen Glove Company Announces New Produ...
Surrey, United Kingdom based TouchAbility specializes in design and manufacture of a wide variety of products compatible with touchscreen devices including smartphones, tablets and computers. Their... Read more
OtterBox Alpha Glass Screen Protectors for iP...
To complement the bigger, sharper displays on the latest Apple devices, OtterBox has introduced Alpha Glass screen protectors to the iPhone 6 and iPhone 6 Plus. The fortified glass screen protectors... Read more
Early Black Friday Mac Pro sale, 6-Core 3.5GH...
 B&H Photo has the 6-Core 3.5GHz Mac Pro on sale today for $3499 including free shipping plus NY sales tax. Their price is $500 off MSRP, and it’s the lowest price available for this model from... Read more
Early Black Friday sale price: 15-inch 2.2GHz...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale today for $1699.99. Shipping is free, and B&H charges NY sales tax only. Their price is $300 off MSRP, equalling Best Buy’s price... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.