diff options
author | Jan Beich <[email protected]> | 2023-02-20 14:15:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-02-20 14:15:15 +0000 |
commit | 474ada9267ccb98015991ee9d0d93fbb5da72034 (patch) | |
tree | b53e9f2f16e47974e3a42d275b457d0aa9542fe4 | |
parent | 784cdd76380b844bec286416de297daca3fbcdc7 (diff) | |
download | Hyprland-474ada9267ccb98015991ee9d0d93fbb5da72034.tar.gz Hyprland-474ada9267ccb98015991ee9d0d93fbb5da72034.zip |
Unbreak CrashReporter on FreeBSD (#1589)
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/debug/CrashReporter.cpp | 36 | ||||
-rw-r--r-- | src/helpers/MiscFunctions.cpp | 4 | ||||
-rw-r--r-- | src/helpers/Vector2D.cpp | 1 | ||||
-rw-r--r-- | src/meson.build | 1 |
6 files changed, 49 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 065f5894..b59b455e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,12 @@ file(GLOB_RECURSE SRCFILES "src/*.cpp") add_executable(Hyprland ${SRCFILES}) +include(CheckLibraryExists) +check_library_exists(execinfo backtrace "" HAVE_LIBEXECINFO) +if(HAVE_LIBEXECINFO) + target_link_libraries(Hyprland PRIVATE execinfo) +endif() + IF(LEGACY_RENDERER MATCHES true) message(STATUS "Using the legacy GLES2 renderer!") add_definitions( -DLEGACY_RENDERER ) diff --git a/meson.build b/meson.build index c2f80adc..0ae3d518 100644 --- a/meson.build +++ b/meson.build @@ -52,6 +52,7 @@ if not have_xwayland add_project_arguments('-DNO_XWAYLAND', language: 'cpp') endif +backtrace_dep = cpp_compiler.find_library('execinfo', required: false) systemd_dep = dependency('libsystemd', required: get_option('systemd')) if get_option('systemd').enabled() 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); } diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index dcc1efbd..10d59316 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -412,7 +412,11 @@ void logSystemInfo() { Debug::log(NONE, "\n"); +#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 Debug::log(LOG, "GPU information:\n%s\n", GPUINFO.c_str()); if (GPUINFO.contains("NVIDIA")) { diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp index 3ab3ce43..afd8b22a 100644 --- a/src/helpers/Vector2D.cpp +++ b/src/helpers/Vector2D.cpp @@ -1,5 +1,6 @@ #include "Vector2D.hpp" #include <algorithm> +#include <cmath> Vector2D::Vector2D(double xx, double yy) { x = xx; diff --git a/src/meson.build b/src/meson.build index d7b1ec22..6c018e12 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,7 @@ executable('Hyprland', src, dependency('xkbcommon'), dependency('libinput'), xcb_dep, + backtrace_dep, systemd_dep, dependency('pixman-1'), |