Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions onnxruntime/core/platform/posix/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@

#include "core/common/common.h"

#include <execinfo.h>
#include <vector>

namespace onnxruntime {

std::vector<std::string> GetStackTrace() {
return {"<stacktrace not implemented>"};
}
std::vector<std::string> stack;

#ifndef NDEBUG
constexpr int kCallstackLimit = 64; // Maximum depth of callstack

void* array[kCallstackLimit];
char** strings = nullptr;

size_t size = backtrace(array, kCallstackLimit);
stack.reserve(size);
strings = backtrace_symbols(array, size);

// NOTE: To get meaningful info from the output, addr2line (or atos on osx) would need to be used.
// See https://gist.github.com/jvranish/4441299 for an example.
//
// To manually translate the output, use the value in the '()' after the executable name with addr2line
// e.g.
// Stacktrace:
// /home/me/src/github/onnxruntime/build/Linux/Debug/onnxruntime_test_all(+0x3f46cc) [0x559543faf6cc]
//
// >addr2line -f -C -e /home/me/src/github/onnxruntime/build/Linux/Debug/onnxruntime_test_all +0x3f46cc

// hide GetStackTrace so the output starts with the 'real' location
constexpr size_t start_frame = 1;
for (size_t i = start_frame; i < size; i++) {
stack.push_back(strings[i]);
}

free(strings);

#endif

return stack;
}
} // namespace onnxruntime