From b0fad21d77a57b43e79b1a9ae013304c70970645 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 18 Jun 2021 16:58:32 -0400 Subject: [PATCH] common/BackTrace: accept list of strings to ctor This may seem a bit backwards: we take nice C++ list and do the C dance. It's a bit defensive: this class is used in the segv handler (in the backtrace() and backtrace_symbol() path), so we want to minimize the work we do on the heap in that case. (For the list path, we can do whatever we like.) Signed-off-by: Sage Weil --- src/common/BackTrace.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/common/BackTrace.h b/src/common/BackTrace.h index 7de30a5f6e0d8..ce3912f52cd00 100644 --- a/src/common/BackTrace.h +++ b/src/common/BackTrace.h @@ -11,6 +11,9 @@ #endif #include +#include +#include + namespace ceph { class Formatter; @@ -23,6 +26,18 @@ struct BackTrace { size_t size; char **strings; + std::list src_strings; + + explicit BackTrace(std::list& s) + : skip(0), + size(s.size()) { + src_strings = s; + strings = (char **)malloc(sizeof(*strings) * src_strings.size()); + unsigned i = 0; + for (auto& s : src_strings) { + strings[i++] = (char *)s.c_str(); + } + } explicit BackTrace(int s) : skip(s) { #ifdef HAVE_EXECINFO_H size = backtrace(array, max); -- 2.39.5