Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode-extensions.vadimcn.vscode-lldb: fix on Darwin #211321

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

mstone
Copy link
Contributor

@mstone mstone commented Jan 18, 2023

Summary

vscode-lldb has been broken on Darwin due to a build-time issue:

and several runtime-issues:

  • codelldb can't find its dynamic libraries (codelldb inside of vscode-lldb extension doesn't work #160874)

  • lldb-server from nixpkgs doesn't work due to missing the

    "com.apple.security.cs.debugger"
    

    macOS codesigning entitlement, ([wip] codesigning on Darwin #38624), also with the symptom that
    tccd, the macOS "Transparency, Consent, and Control" daemon, denies
    requests it receives from vscode/codium with log messages like:

      "AUTHREQ_CTX: msgID=..., function=<private>, service=kTCCServiceDeveloperTool, preflight=yes, query=1,"
      "Service kTCCServiceDeveloperTool does not allow prompting; returning denied."
      "AUTHREQ_RESULT: msgID=..., authValue=0, authReason=5, authVersion=1, error=(null),", etc.
    
  • lldb-server from nixpkgs may also provide a different CLI interface than codelldb expects on macOS.

  • vscode-lldb directs lldb to load rust pretty-printing scripts which need to be preserved through the build process in nixpkgs

Solution
  • The build problem can be fixed by setting HOME="$(pwd)/home", as suggested in vscode-extensions.vadimcn.vscode-lldb: build fails on aarch64-darwin #202507.

  • The dynamic libraries issue can be fixed by setting LD_LIBRARY_PATH while wrapping codelldb

  • The permissions issue and CLI interface issue can both be fixed by using Xcode's debugserver,

    /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver
    

    on macOS, since it has the required entitlement and the expected interface.

  • Finally, the script-loading issue can be fixed by copying the required scripts to the location that vscode-lldb expects to find them in.

Fixes

(I think:)

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

# entitlement which nixpkgs' lldb-server does not yet provide; see
# <https://github.com/NixOS/nixpkgs/pull/38624> for details
lldbServer = if stdenv.isDarwin then
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver"
Copy link
Member

@wegank wegank Feb 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require Xcode to be installed, sadly...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep — absent a way to get the necessary entitlement on a debugserver provided by nixpkgs, Xcode (or another suitably signed binary) is required.

That said, maybe there’s a way to prompt users to install it if needed that I’ve missed — do you see one?

(and in any event, thanks for looking this over + for sharing feedback!)

@DieracDelta
Copy link
Member

I tested this out (trying to debug some rust code) and it didn't build for me on aarch64-darwin. I get the following:

error: Package ‘lldb-8.0.1’ in /nix/store/i88gp0d1f4g2n3px88pi104xz4n4xr7g-source/pkgs/development/compilers/llvm/8/lldb/default.nix:98 is marked as broken, refusing to evaluate.

@mstone
Copy link
Contributor Author

mstone commented Feb 9, 2023

Hi @DieracDelta -- thanks for trying this out. Regarding reproducing the issue you've reported: what nixpkgs commit did you cherry-pick or otherwise apply the diff from this PR onto?

@DieracDelta
Copy link
Member

@mstone I didn't do any rebasing, just ran:

nix run "github:mstone/nixpkgs/darwin-fix-vscode-lldb#legacyPackages.aarch64-darwin.vscode-extensions.llvm-org.lldb-vscode"

@mstone
Copy link
Contributor Author

mstone commented Feb 10, 2023

@DieracDelta -- ah, thanks, I think there may have been a small confusion. The patch that I have written for this PR tries to fix vadimcn.vscode-lldb, which is not the same as llvm-org.lldb-vscode. The latter value, which you tested and which I agree is broken is defined by https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vscode/extensions/default.nix#L3049 to be:

llvm-org.lldb-vscode = llvmPackages_8.lldb;

which is from many years ago and which I haven't looked into the history of.

(Also, for clarity, I think the right way to approach testing this PR is not directly via nix run but instead to test vscode-with-extensions.override { vscodeExtensions = with vscode-extensions; [ vadimcn.vscode-lldb ]; } (likely also with matklad.rust-analyzer or some other analogous rust tooling).

@DieracDelta
Copy link
Member

DieracDelta commented Feb 10, 2023

@mstone Thanks for the helpful reply (and this PR)!! I've tested vadimcn.vscode-lldb on aarch64-darwin (with xcode installed) directly off your branch. Works well in neovim with rust-tools.vnim. I'm able to spin up debugger sessions for my rust projects.

Note: this is not exactly equivalent to vscode-with-extensions, but does directly invoke the codelldb executable in the adapters directory.

I wonder if that llvm-org.lldb-vscode symlink should be deleted...

@superherointj superherointj added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 18, 2023
@hurricanehrndz
Copy link
Contributor

hurricanehrndz commented Apr 2, 2023

Can confirm this patch works tested with nvim as well.

@superherointj superherointj removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 2, 2023
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 3, 2023
@mstone mstone force-pushed the darwin-fix-vscode-lldb branch from 7cc1d77 to fa70e74 Compare April 3, 2023 15:43
@mstone
Copy link
Contributor Author

mstone commented Apr 3, 2023

OK, rebased.

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 3, 2023
@hurricanehrndz
Copy link
Contributor

can we get this merged?

@wegank wegank force-pushed the darwin-fix-vscode-lldb branch from fa70e74 to 135eff0 Compare December 3, 2023 14:04
@mohnishkodnani
Copy link

Also getting these types of errors on M1 Apple for vscode-lldb extension.

                ___cpp_closure_2009449855547362320 in liblldb-4ba65748c70bee9a.rlib(fdcb4320a650e554-cpp_closures.>
            "lldb::SBValue::IsSynthetic()", referenced from:
                ___cpp_closure_15622432981194360367 in liblldb-4ba65748c70bee9a.rlib(fdcb4320a650e554-cpp_closures>
            "lldb::SBInstructionList::GetInstructionAtIndex(unsigned int)", referenced from:
                ___cpp_closure_6565914844347871446 in liblldb-4ba65748c70bee9a.rlib(fdcb4320a650e554-cpp_closures.>
            "lldb::SBBreakpoint::GetLocationAtIndex(unsigned int)", referenced from:
                ___cpp_closure_5306796064114665451 in liblldb-4ba65748c70bee9a.rlib(fdcb4320a650e554-cpp_closures.>
          ld: symbol(s) not found for architecture arm64
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)```

@wegank wegank marked this pull request as draft December 6, 2023 21:08
@WeetHet
Copy link
Contributor

WeetHet commented Feb 25, 2024

Please merge this, I really need this extension

@wegank
Copy link
Member

wegank commented Feb 26, 2024

No. The two neutral checks literally mean that this PR doesn't work.

Probably @reckenrode or @a-n-n-a-l-e-e could help?

@reckenrode
Copy link
Contributor

Instead of requiring Xcode’s debugserver, is it possible to package the one this extension ships (perhaps separately)? It’s notarized and has the required entitlement. It’s not ideal, but it can actually be fetched and cached (unlike Xcode).

@reckenrode
Copy link
Contributor

Linking lldb explicitly seems to build. I also had to manually link libc++abi. Someone with a VS Code setup should test.

diff --git a/pkgs/applications/editors/vscode/extensions/vadimcn.vscode-lldb/default.nix b/pkgs/applications/editors/vscode/extensions/vadimcn.vscode-lldb/default.nix
index d476b1fec536..f6ea6d0257be 100644
--- a/pkgs/applications/editors/vscode/extensions/vadimcn.vscode-lldb/default.nix
+++ b/pkgs/applications/editors/vscode/extensions/vadimcn.vscode-lldb/default.nix
@@ -27,8 +27,14 @@ let
 
     cargoHash = "sha256-Qq2igtH1XIB+NAEES6hdNZcMbEmaFN69qIJ+gTYupvQ=";
 
+    buildInputs = lib.optionals stdenv.isDarwin [ lldb ];
+
     nativeBuildInputs = [ makeWrapper ];
 
+    env = lib.optionalAttrs stdenv.isDarwin {
+      NIX_LDFLAGS = "-llldb -lc++abi";
+    };
+
     buildAndTestSubdir = "adapter";
 
     buildFeatures = [ "weak-linkage" ];

@nixypanda
Copy link
Contributor

nixypanda commented Mar 31, 2024

@reckenrode I tried this nixypanda@87c5aa9. I used this in my own dotfiles -> nixypanda/dotfiles#13.

This does build, however when I try to use it, it does not work.

Details

I tried to debug a rust program with it. I do this by starting a test in debug mode
OS: 14.2.1 (23C71)
Arch: x86_64 (Intel mac)
Editor: neovim (I did not try it with VSCode)

codelldb application logs

logs
[debug-adapter stderr] [DEBUG codelldb] New debug session

[debug-adapter stderr] [DEBUG codelldb::dap_codec] --> {"command":"initialize","arguments":{"clientName":"neovim","adapterID":"nvim-dap","pathFormat":"path","columnsStartAt1":true,"linesStartAt1":true,"supportsRunInTerminalRequest":true,"supportsVariableType":true,"supportsProgressReporting":true,"supportsStartDebuggingRequest":true,"locale":"en_US.UTF-8","clientID":"neovim"},"type":"request","seq":1}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":1,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"exceptionBreakpointFilters":[{"default":true,"filter":"cpp_throw","label":"C++: on throw","supportsCondition":true},{"default":false,"filter":"cpp_catch","label":"C++: on catch","supportsCondition":true}],"supportTerminateDebuggee":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsGotoTargetsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsSetVariable":true,"supportsSteppingGranularity":true,"supportsWriteMemoryRequest":true}}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] --> {"command":"launch","arguments":{"name":"Rust debug client","env":{"DKLD_LIBRARY_PATH":"\/nix\/store\/ji1wi85zhawx0nr9sr32srbmh1l1wnjb-rust-default-1.77.0\/lib\/rustlib\/x86_64-apple-darwin\/lib:\/Users\/sherubthakur\/Documents\/open-source\/delta\/target\/debug\/deps"},"args":["handlers::difftastic_json::tests::test_json_conversion_change","--exact","--nocapture"],"stopOnEntry":false,"program":"\/Users\/sherubthakur\/Documents\/open-source\/delta\/target\/debug\/deps\/delta-7589a50a6e9d8b41","request":"launch","type":"codelldb","cwd":"\/Users\/sherubthakur\/Documents\/open-source\/delta"},"type":"request","seq":2}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":2,"type":"event","event":"output","body":{"category":"console","output":"Console is in 'commands' mode, prefix expressions with '?'.\n"}}
Console is in 'commands' mode, prefix expressions with '?'.

[debug-adapter stderr] INFO(Python) 13:25:06 formatters: Initializing
INFO(Python) 13:25:06 formatters.rust: Initializing

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":3,"type":"event","event":"initialized"}
[DEBUG codelldb::debug_session] Debug event: 0x6000019f7518 Event: broadcaster = 0x7fabb00dd040 (lldb.target), type = 0x00000002 (modules-loaded), data = {delta-7589a50a6e9d8b41}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":4,"type":"event","event":"module","body":{"module":{"addressRange":"FFFFFFFFFFFFFFFF","id":"FFFFFFFFFFFFFFFF","name":"delta-7589a50a6e9d8b41","path":"/Users/sherubthakur/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41","symbolFilePath":"/Users/sherubthakur/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41","symbolStatus":"Symbols loaded."},"reason":"new"}}
[DEBUG codelldb::dap_codec] <-- {"seq":5,"type":"request","command":"runInTerminal","arguments":{"args":["/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/adapter/.codelldb-wrapped","terminal-agent","--connect=64854"],"cwd":"","kind":"integrated","title":"Rust debug client"}}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] --> {"success":true,"body":{"processId":79690},"request_seq":5,"command":"runInTerminal","type":"response","seq":3}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] --> {"command":"setExceptionBreakpoints","arguments":{"filters":["cpp_throw"]},"type":"request","seq":4}
[DEBUG codelldb::dap_codec] <-- {"seq":6,"type":"response","request_seq":4,"success":true,"command":"setExceptionBreakpoints"}
[DEBUG codelldb::debug_session] Debug event: 0x6000019dc058 Event: broadcaster = 0x7fabb00dd040 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] --> {"command":"configurationDone","type":"request","seq":5}

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":7,"type":"event","event":"output","body":{"category":"console","output":"Launching: /Users/sherubthakur/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41 handlers::difftastic_json::tests::test_json_conversion_change --exact --nocapture\n"}}
Launching: /Users/sherubthakur/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41 handlers::difftastic_json::tests::test_json_conversion_change --exact --nocapture

[debug-adapter stderr] [ERROR codelldb::debug_session] Connection shut down by remote side while waiting for reply to initial handshake packet

[debug-adapter stderr] [DEBUG codelldb::dap_codec] <-- {"seq":8,"type":"response","request_seq":2,"success":false,"command":"","message":"Connection shut down by remote side while waiting for reply to initial handshake packet","show_user":true}
[DEBUG codelldb::dap_codec] <-- {"seq":9,"type":"response","request_seq":5,"success":true,"command":"configurationDone"}

nvim-dap logs

logs

[ DEBUG ] 2024-03-31T13:25:05Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1166 ]	"Starting debug adapter server executable"	{
  args = { "--liblldb", "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/lldb/lib/liblldb.dylib", "--port", "64848" },
  command = "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"
}
[ DEBUG ] 2024-03-31T13:25:05Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1296 ]	"Debug adapter server executable started, listening on 64848"
[ DEBUG ] 2024-03-31T13:25:05Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1300 ]	"Connecting to debug adapter"	{
  executable = {
    args = { "--liblldb", "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/lldb/lib/liblldb.dylib", "--port", "64848" },
    command = "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"
  },
  host = "127.0.0.1",
  port = 64848,
  type = "server"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1677 ]	"request"	{
  arguments = {
    adapterID = "nvim-dap",
    clientID = "neovim",
    clientName = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_US.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  body = {
    exceptionBreakpointFilters = { {
        default = true,
        filter = "cpp_throw",
        label = "C++: on throw",
        supportsCondition = true
      }, {
        default = false,
        filter = "cpp_catch",
        label = "C++: on catch",
        supportsCondition = true
      } },
    supportTerminateDebuggee = true,
    supportsCancelRequest = true,
    supportsCompletionsRequest = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsDataBreakpoints = true,
    supportsDelayedStackTraceLoading = true,
    supportsDisassembleRequest = true,
    supportsEvaluateForHovers = true,
    supportsExceptionFilterOptions = true,
    supportsExceptionInfoRequest = true,
    supportsFunctionBreakpoints = true,
    supportsGotoTargetsRequest = true,
    supportsHitConditionalBreakpoints = true,
    supportsInstructionBreakpoints = true,
    supportsLogPoints = true,
    supportsReadMemoryRequest = true,
    supportsSetVariable = true,
    supportsSteppingGranularity = true,
    supportsWriteMemoryRequest = true
  },
  command = "initialize",
  request_seq = 1,
  seq = 1,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1677 ]	"request"	{
  arguments = {
    args = { "handlers::difftastic_json::tests::test_json_conversion_change", "--exact", "--nocapture" },
    cwd = "/Users/<username>/Documents/open-source/delta",
    env = {
      DKLD_LIBRARY_PATH = "/nix/store/ji1wi85zhawx0nr9sr32srbmh1l1wnjb-rust-default-1.77.0/lib/rustlib/x86_64-apple-darwin/lib:/Users/<username>/Documents/open-source/delta/target/debug/deps"
    },
    name = "Rust debug client",
    program = "/Users/<username>/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41",
    request = "launch",
    stopOnEntry = false,
    type = "codelldb"
  },
  command = "launch",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  body = {
    category = "console",
    output = "Console is in 'commands' mode, prefix expressions with '?'.\n"
  },
  event = "output",
  seq = 2,
  type = "event"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  event = "initialized",
  seq = 3,
  type = "event"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  body = {
    module = {
      addressRange = "FFFFFFFFFFFFFFFF",
      id = "FFFFFFFFFFFFFFFF",
      name = "delta-7589a50a6e9d8b41",
      path = "/Users/<username>/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41",
      symbolFilePath = "/Users/<username>/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41",
      symbolStatus = "Symbols loaded."
    },
    reason = "new"
  },
  event = "module",
  seq = 4,
  type = "event"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  arguments = {
    args = { "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/adapter/.codelldb-wrapped", "terminal-agent", "--connect=64854" },
    cwd = "",
    kind = "integrated",
    title = "Rust debug client"
  },
  command = "runInTerminal",
  seq = 5,
  type = "request"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:208 ]	"run_in_terminal"	{
  args = { "/nix/store/lj2i35alw97hl2gk29llw8xf59866asg-vscode-extension-vadimcn-vscode-lldb-1.10.0/share/vscode/extensions/vadimcn.vscode-lldb/adapter/.codelldb-wrapped", "terminal-agent", "--connect=64854" },
  cwd = "",
  kind = "integrated",
  title = "Rust debug client"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1707 ]	"response"	{
  body = {
    processId = 79690
  },
  command = "runInTerminal",
  request_seq = 5,
  seq = 3,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1677 ]	"request"	{
  arguments = {
    filters = { "cpp_throw" }
  },
  command = "setExceptionBreakpoints",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  command = "setExceptionBreakpoints",
  request_seq = 4,
  seq = 6,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:1677 ]	"request"	{
  command = "configurationDone",
  seq = 5,
  type = "request"
}
[ DEBUG ] 2024-03-31T13:25:06Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  body = {
    category = "console",
    output = "Launching: /Users/<username>/Documents/open-source/delta/target/debug/deps/delta-7589a50a6e9d8b41 handlers::difftastic_json::tests::test_json_conversion_change --exact --nocapture\n"
  },
  event = "output",
  seq = 7,
  type = "event"
}
[ DEBUG ] 2024-03-31T13:25:07Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  command = "",
  message = "Connection shut down by remote side while waiting for reply to initial handshake packet",
  request_seq = 2,
  seq = 8,
  show_user = true,
  success = false,
  type = "response"
}
[ DEBUG ] 2024-03-31T13:25:07Z+0530 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:951 ]	1	{
  command = "configurationDone",
  request_seq = 5,
  seq = 9,
  success = true,
  type = "response"
}

@reckenrode
Copy link
Contributor

@reckenrode I tried this nixypanda@87c5aa9. I used this in my own dotfiles -> nixypanda/dotfiles#13.

This does build, however when I try to use it, it does not work.

Thanks for testing. The -lc++abi change is probably not needed anymore since #292043 was merged. Are you able to run the built debugger manually?

I suspect the issue is debugserver. This PR was making a change the wrapper to use the one from Xcode, but codelldb also ships its own that has the required entitlement and is notarized.

@nixypanda
Copy link
Contributor

nixypanda commented Mar 31, 2024

@reckenrode I am able to start the debugger.
It prints

[DEBUG codelldb] Listening on 127.0.0.1:1234

Then I believe waits for more instructions from a client but to test beyond it I will need to look at the debug server protocol which I don't know.

In addition to that I also tried to point it to the debug server from Xcode and it works on the latest release Xcode 15.3

vadimcn/codelldb#456 (reply in thread)
^ This discussion might be helpful.

The following is pure speculation
It looks like on mac the debugger that codelldb does not work(?) and it has to use the system/xcode debugger(?)
I see that on nixpkgs we have xcode can we add that as dependency and then point to the debugger there(?)

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 5, 2024
@wegank wegank force-pushed the darwin-fix-vscode-lldb branch from 135eff0 to a925084 Compare April 10, 2024 09:07
Summary:

  vscode-lldb has been broken on Darwin due to a build-time issue:

    * on Darwin, the vscode-lldb build scripts expect $HOME to exist and be
      writable, NixOS#202507

  and several runtime-issues:

    * codelldb can't find its dynamic libraries (NixOS#160874)

    * lldb-server from nixpkgs doesn't work due to missing the

        "com.apple.security.cs.debugger"

      macOS codesigning entitlement, (NixOS#38624), also with the symptom that
      tccd, the macOS "Transparency, Consent, and Control" daemon, denies
      requests it receives from vscode/codium with log messages like:

	  "AUTHREQ_CTX: msgID=..., function=<private>, service=kTCCServiceDeveloperTool, preflight=yes, query=1,"
          "Service kTCCServiceDeveloperTool does not allow prompting; returning denied."
          "AUTHREQ_RESULT: msgID=..., authValue=0, authReason=5, authVersion=1, error=(null),", etc.

    * lldb-server from nixpkgs may also provide a different CLI interface than
      codelldb expects on macOS.

    * vscode-lldb directs lldb to load rust pretty-printing scripts which need
      to be preserved through the build process in nixpkgs

Solution:

  * The build problem can be fixed by setting HOME="$(pwd)/home", as suggested
    in NixOS#202507.

  * The dynamic libraries issue can be fixed by setting LD_LIBRARY_PATH while
    wrapping codelldb

  * The permissions issue and CLI interface issue can both be fixed by using
    Xcode's debugserver,

      /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver

    on macOS, since it has the required entitlement and the expected interface.

  * Finally, the script-loading issue can be fixed by copying the required
    scripts to the location that vscode-lldb expects to find them in.

Fixes:

  * NixOS#148946: Error failed to get reply to handshake packet on x86_64-darwin
    with vscode-extensions.vadimcn.vscode-lldb

  * NixOS#160874: codelldb inside of vscode-lldb extension doesn't work

  * NixOS#202507: vscode-extensions.vadimcn.vscode-lldb fails to build on aarch64-darwin
@wegank wegank force-pushed the darwin-fix-vscode-lldb branch from a925084 to d0415e5 Compare April 10, 2024 09:08
@wegank wegank marked this pull request as ready for review April 10, 2024 09:10
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants