For Visual Studio Code users working with 4D, a new extension called 4D-Debugger that works with 4D 20 R8 is now available.
The new 4D-Debugger extension brings powerful new debugging capabilities to Visual Studio Code, expanding on the features of the 4D-Analyzer introduced earlier. With this extension, you can set breakpoints, step through 4D code, and inspect variables from the Visual Studio Code interface. This tool integrates seamlessly, simplifying the debugging process and making VS Code a more versatile workspace for 4D projects.
Getting Started
To start, install the 4D-Debugger extension from the VS Code marketplace. Ensure you have a 4D Server on your machine, as this is needed to launch and debug your project. Define configurations in the .vscode/launch.json file to specify how you connect to the 4D server. If no configuration is set, you can attach it to a started server using the default debugger port.
How to debug
Open the method file you want to debug in VS Code, and set breakpoints by clicking next to the line numbers.
Start the debugging session using “Launch and Run” or “Attach and Run” from VS Code’s Debug menu:
- The “Attach and Run” menu attempts to attach the debugger to the running 4D server. If the debugger is already attached elsewhere, you must detach it first. Once the debugger has been attached, the current method is launched in a dedicated worker called “Remote Debugger Console”.
- The “Launch and Run” menu starts the 4D server configured in .vscode/launch.json and attaches the debugger to the VS code. Once the debugger has been attached.
If you want to debug your server code only when an error occurs in your code, use the “Attach” or “Launch” menu.
During the session, code execution will pause at your defined breakpoints, allowing you to inspect variables and step through the code:
You can access local, process variables with real-time values in the inspector, monitor some variables with the watcher or test expressions in the console :
You can find more information about the VS Code debugger and its functionality in the VS Code documentation.
Give It a Try!
Ready to explore? Download the 4D Debugger extension, configure your debugging setup, and experience the streamlined, integrated debugging process directly within Visual Studio Code.
For those who don’t use Visual Studio Code, the 4D debugger hasn’t been left behind. It features a fresh new design and additional functionalities. Check out the updates in the Enhancing the Debugging Experience blog post.