From db5a3f56b46c0e39fd4a398a82896d743162cdaa Mon Sep 17 00:00:00 2001 From: jiriks74 Date: Wed, 25 Sep 2024 23:57:17 +0200 Subject: [PATCH] feat(dap): Added debugger from cpptools Added: - OpenDebugAD7 from [vscode-cpptools](https://github.com/microsoft/vscode-cpptools) It works better with `nvim-dap-ui`. With GDB you have to wait for stdout flush to see program output, the output is in the repl instead of the console, etc. The VSCode debugger doesn't have such issues. --- nix/cpptools.nix | 71 ++++++++++++++++++++++++++++++++++++++++++ nix/neovim-overlay.nix | 1 + nvim/ftplugin/c.lua | 20 +++++------- 3 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 nix/cpptools.nix diff --git a/nix/cpptools.nix b/nix/cpptools.nix new file mode 100644 index 0000000..5b63ea8 --- /dev/null +++ b/nix/cpptools.nix @@ -0,0 +1,71 @@ +{ stdenv, lib +, system ? builtins.currentSystem +, fetchurl +, unzip +, libz +, libcxx +, lttng-ust_2_12 +, autoPatchelfHook +}: + +stdenv.mkDerivation rec { + pname = "cpptools"; + version = "1.21.6"; + + # Get the current system architecture + # arch = builtins.currentSystem; + + linux-x64 = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-linux-x64.vsix"; + linux-arm64 = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-linux-arm64.vsix"; + darwin-x64 = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-macos-x64.vsix"; + darwin-arm64 = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-macos-arm64.vsix"; + + + src = fetchurl { + url = lib.getAttr system { + x86_64-linux = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-linux-x64.vsix"; + aarch64-linux = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-linux-arm64.vsix"; + aarch64-darwin = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-macos-arm64.vsix"; + x86_64-darwin = "https://github.com/microsoft/vscode-cpptools/releases/download/v${version}/cpptools-macos-x64.vsix"; + }; + hash = lib.getAttr system { + x86_64-linux = "sha256-q6SDImUppICJopOi+HiIUMg7Ue1Qu0A41uewNxRdzeA="; + aarch64-linux = "sha256-/Zci8P5RAK26FASHpQnIYR5fvSF9lgTTrgVAT33Wfwc="; + x86_64-darwin = "sha256-P2LacAaCRXnsGUQOLuIyvfgxweeVHsDFTrAEuN/lBIQ="; + aarch64-darwin = "sha256-P2LacAaCRXnsGUQOLuIyvfgxweeVHsDFTrAEuN/lBIQ="; + }; + }; + + nativeBuildInputs = [ + autoPatchelfHook + ]; + + buildInputs = [ + unzip + libz + libcxx + lttng-ust_2_12 + ]; + + unpackPhase = '' + unzip $src + ''; + + sourceRoot = "."; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + mkdir -p $out/opt + cp -r extension/debugAdapters/* $out/opt + install -m755 -D extension/debugAdapters/bin/OpenDebugAD7 $out/opt/bin/OpenDebugAD7 + ln -s $out/opt/bin/OpenDebugAD7 $out/bin/OpenDebugAD7 + runHook postInstall + ''; + + meta = with lib; { + homepage = "https://github.com/microsoft/vscode-cpptools"; + description = "Official repository for the Microsoft C/C++ extension for VS Code. "; + platforms = platforms.linux; + }; +} diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index eddbc09..ce7c438 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -120,6 +120,7 @@ with final.pkgs.lib; let # language servers, etc. asm-lsp # Assembly language server clang-tools # C/C++ language server + (callPackage ./cpptools.nix {}) # C/C++ debugger from VSCode | https://github.com/microsoft/vscode-cpptools nodePackages.bash-language-server # Bash language server lua-language-server nil # nix LSP diff --git a/nvim/ftplugin/c.lua b/nvim/ftplugin/c.lua index 5116d88..088b3d9 100644 --- a/nvim/ftplugin/c.lua +++ b/nvim/ftplugin/c.lua @@ -35,20 +35,16 @@ dap.adapters.gdb = { args = { "-i", "dap" } } +dap.adapters.cppdbg = { + id = 'cppdbg', + type = 'executable', + command = 'OpenDebugAD7', +} + dap.configurations.c = { - -- { - -- name = "Launch", - -- type = "gdb", - -- request = "launch", - -- program = function() - -- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - -- end, - -- cwd = "${workspaceFolder}", - -- stopAtBeginningOfMainSubprogram = false, - -- }, { name = "Launch an executable", - type = "gdb", + type = "cppdbg", request = "launch", cwd = "${workspaceFolder}", program = function() @@ -70,6 +66,6 @@ dap.configurations.c = { :find() end) end, - stopAtBeginningOfMainSubprogram = false, + stopAtBeginningOfMainSubprogram = true, }, }