OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StackTrace.cpp File Reference
#include <Shared/StackTrace.h>
#include <boost/algorithm/string.hpp>
#include <boost/stacktrace.hpp>
+ Include dependency graph for StackTrace.cpp:

Go to the source code of this file.

Macros

#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED   1
 

Functions

std::string getCurrentStackTrace (uint32_t num_frames_to_skip, const char *stop_at_this_frame, bool skip_void_and_stl_frames)
 

Macro Definition Documentation

#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED   1

Definition at line 19 of file StackTrace.cpp.

Function Documentation

std::string getCurrentStackTrace ( uint32_t  num_frames_to_skip,
const char *  stop_at_this_frame,
bool  skip_void_and_stl_frames 
)

Definition at line 24 of file StackTrace.cpp.

References to_string().

26  {
27  std::string stack_trace;
28 
29  uint32_t frame_skip_count = num_frames_to_skip;
30 
31  // get the entire stacktrace
32  auto st = boost::stacktrace::stacktrace();
33 
34  // process frames
35  for (auto& frame : st) {
36  // skip frame?
37  if (frame_skip_count > 0) {
38  frame_skip_count--;
39  continue;
40  }
41 
42  // get function name for this frame
43  std::string frame_string = frame.name();
44 
45  // trim to plain function or template name
46  size_t open_paren_or_angle = frame_string.find_first_of("(<");
47  if (open_paren_or_angle != std::string::npos) {
48  frame_string.erase(open_paren_or_angle, std::string::npos);
49  }
50 
51  // skip stuff that we usually don't want
52  if (skip_void_and_stl_frames) {
53  if (boost::istarts_with(frame_string, "void")) {
54  continue;
55  }
56  if (boost::istarts_with(frame_string, "std::")) {
57  continue;
58  }
59  }
60 
61  // stop when we hit a particular function?
62  if (stop_at_this_frame) {
63  if (boost::starts_with(frame_string, stop_at_this_frame)) {
64  break;
65  }
66  }
67 
68  // stop at main anyway
69  if (boost::starts_with(frame_string, "main")) {
70  break;
71  }
72 
73  // add file and line? (if we can get them)
74  if (frame.source_file().size()) {
75  frame_string +=
76  " (" + frame.source_file() + ":" + std::to_string(frame.source_line()) + ")";
77  }
78 
79  // add to string
80  stack_trace += frame_string + std::string("\n");
81  }
82 
83  // done
84  return stack_trace;
85 }
std::string to_string(char const *&&v)

+ Here is the call graph for this function: