benfred / py-spy

Sampling profiler for Python programs
MIT License
12.13k stars 401 forks source link

test_coredump: fix unaligned pointer dereference #657

Open karolinepauls opened 3 months ago

karolinepauls commented 3 months ago

This fixes the test but I still cannot get a coredump to load locally - the executable cannot be located in it, same goes for any other dump I tried. I'll add details in a comment.

The panic observed on master.

$ cargo test test_coredump
   Compiling py-spy v0.3.14 (/home/karoline/IDE/py-spy)
    Finished test [unoptimized + debuginfo] target(s) in 4.80s
     Running unittests src/lib.rs (target/debug/deps/py_spy-6453fb3149eb3ee2)

running 1 test
thread 'coredump::test::test_coredump' panicked at src/coredump.rs:94:30:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x7fa7adbaa334
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:122:9
   3: core::panicking::panic_misaligned_pointer_dereference
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:221:5
   4: py_spy::coredump::CoreDump::new
             at ./src/coredump.rs:94:30
   5: py_spy::coredump::test::test_coredump
             at ./src/coredump.rs:438:20
   6: py_spy::coredump::test::test_coredump::{{closure}}
             at ./src/coredump.rs:434:23
   7: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `/home/karoline/IDE/py-spy/target/debug/deps/py_spy-6453fb3149eb3ee2 test_coredump` (signal: 6, SIGABRT: process abort signal)
In [1]: 0x7fa7adbaa334 % 8
Out[1]: 4
$ cargo rustc --bin py-spy -- -V
   Compiling py-spy v0.3.14 (/home/karoline/IDE/py-spy)
rustc 1.76.0 (07dca489a 2024-02-04)
$ uname -a
Linux hostname 5.15.0-97-lowlatency #107-Ubuntu SMP PREEMPT Fri Feb 9 11:16:34 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
karolinepauls commented 3 months ago

Separate issue - inability to load a coredump (created on the same machine):

Here it seems the executable segment isn't found (added dbg statements printing program headers). I checked the section headers as well - not found there as well. But that's a separate problem. I'm not actually sure if the coredump feature is finished. I was using a coredump generated from a running python -m http.server process.

Should I create an issue for that?

/proc/pid/maps on the right side image