• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

ADVERTISEMENT
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 can’t 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 that’s 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 don’t have to remember any selection expressions or argument lists. Compare:

 MoveStartOfFile

with

       Find • "{Active}"

2) They’re fast. I haven’t put a stopwatch to it, but you can see the difference immediately in running a script that uses the primitives and one that doesn’t.

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 aren’t 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 isn’t 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 wasn’t 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

 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live