2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-22 01:49:48 +00:00
8
IDE configuration tips
Andrei Pavel edited this page 2022-01-25 13:54:50 +02:00

IDE configuration tips

Some remarks on how to configure the IDE to pleasant work with Kea.

vscode

The Visual Studio Code is a popular IDE with built-in syntax checkers, debugging, and extensions support. The vscode can easily handle the Kea repository, but the full integration is more challenging.

tl;dr

  1. Install all recommended extensions
  2. Put these files in .vscode directory:
    1. settings.json
    2. launch.json
    3. tasks.json
  3. Run these tasks by pressing Ctrl+Shift+P and selecting Tasks: Run Task:
    1. autoreconf
    2. configure
    3. make
  4. Reload the unit tests by pressing Ctrl + Shift + P and selecting Test: Reload tests by C++ TestMate
  5. Use the Run and Debug (icon with triangle and bug) or Test Explorer (icon with measuring cup) from the left sidebar to run a specific application or test.
  • Autoconf (maelvalais.autoconf)
  • C++ (ms-vscode.cpptools)
  • C++ Extension Pack (ms-vscode.cpptools-extension-pack)
  • C++ Test Mate (matepek.vscode-catch2-test-adapter)

Intellisense

The syntax helper should work out-of-the-box, but it takes time to initialize.

Tasks

The VsCode has a built-in solution to manage project-related shell scripts. They are stored in .vscode/tasks.json file. You need the below content of this one:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "autoreconf",
            "type": "shell",
            "command": "autoreconf --install",
            "problemMatcher": []
        },
        {
            "label": "configure",
            "type": "shell",
            "command": "./configure --with-gtest",
            "problemMatcher": [],
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make -j10 -e CXXFLAGS=\"-g -O0\" && find ~+ -type d -name .libs | tr '\n' ':' | awk '{print \"LD_LIBRARY_PATH=\"$0}'> ${workspaceFolder}/.vscode/.env"
        }
    ]
}

There are three tasks:

  • autoreconf - call the autoreconf utility in the standard way. It should be called once after cloning the repository.
  • configure - run the configure tool with the Google Test flag
  • make - first, run the compilation with disabled optimizations to improve the debugging experience, and next it prepares the envfile. The VsCode C++ extensions very dislike libtool wrappers. The best workaround I found is to avoid using these wrappers and directly call the executables. But it requires setting the LD_LIBRARY_PATH environment variable. This script searches the proper paths and puts them into envfile. This file is further used in the configurations.

You can run the task by pressing Ctrl + Shift + P and typing Tasks: Run Task.

Debugging

The launch/debugging configurations are stored in .vscode/launch.json. There is an example content:

{
    // 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": "(gdb) Launch DHCPv4",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/src/bin/dhcp4/.libs/kea-dhcp4",
            "args": [
                "-v"
                //"-t", "kea-dhcp4.conf"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "envFile": "${workspaceFolder}/.vscode/.env",
            "externalConsole": false,
            "miDebuggerPath": "gdb",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "make"
        },
    ]
}

It runs the DHCPv4 daemon in debug mode with the -v flag. If you need to debug another executable, copy and paste this entry and change the program and `args fields.

Test Explorer

You need to install the C++ Test Mate (matepek.vscode-catch2-test-adapter) extension first. Next, you open .vscode/settings.json and add similar content:

{
    "testMate.cpp.test.advancedExecutables": [
        {
            "envFile": "${workspaceFolder}/.vscode/.env",
            "pattern": "src/**/.libs/*_unittests"
        }
    ]
}

Next, you need to reload the unit tests by pressing Ctrl + Shift + P and selecting Test: Reload tests by C++ TestMate.

Now you can click the measuring cup icon to run, debug, and go to your tests.