Linux: Print demangled symbols on backtrace (#312)

This commit is contained in:
goeiecool9999 2022-10-10 02:35:04 +02:00 committed by GitHub
parent 0c9fb3143f
commit 431c5a101f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 6 deletions

View file

@ -35,6 +35,10 @@ elseif(UNIX)
add_compile_options(-Wno-ambiguous-reversed-operator)
endif()
if(NOT APPLE)
add_link_options(-rdynamic)
endif()
add_compile_options(-Wno-multichar -Wno-invalid-offsetof -Wno-switch -Wno-ignored-attributes -Wno-deprecated-enum-enum-conversion)
endif()

View file

@ -15,9 +15,9 @@ extern bool g_vulkan_available;
#endif
#ifdef VKFUNC_DEFINE
#define VKFUNC(__FUNC__) PFN_##__FUNC__ __FUNC__ = nullptr
#define VKFUNC_INSTANCE(__FUNC__) PFN_##__FUNC__ __FUNC__ = nullptr
#define VKFUNC_DEVICE(__FUNC__) PFN_##__FUNC__ __FUNC__ = nullptr
#define VKFUNC(__FUNC__) NOEXPORT PFN_##__FUNC__ __FUNC__ = nullptr
#define VKFUNC_INSTANCE(__FUNC__) NOEXPORT PFN_##__FUNC__ __FUNC__ = nullptr
#define VKFUNC_DEVICE(__FUNC__) NOEXPORT PFN_##__FUNC__ __FUNC__ = nullptr
#else
#if defined(VKFUNC_INIT)
#if BOOST_OS_WINDOWS

View file

@ -1,9 +1,43 @@
#include <signal.h>
#include <execinfo.h>
#include <string.h>
#include <string>
#include "config/CemuConfig.h"
void demangleAndPrintBacktrace(char** backtrace, size_t size)
{
for (char** i = backtrace; i < backtrace + size; i++)
{
std::string traceLine{*i};
size_t parenthesesOpen = traceLine.find_last_of('(');
size_t parenthesesClose = traceLine.find_last_of(')');
size_t offsetPlus = traceLine.find_last_of('+');
if (!parenthesesOpen || !parenthesesClose || !offsetPlus ||
offsetPlus < parenthesesOpen || offsetPlus > parenthesesClose)
{
// something unexpected was read. fall back to default string
std::cerr << traceLine << std::endl;
continue;
}
std::string symbolName = traceLine.substr(parenthesesOpen+1,offsetPlus-parenthesesOpen-1);
int status = -1;
char* demangled = abi::__cxa_demangle(symbolName.c_str(), nullptr, nullptr, &status);
if (demangled)
{
std::cerr << traceLine.substr(0, parenthesesOpen+1);
std::cerr << demangled;
std::cerr << traceLine.substr(offsetPlus) << std::endl;
free(demangled);
}
else
{
std::cerr << traceLine << std::endl;
}
}
}
// handle signals that would dump core, print stacktrace and then dump depending on config
void handlerDumpingSignal(int sig)
{
@ -18,15 +52,26 @@ void handlerDumpingSignal(int sig)
printf("Unknown core dumping signal!\n");
}
void *array[32];
void *array[128];
size_t size;
// get void*'s for all entries on the stack
size = backtrace(array, 32);
size = backtrace(array, 128);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
char** symbol_trace = backtrace_symbols(array, size);
if (symbol_trace)
{
demangleAndPrintBacktrace(symbol_trace, size);
free(symbol_trace);
}
else
{
std::cerr << "Failed to read backtrace" << std::endl;
}
if (GetConfig().crash_dump == CrashDump::Enabled)
{

View file

@ -246,6 +246,12 @@ inline uint64 _udiv128(uint64 highDividend, uint64 lowDividend, uint64 divisor,
#error No definition for DLLEXPORT
#endif
#if BOOST_OS_WINDOWS
#define NOEXPORT
#elif defined(__GNUC__)
#define NOEXPORT __attribute__ ((visibility ("hidden")))
#endif
#ifdef __GNUC__
#include <cpuid.h>
#endif