OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StackTrace.cpp File Reference
#include <Shared/StackTrace.h>
#include "Shared/StringTransform.h"
#include "Shared/boost_stacktrace.hpp"
#include <boost/algorithm/string.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 26 of file StackTrace.cpp.

References strip(), and to_string().

Referenced by logger::check_failed().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: