build: Fix build on systems that have no backtrace or execinfo
Fixes #932
This commit is contained in:
parent
4b451fd1d3
commit
61ce88ba9b
@ -94,75 +94,82 @@
|
||||
|
||||
}
|
||||
|
||||
#elif defined(HEX_HAS_EXECINFO) && __has_include(BACKTRACE_HEADER)
|
||||
#elif defined(HEX_HAS_EXECINFO)
|
||||
|
||||
#include BACKTRACE_HEADER
|
||||
#include <llvm/Demangle/Demangle.h>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#if __has_include(BACKTRACE_HEADER)
|
||||
|
||||
namespace hex::stacktrace {
|
||||
#include BACKTRACE_HEADER
|
||||
#include <llvm/Demangle/Demangle.h>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
void initialize() {
|
||||
namespace hex::stacktrace {
|
||||
|
||||
}
|
||||
|
||||
std::vector<StackFrame> getStackTrace() {
|
||||
static std::vector<StackFrame> result;
|
||||
|
||||
std::array<void*, 128> addresses;
|
||||
auto count = backtrace(addresses.data(), addresses.size());
|
||||
auto functions = backtrace_symbols(addresses.data(), count);
|
||||
|
||||
for (i32 i = 0; i < count; i++)
|
||||
result.push_back(StackFrame { "", functions[i], 0 });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#elif defined(HEX_HAS_BACKTRACE) && __has_include(BACKTRACE_HEADER)
|
||||
|
||||
#include BACKTRACE_HEADER
|
||||
#include <llvm/Demangle/Demangle.h>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
namespace hex::stacktrace {
|
||||
|
||||
static struct backtrace_state *s_backtraceState;
|
||||
|
||||
|
||||
void initialize() {
|
||||
if (auto executablePath = fs::getExecutablePath(); executablePath.has_value()) {
|
||||
static std::string path = executablePath->string();
|
||||
s_backtraceState = backtrace_create_state(path.c_str(), 1, [](void *, const char *msg, int) { log::error("{}", msg); }, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<StackFrame> getStackTrace() {
|
||||
static std::vector<StackFrame> result;
|
||||
|
||||
result.clear();
|
||||
if (s_backtraceState != nullptr) {
|
||||
backtrace_full(s_backtraceState, 0, [](void *, uintptr_t, const char *fileName, int lineNumber, const char *function) -> int {
|
||||
if (fileName == nullptr)
|
||||
fileName = "??";
|
||||
if (function == nullptr)
|
||||
function = "??";
|
||||
|
||||
result.push_back(StackFrame { std::fs::path(fileName).filename().string(), llvm::demangle(function), u32(lineNumber) });
|
||||
|
||||
return 0;
|
||||
}, nullptr, nullptr);
|
||||
void initialize() {
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
std::vector<StackFrame> getStackTrace() {
|
||||
static std::vector<StackFrame> result;
|
||||
|
||||
std::array<void*, 128> addresses;
|
||||
auto count = backtrace(addresses.data(), addresses.size());
|
||||
auto functions = backtrace_symbols(addresses.data(), count);
|
||||
|
||||
for (i32 i = 0; i < count; i++)
|
||||
result.push_back(StackFrame { "", functions[i], 0 });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(HEX_HAS_BACKTRACE)
|
||||
|
||||
#if __has_include(BACKTRACE_HEADER)
|
||||
|
||||
#include BACKTRACE_HEADER
|
||||
#include <llvm/Demangle/Demangle.h>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
namespace hex::stacktrace {
|
||||
|
||||
static struct backtrace_state *s_backtraceState;
|
||||
|
||||
|
||||
void initialize() {
|
||||
if (auto executablePath = fs::getExecutablePath(); executablePath.has_value()) {
|
||||
static std::string path = executablePath->string();
|
||||
s_backtraceState = backtrace_create_state(path.c_str(), 1, [](void *, const char *msg, int) { log::error("{}", msg); }, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<StackFrame> getStackTrace() {
|
||||
static std::vector<StackFrame> result;
|
||||
|
||||
result.clear();
|
||||
if (s_backtraceState != nullptr) {
|
||||
backtrace_full(s_backtraceState, 0, [](void *, uintptr_t, const char *fileName, int lineNumber, const char *function) -> int {
|
||||
if (fileName == nullptr)
|
||||
fileName = "??";
|
||||
if (function == nullptr)
|
||||
function = "??";
|
||||
|
||||
result.push_back(StackFrame { std::fs::path(fileName).filename().string(), llvm::demangle(function), u32(lineNumber) });
|
||||
|
||||
return 0;
|
||||
}, nullptr, nullptr);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user