mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
Add basic stacktrace output for posix debug builds. (#2749)
This commit is contained in:
parent
382fa86af8
commit
a2c8981a9e
1 changed files with 36 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue