ZWCAD supports Lisp since its first version, but doesn’t have a debugger for a long time. So in the old days if we want to debug a Lisp program, we might have to copy the codes line by line to ZWCAD command line to find out the error. However, sometimes this method does not work well. Let’s take the following program I wrote to define FOO command and call BAR function as an example.
It is difficult to debug these codes line by line because inside function FOO there is a mapcar function calling a lambda expression.
The good news is, now we have Lisp Debugger in ZWCAD 2020
, to better debug our Lisp programs in ZWCAD. This tool is in fact an extension of Visual Studio Code, which is a lightweight but powerful source code editor from Microsoft®, and is free and open source. This extension and VSCode are installed along with ZWCAD 2020. Of course, you can also download VSCode from Microsoft®’s website and install ZWLisp debugger extension from its extension market.
[caption id="attachment_1355" align="aligncenter" width="800"]
Figure 1. ZwLisp in Microsoft® Extension Market[/caption]
Come back to the FOO Lisp. So how do I debug it in ZWCAD 2020? First of all, I launch VSCode by running command VLIDE or VLISP. You may ask whether VSCode can be launched manually, but I won’t suggest that because VLIDE or VLISP will do one more important thing except for launching VSCode – to notice ZWCAD to collect debug information. In other words, to tell ZWCAD to be prepared for the debugging.
[caption id="attachment_1362" align="aligncenter" width="800"]
Figure 2. The interface of VSCode launched by VLIDE or VLISP[/caption]
Then I open the source file in VSCode and do some necessary configuration to start the debug session. I choose Attach to ZWCAD as the debugging mode, since I am going to attach the debug session to a running ZWCAD process. If you need to start a new ZWCAD process, you can choose the Launch mode.
[caption id="attachment_1357" align="aligncenter" width="400"]
Figure 3. Select debugging mode[/caption]
After the debug session is launched, I go back to ZWCAD and load the source file bar.lsp. Please notice that this step should be done after running VLIDE or VLISP command because ZWCAD should collect information while loading the source file.
[caption id="attachment_1358" align="aligncenter" width="800"]
Figure 4. Load the source file in ZWCAD[/caption]
And then we can run FOO command and when an exception occurs it will be shown in VSCode, including its location, call stack and variable information.
[caption id="attachment_1360" align="aligncenter" width="800"]
Figure 5. Debug the program in VSCode[/caption]
After the error was found, the debug session will be disconnected, so if I want to debug the FOO Lisp again, I need to launch another debug session again.
This debugger can be very helpful for us to find out what is the problem in our Lisp programs. If you want to learn more, you can watch this video
. And if you have any question, welcome to discuss with me in the comment area.