diff options
| author | Jan Beich <jbeich@FreeBSD.org> | 2023-02-20 14:15:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-20 14:15:15 +0000 |
| commit | 474ada9267ccb98015991ee9d0d93fbb5da72034 (patch) | |
| tree | b53e9f2f16e47974e3a42d275b457d0aa9542fe4 /src/debug/CrashReporter.cpp | |
| parent | 784cdd76380b844bec286416de297daca3fbcdc7 (diff) | |
Unbreak CrashReporter on FreeBSD (#1589)
Diffstat (limited to 'src/debug/CrashReporter.cpp')
| -rw-r--r-- | src/debug/CrashReporter.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp index 6876e390..5738f180 100644 --- a/src/debug/CrashReporter.cpp +++ b/src/debug/CrashReporter.cpp @@ -4,6 +4,10 @@ #include <execinfo.h> #include <fstream> +#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) +#include <sys/sysctl.h> +#endif + std::string getRandomMessage() { const std::vector<std::string> MESSAGES = {"Sorry, didn't mean to...", @@ -47,7 +51,11 @@ void CrashReporter::createAndSaveCrash() { finalCrashReport += getFormat("\tSystem name: %s\n\tNode name: %s\n\tRelease: %s\n\tVersion: %s\n\n", unameInfo.sysname, unameInfo.nodename, unameInfo.release, unameInfo.version); +#if defined(__DragonFly__) || defined(__FreeBSD__) + const std::string GPUINFO = execAndGet("pciconf -lv | fgrep -A4 vga"); +#else const std::string GPUINFO = execAndGet("lspci -vnn | grep VGA"); +#endif finalCrashReport += "GPU:\n\t" + GPUINFO; @@ -61,12 +69,40 @@ void CrashReporter::createAndSaveCrash() { btSize = backtrace(bt, 1024); btSymbols = backtrace_symbols(bt, btSize); + +#if defined(KERN_PROC_PATHNAME) + int mib[] = { + CTL_KERN, +#if defined(__NetBSD__) + KERN_PROC_ARGS, + -1, + KERN_PROC_PATHNAME, +#else + KERN_PROC, + KERN_PROC_PATHNAME, + -1, +#endif + }; + u_int miblen = sizeof(mib) / sizeof(mib[0]); + char exe[PATH_MAX] = ""; + size_t sz = sizeof(exe); + sysctl(mib, miblen, &exe, &sz, NULL, 0); + const auto FPATH = std::filesystem::canonical(exe); +#elif defined(__OpenBSD__) + // Neither KERN_PROC_PATHNAME nor /proc are supported + const auto FPATH = std::filesystem::canonical("/usr/local/bin/Hyprland"); +#else const auto FPATH = std::filesystem::canonical("/proc/self/exe"); +#endif for (size_t i = 0; i < btSize; ++i) { finalCrashReport += getFormat("\t#%i | %s\n", i, btSymbols[i]); +#ifdef __clang__ + const auto CMD = getFormat("llvm-addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)bt[i]); +#else const auto CMD = getFormat("addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)bt[i]); +#endif const auto ADDR2LINE = replaceInString(execAndGet(CMD.c_str()), "\n", "\n\t\t"); finalCrashReport += "\t\t" + ADDR2LINE.substr(0, ADDR2LINE.length() - 2); } |
