Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
SysStackTraces


NAME

SysStackTraces - print stack traces

SYNOPSIS

PROCEDURE PrintBackTrace(s: Streams.Stream; cr: Coroutines.Coroutine);
PROCEDURE PrintAllBackTraces(s: Streams.Stream);

DESCRIPTION

SysStackTraces allows to print out simple backtraces of invocation chains of coroutines. This is mainly useful on platforms where no helpful debugger is available.

Each line in a backtrace specifies the contents of two major registers (frame pointer and program counter) in hex and the qualified name of the procedure.

PrintBackTrace prints the backtrace for cr onto s. The results are undefined if cr is the current coroutine.

PrintAllBackTraces prints the backtraces of all coroutines onto s. Multiple back traces are separated by empty lines.

EXAMPLE

Following module, if imported, provides a backtrace of the offending coroutine in case of a runtime error or similar event that caused Process.Abort to be called:
MODULE CrashHandler;

   IMPORT Coroutines, Errors, Events, Process, Streams, SysStackTraces,
      SYSTEM, Write;

   PROCEDURE PrintBackTrace(VAR cr: Coroutines.Coroutine);
   BEGIN
      SYSTEM.CRSPAWN(cr);
      SysStackTraces.PrintBackTrace(Streams.stderr, Coroutines.source);
      SYSTEM.CRSWITCH(Coroutines.source);
   END PrintBackTrace;

   PROCEDURE AbortHandler(event: Events.Event);
      VAR
         cr: Coroutines.Coroutine;
   BEGIN
      Write.StringS(Streams.stderr, Process.name);
      Write.StringS(Streams.stderr, ": ");
      Errors.Write(Streams.stderr, event);
      Write.LnS(Streams.stderr);
      Write.LineS(Streams.stderr, "backtrace of current coroutine:");
      PrintBackTrace(cr); SYSTEM.CRSWITCH(cr);
   END AbortHandler;

BEGIN
   Events.Handler(Process.abort, AbortHandler);
END CrashHandler.
Please note that SysStackTraces.PrintBackTrace creates a new coroutine for printing the backtrace as a coroutine shall not print its own backtrace.

SEE ALSO

SysModules
is used to map program counters into module / procedure combinations
SysStacks
allows the examination of coroutine stacks

Edited by: borchert, last change: 2005/08/25, revision: 1.1, converted to HTML: 2005/08/25

Oberon || Library || Module Index || Search Engine || Definition || Module