Skip to content

gdb can't print backtraces in musl binaries during syscalls  #90103

Closed
@wesleywiser

Description

If you run gdb and attempt to get the backtrace during a sycall (or are debugging a crash dump that includes frames in the middle of syscalls), gdb is unable to correctly print the backtrace and shows a truncated stack instead.

Repro:

$ cat test.rs
fn main() {
    a();
}

fn a() {
    b();
}

fn b() {
    c();
}

fn c() {
    d();
}

fn d() {
    println!("hello world");
}

$ rustc +nightly --version
rustc 1.58.0-nightly (1af55d19c 2021-10-19)

$ rustc +nightly --crate-name musl_test -g --target x86_64-unknown-linux-musl test.rs

$ gdb --version
GNU gdb (Ubuntu 10.1-2ubuntu2) 10.1.90.20210411-git 

$ gdb -q ./musl_test -ex "catch syscall write" -ex "run" -ex "bt"
Reading symbols from ./musl_test...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /tmp/musl_test.
Use `info auto-load python-scripts [REGEXP]' to list them.
Catchpoint 1 (syscall 'write' [1])
Starting program: /tmp/musl_test

Catchpoint 1 (call to syscall write), 0x00007ffff7fe0ffd in sccp ()
#0  0x00007ffff7fe0ffd in sccp ()
#1  0x00007ffff7fe1bb1 in write ()
#2  0x0000000000000000 in ?? ()

For comparison, the same program compiled using x86_64-unknown-linux-gnu produces a backtrace like this:

Catchpoint 1 (call to syscall write), 0x00007ffff7f95297 in __libc_write (fd=1, buf=0x555555590057, nbytes=12)
    at ../sysdeps/unix/sysv/linux/write.c:26
26      ../sysdeps/unix/sysv/linux/write.c: No such file or directory.
#0  0x00007ffff7f95297 in __libc_write (fd=1, buf=0x555555590057, nbytes=12) at ../sysdeps/unix/sysv/linux/write.c:26
#1  0x000055555556e4fe in std::sys::unix::fd::FileDesc::write () at library/std/src/sys/unix/fd.rs:132
#2  <std::sys::unix::stdio::Stdout as std::io::Write>::write () at library/std/src/sys/unix/stdio.rs:39
#3  std::io::Write::write_all () at library/std/src/io/mod.rs:1556
#4  <std::io::stdio::StdoutRaw as std::io::Write>::write_all () at library/std/src/io/stdio.rs:145
#5  <std::io::buffered::linewritershim::LineWriterShim<W> as std::io::Write>::write_all ()
    at library/std/src/io/buffered/linewritershim.rs:260
#6  <std::io::buffered::linewriter::LineWriter<W> as std::io::Write>::write_all ()
    at library/std/src/io/buffered/linewriter.rs:206
#7  <std::io::stdio::StdoutLock as std::io::Write>::write_all () at library/std/src/io/stdio.rs:875
#8  0x000055555556f437 in <std::io::Write::write_fmt::Adapter<T> as core::fmt::Write>::write_str ()
    at library/std/src/io/mod.rs:1685
#9  0x000055555558b91f in core::fmt::write () at library/core/src/fmt/mod.rs:1187
#10 0x000055555556e24e in std::io::Write::write_fmt () at library/std/src/io/mod.rs:1696
#11 <&std::io::stdio::Stdout as std::io::Write>::write_fmt () at library/std/src/io/stdio.rs:855
#12 0x000055555556e81c in <std::io::stdio::Stdout as std::io::Write>::write_fmt () at library/std/src/io/stdio.rs:829
#13 std::io::stdio::print_to () at library/std/src/io/stdio.rs:1196
#14 std::io::stdio::_print () at library/std/src/io/stdio.rs:1209
#15 0x000055555555c811 in musl_test::d () at test.rs:18
#16 0x000055555555c7d6 in musl_test::c () at test.rs:14
#17 0x000055555555c7c6 in musl_test::b () at test.rs:10
--Type <RET> for more, q to quit, c to continue without paging--
#18 0x000055555555c7b6 in musl_test::a () at test.rs:6
#19 0x000055555555c7a6 in musl_test::main () at test.rs:2

I believe the issue is that we need CFI directives to be included in our musl build. I'm working on resolving this now.

Metadata

Assignees

Labels

A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.O-muslTarget: The musl libc

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions