Skip to content

Commit

Permalink
WIP: Make it possible to use nwind-capi as alternative unwinding backend
Browse files Browse the repository at this point in the history
See also: koute/not-perf#37

This is supposedly faster. tst_trace works, which is good, but trying
to use a heaptrack build with this API on the multi threaded test
crashes:

```
RUST_BACKTRACE=full ./bin/heaptrack --debug --record-only --raw ./tests/manual/threaded
heaptrack output will be written to "/home/milian/projects/src/heaptrack/build-nwind/heaptrack.threaded.68148.raw.zst"
starting application in GDB, this might take some time...
Reading symbols from ./tests/manual/threaded...
Starting program: /home/milian/projects/src/heaptrack/build-nwind/tests/manual/threaded
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff73ff6c0 (LWP 68207)]
thread '<unnamed>' panicked at 'assertion failed: !duplicate_matches', nwind/src/address_space.rs:929:5
stack backtrace:
   0:     0x7ffff7676e0a - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ffff7676e0a - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ffff7676e0a - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ffff7676e0a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ffff7696e6f - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x7ffff7674745 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x7ffff7676bd5 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7ffff7676bd5 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7ffff7677f6e - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x7ffff7677d15 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x7ffff767852e - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:     0x7ffff76783e2 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:580:13
  12:     0x7ffff7677276 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x7ffff7678182 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x7ffff76946d3 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:     0x7ffff769476d - core::panicking::panic::h0ead933cb8f56d66
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:117:5
  16:     0x7ffff750c587 - nwind::address_space::match_mapping::h571f20ecd5df2ae9
                               at /home/milian/projects/src/not-perf/nwind/src/address_space.rs:929:5
  17:     0x7ffff74f8703 - nwind::address_space::reload::h7bdbef3c4ecee369
                               at /home/milian/projects/src/not-perf/nwind/src/address_space.rs:1098:34
  18:     0x7ffff759a769 - nwind::local_unwinding::LocalAddressSpace::reload::h3b5f5e2abb8bcbde
                               at /home/milian/projects/src/not-perf/nwind/src/local_unwinding.rs:738:9
  19:     0x7ffff759a399 - nwind::local_unwinding::LocalAddressSpace::new_with_opts::hc3923e5b6a30003f
                               at /home/milian/projects/src/not-perf/nwind/src/local_unwinding.rs:715:9
  20:     0x7ffff749c633 - nwind_create_address_space
                               at /home/milian/projects/src/not-perf/nwind-capi/src/lib.rs:58:29
  21:     0x7ffff7fbe84a - AddressSpace
                               at /home/milian/projects/src/heaptrack/src/track/trace_nwind_capi.cpp:21:44
  22:     0x7ffff7fbe84a - addressSpace
                               at /home/milian/projects/src/heaptrack/src/track/trace_nwind_capi.cpp:36:25
  23:     0x7ffff7fbe916 - _ZN5Trace6unwindEPPv
                               at /home/milian/projects/src/heaptrack/src/track/trace_nwind_capi.cpp:87:27
  24:     0x7ffff7fbda1a - _ZN5Trace4fillEi
                               at /home/milian/projects/src/heaptrack/src/track/trace.h:47:26
  25:     0x7ffff7fbda1a - heaptrack_malloc
                               at /home/milian/projects/src/heaptrack/src/track/libheaptrack.cpp:879:19
  26:     0x7ffff7fb9d98 - malloc
                               at /home/milian/projects/src/heaptrack/src/track/heaptrack_preload.cpp:214:21
  27:     0x7ffff7cac4fb - pool
                               at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc:235:30
  28:     0x7ffff7cac4fb - __static_initialization_and_destruction_0
                               at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc:373:8
  29:     0x7ffff7cac4fb - _GLOBAL__sub_I_eh_alloc.cc
                               at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc:456:1
  30:     0x7ffff7fcf0fe - <unknown>
  31:     0x7ffff7fcf1ec - <unknown>
  32:     0x7ffff7fe5560 - <unknown>
terminate called without an active exception
```
  • Loading branch information
milianw committed Sep 17, 2023
1 parent 55d40ce commit 56cada6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ else()
set(QT_MIN_VERSION 5.10.0)
endif()

option(
HEAPTRACK_USE_NWIND_CAPI
"Use nwind_capi for unwind, see https://github.com/koute/not-perf"
OFF
)

option(
HEAPTRACK_USE_LIBUNWIND
"Define preferred unwind functionality - Libunwind as ON and unwind_tables as OFF."
Expand Down Expand Up @@ -151,7 +157,9 @@ if (ECM_ENABLE_SANITIZERS)
endif()

if (HEAPTRACK_BUILD_TRACK)
if (HEAPTRACK_USE_LIBUNWIND)
if (HEAPTRACK_USE_NWIND_CAPI)
find_package(nwind_capi REQUIRED)
elseif (HEAPTRACK_USE_LIBUNWIND)
find_package(Libunwind REQUIRED)
endif()

Expand Down
6 changes: 5 additions & 1 deletion src/track/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ install(PROGRAMS ${PROJECT_BINARY_DIR}/${BIN_INSTALL_DIR}/heaptrack
DESTINATION ${BIN_INSTALL_DIR}
)

if (HEAPTRACK_USE_LIBUNWIND)
if (HEAPTRACK_USE_NWIND_CAPI)
add_library(heaptrack_unwind STATIC trace_nwind_capi.cpp)
target_include_directories(heaptrack_unwind PRIVATE ${NWIND_CAPI_INCLUDE_DIRS})
target_link_libraries(heaptrack_unwind PRIVATE ${NWIND_CAPI_LIBRARIES})
elseif (HEAPTRACK_USE_LIBUNWIND)
add_library(heaptrack_unwind STATIC trace_libunwind.cpp)
target_include_directories(heaptrack_unwind PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
target_link_libraries(heaptrack_unwind PRIVATE ${LIBUNWIND_LIBRARIES})
Expand Down
1 change: 1 addition & 0 deletions src/track/libheaptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ class HeapTrack
return;
}
s_data->moduleCacheDirty = true;
Trace::invalidateModuleCache();
}

void writeTimestamp()
Expand Down
1 change: 1 addition & 0 deletions src/track/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct Trace
}

static void setup();
static void invalidateModuleCache();

static void print();

Expand Down
4 changes: 4 additions & 0 deletions src/track/trace_libunwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ void Trace::setup()
#endif
}

void Trace::invalidateModuleCache()
{
}

int Trace::unwind(void** data)
{
return unw_backtrace(data, MAX_SIZE);
Expand Down
4 changes: 4 additions & 0 deletions src/track/trace_unwind_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void Trace::setup()
{
}

void Trace::invalidateModuleCache()
{
}

void Trace::print()
{
Trace trace;
Expand Down

0 comments on commit 56cada6

Please sign in to comment.