Partner sites: Aminet - Amiga downloadsIntuitionBase - Amiga guidesAmigaNN - Amiga newsAmiFund - Sponsor projects

[Y]UtilityBase
Your guide to Amiga development
Sign up at our provider 
and get $50 off!
Not logged in
  HomeProjectsForumArticlesResourcesLinksChatAbout 
Search
Login
Username:
Password:
Register now!
Forgot your password?
Aminet - Development
Blitz_AVI.lha (dev/basic)
bullet.lha (dev/lib)
MCC_TheBar-26.6.lha (dev/mui)
MCC_TextEditor-15.35.lha (dev/mui)
MCC_BetterString-11.19.lha (dev/mui)
fw_c2p_p2c.lha (dev/lib)
plib_examples.lha (dev/src)
plib.lha (dev/lib)
MCC_NList-0.107.lha (dev/mui)
MCC_NList-0.106.lha (dev/mui)
More...
Newest users
prowler
apache64 (Chris)
cpeel2300 (Chris)
Branquito
chris (Chris Young)

Pending:
ZebraZeem, Mad_Dog, hhjoker, voxel, JosDuchIt, MarcB, MarBo, Sollaris, sara, species
More...
Who's Online
Online members:

obarthel 3 min(s) ago

15 guests are online.

You are an Anonymous user. You can register for free by clicking here.
News sites
Amiga-News.de
Amiga.org
AmigaNN
Amigans.net
Amigaweb.net
AmigaWorld.net
AROS-Exec
MorphOS-News.de
MorphZone
polarBoing
Tutorials
Change Graphics cards in AmigaOS 4.
Installing the latest OS4 SDK in Cubic IDE
Writing Installer scripts for AmiUpdate
Cross Compiling for OS4 or OS3 using MS Visual Studio 2005
Installing an AmigaOS 4 cross compiler
More...
Sources
How to open and use the exec debug interface
How to install a hardware interrupt
Install SObjs with Installer
How to make clean picture datatypes
Most of the old ClassACT examples converted to OS4
More...
Documentations
How to write portable code for Amiga (english)
Comment écrire du code portable pour Amiga (français)
Development How to with OS3.9 SDK
The PartyPack Hack
The Amiga PDA Programming Guidelines
More...
DreamHost

Support
UtilityBase

[Valid RSS]

UtilityBase needs your help!

How to open and use the exec debug interface
by Alfkil Wennermark
Link: How to open and use the exec debug interface

Next step in my small series concerns itself with how to open and use the "secret" (but very useful) debug interface. Thanks to Steven Solie and Thomas Frieden.

Probably the best way to trap exceptions from within
your code is to use the debug interface, that is "hidden"
inside exec.library. The main problem with this interface is,
that it is not very well documented. My main source of
documentation on this issue is the amigaos-nat.c file from
Thomas Friedens GDB sources. These can be found inside
the adtools project on sourceforge.net.

The following code just plainly opens the interface, attaches
a debug hook to itself, causes an exception and tells you
what has happened. Normally you wouldn't attach the hook
to your own process. Rather you would open whatever code
you want to debug with fx. LoadSeg(), run it with CreateNewProc()
(or some other way) and attach the debug hook to it. To keep
things simple, though, this code just attaches the hook to itself.



/* debugtrap.cExample of use of the exec debug interface
by Alfkil Wennermark 2010

Thanks to Steven Solie, Thomas Frieden and others

This code is partially copied from Thomas' GDB source
*/



#include <proto/exec.h>
#include <proto/dos.h>

#include <exec/types.h>
#include <exec/interrupts.h>
#include <exec/tasks.h>

#include <dos/dos.h>

#include <stdio.h>


struct DebugIFace *IDebug = 0;

struct KernelDebugMessage
{
uint32 type;
union
{
struct ExceptionContext *context;
struct Library *library;
} message;
};

static ULONG amigaos_debug_callback(struct Hook *, struct Task *, struct KernelDebugMessage *);

struct Hook debug_hook;
struct Task *amiga_task;

BPTR exec_seglist;
ULONG debug_data = 1234;

void init()
{
IDebug = (struct DebugIFace *)IExec->GetInterface((struct Library *)SysBase, "debug", 1, 0);
if (!IDebug)
{
printf("Can't get DEBUG accessn");
exit(RETURN_FAIL);
}

debug_hook.h_Entry = (ULONG (*)())amigaos_debug_callback;
debug_hook.h_Data =(APTR)&debug_data;

/* NB: Ideally we would start up another task, that
we want to debug, and attach ourselves to that
task using the debug hook, but for simplicity
we just use our own task here */

amiga_task = IExec->FindTask(NULL);
IDebug->AddDebugHook(amiga_task, &debug_hook);
}

void end()
{
IDebug->AddDebugHook(amiga_task, 0);

if (IDebug)IExec->DropInterface((struct Interface *)IDebug);
IDebug = NULL;
}



ULONG
amigaos_debug_callback(struct Hook *hook, struct Task *currentTask,
struct KernelDebugMessage *dbgmsg)
{
struct ExecIFace *IExec = (struct ExecIFace *)((struct ExecBase *)SysBase)->MainInterface;

uint32 *data = (uint32 *)hook->h_Data;

/* these are the 4 types of debug msgs: */
switch (dbgmsg->type)
{
case DBHMT_REMTASK:
*data = 9;
break;
case DBHMT_EXCEPTION:
*data = 11;
break;

case DBHMT_OPENLIB:
*data = 13;
break;

case DBHMT_CLOSELIB:
*data = 15;
break;

default:
*data = 0;
break;
}
/* returning 1 will suspend the task ! */
return 0;
}



int main()
{
init();

/* Cause an exception on purpose: */
uint32 *beef = 0;
*beef = 0L;

printf("We received a");
switch (debug_data)
{
case 9:
printf(" REMTASK");
break;
case 11:
printf("n EXCEPTION");
break;
case 13:
printf("n OPENLIB");
break;
case 15:
printf(" CLOSELIB");
break;

default:
printf("n unknown");
break;
}
printf(" signal!n");

end();

return RETURN_OK;
}


Rate this item
12345678910


Last poster Message


Posted: 2010-06-15 06:19
Thanks for this one. How interesting! I have used the interface for disassembling code but didn't know about this one. :-)

:: Your comment
Bold Style  Italic Style  Underlined Style  Image Link  Insert URL  Email Link  Quote  C/C++ Source  Disable *What`s that?


Before posting non-english message, check your browser`s encoding!
» Name » Password

UtilityBase is a site focused on development for Amiga systems,
spanning over all different Amiga clones, that be AmigaOS 3.x, 4.x, MorphOS, AROS or AmigaDE/Anywhere.
News syndication: RSS
Contact address: mail@utilitybase com