Skip to content

Instantly share code, notes, and snippets.

@tmr232
Last active January 26, 2024 13:49
Show Gist options
  • Save tmr232/0d28aab9dffa9d06093a22dfb432d99f to your computer and use it in GitHub Desktop.
Save tmr232/0d28aab9dffa9d06093a22dfb432d99f to your computer and use it in GitHub Desktop.
Debugging Inkscape on Windows using Visual Studio

Debugging Inkscape with Visual Studio

Debug Build

To properly debug with Visual Studio, it's recommended that you use a debug build.

Follow the instructions for building Inkscape on Windows and substitute the first cmake command with:

cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ..

If you've already built Inkscape, I recommend creating the debug build in a new directory. Otherwise it'll overwrite files and cost you time when you want a release build again.

If you do build it in the same directory, you might need to delete CMakeCache.txt for it to work.

Debugging in VS

In Visual Studio, open the Inkscape project folder as a folder:

image

Once you have it open, go to the Solution Explorer, click Show All Files:

image

And navigate to inkscape.exe (should be under build/inkscape/bin/inkscape.exe).

Right click it, and select Add Debug Configuration:

image

Then choose C/C++ Launch for MinGW/Cygwin (gdb):

image

This will open up launch.vs.json with a default config. Modify it to look like this (adjust paths based on your configuration if needed):

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "cppdbg",
      "name": "inkscape.exe",
      "project": "build\\inkscape\\bin\\inkscape.exe",
      "projectTarget": "",
      "cwd": "${workspaceRoot}",
      "program": "build\\inkscape\\bin\\inkscape.exe",
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe",
      "externalConsole": true
    }
  ]
}

To debug, right-click inkscape.exe again in the Solution Explorer and press Debug:

image

I could not find any other way to successfully start the debugger.

To make sure everything works, I recommend going to src/inkscape-main.cpp and setting a breakpoint at the first line of the main function. That way, you'll know whether it works as soon as it launches, and won't need to wait for the Inkscape GUI to show.

Extra Integration

The above is sufficient for debugging with Visual Studio, but there's a bit more we can do. We can trigger a build from VS, and we can better integrate with IntelliSense.

Triggering a Build

To configure a build, right-click the top-level inkscape directory in the Solution Explorer and choose Configure Tasks:

image

Replace the file contents with the following:

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskLabel": "Build-All",
      "taskName": "Build-All",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "build",
      "workingDirectory": "${workspaceRoot}/build",
      "command": "cmd.exe",
      "args": [ "..\\build-all.bat" ]
    }
  ]
}

And add build-all.bat to your project root with the following contents:

mkdir build
cd build

C:\msys64\msys2_shell.cmd -defterm -no-start -ucrt64 -here -c "cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja .."
C:\msys64\msys2_shell.cmd -defterm -no-start -ucrt64 -here -c ninja
C:\msys64\msys2_shell.cmd -defterm -no-start -ucrt64 -here -c "ninja install"

With those steps done, you can right-click the inkscape directory again and select Build to build it.

CMake Integration

This is based on Visual Studio's CMake integration. I managed to make it configure, build, and install Inkscape. Debugging may be possible, but after several hours I haven't managed it.

Create a CMakeSettings.json file in the root directory of the project, and add the following contents:

{
  "configurations": [
    {
      "name": "Mingw64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeExecutable": "${env.BIN_ROOT}/cmake",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "mingw_64" ],
      "environments": [
        {
          "INSTALL_ROOT": "${projectDir}/out/install/Mingw64-Debug",
          "MINGW64_ROOT": "C:/msys64/ucrt64",
          "BIN_ROOT": "${env.MINGW64_ROOT}/bin",
          "MINGW_CHOST": "x86_64-w64-mingw32",
          "MINGW_PREFIX": "${env.MINGW64_ROOT}",
          "MINGW_PACKAGE_PREFIX": "mingw-w64-ucrt-x86_64",
          "MSYSTEM": "UCRT64",
          "MSYSTEM_CARCH": "x86_64",
          "FLAVOR": "x86_64-w64-mingw32",
          "TOOLSET_VERSION": "13.2.0",
          "PATH": "${env.MINGW64_ROOT}/bin;${env.MINGW64_ROOT}/../usr/local/bin;${env.MINGW64_ROOT}/../usr/bin;${env.MINGW64_ROOT}/../bin;${env.PATH}",
          "INCLUDE": "${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/tr1;${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/${env.FLAVOR}",
          "SHELL": "/usr/bin/bash",
          "environment": "mingw_64"
        }
      ],
      "variables": [
        {
          "name": "CMAKE_C_COMPILER",
          "value": "${env.BIN_ROOT}/cc.exe",
          "type": "STRING"
        },
        {
          "name": "CMAKE_CXX_COMPILER",
          "value": "${env.BIN_ROOT}/c++.exe",
          "type": "STRING"
        }
      ],
      "intelliSenseMode": "linux-gcc-x64",
      "cmakeToolchain": ""
    }
  ]
}

This is more or less configuring all the environment variables you'll find in your ucrt64 shell. You'll also notice that this is a Debug build. For a release build, you can copy this and change configurationType to Release.

With this, VS should successfully configure the CMake project. If you right-click the CMakeLists.txt file, you can choose to Build or Install it:

image

With the output going to the configured directories:

      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",

If you select Debug it will fail, and I don't know how to remedy that.


Reference Articles

While researching this, I read the following. They may prove useful if you're having issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment