... | ... | @@ -12,124 +12,15 @@ The vscode can easily handle the Kea repository, but the full integration is mor |
|
|
- Autoconf (maelvalais.autoconf)
|
|
|
- C++ (ms-vscode.cpptools)
|
|
|
- C++ Extension Pack (ms-vscode.cpptools-extension-pack)
|
|
|
- GoogleTest Adapter (davidschuldenfrei.gtest-adapter)
|
|
|
- C++ Test Mate (matepek.vscode-catch2-test-adapter)
|
|
|
|
|
|
### Intelisensse
|
|
|
|
|
|
The syntax helper should work out-of-the-box, but it takes some time to initialization.
|
|
|
The syntax helper should work out-of-the-box, but it takes time to initialize.
|
|
|
|
|
|
### Debugging
|
|
|
|
|
|
It's pretty tricky. The Kea was designed for dynamic linking with the `libtool` wrapper. The static linking can be used for most use cases, excluding hook support.
|
|
|
Using static linking is also the only known way to integrate the Test Explorer with Kea.
|
|
|
|
|
|
### Files
|
|
|
|
|
|
The Vscode configuration is stored in three files in `.vscode` directory:
|
|
|
|
|
|
- `launch.json` - runner configurations (including debugger)
|
|
|
- `tasks.json` - external command calls
|
|
|
- `settings.json` - general purpose settings
|
|
|
### Tasks
|
|
|
|
|
|
`Launch.json`:
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
// 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 (static)",
|
|
|
"type": "cppdbg",
|
|
|
"request": "launch",
|
|
|
"program": "${workspaceFolder}/src/bin/dhcp4/kea-dhcp4",
|
|
|
"args": [
|
|
|
"-v"
|
|
|
],
|
|
|
"stopAtEntry": false,
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"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"
|
|
|
},
|
|
|
{
|
|
|
"name": "(gdb) Test DHCPv4 (static)",
|
|
|
"type": "cppdbg",
|
|
|
"request": "launch",
|
|
|
"program": "${workspaceFolder}/src/bin/dhcp4/tests/dhcp4_unittests",
|
|
|
"args": [ ],
|
|
|
"stopAtEntry": false,
|
|
|
"cwd": "${workspaceFolder}/src/bin/dhcp4/tests/",
|
|
|
"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"
|
|
|
},
|
|
|
{
|
|
|
"name": "(gdb) Launch DHCPv4 (dynamic)",
|
|
|
"type": "cppdbg",
|
|
|
"request": "launch",
|
|
|
"program": "kea-dhcp4",
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"miDebuggerPath": "gdb",
|
|
|
"pipeTransport": {
|
|
|
"pipeCwd": "${workspaceFolder}",
|
|
|
"pipeProgram": "/usr/bin/libtool",
|
|
|
"pipeArgs": ["--mode=execute"],
|
|
|
"debuggerPath": "gdb ${workspaceFolder}/src/bin/dhcp4/kea-dhcp4",
|
|
|
"quoteArgs": false
|
|
|
},
|
|
|
"MIMode": "gdb",
|
|
|
"customLaunchSetupCommands": [
|
|
|
{ "text": "set args -v", "description": "suppress default commands", "ignoreFailures": false },
|
|
|
],
|
|
|
"targetArchitecture": "x64",
|
|
|
"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"
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
```
|
|
|
|
|
|
`tasks.json`:
|
|
|
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:
|
|
|
|
|
|
```json
|
|
|
{
|
... | ... | @@ -144,67 +35,49 @@ The Vscode configuration is stored in three files in `.vscode` directory: |
|
|
"problemMatcher": []
|
|
|
},
|
|
|
{
|
|
|
"label": "configure (static)",
|
|
|
"type": "shell",
|
|
|
"command": "./configure --with-gtest --enable-static-link --disable-shared",
|
|
|
"problemMatcher": []
|
|
|
},
|
|
|
{
|
|
|
"label": "configure (dynamic)",
|
|
|
"label": "configure",
|
|
|
"type": "shell",
|
|
|
"command": "./configure --with-gtest",
|
|
|
"problemMatcher": []
|
|
|
"problemMatcher": [],
|
|
|
},
|
|
|
{
|
|
|
"label": "make",
|
|
|
"type": "shell",
|
|
|
"command": "make -j10 -e CXXFLAGS=\"-g -O0\"",
|
|
|
"dependsOn": "create envfile"
|
|
|
},
|
|
|
{
|
|
|
"label": "create envfile",
|
|
|
"type": "shell",
|
|
|
"detail": "The vscode omits the libtool wrapper. It's a workaround for this problem. It creates the envvar file all necessary environment variables.",
|
|
|
"command": "find ~+ -type d -name .libs | tr '\n' ':' | awk '{print \"LD_LIBRARY_PATH=\"$0}'> ${workspaceFolder}/.vscode/.env"
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
```
|
|
|
|
|
|
There are four tasks:
|
|
|
|
|
|
### Static linking
|
|
|
|
|
|
First, you need to call the `autoreconf` and `configure (static)` commands.
|
|
|
Now, you should be able to run the `(gdb) Launch DHCPv4 (static)` configuration to start debugging the DHCPv4 service. You can quickly put the breakpoints in any place and show the variable values.
|
|
|
|
|
|
You can add configuration for another service by coping and pasting the existing one and replacing the `program` entry and the `args` array.
|
|
|
|
|
|
In this case, all hook loadings will fail.
|
|
|
|
|
|
### Dynamic linking
|
|
|
|
|
|
First, you need to call the `autoreconf` and `configure (dynamic)` commands.
|
|
|
Now, you should be able to run the `(gdb) Launch DHCPv4 (dynamic)` configuration to start debugging the DHCPv4 service.
|
|
|
|
|
|
This configuration is more complex as the `gdb` is piping by `libtool`. It requires some workarounds in the configuration.
|
|
|
- `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` - run the compilation with disabled optimizations to improve the debugging experience
|
|
|
- `create envfile` - run automatically before the `make` command. 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.
|
|
|
|
|
|
The `args` array is ignored, and the `program` entry is used only for logging purposes.
|
|
|
The executable path must be provided in the `debuggerPath` entry.
|
|
|
You can pass the arguments in the `customLaunchSetupCommands` entry after `set args` command.
|
|
|
You can run the task by pressing `Ctrl + Shift + P` and typing `Tasks: Run Task`.
|
|
|
|
|
|
If you have no arguments, you need to provide the empty `set args` command to suppress default target loading (the target is just loaded at `gdb` startup).
|
|
|
|
|
|
```
|
|
|
"customLaunchSetupCommands": [
|
|
|
{ "text": "set args -v", "description": "suppress default commands", "ignoreFailures": false },
|
|
|
]
|
|
|
```
|
|
|
|
|
|
### Test Explorer
|
|
|
|
|
|
The Test Explorer can be integrated with the Kea only when the static linking is used.
|
|
|
You need to call the `GTest: Switch Test Configuration` command from the Command Palette and select the `(gdb) Test DHCPv4 (static)` configuration.
|
|
|
|
|
|
### Alternatives
|
|
|
### Debugging
|
|
|
|
|
|
It is possible to configure the dynamic linking solution in the same way as the static linking. But it requires a workaround for the `libtool` and manually set the `LD_LIBRARY_PATH` environment variable:
|
|
|
The launch/debugging configurations are stored in `.vscode/launch.json`. There is an example content:
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
"name": "(gdb) Launch",
|
|
|
{
|
|
|
// 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",
|
... | ... | @@ -214,9 +87,7 @@ It is possible to configure the dynamic linking solution in the same way as the |
|
|
],
|
|
|
"stopAtEntry": false,
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"environment": [
|
|
|
{ "name": "LD_LIBRARY_PATH", "value": "src/lib/dhcpsrv/.libs:src/lib/dhcpsrv/.libs:src/lib/dhcp_ddns/.libs:src/lib/process/.libs:src/lib/http/.libs:src/lib/hooks/.libs" }
|
|
|
],
|
|
|
"envFile": "${workspaceFolder}/.vscode/.env",
|
|
|
"externalConsole": false,
|
|
|
"miDebuggerPath": "gdb",
|
|
|
"MIMode": "gdb",
|
... | ... | @@ -233,6 +104,30 @@ It is possible to configure the dynamic linking solution in the same way as the |
|
|
}
|
|
|
],
|
|
|
"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:
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
"testMate.cpp.test.advancedExecutables": [
|
|
|
{
|
|
|
"envFile": "${workspaceFolder}/.vscode/.env",
|
|
|
"pattern": "**/.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.
|
|
|
|