Nov 95 Tips
Volume Number: | | 11
|
Issue Number: | | 11
|
Column Tag: | | Tips & Tidbits
|
Tips & Tidbits
By Steve Sisak, Contributing Editor
Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.
TIP OF THE MONTH
Two Screen MacsBug
One feature of MacsBug that I like is the "swap" command, which lets you leave a second monitor display the debugger (and punches it out of the desktop).
Then, if each DebugStr() ends in ";g" you will get an onscreen log of the last 10 or 15 breaks. I used this to track an elusive bug that would freeze my Mac and trash Macsbug memory... I could see which breakpoint went last.
Matt Slot
Informant in the Menu Bar
I do drivers, and you just plain cant set a breakpoint in ADB completion routines (freezes the keyboard so MacsBug is worthless!).
So I throw one of the routines below into the routine to see when a piece of code gets executed.
What does it do? It "lights up" a bar (length dependant on screen resolution) in the menu bar. So if you DotToggle(300); you get a flashing short line in the menu bar.
[Leave this out of production code! Beware of using this on 24 bit color screens. Make sure that the value of where will not cause anything to be written into the alpha channel. Your best bet is to test with the screen thats only 8 bits deep. -sgs]
void DotOn(long where) {
long *dot;
dot = (long *)(LMGetScrnBase() + where);
*dot |= -1;
}
void DotOff(long where) {
long *dot;
dot = (long *)(LMGetScrnBase() + where);
*dot &= 0;
}
void DotToggle(long where) {
long *dot;
dot = (long *)(LMGetScrnBase() + where);
*dot ^= -1;
}
Dave Fleck
Informative Cursors
One technique that I have used in the past where dropping into the debugger wasn't an option, and logging wasn't getting flushed in time/took too long, was to create a bunch of cursors numbering 00 - 99, and made a call to set the cursor and return the number of the previous cursor:
routine1()
{
short oldCursor = setDebugCursor(15);
...
(void) setDebugCursor(oldCursor);
}
This way when the machine froze, the cursor would tell me what routine it had frozen in.
Tom Kimpton
MPW Editor Primitives
The MPW Command Reference describes 32 editor primitives which may be attached to any key sequence using the SetKey command. While the SetKey command itself is useful, the list of editor primitives alone is useful to MPW script writers.
Though only documented for use with SetKey, editor primitives may be used like any other MPW command: in scripts, command aliases, or AddMenu items. There are a couple of advantages:
1) They only work on the active window and have sharply defined functions, you dont have to remember any selection expressions or argument lists. Compare:
MoveStartOfFile
with
Find "{Active}"
2) Theyre fast. I havent put a stopwatch to it, but you can see the difference immediately in running a script that uses the primitives and one that doesnt.
The MPW Command reference lists these 32 primitives, the names of which should be self-explanatory:
DeleteCharLeft
DeleteCharRight
DeleteEndOfFile
DeleteEndOfLine
DeleteStartOfFile
DeleteStartOfLine
DeleteWordLeft
DeleteWordRight
MoveCharLeft
MoveCharRight
MoveEndOfLine
MoveLineDown
MoveLineUp
MovePageDown
MovePageUp
MoveStartOfFile
MoveStartOfLine
MoveWordLeft
MoveWordRight
SelectCharLeft
SelectCharRight
SelectEndOfFile
SelectEndOfLine
SelectLineDown
SelectLineUP
SelectPageDown
SelectPageUp
SelectStartOfFile
SelectStartOfLine
SelectWordLeft
SelectWordRight
There are also at least five primitives that arent in the command reference:
ScrollEnd
ScrollHome
ScrollPageDn
ScrollPageUp
DebuggerCommand
I can understand why Apple might not want users to casually drop into MacsBug from an MPW script, but I wonder why they chose not to document the scrolling commands? Whatever the reason, you should obviously use caution when playing with undocumented features.
Lee David Rimar
Absoft Corporation
Once Bitten Twice Shy
HGetState does not return a valid handle state when you pass it an empty handle (one whose master pointer is NULL). Instead, it returns an error code, so before you call HGetState, be sure to check that the handle isnt empty and execute an alternate code path if it is.
I was bitten by this because I was using HGetState to determine if a handle was to a resource, and the resourced had been purged, so HGetStaate returned an error code instead of the handle flags and I incorrectly thought the handle wasnt to a resource.
This is documented in Inside Macintosh, Memory, p. 1-61, but it bears some repeating. Remember to check the error values returned by the toolbox calls.
Eric Schlegel