libfoedus-core
FOEDUS Core Library
foedus::assorted::BacktraceContext Struct Reference

Detailed Description

Definition at line 36 of file rich_backtrace.cpp.

Collaboration diagram for foedus::assorted::BacktraceContext:

Classes

struct  GlibcBacktraceInfo
 
struct  LibBacktraceInfo
 

Public Types

enum  Constants { kMaxDepth = 64 }
 

Public Member Functions

 BacktraceContext ()
 
 ~BacktraceContext ()
 
void release ()
 
void call_glibc_backtrace ()
 
void on_libbt_create_state_error (const char *msg, int errnum)
 
void on_libbt_full_error (const char *msg, int errnum)
 
void on_libbt_full (uintptr_t pc, const char *filename, int lineno, const char *function)
 
std::vector< std::string > get_results (uint16_t skip)
 

Public Attributes

std::string error_
 
std::vector< GlibcBacktraceInfoglibc_bt_info_
 
std::vector< LibBacktraceInfolibbt_info_
 

Class Documentation

struct foedus::assorted::BacktraceContext::LibBacktraceInfo

Definition at line 48 of file rich_backtrace.cpp.

Collaboration diagram for foedus::assorted::BacktraceContext::LibBacktraceInfo:
Class Members
uintptr_t address_
string function_
string srcfile_
int srclineno_

Member Enumeration Documentation

Enumerator
kMaxDepth 

Definition at line 37 of file rich_backtrace.cpp.

Constructor & Destructor Documentation

foedus::assorted::BacktraceContext::BacktraceContext ( )
inline

Definition at line 55 of file rich_backtrace.cpp.

55 {}
foedus::assorted::BacktraceContext::~BacktraceContext ( )
inline

Definition at line 56 of file rich_backtrace.cpp.

References release().

Here is the call graph for this function:

Member Function Documentation

void foedus::assorted::BacktraceContext::call_glibc_backtrace ( )
inline

Definition at line 63 of file rich_backtrace.cpp.

References foedus::assorted::BacktraceContext::GlibcBacktraceInfo::address_, glibc_bt_info_, kMaxDepth, foedus::assorted::BacktraceContext::GlibcBacktraceInfo::parse_symbol(), release(), and foedus::assorted::BacktraceContext::GlibcBacktraceInfo::symbol_.

Referenced by foedus::assorted::get_backtrace().

63  {
64  release();
65  void* addresses[kMaxDepth];
66  int depth = ::backtrace(addresses, kMaxDepth);
67  char** symbols = ::backtrace_symbols(addresses, depth);
68  for (int i = 1; i < depth; ++i) { // start from 1 to skip this method (call_glibc_backtrace)
69  GlibcBacktraceInfo info;
70  info.address_ = addresses[i];
71  info.symbol_ = symbols[i];
72  info.parse_symbol();
73  glibc_bt_info_.emplace_back(info);
74  }
75  ::free(symbols);
76  }
std::vector< GlibcBacktraceInfo > glibc_bt_info_

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::string > foedus::assorted::BacktraceContext::get_results ( uint16_t  skip)

Definition at line 217 of file rich_backtrace.cpp.

References foedus::assorted::BacktraceContext::GlibcBacktraceInfo::address_, foedus::assorted::BacktraceContext::LibBacktraceInfo::address_, foedus::assorted::BacktraceContext::GlibcBacktraceInfo::binary_path_, foedus::assorted::demangle_type_name(), error_, foedus::assorted::BacktraceContext::GlibcBacktraceInfo::function_, foedus::assorted::BacktraceContext::LibBacktraceInfo::function_, glibc_bt_info_, libbt_info_, foedus::assorted::BacktraceContext::LibBacktraceInfo::srcfile_, foedus::assorted::BacktraceContext::LibBacktraceInfo::srclineno_, and foedus::assorted::BacktraceContext::GlibcBacktraceInfo::symbol_.

Referenced by foedus::assorted::get_backtrace().

