fix: Fixes for previous PR merge

This commit is contained in:
WerWolv
2025-08-09 19:53:22 +02:00
parent ae8a12fa27
commit f3d9f224b7
2 changed files with 28 additions and 21 deletions

View File

@@ -28,11 +28,18 @@ namespace hex::trace {
#include <filesystem>
#include <dlfcn.h>
#include <fmt/format.h>
#endif
namespace hex::trace {
static std::string toUTF8String(const auto &value) {
auto result = value.generic_u8string();
return { result.begin(), result.end() };
}
void initialize() {
}
@@ -44,31 +51,31 @@ namespace hex::trace {
for (const auto &entry : stackTrace) {
if (entry.source_line() == 0 && entry.source_file().empty()) {
#if __has_include(<dlfcn.h>)
Dl_info info = {};
dladdr(reinterpret_cast<const void*>(entry.native_handle()), &info);
#if __has_include(<dlfcn.h>)
Dl_info info = {};
dladdr(reinterpret_cast<const void*>(entry.native_handle()), &info);
std::string description;
std::string description;
auto path = info.dli_fname != nullptr ? std::optional<std::filesystem::path>{info.dli_fname} : std::nullopt;
auto filePath = path ? path->string() : "??";
auto fileName = path ? path->filename().string() : "";
auto path = info.dli_fname != nullptr ? std::optional<std::filesystem::path>{info.dli_fname} : std::nullopt;
auto filePath = path ? toUTF8String(*path) : "??";
auto fileName = path ? toUTF8String(path->filename()) : "";
if (info.dli_sname != nullptr) {
description = tryDemangle(info.dli_sname);
if (info.dli_saddr != reinterpret_cast<const void*>(entry.native_handle())) {
auto symOffset = entry.native_handle() - reinterpret_cast<uintptr_t>(info.dli_saddr);
description += std::format("+0x{:x}", symOffset);
if (info.dli_sname != nullptr) {
description = demangle(info.dli_sname);
if (info.dli_saddr != reinterpret_cast<const void*>(entry.native_handle())) {
auto symOffset = entry.native_handle() - reinterpret_cast<uintptr_t>(info.dli_saddr);
description += fmt::format("+0x{:x}", symOffset);
}
} else {
auto rvaOffset = entry.native_handle() - reinterpret_cast<uintptr_t>(info.dli_fbase);
description = fmt::format("{}+0x{:08x}", fileName, rvaOffset);
}
} else {
auto rvaOffset = entry.native_handle() - reinterpret_cast<uintptr_t>(info.dli_fbase);
description = std::format("{}+0x{:08x}", fileName, rvaOffset);
}
result.emplace_back(filePath, description, 0);
#else
result.emplace_back("", "??", 0);
#endif
result.emplace_back(filePath, description, 0);
#else
result.emplace_back("", "??", 0);
#endif
} else {
result.emplace_back(entry.source_file(), entry.description(), entry.source_line());
}