jeremy-rifkin / cpptrace

Simple, portable, and self-contained stacktrace library for C++11 and newer
MIT License
701 stars 75 forks source link

at least get frame address and object path on resolver exceptions #87

Closed eyalgolan1337 closed 8 months ago

eyalgolan1337 commented 8 months ago

In resolve_frames() (symbols_with_libdwarf.cpp) line 1115 (frame = resolver->resolve_frame(dlframe);) can throw, skipping the initialisation of frame.

This causes incomplete stack traces that contain lines that look like this: 0x00000000000

i suggest changing the for-loop so even when the resolver throws, the address and filename (which we already have) don't get lost:

index 20d691b..5553754 100644
--- a/src/symbols/symbols_with_libdwarf.cpp
+++ b/src/symbols/symbols_with_libdwarf.cpp
@@ -1109,11 +1109,13 @@ namespace libdwarf {
                     resolver = resolver_object.get();
                 }
                 for(const auto& entry : object_entry.second) {
+                    const auto& dlframe = entry.first.get();
+                    auto& frame = entry.second.get();
                     try {
-                        const auto& dlframe = entry.first.get();
-                        auto& frame = entry.second.get();
                         frame = resolver->resolve_frame(dlframe);
                     } catch(...) {
+                        frame.frame.address = dlframe.raw_address;
+                        frame.frame.filename = dlframe.object_path;
                         if(!should_absorb_trace_exceptions()) {
                             throw;
                         }
jeremy-rifkin commented 8 months ago

Hello, thanks for opening this! I agree this would be better. Happy to accept a PR or I can commit your proposed changes later today.

jeremy-rifkin commented 8 months ago

Thanks, this will be in the next release. Likely a 0.4.1 patch.

eyalgolan1337 commented 8 months ago

great! thank you