217  {
218  std::vector< std::string > ret;
219  if (!error_.empty()) {
220  // If error happened, add it as the first entry.
221  ret.emplace_back(error_);
222  // still outputs the following as best-effort
223  }
224 
225  for (uint16_t i = skip; i < glibc_bt_info_.size(); ++i) {
226  std::stringstream str;
227  const GlibcBacktraceInfo& libc = glibc_bt_info_[i];
228  bool has_libbt = i < libbt_info_.size();
229  str << "in ";
230  std::string function;
231  if (has_libbt && !libbt_info_[i].function_.empty()) {
232  const LibBacktraceInfo& libbt = libbt_info_[i];
233  // libbacktrace successfully got the information. it can provide the most helpful info
234  str << demangle_type_name(libbt.function_.c_str())
235  << " " << libbt.srcfile_ << ":" << libbt.srclineno_
236  << " (" << libc.binary_path_ << ")"
237  << " [" << assorted::Hex(libbt.address_) << "]";
238  // also append glibc backtrace info.
239  str << " (glibc: " << assorted::Hex(reinterpret_cast<uintptr_t>(libc.address_)) << ")";
240  } else {
241  // sometimes libbacktrace fails to parse a stack even glibc can parse.. probably a bug
242  if (!libc.function_.empty()) {
243  str << demangle_type_name(libc.function_.c_str());
244  } else {
245  str << "???";
246  }
247  str << " : " << libc.symbol_;
248  if (has_libbt) {
249  // also append libbacktrace info.
250  const LibBacktraceInfo& libbt = libbt_info_[i];
251  str << " (libbacktrace:";
252  if (!libbt.srcfile_.empty() || libbt.srclineno_ != 0) {
253  str << " " << libbt.srcfile_ << ":" << libbt.srclineno_;
254  }
255  str << " [" << assorted::Hex(libbt.address_) << "]" << ")";
256  }
257  }
258  ret.emplace_back(str.str());
259  }
260  return ret;
261 }
std::vector< GlibcBacktraceInfo > glibc_bt_info_
std::string demangle_type_name(const char *mangled_name)
Demangle the given C++ type name if possible (otherwise the original string).
std::vector< LibBacktraceInfo > libbt_info_

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::assorted::BacktraceContext::on_libbt_create_state_error ( const char *  msg,
int  errnum 
)
inline

Definition at line 77 of file rich_backtrace.cpp.

References error_, and foedus::assorted::os_error().

77  {
78  std::stringstream message;
79  message << "libbacktrace failed to create state. msg=" << msg << ", err=" << os_error(errnum);
80  error_ = message.str();
81  }
std::string os_error()
Thread-safe strerror(errno).

Here is the call graph for this function:

void foedus::assorted::BacktraceContext::on_libbt_full ( uintptr_t  pc,
const char *  filename,
int  lineno,
const char *  function 
)
inline

Definition at line 90 of file rich_backtrace.cpp.

References foedus::assorted::BacktraceContext::LibBacktraceInfo::address_, foedus::assorted::BacktraceContext::LibBacktraceInfo::function_, libbt_info_, foedus::assorted::BacktraceContext::LibBacktraceInfo::srcfile_, and foedus::assorted::BacktraceContext::LibBacktraceInfo::srclineno_.

94  {
95  if (pc == -1ULL && filename == nullptr && function == nullptr) {
96  // not sure why this happens, but libbacktrace occasionally gives such a dummy entry
97  return;
98  }
99  LibBacktraceInfo info;
100  info.address_ = pc;
101  if (filename) {
102  info.srcfile_ = filename;
103  }
104  info.srclineno_ = lineno;
105  if (function) {
106  info.function_ = function;
107  }
108  libbt_info_.emplace_back(info);
109  }
std::vector< LibBacktraceInfo > libbt_info_
void foedus::assorted::BacktraceContext::on_libbt_full_error ( const char *  msg,
int  errnum 
)
inline

Definition at line 83 of file rich_backtrace.cpp.

References error_, and foedus::assorted::os_error().

83  {
84  std::stringstream message;
85  std::cerr << "libbacktrace failed to obtain backtrace. msg=" << msg
86  << ", err=" << os_error(errnum);
87  error_ = message.str();
88  }
std::string os_error()
Thread-safe strerror(errno).

Here is the call graph for this function:

void foedus::assorted::BacktraceContext::release ( )
inline

Definition at line 57 of file rich_backtrace.cpp.

References error_, glibc_bt_info_, and libbt_info_.

Referenced by call_glibc_backtrace(), and ~BacktraceContext().

57  {
58  error_.clear();
59  glibc_bt_info_.clear();
60  libbt_info_.clear();
61  }
std::vector< GlibcBacktraceInfo > glibc_bt_info_
std::vector< LibBacktraceInfo > libbt_info_

Here is the caller graph for this function:

Member Data Documentation

std::string foedus::assorted::BacktraceContext::error_
std::vector<GlibcBacktraceInfo> foedus::assorted::BacktraceContext::glibc_bt_info_

Definition at line 114 of file rich_backtrace.cpp.

Referenced by call_glibc_backtrace(), get_results(), and release().

std::vector<LibBacktraceInfo> foedus::assorted::BacktraceContext::libbt_info_

Definition at line 115 of file rich_backtrace.cpp.

Referenced by get_results(), on_libbt_full(), and release().


The documentation for this struct was generated from the following file: