Debugging the Project in Visual Studio Code

We received numerous questions asking whether it is possible to debug the current project inside Visual Studio Code. With the correct configuration files, this is indeed possible. The following archive contains the necessary configuration files: vscode.zip (2.0 KB)

Extract the configuration folder into the root directory of the project by entering the command unzip vscode.zip -d <path/to/project/dir>. Now you can

  • Launch and debug the main program from inside VSCode.
  • Launch and debug single public tests from inside VSCode.
  • Build the project at any time by simply pressing Ctrl + Shift + B

Debugging in VSCode

To debug your project, switch to the β€œRun & Debug” panel by clicking the icon on the left side bar which looks like a play button with a small bug. Alternatively, press Ctrl + Shift + D. At the top of the panel, you can see a dropdown menu which contains all relevant program launch configurations for the project, e.g. β€œ(Debug) Print statistics” which corresponds to the command carve_debug -s <input file>. You can also debug the public tests with the configuration β€œDebug public test”.

To launch the program with the specified configuration, press the play button next to the dropdown menu. Before launch, the project is automatically rebuilt such that you do not accidentally run an older version of the program that does not match with the source files. Upon launch, you will be prompted for the necessary program arguments, e.g. the path to the input file or the number of steps for the algorithm.

After launching, the program will run until it hits a breakpoint, allowing you to inspect the program state at that specific moment. You may then let the program continue from that breakpoint, execute the program step by step, or let the program run until it exits the current function. The debug session ends upon exit of the program or when the program is forcefully stopped (by pressing the stop button). Importantly, detecting memory leaks at runtime is not supported by the VSCode debugger, so keep that in mind.

8 Likes

2 posts were split to a new topic: Debugging outside of the VM

In case you can not unzip the zip file, either run the following (which may take a while)

sudo pacman -Sy archlinux-keyring; sudo pacman -Syu unzip

or double click the zipfile in the file explorer and use the GUI to extract this

I’ve extracted the files and see the debugger in the Code OSS GUI. I can also choose β€œDebug public test” and choose from a number of tests in the dropdown menu which appears.

However, some tests do not show up in this dropdown menu, even if I start typing their names, e.g. β€œpublic.min_path.owl” or β€œpublic.min_path.small1”.

What is causing this? These are both tests that I’ve failed so far, so debugging these in particular would be very helpful.

The tests which are not in the dropdown menu use the carve_debug binary directly with appropriate commands instead of starting from the main function in test_main.c. For those you can run the corresponding program configuration (-p for min_path) with the corresponding input file (owl.ppm etc.).

i can’t debug with even after unzip the file. Where should i put extract the file. Src? or the project2 file?

After extraction, your folder structure should look like this:

.
β”œβ”€β”€ .git
β”œβ”€β”€ .gitignore
β”œβ”€β”€ Makefile
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ argparser.c
β”‚   β”œβ”€β”€ argparser.h
β”‚   β”œβ”€β”€ energy.c
β”‚   β”œβ”€β”€ energy.h
β”‚   β”œβ”€β”€ image.c
β”‚   β”œβ”€β”€ image.h
β”‚   β”œβ”€β”€ indexing.c
β”‚   β”œβ”€β”€ indexing.h
β”‚   β”œβ”€β”€ main.c
β”‚   β”œβ”€β”€ test_common.h
β”‚   β”œβ”€β”€ test_main.c
β”‚   β”œβ”€β”€ unit_tests.c
β”‚   └── util.h
β”œβ”€β”€ test
β”‚   β”œβ”€β”€ data
β”‚   β”‚   β”œβ”€β”€ imgs.tgz
β”‚   β”‚   β”œβ”€β”€ Makefile
β”‚   β”œβ”€β”€ ref_output
β”‚   β”‚   β”œβ”€β”€ Makefile
β”‚   β”‚   β”œβ”€β”€ refs.tgz
β”‚   β”œβ”€β”€ run_tests.py
β”‚   └── test_registry.py
β”œβ”€β”€ .vscode
β”‚   β”œβ”€β”€ keybindings.json
β”‚   β”œβ”€β”€ launch.json
β”‚   └── tasks.json
...

Notice the new .vscode folder with the three .json files.

2 Likes

i was in src folder. I need to go out open the root folder. And now i can debug :slight_smile: Thanks a lot.