From cd75978cbb623849a31f26911d3fef93454818f8 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Tue, 6 Jun 2023 23:30:30 -0400 Subject: [PATCH] Handle failures to unwind better We can fail to find any frames even without `libdw` reporting an error, and in that case `dwfl_errmsg` can return a `nullptr`, which we cannot pass to the `std::string` constructor. This fixes a Engine error: basic_string::_S_construct null not valid when unwinding has failed. Signed-off-by: Matt Wozniski --- src/pystack/_pystack/unwinder.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pystack/_pystack/unwinder.cpp b/src/pystack/_pystack/unwinder.cpp index d426e405..6a32b078 100644 --- a/src/pystack/_pystack/unwinder.cpp +++ b/src/pystack/_pystack/unwinder.cpp @@ -445,7 +445,8 @@ Unwinder::unwindThread(pid_t tid) const // unwinding. if (frames.empty()) { int dwfl_err = dwfl_errno(); - std::string error(dwfl_errmsg(dwfl_err)); + std::string error( + dwfl_err ? dwfl_errmsg(dwfl_err) : "unwinding failed with no error reported"); throw UnwinderError("Unknown error happened when gathering thread frames: " + error); } break; @@ -492,7 +493,8 @@ thread_callback_for_frames(Dwfl_Thread* thread, void* arg) // unwinding. if (thread_arg->frames.empty()) { int dwfl_err = dwfl_errno(); - std::string error(dwfl_errmsg(dwfl_err)); + std::string error( + dwfl_err ? dwfl_errmsg(dwfl_err) : "unwinding failed with no error reported"); throw UnwinderError("Unknown error happened when gathering thread frames: " + error); } break; @@ -525,7 +527,8 @@ CoreFileUnwinder::unwindThread(pid_t tid) const // unwinding. if (frames.empty()) { int dwfl_err = dwfl_errno(); - std::string error(dwfl_errmsg(dwfl_err)); + std::string error( + dwfl_err ? dwfl_errmsg(dwfl_err) : "unwinding failed with no error reported"); throw UnwinderError("Unknown error happened when gathering thread frames: " + error); } break;