Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Vala in VSCode on Linux

There is really no good documentation on how Vala and Visual Studio Code work together for a newbie to Vala and VSCode.

When trying to work with vala projects on the command line(Ubuntu 20.04), doing a build is as simple as running meson and ninja. What I am looking for is how this then maps to VSCode. Basically how do I take my folder of vala code with its meson scripts and integrate it into the build/debug system of vscode.

I tried the extensions available for Vala on the marketplace and I get syntax highlighting. Beyond that I am looking for how to get VSCode to run the meson and ninja scripts and debugging. Thanks!
(Trying to debug some GNOME desktop apps)

like image 261
Sharun Avatar asked Oct 30 '25 03:10

Sharun


2 Answers

This isn't a definitive answer, but the integration with Meson build and a debugger is probably still work in progress.

There is a page on the GNOME wiki: Coding in Vala with Visual Studio Code. So if anyone has any experiences to share that would be a good place.

You should try a Vala language server. That will give more than syntax highlighting.

The Meson Tools VS Code extension looks interesting. Meson also provides metadata in the build that could be used if anyone wants to enhance these tools.

Vala uses C as its intermediate language and any debugging is done with a C debugger like GDB or LLDB. The Vala compiler will insert source code line references in the C when compiled for development, so the debugger will show the Vala source references as well. This is described in a bit more detail on the GNOME Wiki page referenced above, but this does need some tidying up in the Vala compiler. Symbol resolution from the C to Vala is more troublesome and I don't believe anyone has come up with a working solution as yet.

like image 124
AlThomas Avatar answered Nov 01 '25 09:11

AlThomas


From my experience, you can try VS Code + CodeLLDB plugin, which generally works well for me. The steps are as follows:

  1. Run valac during your build step with the --debug option to add debug symbols to the resulting binaries. When using Meson as a build system, this is done for you by default.
  2. Generate a launch.json for LLDB. This can be done with "create a launch.json file" in "Run and Debug" of VS Code. Create launch.json
  3. It will create a .vscode directory and a launch.json file inside it. Ensure that you have installed CodeLLDB plugin. Modify the "configurations" in the launch.json, such that "configurations" in the file becomes (<my program> needs to be changed to your executable file name)
"configurations": [
        {
            "name": "Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/<my program>",
            "args": ["-arg1", "-arg2"],
        }
    ]
  1. Then you can set breakpoints and start debugging in VS Code. Debugging in VS Code
like image 22
Akarin Avatar answered Nov 01 '25 11:11

Akarin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!