(sagittarius debug) - Debugging support

Library (sagittarius debug)

This library provides debugging support reader macro.

Reader Macro #?= expr

This reader macro reads the next expression as followings;

(debug-print _expr_)

debug-print is an internal macro of this library which prints the read expression and its result.

Following example shows how to enable this;

#!read-macro=sagittarius/debug
#!debug
(let ((a (+ 1 2)))
  #?=(expt a 2))

#|
#?=(expt a 2)
#?-    9
|#

#!debug enables the debug print.

Function macroexpand expr

Expands given expr. The returning value may or may not be used as proper Scheme expression.

Function macroexpand-1 expr
Function macroexpand-n expr n

Expands given expr n times. The first form's n is 1.

This procedure expands only globally defined macro and the result of expansion is other macro such as next rule of syntax-rules. It doesn't consider locally bound macros.

The returning value may or may not be used as proper Scheme expression.

Above 2 procedures are no more than debug aid. Depending on the result of expansion is not guaranteed to work.

Remote debugger (experimental feature)

CAVEAT This functionality and interface is subjected to be changed in the future.

When you want to debug a running script, you can use a remote debugger provided this library. Below example shows how to use it.

(import (rnrs)
        (sagittarius debug))

;; Using random port
(define remote-debugger (make-remote-debugger "0"))
(print "Debugger port: " (remote-debugger-port remote-debugger))

;; Do heavy process or multi threading program which hangs :)

To connect the remote debugger, you can use simpley use (sagittarius remote-repl) towards the debugger node and port.

(import (rnrs)
        (sagittarius remote-repl))
(connect-remote-repl "localhost" "${port number shown on the console}")
Function remote-debugger? obj

Returns #t if the given obj is a remote debugger object.

Function make-remote-debugger ( port string? )

Creates a remote debugger. The port must be an available port number, or "0" for random port.

Function remote-debugger-terminate! (remote-debugger remote-debugger? )

Terminates the given remote-debugger.

Function remote-debugger-port (remote-debugger remote-debugger? )

Returns the port number of the given remote-debugger.


The bindings listed below are only available on the remote debugger's REPL.

Function all-threads

Get a list of threads created on Scheme world.

Function sleeping-threads :optional ( timeout 0.01)

Get a list of sleeping threads created on Scheme world.

Ssleeping thread is a thread which can't suspend within the given timeout.

Function thread? obj

[SRFI-18] Returns if the given obj is a thread.

Function thread-name ( thread thread? )

[SRFI-18] Returns the name of the given thread.

Function thread-specific ( thread thread? )

[SRFI-18] Returns the specific value of the given thread.

Function thread->pretty-backtrace-string ( thread thread? )

Returns a human readable string representation of the given thread's backtrace.

Function thread-current-procedure ( thread thread? )

Returns the current procedure of the thread.

Function thread-backtrace ( thread thread? )

Returns the backtrace of the given thread.

Currently, a backtrace is a list, however it may change in the future, to access the value of backtrace, use the procedures listed below.

NOTE: A backtrace starts with 1, not zero base.

Function thread-backtrace-type backtrace n

Returns the type of nth backtrace. The value is

*cproc

For C procedure.

*proc

For Scheme procedure.

Function thread-backtrace-procedure backtrace n

Returns the procedure of the nth backtrace.

Function thread-backtrace-source backtrace n

Returns the source, list of file and line number` of the nth backtrace, if available.

Function thread-backtrace-arguments backtrace n

Returns alist of the arguments of the nth backtrace's procedure.

For local variable, the key is local. For free variable, the key is free.

NOTE: local variable may contain more than the argument of the current procedure. This is bacause it also retrieves the available local variable of the current call frame.

Function thread-backtrace-local-variables backtrace n

Returns local part of the nth backtrace arguments.

Function thread-backtrace-free-variables backtrace n

Returns free part of the nth backtrace arguments.

Function thread-backtrace->pretty-string backtrace

Returns a human readable string representation of the given backtrace.

Function slot-ref obj slot

Returns the slot value of given obj.

Function inspect-object obj

Returns the available slots of the given obj.

Function print arg ...
Function print/ss arg ...

Prints the given args and newline at the end. The first form uses display to print, the latter form uses write/ss.

Function string-prefix? s1 s2

[SRFI-13] Returns #t if the given s1 is the prefix of s2.

Function string-suffix? s1 s2

[SRFI-13] Returns #t if the given s1 is the suffix of s2.