Hi all,
I started this thread at the NixOS discourse a couple months ago, and it hasn't gotten any attention, so I thought I'd try here as well.
In short, I'm using nix's buildRustPackage
with buildType = "debug";
and dontStrip = true;
, and yet when I run rust-lldb
on the resulting binary, I'm not seeing human-readable names (EDIT: and my function name breakpoints don't work).
// src/main.rs
fn a_function() -> u32 {
dbg!("this is from debug!");
4
}
fn main() {
println!("{}", a_function());
println!("Hello, world!");
}
# 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=";
};
};
}
Running with cargo build
and then rust-lldb
seems fine:
$ cargo build
$ rust-lldb -o 'break set --name a_function' -o run ./target/debug/foo
(lldb) command script import "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_lookup.py"
(lldb) command source -s 0 '/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'
Executing commands in '/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'.
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
(lldb) type category enable Rust
(lldb) target create "./target/debug/foo"
Current executable set to '/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.4zz7jkEjQF/foo/target/debug/foo' (arm64).
(lldb) break set --name a_function
Breakpoint 1: where = foo`foo::a_function::h6de5a9fc4db6253c + 20 at main.rs:3:5, address = 0x0000000100000b28
(lldb) run
Process 65944 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000b28 foo`foo::a_function::h6de5a9fc4db6253c at main.rs:3:5
1 // src/main.rs
2 fn a_function() -> u32 {
-> 3 dbg!("this is from debug!");
4 4
5 }
6
7 fn main() {
Target 0: (foo) stopped.
Process 65944 launched: '/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.4zz7jkEjQF/foo/target/debug/foo' (arm64)
(lldb)
In contrast, running nix build
, I get Breakpoint 1: no locations (pending).
,
$ nix build
$ rust-lldb -o 'break set --name a_function' -o run ./result/bin/foo
(lldb) command script import "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_lookup.py"
(lldb) command source -s 0 '/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'
Executing commands in '/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/etc/lldb_commands'.
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
(lldb) type category enable Rust
(lldb) target create "./result/bin/foo"
Current executable set to '/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.4zz7jkEjQF/foo/result/bin/foo' (arm64).
(lldb) break set --name a_function
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) run
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100000000 maps to more than one section: foo.__TEXT and foo.__TEXT
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100050000 maps to more than one section: foo.__DATA_CONST and foo.__DATA_CONST
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100054000 maps to more than one section: foo.__DATA and foo.__DATA
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100000000 maps to more than one section: foo.__TEXT and foo.__TEXT
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100050000 maps to more than one section: foo.__DATA_CONST and foo.__DATA_CONST
warning: (arm64) /nix/store/bp7fq96ciy906kf8xkq8hmjhgcjncx1q-foo-0.0.1/bin/foo(0x0000000100000000) address 0x0000000100054000 maps to more than one section: foo.__DATA and foo.__DATA
[src/main.rs:3] "this is from debug!" = "this is from debug!"
4
Hello, world!
Process 66626 exited with status = 0 (0x00000000)
Process 66626 launched: '/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.4zz7jkEjQF/foo/result/bin/foo' (arm64)
(lldb)
The buildType = "debug";
and dontStrip
seem to be doing something, but still has way less output than the cargo build
version:
$ cargo build
$ objdump --syms ./target/debug/foo | wc -l
2242
$
$ # normal release build / *without* `buildType = "debug"`
$ nix build && objdump --syms ./result/bin/foo | wc -l
1262
$
$ # adding `buildType = "debug";`:
$ nix build && objdump --syms ./result/bin/foo | wc -l
1272
$
$ # adding `dontStrip = true;` as well:
$ nix build && objdump --syms ./result/bin/foo | wc -l
1375
Are there any nix + rust users that can help me build a rust binary with nix that can be debugged with rust-lldb
?
FWIW, I'm seeing the same behavior with rust-gdb
on x86_64-linux
.
TIA for any suggestions!