OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StackTrace.cpp File Reference
#include <Shared/StackTrace.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 25 of file StackTrace.cpp.

References to_string().

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

+ Here is the call graph for this function: