chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] A simple debugger


From: felix . winkelmann
Subject: [Chicken-hackers] A simple debugger
Date: Fri, 27 Nov 2015 12:46:40 +0100

Hello!


This patch provides a graphical debugger, both for master and chicken-5.
The debugging-support consists of two parts: 1. An extension to the runtime 
system
that connects to a TCP server on port 9999 and communicates through a 
text/s-expr
based protocol and a graphical front-end written in Tcl/Tk. The runtime-part is
provided in a separate file ("dbg-stub.c"), wrapped by a new library unit 
("debugger-client").
The compiler-backend has been modified to decorate the intermediate 
representation
and generated C code to invoke a hook function ("C_debugger") that sends a 
message
to the server whenever a "debug event" happens (procedure call, entry, global 
variable assignment,
exceptions, garbage collection and process termination). TCP has been chosen as
communication medium as it is available on all platforms and allows remote 
debugging.

Debugging is enabled with debug-level 3 ("-d3"). This uses the 
"debugger-client" unit
and suspends the program at startup if a TCP server is listening at the address 
given
in the environment variable "CHICKEN_DEBUGGER". If no server is listening the
program executes as normal. The debugging-support is mostly non-invasive, but 
will slow
down execution and may influence stack-allocation, of course.

The front-end provides 3 views: a view of the source-file with lines 
highlighted that
contain debug-events and of which line-number information could be recovered,
a "data" view showing procedure arguments and global variables, and another code
view that shows the location of the debug-event in the generated C code. Note 
that
it is currently not possible to directly inspect local/lexical variables - 
these are buried
in the current closure and/or continuation. Accessing these by name would 
require
embedding more information in the C code that maps closure-slots to variables.

One can set breakpoints on highlighted source code lines, step through the code
or set breakpoints whenever global variables change. The data-view allows basic
destructuring of values using a tree-widget. That's currently all, which is 
somewhat
limited, but at least allows following the control flow quite easily.

I have added a new chapter to the manual ("Debugging") that roughly explains the
GUI. This might need to be extended.

The Tcl/Tk front-end is about 1800 lines and is a bit involved, mostly because 
it
communicates in an asynchronous manner with the client, even though the protocol
is synchronous. It seems to work so far, at least for the tests I ran.

With DEBUGBUILD enabled, the whole core-system will be compiled with debug
information - take this into account when bootstrapping, as doing so will 
require
a compiler with support for "-d3".

The protocol is currently undocumented, but this will be done at a later stage. 
It should
allow writing other debuggers (for example emacs-based). If you intend to do so,
feel free to contact me.

The usual caveat applies, regarding syntax-expansion and line-number recovery:
our expander does not transparently transport source-locations through each 
expansion
step, so code that is heavily transformed by macros reduces the number of 
debug-events
that can be detected (and subsequently been used as breakpoints).

I had some trouble rebasing the chicken-5 version, and hope I didn't break 
anything.


felix



Attachment: 0001-debugger-master.patch
Description: Text document

Attachment: 0001-debugger-chicken-5.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]