Skip to content

Commit

Permalink
vscode-extensions.vadimcn.vscode-lldb: fix on Darwin
Browse files Browse the repository at this point in the history
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, #202507

  and several runtime-issues:

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

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

        "com.apple.security.cs.debugger"

      macOS codesigning entitlement, (#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 #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:

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

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

  * #202507: vscode-extensions.vadimcn.vscode-lldb fails to build on aarch64-darwin
  • Loading branch information
mstone authored and wegank committed Dec 3, 2023
1 parent d1fc3a5 commit 135eff0
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ let
'';
};

# debugservers on macOS require the 'com.apple.security.cs.debugger'
# 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"
else
"${lldb.out}/bin/lldb-server";

in stdenv.mkDerivation {
pname = "vscode-extension-${publisher}-${pname}";
inherit src version vscodeExtUniqueId vscodeExtPublisher vscodeExtName;
Expand All @@ -86,6 +94,9 @@ in stdenv.mkDerivation {

postConfigure = ''
cp -r ${nodeDeps}/lib/node_modules .
'' + lib.optionalString stdenv.isDarwin ''
export HOME="$TMPDIR/home"
mkdir $HOME
'';

cmakeFlags = [
Expand All @@ -109,7 +120,8 @@ in stdenv.mkDerivation {
cp -t $ext/adapter ${adapter}/{bin,lib}/*
cp -r ../adapter/scripts $ext/adapter
wrapProgram $ext/adapter/codelldb \
--set-default LLDB_DEBUGSERVER_PATH "${lldb.out}/bin/lldb-server"
--prefix LD_LIBRARY_PATH : "$ext/lldb/lib" \
--set-default LLDB_DEBUGSERVER_PATH "${lldbServer}"
cp -t $ext/formatters ../formatters/*.py
ln -s ${lldb.lib} $ext/lldb
# Mark that all components are installed.
Expand Down

0 comments on commit 135eff0

Please sign in to comment.