Next: , Previous: Tracing Examples, Up: Traps


5.21.3.6 Tracing Configuration

The detail of what gets printed in each trace line, and the port to which tracing is written, can be configured by the procedures set-trace-layout and trace-port, both exported by the (ice-9 debugging trace) module.

— Procedure with Setter: trace-port

Get or set the port to which tracing is printed. The default is the value of (current-output-port) when the (ice-9 debugging trace) module is first loaded.

— Procedure: set-trace-layout format-string . arg-procs

Layout each trace line using format-string and arg-procs. For each trace line, the list of values to be printed is obtained by calling all the arg-procs, passing the trap context as the only parameter to each one. This list of values is then formatted using the specified format-string.

The (ice-9 debugging trace) module exports a set of arg-proc procedures to cover most common needs, with names beginning trace/. These are all implemented on top of the tc: trap context accessor procedures documented in Trap Context, and if any trace output not provided by the following is needed, it should be possible to implement based on a combination of the tc: procedures.

— Procedure: trace/pid trap-context

An arg-proc that returns the current process ID.

— Procedure: trace/stack-id trap-context

An arg-proc that returns the stack ID of the stack in which the current trap occurred.

— Procedure: trace/stack-depth trap-context

An arg-proc that returns the length (including non-real frames) of the stack at the point of the current trap.

— Procedure: trace/stack-real-depth trap-context

An arg-proc that returns the length excluding non-real frames of the stack at the point of the current trap.

— Procedure: trace/stack trap-context

An arg-proc that returns a string summarizing stack information. This string includes the stack ID, real depth, and count of additional non-real frames, with the format "~a:~a+~a".

— Procedure: trace/source-file-name trap-context

An arg-proc that returns the name of the source file for the innermost stack frame, or an empty string if source is not available for the innermost frame.

— Procedure: trace/source-line trap-context

An arg-proc that returns the line number of the source code for the innermost stack frame, or zero if source is not available for the innermost frame.

— Procedure: trace/source-column trap-context

An arg-proc that returns the column number of the start of the source code for the innermost stack frame, or zero if source is not available for the innermost frame.

— Procedure: trace/source trap-context

An arg-proc that returns the source location for the innermost stack frame. This is a string composed of file name, line and column number with the format "~a:~a:~a", or an empty string if source is not available for the innermost frame.

— Procedure: trace/type trap-context

An arg-proc that returns a three letter abbreviation indicating the type of the current trap: "APP" for an application frame, "EVA" for an evaluation, "RET" for an exit trap, or "ERR" for an error (pseudo-)trap.

— Procedure: trace/real? trap-context

An arg-proc that returns " " if the innermost stack frame is a real frame, or "t" if it is not.

— Procedure: trace/info trap-context

An arg-proc that returns a string describing the expression being evaluated, application being performed, or return value, according to the current trap type.

trace/stack-depth and trace/stack-real-depth are identical to the trap context methods tc:depth and tc:real-depth described before (see Trap Context), but renamed here for convenience.

The default trace layout, as exhibited by the examples of the previous subsubsubsection, is set by this line of code from the (ice-9 debugging traps) module:

     (set-trace-layout "|~3@a: ~a\n" trace/stack-real-depth trace/info)

If we rerun the first of those examples, but with trace layout configured to show source location and trap type in addition, the output looks like this:

     guile> (set-trace-layout "| ~25a ~3@a: ~a ~a\n"
                              trace/source
                              trace/stack-real-depth
                              trace/type
                              trace/info)
     guile> (rev '(a b c))
     | standard input:29:0         2: APP [rev (a b c)]
     | standard input:4:21         3: APP [rev (b c)]
     | standard input:4:21         4: APP [rev (c)]
     | standard input:4:21         5: APP [rev ()]
     | standard input:2:9          5: RET =>()
     | standard input:4:13         4: RET =>(c)
     | standard input:4:13         3: RET =>(c b)
     | standard input:4:13         2: RET =>(c b a)
     (c b a)