vscode: Add configurations to run the executables under the debugger master
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Apr 2024 19:34:46 +0000 (15:34 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Apr 2024 20:44:54 +0000 (16:44 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: Iee6d6e012bef82f5d3df4296925a3669ad7027d6

.gitignore
.vscode/build.sh [new file with mode: 0755]
.vscode/launch.json [new file with mode: 0644]
.vscode/libtool_gdb_wrapper.sh [new file with mode: 0755]
.vscode/tasks.json [new file with mode: 0644]

index 4c5a4e5e9999f9b0dbf86be3eb07f51df7a0983d..b0884eb16f858d8d970b3ba478048fc3b1b97e31 100644 (file)
@@ -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 (executable)
index 0000000..9a4e362
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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 (file)
index 0000000..4541842
--- /dev/null
@@ -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 (executable)
index 0000000..0f60c83
--- /dev/null
@@ -0,0 +1,9 @@
+#!/usr/bin/env sh
+# Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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 (file)
index 0000000..9f28bc5
--- /dev/null
@@ -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
This page took 0.027433 seconds and 4 git commands to generate.