Nov 99 Tips
Volume Number: 15 (1999)
Issue Number: 11
Column Tag: Tips & Tidbits
Tips and Tidbits
by Jeff Clites <email@example.com>
Poor Man's Debug Console
I've been doing some USB Device Driver development recently using Apple's USB DDK. One of the utilities supplied with this DDK is USB Prober, whose main use is to provide a console for debug messages from the USB Manager and from USB device drivers (the "USB Expert Log"). However there is nothing to prevent any piece of code, whether it be an application, device driver, or even an interrupt handler, from sending messages to USB Prober. This makes it a particularly useful debug console, particularly for code which has no user interface, such as device drivers or faceless background applications, and for code which may run at interrupt level, such as completion routines.
In order to use USB Prober for debugging, you need:
- a Mac with USB (iMac, G3, G4, 1999 G3 PowerBook, etc.)
- Apple’s USB DDK
In your project, you need to #include <USB.h> and link against the library USBServices.lib. To send a debug message, use the USBExpertStatus() call, e.g.
if (err != noErr)
“\pOh no ! err = “, err);
Before running your application, launch USB Prober, and open the USB Expert Log.
Paul Russell firstname.lastname@example.org
Adding Descriptions to StdLog
If you are logging a series of crashes, the MacsBug 'stdlog' macro is very useful for appending a series of MacsBug commands to the file StdLog on your desktop. It includes the date and time but unfortunately doesn't allow you to enter a comment explaining the context of the crash. The following sequence of commands allows you to precede the stdlog dump with your own comments:
log "StdLog" // opens the same file used by stdlog, creating if absent
printf "some comment in double quotes"
// prints whatever's in quotes
log // closes the log
stdlog // runs the stdlog macro
If you don't have the 'printf' DCMD installed, you can use a slower method of just entering your comment in quotes on the command line:
"some comment in double quotes"
// records comment, as seen below
The trick here is the way log recording works-anything displayed in the macsbug output window is logged. When you enter the comment in quotes, MacsBug attempts to evaluate it, resulting in an entry like:
Unrecognized symbol "some comment in double quotes"
You can of course enter as many comments as you like before closing the log - this technique is not limited to a single line.
Andy Dent email@example.com