OmniSciDB  04ee39c94c
StackTrace.h File Reference
#include <string>
+ Include dependency graph for StackTrace.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string getCurrentStackTrace (uint32_t num_frames_to_skip=1, const char *stop_at_this_frame=nullptr, bool skip_void_and_stl_frames=true)
 

Function Documentation

◆ getCurrentStackTrace()

std::string getCurrentStackTrace ( uint32_t  num_frames_to_skip = 1,
const char *  stop_at_this_frame = nullptr,
bool  skip_void_and_stl_frames = true 
)

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: