headcrab-rs / headcrab

A modern Rust debugging library 🦀
https://headcrab.rs
Other
888 stars 32 forks source link

Feature request: stand-alone binary to dump a running process' stacktrace #130

Open matklad opened 3 years ago

matklad commented 3 years ago

Sort version of an ask:

$ cargo-install print-stacktrace
   Installing ...
$ print-stacktrace rust-analyzer
thread #10, name = 'rust-analyzer'
    frame #0: 0x00007f7133cd7bb9 libc.so.6`sysmalloc(nb=336, av=0x00007f7108000020) at malloc.c:2739
    frame #1: 0x00007f7133cd8ff0 libc.so.6`_int_malloc(av=0x00007f7108000020, bytes=321) at malloc.c:4125
    frame #2: 0x00007f7133cd98f5 libc.so.6`_int_realloc(av=0x00007f7108000020, oldp=0x00007f70afffff30, oldsize=176, nb=336) at malloc.c:4570
    frame #3: 0x00007f7133cdcf9b libc.so.6`__GI___libc_realloc(oldmem=&0x7f70afffff40, bytes=320) at malloc.c:3230
    frame #4: 0x00005571f6b8846b rust_analyzer`_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$alloc..vec..SpecExtend$LT$T$C$I$GT$$GT$::from_iter::hdc9ae08fd4d2dcd5 [inlined] alloc::alloc::realloc::h7df9eca016b70494 at alloc.rs:128
    ...

Long version:

For my personal use, I reach for debuggers mostly to get stactraces on deadlocks/livelocks. Every time I need to google how to gdb and recollect that bt thread all incantation. Moreover, when I debug a hang on someone-else's computer, I need to teach them how to work with gdb. My life would be much easier if I can ask them to just cargo install print-stacktrace .

This utility should dump a stack of a running process using either process name (default) or PID (with -p argument). Defaulting to name makes sense, as figuring out a PID is often a stumbling block. If there's more than one process with a matching name, I think the tool should print:

Found 2 processes with a name `foo`:
  Pid:    Process:
  1234    '/usr/bin/foo --eggs'
  9292    '/home/alice/bin/foo --spam'

Use the following command to disambiguate:

  print-stacktrace -p Pid

It seems like implementing this should be possible in the early stages of headcrab (I've said it already, and I say it again: what a delightful name!), and it'll put some part of the infra into production usage.

bjorn3 commented 3 years ago

Headcrab doesn't have support for DWARF unwinding yet (#60). It shouldn't be too implement this tool for the existing frame pointer unwinder though. I don't think I will be able to implement this myself very soon unfortunately.