From: Pho Van Son
Subject: Help: How to implement a Lisp debugger?
Date: 
Message-ID: <6t82sd$u2i$1@minus.oleane.net>
Hi,

For my job, the idl compiler is implemented as a two language modules.
The first module is a parser and is programmed in C++, it builds in memory
an decorated AST (Abstract Syntax Tree)
The second module is a generator implemented in LISP. From the previously
build AST, it generate C code, pascal code and COBOL code.

The product works fine and is already sold to our client.

From this experience, I realize that debugging the lisp module is a little
painful.
Because the LISP interpreter is my own implementation (in C) and lack a lisp
debugger.
To debug my Lisp program I had to insert at my source a break statement. And
when this statement is reached, I enter the interactive loop, and all I can
do is show variable, call other fonction and continue.
There is no step statement, no next statement, no dynamic break...

My question is:
How to implement a simple debugger?
Anyone can point me to some code source, references, ressources?

I have already looked at XLISP implementation (version1.6).
It used an eval hook, and the debugger module is written in lisp. In real
sutuation, it crashes because of stack overflow.

I have already read Norvig book. The debugger is written in LISP, and I
don't know how to adapt it in C to my interpreter.

I like Lisp programming language.

For next projects, I would like to use it as an extension language. But
having a Lisp debugger will help me.

Thanks you for your help.

From: Martin Rodgers
Subject: Re: Help: How to implement a Lisp debugger?
Date: 
Message-ID: <MPG.1061e14144960b7c989c5a@news.demon.co.uk>
In article <············@minus.oleane.net>, ···@goaltech.com says...

> My question is:
> How to implement a simple debugger?
> Anyone can point me to some code source, references, ressources?
 
As you've written your own Lisp in C, then I'll tell you how I solved 
this in my own Lisp. (It also works in other kinds of program!)

You add diagnostic code that displays a trace. This can be as simple as 
sprinkling a few printf statements at strategic points in your code. They 
can say something simple, like "Point foobar has been reached", or they 
can also display the values of any relevant variables at that point.

I've found this works well in recursive code. It also helps debugging 
threaded code, for similar reasons. You can repeat tests over and over, 
with different data or small changes in code, and you get consistant 
diagnostic traces. Any changes in the trace can quickly be revealed by 
standard text processing tools. Just compare the new trace with the last 
one, or the last trace for a "correct" version of your code. It helps if 
you write your trace to a file!

So, it's been years since I last did any serious work with an interactive 
non-Lisp debugger. Sometimes, in Lisp, when I find myself in the debugger 
I'll use it to inspect a few objects, but this doesn't give me a history 
of the variables that interest me. I'd go mad if I had to single step any 
of my programs, esp the resursive and event driven ones.

In Lisp, you can build even smarter "trace"-like tools. For example, 
recording all function calls and their arguments. The result can be a 
call tree that you can examine after your program has stopped. It should 
be possible to do this in C, but you'll have more work to do.

I hope this helps.
-- 
Remove insect from address to email me | You can never browse enough
"Ahh, aren't they cute" -- Anne Diamond describing drowning dolphins
From: Howard R. Stearns
Subject: Re: Help: How to implement a Lisp debugger?
Date: 
Message-ID: <35F817DE.5B61139A@elwood.com>
I find Lisp-style debuggers easier to use then C-style debuggers, and I always
try to debug Lisp code
in a Lisp implementation that has a good Lisp-style debugger -- even if that
means debugging
only the part of the application that is developed in pure Lisp.

Our Eclipse Common Lisp implementation  takes the approach that an integrated
Lisp/C
application may need to be debugged using a C debugger.  Accordingly, the Lisp
implementation in
Eclipse was designed to be compatible with standard C debuggers.  I have used
the VC++ debugger
to track down Windows bugs within Eclipse Lisp code that appeared during
development of the Eclipse/Windows port.   See
http://www.elwood.com/eclipse-info, or contact me if you want to know more
about how this was done.

With respect to writing good Lisp debuggers within Lisp,  I have often thought
that it might be nice to define a portable Lisp "debugger-MOP", built on the
following principles:
 + The read-eval-print loop, STEP, INSPECT, DESCRIBE-OBJECT and INVOKE-DEBUGGER
would all be written as a CLIM-style application frame.  (This is not meant to
imply that all of CLIM would be required.)
+ This frame would  use a documented set of CLOS protocols for implementing
commands, including stack manipulation and form evaluation.
+ Hooks would be provided within these protocols for implementation-specific
attachment to the compiled code stacks, etc.
+ The result would be portable (except for the hooks) between different Lisp
implementations and environments (windowed, vs. text based vs. inside-Emacs,
etc.) .   It could be directly extended by applications to provide either
expanded or decreased capabilities for application-end-users.

Alas, Eclipse does NOT now define such a thing.  I'd be interested in hearing
any comments about this approach.

Howard R. Stearns, Eclipse product manager
······@elwood.com
U.S. telepehone: 414-764-7500


Pho Van Son wrote:

> Hi,
>
> For my job, the idl compiler is implemented as a two language modules.
> The first module is a parser and is programmed in C++, it builds in memory
> an decorated AST (Abstract Syntax Tree)
> The second module is a generator implemented in LISP. From the previously
> build AST, it generate C code, pascal code and COBOL code.
>
> The product works fine and is already sold to our client.
>
> From this experience, I realize that debugging the lisp module is a little
> painful.
> Because the LISP interpreter is my own implementation (in C) and lack a lisp
> debugger.
> To debug my Lisp program I had to insert at my source a break statement. And
> when this statement is reached, I enter the interactive loop, and all I can
> do is show variable, call other fonction and continue.
> There is no step statement, no next statement, no dynamic break...
>
> My question is:
> How to implement a simple debugger?
> Anyone can point me to some code source, references, ressources?
>
> I have already looked at XLISP implementation (version1.6).
> It used an eval hook, and the debugger module is written in lisp. In real
> sutuation, it crashes because of stack overflow.
>
> I have already read Norvig book. The debugger is written in LISP, and I
> don't know how to adapt it in C to my interpreter.
>
> I like Lisp programming language.
>
> For next projects, I would like to use it as an extension language. But
> having a Lisp debugger will help me.
>
> Thanks you for your help.