Development help - how to properly debug Darktable?

I am trying to make changes to Darktable (fix an open issue), but I don’t have a lot if experience with C as a language. I cloned the github repository (on Linux) and now my process is this:

  • Add some printfs to the code, so I see what is going on,
  • run ./build.sh,
  • run ./build/bin/darktable,
  • click around and see the output of my printfs.

Since the code I work on (masking) is pretty complicated, I am getting to the limits of this workflow, especially since I need to inspect more complex data structures.

Are there any developers here, who can give a short explanation on how to debug Darktable with VS Code, so I have breakpoints etc. available?

This is the way I use VS Code to debug darktable:

Add a configuration (Run–>Add Configuration…)
This creates a new folder/file .vscode/launch.json.

I have set it like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) darktable",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/bin/darktable",
            "args": [
                "--cachedir", "/Users/mario/src/darktable_test_data/cache",
                "--configdir", "/Users/mario/src/darktable_test_data/config",
                "-d", "common"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                // {
                //     "name": "LANG",
                //     "value": "de_DE.UTF-8"
                // },
                // {
                //     "name": "LC_ALL",
                //     "value": "de_DE.UTF-8"
                // }
                // {
                //     "name": "GTK_DEBUG",
                //     "value": "interactive"
                // }
            ],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

Change the paths to your configuration.

Then in VS Code you can press F5 to run darktable. Set breakpoints at the points of interest, inspect variables, step through the code, …

1 Like

Thanks, I will try this tomorrow.

For building you still use build.sh on the console, with build-type Debug?

Yes, exactly