[M3devel] Internal debugging - a simple design
Darko
darko at darko.org
Tue Apr 2 19:51:48 CEST 2013
Here's an idea for how simple internal debugging might work.
A command line option is created that turns on debug code generation globally. A pragma is created, <*DEBUG*> which turns on debugging for all of the procedures within the scope that the pragma precedes, being an implementation module or a possibly nested procedure. Both must be done for debugging code to actually be generated for a procedure.
For each procedure within a debugging scope the following declaration is inserted (the offsets are byte offsets):
CONST
ProcName: TEXT = "Module.ProcName";
ProcType: CARDINAL = 12345678;
ProcAdr: ADDRESS = 123456;
ParamNames = ARRAY OF TEXT{"param1", "param2", "param3"};
ParamTypes = ARRAY OF CARDINAL{1, 2, 3};
ParamOffs = ARRAY OF INTEGER{0, 4, 8, 16);
ReturnType: CARDINAL = 12345678;
ReturnOffs: INTEGER = 32;
LocalNames = ARRAY OF TEXT{"local1", "local2", "local3"};
LocalTypes = ARRAY OF CARDINAL{1, 2, 3};
LocalOffs = ARRAY OF INTEGER{20, 24, 28, 36);
Extra calls are inserted into a procedure within a debugging scope so that whenever the procedure is called DebugProcEntry is called first. DebugProcEntry must be declared or imported in the procedure's module. DebugProcEntry passes all the above constant declarations as parameters, plus an extra parameter which gives the address of the zero offset for the parameters and local variables:
PROCEDURE DebugProcEntry(
READONLY frame: ADDRESS;
READONLY procName: ProcName;
READONLY procType: ProcType;
READONLY procAdr: ProcAdr;
READONLY paramNames: ParamNames;
READONLY paramTypes: ParamTypes;
READONLY paramOffs: ParamOffs;
READONLY returnType: ReturnType;
READONLY returnOffs: ReturnOffs;
READONLY localNames: LocalNames;
READONLY localTypes: LocalTypes;
READONLY localOffs: LocalOffs
);
Whenever a procedure returns a procedure called DebugProcExit is called just before it exits, with the same parameters as DebugProcEntry.
- Darko
More information about the M3devel
mailing list