Ok... I've had several requests for more details, so here it is. Enjoy!


Alan Pinstein
Synergy Solutions, Inc.
http://www.synsolutions.com
1-800-210-5293

---


/*

How to set up a project to debug a HACK with source-level debugging in CW.

The basic idea is to make a mini-hack that gets called from within the
program which will then
perform a sub-call of the app which calls the real hack's entry point.
Since the real HACK's entry point
is now being called by an 'official' launch of the application, CW will
respond to breakpoints
and allow source-level debugging of the HACK code.

I simply created a new starter project, and added all of the files from my
HACK to the project.
Then make the modifications listed below to the source code. For my HACK, I
needed a field to do
testing on, so I also added a field to the main form of the project.

Enjoy!

*/

// include a prototype to the main entry point of your HACK
#include "TextEditHack.h"       // it's in there!

// you'll need a global for the address of the trap you're patching.
static void* gOldAddr;

// a mini-hack to call our real hack:
#define DEBUG_HACK_LAUNCH sysAppLaunchCmdCustomBase

static Boolean DebugHackMain (EventPtr event)
{

        UInt                                    cardNo;
        LocalID                         dbID;
        DmSearchStateType       searchState;
        DWord result;
        Err err;

        DmGetNextDatabaseByTypeCreator(true, &searchState,
sysFileTApplication, 'strt', true, &cardNo, &dbID);
        ErrNonFatalDisplayIf(!dbID, "Could not find app");
        if (dbID) {
                err = SysAppLaunch(cardNo, dbID, 0, DEBUG_HACK_LAUNCH,
(Ptr) event, &result);
                ErrNonFatalDisplayIf(err, "Could not launch app");
        }
        return result;
}


static Err AppStart(void)
{
        // install my HACK
        gOldAddr = SysGetTrapAddress(0xA0A9);
        Err error =     SysSetTrapAddress(0xA0A9, DebugHackMain);
        ErrNonFatalDisplayIf(error, "AppStart - SysSetTrapAddress Failed");

        // HackMaster does this, so we need to as well! The entry point of
the hack
        FtrSet(TextEditHackCreator, TextEditTrapFtrID, (DWord) gOldAddr);

   return 0;
}

static void AppStop(void)
{
   // remove hack
        Err error =     SysSetTrapAddress(0xA0A9, gOldAddr);
        ErrNonFatalDisplayIf(error, "AppStop - SysSetTrapAddress Failed");
}

// Call our REAL hack code
// in PilotMain:
                case DEBUG_HACK_LAUNCH:         // from a switch(launchCmd)
                        return TextEditHackMain((EventPtr) cmdPBP);
                        break;


Reply via email to