]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/BackTrace: accept list of strings to ctor
authorSage Weil <sage@newdream.net>
Fri, 18 Jun 2021 20:58:32 +0000 (16:58 -0400)
committerSage Weil <sage@newdream.net>
Wed, 23 Jun 2021 17:00:49 +0000 (13:00 -0400)
This may seem a bit backwards: we take nice C++ list<string> 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<string> path,
we can do whatever we like.)

Signed-off-by: Sage Weil <sage@newdream.net>
src/common/BackTrace.h

index 7de30a5f6e0d89b93ec0f10f48f143185c977e64..ce3912f52cd00efb0e3b960856bfbd64cc09a281 100644 (file)
@@ -11,6 +11,9 @@
 #endif
 #include <stdlib.h>
 
+#include <list>
+#include <string>
+
 namespace ceph {
 
 class Formatter;
@@ -23,6 +26,18 @@ struct BackTrace {
   size_t size;
   char **strings;
 
+  std::list<std::string> src_strings;
+
+  explicit BackTrace(std::list<std::string>& 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);