Re: [Oberon] Identify Calling Command
Is there a portable way to identify the caller of a procedure, I need
I don't really know a portable way (since ETH Oberon does not have full-featured metaprogramming facilities in all versions), but the following works on Native Oberon and Windows Oberon. MODULE Temp; IMPORT SYSTEM, Kernel, Out; PROCEDURE Identify(VAR modname: ARRAY OF CHAR; VAR pc: LONGINT); VAR ebp, eip: LONGINT; m: Kernel.Module; BEGIN SYSTEM.GETREG(SYSTEM.EBP, ebp); SYSTEM.GET(ebp, ebp); (* stack frame of caller *) SYSTEM.GET(ebp+4, eip); (* return address from caller *) m := Kernel.GetMod(eip); IF m # NIL THEN COPY(m.name, modname); pc := eip - SYSTEM.ADR(m.code[0]) ELSE modname[0] := 0X; pc := MAX(LONGINT) END END Identify; PROCEDURE Test*; VAR name: ARRAY 32 OF CHAR; pc: LONGINT; BEGIN Identify(name, pc); Out.String(name); Out.String(" PC="); Out.Int(pc, 1); Out.Ln END Test; END Temp. The gives you the calling module name and PC offset, which can be used with Compiler.Compile \f to find the calling location. If you just want this for debugging, consider writing a HALT statement, which also gives a stack traceback. On Native Oberon you can use the hack HALT(MAX(INTEGER)) for a halt that produces a trap and then continues running. -- Pieter -- Pieter Muller, Computer Systems Institute, ETH Zurich / MCT Lab, Zurich Native Oberon OS: http://www.oberon.ethz.ch/native/
Is there a portable way to identify the caller of a procedure, I need
I don't really know a portable way (since ETH Oberon does not have full-featured metaprogramming facilities in all versions), but the following works on Native Oberon and Windows Oberon. Thanks a lot, Pieter, that's exactly what I need. I need it for the following: consider the Procedure
PROCEDURE New*; VAR l: antsCommands.tScanList; name: vyName.tNameArray; c: Chain; BEGIN aM.enter("antsMC.New"); l := antsCommands.ScanFromPar("name=NAME # create new markov chain"); IF antsCommands.ExpectNameFromKeyword(l, "name", name) THEN Gen; c := Objects.NewObj(Chain); vyName.RegisterNamed(c, name) END END New; The third line is the one I wanted to circumvent. The mechanism is the following: The user should give a command like antsMC.New myMarkovChain or antsMC.New name=myMarkovChain. Suppose he makes some mistake like executing antsMC.New without any parameters then I want a statement in the Log like usage: antsMC.New name=NAME # create new markov chain Now, since you have answered I can ommit the statement aM.enter("antsMC.New"); Thank you again, Felix. -- Felix Friedrich Institut für Biomathematik und Biometrie GSF - Forschungszentrum für Umwelt und Gesundheit, GmbH Ingolstädter Landstraße 1, D-85764 Neuherberg Tel: ++49 89 3187 2436 email: friedrich@gsf.de --
participants (2)
-
Felix Friedrich -
muller@inf.ethz.ch