20 #include <backtrace.h>
66 int depth = ::backtrace(addresses,
kMaxDepth);
67 char** symbols = ::backtrace_symbols(addresses, depth);
68 for (
int i = 1; i < depth; ++i) {
78 std::stringstream message;
79 message <<
"libbacktrace failed to create state. msg=" << msg <<
", err=" <<
os_error(errnum);
84 std::stringstream message;
85 std::cerr <<
"libbacktrace failed to obtain backtrace. msg=" << msg
94 const char *
function) {
95 if (pc == -1ULL && filename ==
nullptr &&
function ==
nullptr) {
111 std::vector<std::string>
get_results(uint16_t skip);
118 if (data ==
nullptr) {
119 std::cerr <<
"[FOEDUS] wtf. libbt_create_state_error received null" << std::endl;
121 reinterpret_cast<BacktraceContext*
>(data)->on_libbt_create_state_error(msg, errnum);
125 if (data ==
nullptr) {
126 std::cerr <<
"[FOEDUS] wtf. libbt_full_error received null" << std::endl;
128 reinterpret_cast<BacktraceContext*
>(data)->on_libbt_full_error(msg, errnum);
131 int libbt_full(
void* data, uintptr_t pc,
const char *filename,
int lineno,
const char *
function) {
132 if (data ==
nullptr) {
133 std::cerr <<
"[FOEDUS] wtf. libbt_full received null" << std::endl;
136 reinterpret_cast<BacktraceContext*
>(data)->on_libbt_full(pc, filename, lineno,
function);
146 std::size_t pos =
symbol_.find(
"(");
147 std::size_t pos2 =
symbol_.find(
")");
148 if (pos == std::string::npos || pos2 == std::string::npos || pos >= pos2) {
153 if (pos2 == pos + 1) {
154 }
else if (
symbol_[pos + 1] ==
'+') {
157 std::size_t plus =
symbol_.find(
"+", pos);
158 if (plus == std::string::npos || plus > pos2) {
160 std::string mangled =
symbol_.substr(pos + 1, plus - pos - 1);
218 std::vector< std::string > ret;
226 std::stringstream str;
230 std::string
function;
231 if (has_libbt && !
libbt_info_[i].function_.empty()) {
251 str <<
" (libbacktrace:";
258 ret.emplace_back(str.str());
268 backtrace_state* state = ::backtrace_create_state(
274 int full_result = ::backtrace_full(
280 if (full_result != 0) {
282 std::cerr <<
"[FOEDUS] libbacktrace backtrace_full failed: " << full_result << std::endl;
void libbt_full_error(void *data, const char *msg, int errnum)
void on_libbt_full(uintptr_t pc, const char *filename, int lineno, const char *function)
int libbt_full(void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
void libbt_create_state_error(void *data, const char *msg, int errnum)
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
std::vector< std::string > get_backtrace(bool rich=true)
Returns the backtrace information of the current stack.
std::string function_offset_
std::vector< GlibcBacktraceInfo > glibc_bt_info_
void call_glibc_backtrace()
std::string os_error()
Thread-safe strerror(errno).
std::string demangle_type_name(const char *mangled_name)
Demangle the given C++ type name if possible (otherwise the original string).
Convenient way of writing hex integers to stream.
void on_libbt_full_error(const char *msg, int errnum)
std::vector< std::string > get_results(uint16_t skip)
std::vector< LibBacktraceInfo > libbt_info_
void on_libbt_create_state_error(const char *msg, int errnum)