mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 22:45:59 +01:00
internal: move backtrace to specific func
This commit is contained in:
parent
901236a535
commit
60b548296d
3 changed files with 48 additions and 30 deletions
|
@ -79,12 +79,7 @@ void CrashReporter::createAndSaveCrash(int sig) {
|
||||||
|
|
||||||
finalCrashReport += "Backtrace:\n";
|
finalCrashReport += "Backtrace:\n";
|
||||||
|
|
||||||
void* bt[1024];
|
const auto CALLSTACK = getBacktrace();
|
||||||
size_t btSize;
|
|
||||||
char** btSymbols;
|
|
||||||
|
|
||||||
btSize = backtrace(bt, 1024);
|
|
||||||
btSymbols = backtrace_symbols(bt, btSize);
|
|
||||||
|
|
||||||
#if defined(KERN_PROC_PATHNAME)
|
#if defined(KERN_PROC_PATHNAME)
|
||||||
int mib[] = {
|
int mib[] = {
|
||||||
|
@ -111,20 +106,18 @@ void CrashReporter::createAndSaveCrash(int sig) {
|
||||||
const auto FPATH = std::filesystem::canonical("/proc/self/exe");
|
const auto FPATH = std::filesystem::canonical("/proc/self/exe");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < btSize; ++i) {
|
for (size_t i = 0; i < CALLSTACK.size(); ++i) {
|
||||||
finalCrashReport += getFormat("\t#%lu | %s\n", i, btSymbols[i]);
|
finalCrashReport += getFormat("\t#%lu | %s\n", i, CALLSTACK[i].desc.c_str());
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
const auto CMD = getFormat("llvm-addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)bt[i]);
|
const auto CMD = getFormat("llvm-addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
|
||||||
#else
|
#else
|
||||||
const auto CMD = getFormat("addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)bt[i]);
|
const auto CMD = getFormat("addr2line -e %s -f 0x%lx", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
|
||||||
#endif
|
#endif
|
||||||
const auto ADDR2LINE = replaceInString(execAndGet(CMD.c_str()), "\n", "\n\t\t");
|
const auto ADDR2LINE = replaceInString(execAndGet(CMD.c_str()), "\n", "\n\t\t");
|
||||||
finalCrashReport += "\t\t" + ADDR2LINE.substr(0, ADDR2LINE.length() - 2);
|
finalCrashReport += "\t\t" + ADDR2LINE.substr(0, ADDR2LINE.length() - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(btSymbols);
|
|
||||||
|
|
||||||
finalCrashReport += "\n\nLog tail:\n";
|
finalCrashReport += "\n\nLog tail:\n";
|
||||||
|
|
||||||
finalCrashReport += execAndGet(("cat \"" + Debug::logFile + "\" | tail -n 50").c_str());
|
finalCrashReport += execAndGet(("cat \"" + Debug::logFile + "\" | tail -n 50").c_str());
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <execinfo.h>
|
||||||
|
|
||||||
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
@ -696,3 +697,20 @@ std::string replaceInString(std::string subject, const std::string& search, cons
|
||||||
}
|
}
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<SCallstackFrameInfo> getBacktrace() {
|
||||||
|
std::vector<SCallstackFrameInfo> callstack;
|
||||||
|
|
||||||
|
void* bt[1024];
|
||||||
|
size_t btSize;
|
||||||
|
char** btSymbols;
|
||||||
|
|
||||||
|
btSize = backtrace(bt, 1024);
|
||||||
|
btSymbols = backtrace_symbols(bt, btSize);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < btSize; ++i) {
|
||||||
|
callstack.emplace_back(SCallstackFrameInfo{bt[i], std::string{btSymbols[i]}});
|
||||||
|
}
|
||||||
|
|
||||||
|
return callstack;
|
||||||
|
}
|
||||||
|
|
|
@ -4,22 +4,29 @@
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/util/box.h>
|
#include <wlr/util/box.h>
|
||||||
#include "Vector2D.hpp"
|
#include "Vector2D.hpp"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
std::string absolutePath(const std::string&, const std::string&);
|
struct SCallstackFrameInfo {
|
||||||
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
|
void* adr = nullptr;
|
||||||
std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
|
std::string desc;
|
||||||
std::string escapeJSONStrings(const std::string& str);
|
};
|
||||||
void scaleBox(wlr_box*, float);
|
|
||||||
std::string removeBeginEndSpacesTabs(std::string);
|
std::string absolutePath(const std::string&, const std::string&);
|
||||||
bool isNumber(const std::string&, bool allowfloat = false);
|
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
|
||||||
bool isDirection(const std::string&);
|
std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
|
||||||
int getWorkspaceIDFromString(const std::string&, std::string&);
|
std::string escapeJSONStrings(const std::string& str);
|
||||||
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
|
void scaleBox(wlr_box*, float);
|
||||||
void logSystemInfo();
|
std::string removeBeginEndSpacesTabs(std::string);
|
||||||
std::string execAndGet(const char*);
|
bool isNumber(const std::string&, bool allowfloat = false);
|
||||||
int64_t getPPIDof(int64_t pid);
|
bool isDirection(const std::string&);
|
||||||
int64_t configStringToInt(const std::string&);
|
int getWorkspaceIDFromString(const std::string&, std::string&);
|
||||||
float getPlusMinusKeywordResult(std::string in, float relative);
|
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
|
||||||
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
|
void logSystemInfo();
|
||||||
double normalizeAngleRad(double ang);
|
std::string execAndGet(const char*);
|
||||||
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
|
int64_t getPPIDof(int64_t pid);
|
||||||
|
int64_t configStringToInt(const std::string&);
|
||||||
|
float getPlusMinusKeywordResult(std::string in, float relative);
|
||||||
|
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
|
||||||
|
double normalizeAngleRad(double ang);
|
||||||
|
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
|
||||||
|
std::vector<SCallstackFrameInfo> getBacktrace();
|
Loading…
Reference in a new issue