From: Jérémie Galarneau Date: Wed, 24 Apr 2024 19:34:46 +0000 (-0400) Subject: vscode: Add configurations to run the executables under the debugger X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a881d7c95fa9f6d47dbc89e9ddffbc2e950c05cb;p=lttng-tools.git vscode: Add configurations to run the executables under the debugger Add tasks.json and launch.json which allow VSCode users to build the project and run the various binaries (lttng, lttng-relayd, lttng-sessiond) under the integrated debugger. For the moment, the configuration assumes the user wants to build "in-tree" and has setup the tree to build the project (running ./bootstrap and ./configure). The build job attempts to build a compile database if 'bear' is available on the system. To debug the LTTng client, make sure to edit the matching configuration in .vscode/launch.json to provide your desired arguments (for the moment, 'help' is passed by default). Signed-off-by: Jérémie Galarneau Change-Id: Iee6d6e012bef82f5d3df4296925a3669ad7027d6 --- diff --git a/.gitignore b/.gitignore index 4c5a4e5e9..b0884eb16 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ TAGS /.clangd/ compile_commands.json *_flymake* -/.vscode/* # m4 macros not automatically generated /m4/libtool.m4 diff --git a/.vscode/build.sh b/.vscode/build.sh new file mode 100755 index 000000000..9a4e3625a --- /dev/null +++ b/.vscode/build.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Copyright (C) 2024 Jérémie Galarneau +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +source_dir="$1" + +# Run make quietly to check if a Makefile exists +make_output=$(make -C "$source_dir" -q 2>&1) +make_exit_status=$? + +# Check the return status of make -q +if [ $make_exit_status -eq 2 ]; then + # It seems the Makefiles don't exist. Most likely the user forgot to + # setup their tree. + echo "$make_output" + echo -e "\033[33mMake couldn't find a Makefile: did you run ./bootstrap and ./configure ?\033[0m" + exit 1 +fi + +# Check if compile_commands.json does not exist in the source directory and if bear is installed +if [ ! -f "$source_dir/compile_commands.json" ] && which bear >/dev/null 2>&1; then + # Bear is installed and compile_commands.json is not present + # Perform a make clean since compile_commands.json is missing and bear is installed + make -C "$source_dir" clean + + # Prefix bear to the make command + command_prefix="bear -- " +fi + +# Run make with or without bear prefix, depending on the condition above +eval "${command_prefix}"make -C "$source_dir" -j "$(nproc)" diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..4541842e1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,76 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug LTTng Client", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/src/bin/lttng/.libs/lttng", + // Replace with your args + "args": [ + "help" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Build LTTng-tools" + }, + { + "name": "Debug LTTng Session Daemon", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/src/bin/lttng-sessiond/.libs/lttng-sessiond", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + // The session daemon fails to launch if it can't find the session schema description + "environment": [ + { + "name": "LTTNG_SESSION_CONFIG_XSD_PATH", + "value": "${workspaceFolder}/src/common/" + } + ], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Build LTTng-tools" + }, + { + "name": "Debug LTTng Relay Daemon", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/src/bin/lttng-relayd/lttng-relayd", + "args": [], + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "${workspaceFolder}/.vscode/libtool_gdb_wrapper.sh", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Build LTTng-tools" + }, + ] +} \ No newline at end of file diff --git a/.vscode/libtool_gdb_wrapper.sh b/.vscode/libtool_gdb_wrapper.sh new file mode 100755 index 000000000..0f60c832d --- /dev/null +++ b/.vscode/libtool_gdb_wrapper.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +# Copyright (C) 2024 Jérémie Galarneau +# +# SPDX-License-Identifier: LGPL-2.1-only +# +# Wrapper script to setup the environment before invoking gdb +# on the in-tree binaries (under `.libs`) + +libtool --mode=execute gdb "$@" diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..9f28bc573 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,21 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "Build LTTng-tools", + // Assumes you ran ./bootstrap and ./configure with your preferred options + "command": "${workspaceFolder}/.vscode/build.sh ${workspaceFolder}", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file