Technical Q&As


PLAT 30 - Detecting Macsbug (2-May-97)


Q How do I detect if Macsbug is installed?

A To detect if Macsbug is loaded, or if any debugger is loaded, you need to look at some low memory variables as documented in the "Macsbug Reference & Debugging Guide", page 412. If you are running on a machine which has a 32 bit capable Memory Manager, debugger flags are at low memory location $BFF. If you are running on an older machine which only contained a 24 bit capable Memory Manager, the debugger flags are at low memory location $120. Note that the documentation is slightly obscure--you check if the machine is capable of 32-bit mode, _not_ if you are running in 32 bit mode.

Think Reference 2.0.1 has a statement in its sample code which states:

ADDENDUM: The above information seems to be incorrect in the reference manual. I have found through testing etc. that in both modes, the Flag Byte appears at location 0xBFF. The code reflects these findings.

This is because they confused running in 24 bit mode, running in 32 bit mode, and the _ability_ to run in 32 bit mode. It is the latter ability which you must test to determine the location of the debugger flags.

#include 

/* the 2 low memory locations you might need */
#define MacJmpByte  (char *) 0x120  /* Macsbug flag on old machines */
#define MacJmpFlag  (char *) 0xBFF  /* MacsBug flag [byte] */

#define DebuggerInstalled   5

Boolean DebuggerIsPresent()
{
    long    addressingMode;
    short   debugFlags;

    Gestalt(gestaltAddressingModeAttr, &addressingMode);
    if (addressingMode & (1 << gestalt32BitCapable))
        debugFlags = *MacJmpFlag;
    else
        debugFlags = *MacJmpByte;

    return (debugFlags & (1 << DebuggerInstalled));
}

-- Brian Bechtel
Worldwide Developer Technical Support

Technical Q&As
Previous Question | Contents| Next Question

To contact us, please use the Contact Us page.