Skip to content

Android Studio's debugger is broken (android-studio-canary)  #112266

Closed

Description

@PixelyIon

Bug Description

Android Studio (android-studio-canary) debugging doesn't work, it internally uses LLDB for debugging (and ships binaries for it with itself). It embeds LLDB inside a closed-source wrapper present in PACKAGE_ROOT/bin/lldb/bin/LLDBFrontend.

On attempting to execute this binary during debugging, it runs into the following error:

/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/LLDBFrontend: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

Reproduction Steps

  • Open any NDK project on Android Studio
  • Use the native debugging functionality
  • Check the LLDB tab in the Debugger

Additional Observations

  • Android Studio uses an FSH environment (environment will be omitted henceforth) as opposed to using patchelf
  • Android Studio comes with an in-built terminal, this launches a shell which should be in the aforementioned FSH environment
    • This can be confirmed by checking the relevant FSH directories
    • Additionally, it was confirmed using this that /lib, /usr/lib, /usr/lib32 and /usr/lib64 contained libncurses.so.5 (as defined by the derivation)
  • strace -f'ing Android Studio shows the linker not going through directories specified by the FSH $LD_LINKER_PATH (Full Trace)
...
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/haswell/x86_64/libncurses.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/haswell/x86_64", 0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/haswell/libncurses.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/haswell", 0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/x86_64/libncurses.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/x86_64", 0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/tls",  <unfinished ...>
21308 <... stat resumed>0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/haswell/x86_64/libncurses.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/haswell/x86_64",  <unfinished ...>
21308 <... stat resumed>0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/haswell/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/haswell",  <unfinished ...>
21308 <... stat resumed>0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/x86_64/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/x86_64",  <unfinished ...>
21308 <... stat resumed>0x7ffce8d2ff40) = -1 ENOENT (No such file or directory)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 stat("/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/../lib64", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
21308 openat(AT_FDCWD, "/nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libncurses.so.5", O_RDONLY|O_CLOEXEC <unfinished ...>
21308 <... openat resumed>)             = -1 ENOENT (No such file or directory)
21308 writev(2, [{iov_base="/nix/store/lam2yvqbrjgyv5m2b8rpb"..., iov_len=112}, {iov_base=": ", iov_len=2}, {iov_base="error while loading shared libra"..., iov_len=36}, {iov_base=": ", iov_len=2}, {iov_base="libncurses.so.5", iov_len=15}, {iov_base=": ", iov_len=2}, {iov_base="cannot open shared object file", iov_len=30}, {iov_base=": ", iov_len=2}, {iov_base="No such file or directory", iov_len=25}, {iov_base="\n", iov_len=1}], 10 <unfinished ...>
21308 <... writev resumed>)             = 227
...
  • To further confirm that LLDBFrontend is not in the FSH environment, lld was run inside and outside it
    • Inside FSH
nixos% ldd /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/LLDBFrontend
        linux-vdso.so.1 (0x00007ffd189d6000)
        liblldb.so.11git => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/liblldb.so.11git (0x00007f1391167000)
        libc++.so.1 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/libc++.so.1 (0x00007f1391083000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f1390f40000)
        libgcc_s.so.1 => /nix/store/jpf7r0zvv7a8xlk6330g0qcnimwxqc7l-gcc-10.2.0-lib/lib/libgcc_s.so.1 (0x00007f1390f26000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1390f05000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f1390d44000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/9p681337dfwxskgsszggb5px5r7zs3g2-glibc-multi-2.32-25/lib/ld-linux-x86-64.so.2 (0x00007f139578b000)
        libpython3.8.so.1.0 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libpython3.8.so.1.0 (0x00007f13907a5000)
        libncurses.so.5 => /usr/lib/libncurses.so.5 (0x00007f139073f000)
        libform.so.5 => /usr/lib/libform.so.5 (0x00007f139072b000)
        libpanel.so.5 => /usr/lib/libpanel.so.5 (0x00007f1390725000)
    • Outside FSH
[mark@nixos:~]$ ldd /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/LLDBFrontend 
    linux-vdso.so.1 (0x00007ffc2d995000)
    liblldb.so.11git => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/liblldb.so.11git (0x00007eff4f44c000)
    libc++.so.1 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/libc++.so.1 (0x00007eff4f368000)
    libm.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libm.so.6 (0x00007eff4f225000)
    libgcc_s.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libgcc_s.so.1 (0x00007eff4f20b000)
    libpthread.so.0 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libpthread.so.0 (0x00007eff4f1ea000)
    libc.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libc.so.6 (0x00007eff4f027000)
    /lib64/ld-linux-x86-64.so.2 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib64/ld-linux-x86-64.so.2 (0x00007eff53a6e000)
    libpython3.8.so.1.0 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libpython3.8.so.1.0 (0x00007eff4ea8a000)
    libncurses.so.5 => not found
    libtinfo.so.5 => not found
    libform.so.5 => not found
    libpanel.so.5 => not found
    libxml2.so.2.9.10 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libxml2.so.2.9.10 (0x00007eff4e8e4000)
    libedit.so.0 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libedit.so.0 (0x00007eff4e8a9000)    
    libz.so.1 => not found
    librt.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/librt.so.1 (0x00007eff4e89e000)
    libdl.so.2 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libdl.so.2 (0x00007eff4e897000)
    libutil.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libutil.so.1 (0x00007eff4e892000)
    libz.so.1 => not found
    libncurses.so.5 => not found
    libtinfo.so.5 => not found
  • It can be safely concluded when combining this with the prior strace -f that LLDBFrontend is running outside of FSH
# libm.so.6
libm.so.6 => /usr/lib/libm.so.6 (0x00007f1390f40000)
libm.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libm.so.6 (0x00007eff4f225000)
21308 openat(AT_FDCWD, "/nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3

# libgcc_s.so.1
libgcc_s.so.1 => /nix/store/jpf7r0zvv7a8xlk6330g0qcnimwxqc7l-gcc-10.2.0-lib/lib/libgcc_s.so.1 (0x00007f1390f26000)
libgcc_s.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libgcc_s.so.1 (0x00007eff4f20b000)
21308 openat(AT_FDCWD, "/nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3

# libpthread.so.0
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1390f05000)
libpthread.so.0 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libpthread.so.0 (0x00007eff4f1ea000)
21308 openat(AT_FDCWD, "/nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3

# libc.so.6
libc.so.6 => /usr/lib/libc.so.6 (0x00007f1390d44000)
libc.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libc.so.6 (0x00007eff4f027000)
21308 openat(AT_FDCWD, "/nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3

# libpython.3.8.so.1.0
libpython3.8.so.1.0 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libpython3.8.so.1.0 (0x00007f13907a5000)
libpython3.8.so.1.0 => /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/../lib64/../lib64/libpython3.8.so.1.0 (0x00007eff4ea8a000)
21308 openat(AT_FDCWD, "/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64/libpython3.8.so.1.0", O_RDONLY|O_CLOEXEC) = 3

# libncurses.so.5
libncurses.so.5 => /usr/lib/libncurses.so.5 (0x00007f139073f000)
libncurses.so.5 => not found
21308 openat(AT_FDCWD, "{All Outside FSH $LD_LIBRARY_PATH Entries}/libncurses.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  • LLDBFrontend was invoked from inside FSH (Through Android Studio's Terminal), this resulted in a successful invocation
nixos% /nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/bin/LLDBFrontend 
Usage: <portnum> | <--version>

Potential Solutions

  • FSH being fixed assuming this is a bug and not intended behavior, inconsistent behavior between zsh and LLDBFrontend point to this. As far as I can tell, bubblewrap is at fault in that case.
  • patchelf the LLDBFrontend executable to use the correct libraries, I'm not familiar enough with patchelf nor modifying Nix derivations to do this.

Notify maintainers

@meutraa

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.10.12, NixOS, 21.03pre267812.7cbec40a095 (Okapi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.10
  • channels(mark): "home-manager, nixos-21.03pre265130.f217c0ea7c1, nixpkgs-21.03pre265593.fcef64cc398"
  • channels(root): "nixos-21.03pre267812.7cbec40a095, nixpkgs-21.03pre268025.2c58a9dac0b"
  • nixpkgs: /home/mark/.nix-defexpr/channels/nixpkgs

Maintainer information:

attribute: 
  - androidStudioPackages.canary
module:

Activity

  1. added
    0.kind: bug
    on Feb 7, 2021
  2. PixelyIon commented on Feb 7, 2021

    @PixelyIon
    ContributorAuthor

    @IvarWithoutBones and I have further looked into the bug, we landed on an issue #103648 which presented a similar bug. We attempted to apply the solution they found by exporting ALLOW_NINJA_ENV=true to the FSH environment. As expected, this didn't work as the LLDB debugger isn't invoked via ninja.

    It did provide introspection into why the issue might be caused, Android Studio overriding the LD_LINKER_PATH provided to the LLDBFrontend. We tested this by creating an executable which prints out all environment variables and swapping out LLDBFrontend with it.

    Environment

    # Android Studio LLDBFrontend
    LD_LIBRARY_PATH=/nix/store/lam2yvqbrjgyv5m2b8rpb4vrcv0h4ns4-android-studio-canary-2020.3.1.4-unwrapped/bin/lldb/lib64
    
    ## Contents of .../bin/lldb/lib64
    * libc++abi.so.1
    * libc++.so.1
    * libedit.so.0
    * liblldb.so.11git
    * libpython3.8.so.1.0
    * libxml2.so.2.9.10
    
    # Android Studio Terminal
    LD_LIBRARY_PATH=/nix/store/vfpv3gf49b1dkx040sg78bd9dc7ry9ra-fontconfig-2.13.92-lib/lib:/nix/store/j8fc8jjjqqh0sxnlvfbh6dbv6nclibb9-freetype-2.10.4/lib:/nix/store/c3y8m27dkr1vs608m11v3x67chwl9za6-libXext-1.3.4/lib:/nix/store/x6rj990ml286l2scndyr099n9g3s4nim-libXi-1.7.10/lib:/nix/store/pvzavsnwns0xy54kmmf83na3vffd0p61-libXrender-0.9.10/lib:/nix/store/ssjl4gaqwmnhn9qrbqrgd606pj1y73ny-libXtst-1.2.3/lib:/nix/store/jpf7r0zvv7a8xlk6330g0qcnimwxqc7l-gcc-10.2.0-lib/lib:/nix/store/xgrmppnlwngw0inr6w4ca8ihfca3phqa-gcc-10.2.0-lib/lib:/nix/store/pvy77kjmkvcjfjhsva65cgi7v6hc1262-zlib-1.2.11/lib:/nix/store/vxqs8cxz9k8nwg5268yd19zs4l09b7g2-zlib-1.2.11/lib:/nix/store/lkqina68qfpyarin9krqq6j7rnmdb9fn-libXrandr-1.5.2/lib:/nix/store/g02m7hwaxlii7y3pq2ayav29jhbd0nb9-alsa-lib-1.2.4/lib:/nix/store/1cp11km3f68pwfry9fp2wx7pwl4kfnmr-dbus-1.12.20-lib/lib:/nix/store/h2l7m2hxg18r5gwkywxkxhmd64889lz8-expat-2.2.10/lib:/nix/store/8bsm1k11b153n3vcnj4kw3x87rmpxxk9-libpulseaudio-14.0/lib:/nix/store/ff2abkrx8vfdlvmj4d1ababgylvy487i-util-linux-2.36.1/lib:/nix/store/wjz5m03hzggpzjvb5i4vxffrjlh3z66n-libX11-1.7.0/lib:/nix/store/zlqk1wz6lfgkjqrb85daxsfpnszqm38i-libxcb-1.14/lib:/nix/store/r5yckz9j5a4lssxxs2a3gjbxrdxijj84-libXcomposite-0.4.5/lib:/nix/store/5b05mkc7vl8djjd2c1q285c1sdgjyld2-libXcursor-1.2.0/lib:/nix/store/9g2f3i81zdaw8x8kasmblihc0iyzwfvv-libXdamage-1.1.5/lib:/nix/store/iyl13mvabrj2gpfa5ch6gb5lsc7p289m-libXfixes-5.0.3/lib:/nix/store/7bar2wr0mak3y107q5jmjcdphbbbpnc7-libGL-1.3.2/lib:/nix/store/bsh0kk8yv9y84ww8nf1mglasrcislzbn-nspr-4.29/lib:/nix/store/990q0rqj5qs7jrfqgamfzpfiq0ck8x6d-nss-3.60/lib:/nix/store/zhd4gciw3fqa8pgr9x33k6zzansr1ckw-systemd-247.2/lib:/nix/store/irmsn9wlhaacmrqydjgqhdlwji2r31vm-gtk+-2.24.32/lib:/nix/store/7lhzw1xshqlhyjz2g7lgzgz28kwccqr9-gnome-vfs-2.24.4/lib:/nix/store/xlgi1m9s42syv76l0kzqf9mcxxdvkb73-glib-2.66.4/lib:/nix/store/3n8d35rqi0q8x5nkjm9gm7if4fjr5hal-gconf-3.2.6/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:/run/current-system/sw/lib/pipewire
    
    # Outside FSH
    LD_LIBRARY_PATH=/run/current-system/sw/lib/pipewire

    This essentially confirms our theory regarding it and explains why the linker behavior is mostly consistent for LLDBFrontend and outside FSH. This essentially proves that FSH is not at fault and sheds some light on Android Studio's odd behavior here, the LD_LINKER_PATH it sets does not have the required libraries to run LLDBFrontend.

    As we've diagnosed the issue to be the lack of the required libraries in LD_LIBRARY_PATH, a clear solution is to use a wrapper to fix-up the LD_LINKER_PATH that LLDBFrontend receives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions