Rust debug symbols not working in `rust-lldb`?

Trying to debug this issue (for nixpkgs#espanso on aarch64-darwin)

I’m building from a local checkout where I’ve added buildType = "debug"; and dontStrip = true; to the buildRustPackage definition.

It seems to be working, because when I build with these changes, I get a magnitude of order more output from objdump (not sure how else to check, I’m on aarch64-darwin):

$ # without `buildType = "debug";` / `dontStrip`
$ objdump --syms ./result/bin/espanso  | wc -l
40490
$
$ # with `buildType = "debug";` + `dontStrip = true`
$ objdump --syms ./result/bin/espanso  | wc -l
410374

However, rust-lldb has a hard time finding breakpoints, and when I stop at a breakpoint it just looks like assembly (I think):

thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.4 1.5
    frame #0: 0x00000001000484e0 espanso`espanso::cli::launcher::daemon::launch_daemon::h8e14659196a7028e
espanso`espanso::cli::launcher::daemon::launch_daemon::h8e14659196a7028e:
->  0x1000484e0 <+0>:  stp    x28, x27, [sp, #-0x20]!
    0x1000484e4 <+4>:  stp    x29, x30, [sp, #0x10]
    0x1000484e8 <+8>:  add    x29, sp, #0x10
    0x1000484ec <+12>: sub    sp, sp, #0xce0
Target 0: (espanso) stopped.

In contrast, if I manually compile a debug build from the espanso repository (using the usual rust toolchain), stopping at a breakpoint looks like this:

Process 84178 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 7.1 11.1
    frame #0: 0x0000000100160184 espanso`espanso::cli::launcher::daemon::launch_daemon::h68a5a2a46a9d1439(paths_overrides=0x000000016fdcacb0) at daemon.rs:30:7
   27   use crate::cli::PathsOverrides;
   28
   29   pub fn launch_daemon(paths_overrides: &PathsOverrides) -> Result<()> {
-> 30       dbg!(paths_overrides);
   31     let espanso_exe_path = std::env::current_exe()?;
   32     let mut command = Command::new(&espanso_exe_path.to_string_lossy().to_string());
   33     command.args(&["daemon"]);
Target 0: (espanso) stopped.

Why am I unable to get the debugger to show the symbols properly when I’m building from nix?

POC:

# flake.nix
{
  inputs.nixpkgs.url = "github:nixos/nixpkgs";
  outputs = {nixpkgs, ...}: let
    system = "aarch64-darwin";
  in {
    packages.${system}.default = let
      pkgs = import nixpkgs {inherit system;};
    in
      pkgs.rustPlatform.buildRustPackage {
        pname = "foo";
        buildType = "debug";
        dontStrip = true;
        version = "0.0.1";
        src = ./.;
        cargoHash = "sha256-p1UJmkerUpvbkZKZYPpqMixWdL3mHSwYsiHo14AUih8=";
      };
  };
}
// src/main.rs
fn a_function() -> u32 {
    dbg!("this is from debug!");
    4
}

fn main() {
    println!("{}", a_function());
    println!("Hello, world!");
}
$ nix build
$ rust-lldb ./result/bin/foo
...
(lldb) break set --name main
Breakpoint 3: 3 locations.
(lldb) run
There is a running process, kill it and restart?: [Y/n] y
Process 22964 exited with status = 9 (0x00000009)
1 location added to breakpoint 3
Process 23086 launched: '/nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo' (arm64)
1 location added to breakpoint 3
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100000000 maps to more than one section: foo.__TEXT and foo.__TEXT
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100044000 maps to more than one section: foo.__DATA_CONST and foo.__DATA_CONST
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100048000 maps to more than one section: foo.__DATA and foo.__DATA
1 location added to breakpoint 3
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100000000 maps to more than one section: foo.__TEXT and foo.__TEXT
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100044000 maps to more than one section: foo.__DATA_CONST and foo.__DATA_CONST
warning: (arm64) /nix/store/sdh19fqx5cbjcq78nhvk3pgclnhi13dp-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100048000 maps to more than one section: foo.__DATA and foo.__DATA
1 location added to breakpoint 3
Process 23086 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.6 3.7
    frame #0: 0x0000000100001130 foo`main
foo`main:
->  0x100001130 <+0>:  stp    x29, x30, [sp, #-0x10]!
    0x100001134 <+4>:  mov    x29, sp
    0x100001138 <+8>:  mov    x2, x1
    0x10000113c <+12>: mov    x8, x0
Target 0: (foo) stopped.

In contrast:

$ cargo build
$ rust-lldb ./target/debug/foo
...
(lldb) break set --name main
Breakpoint 1: 2 locations.
(lldb) run
Process 23441 launched: '/Users/n8henrie/Desktop/nix-rust-debug-foo/target/debug/foo' (arm64)
Process 23441 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
    frame #0: 0x0000000100000af8 foo`main
foo`main:
->  0x100000af8 <+0>:  stp    x29, x30, [sp, #-0x10]!
    0x100000afc <+4>:  mov    x29, sp
    0x100000b00 <+8>:  mov    x2, x1
    0x100000b04 <+12>: mov    x8, x0
Target 0: (foo) stopped.
(lldb) c
Process 23441 resuming
Process 23441 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000a5c foo`foo::main::h54adae2855c7ea3a at main.rs:7:20
   4    }
   5
   6    fn main() {
-> 7        println!("{}", a_function());
   8        println!("Hello, world!");
   9    }
Target 0: (foo) stopped.

FWIW I see the same behavior on x86_64-linux.