summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2023-08-11 17:22:16 +0200
committervaxerski <vaxry@vaxry.net>2023-08-11 17:22:19 +0200
commit60b548296d9465c77a3f96f01305df5b83084903 (patch)
treecbd98a010b7a63b41c7533ed5009f6f3e70f16e9 /src
parent901236a5356a3f249af7d55e5db69889e50256b8 (diff)
internal: move backtrace to specific func
Diffstat (limited to 'src')
-rw-r--r--src/debug/CrashReporter.cpp17
-rw-r--r--src/helpers/MiscFunctions.cpp18
-rw-r--r--src/helpers/MiscFunctions.hpp43
3 files changed, 48 insertions, 30 deletions
diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp
index 57271f99..a580ecd8 100644
--- a/src/debug/CrashReporter.cpp
+++ b/src/debug/CrashReporter.cpp
@@ -79,12 +79,7 @@ void CrashReporter::createAndSaveCrash(int sig) {
finalCrashReport += "Backtrace:\n";
- void* bt[1024];
- size_t btSize;
- char** btSymbols;
-
- btSize = backtrace(bt, 1024);
- btSymbols = backtrace_symbols(bt, btSize);
+ const auto CALLSTACK = getBacktrace();
#if defined(KERN_PROC_PATHNAME)
int mib[] = {
@@ -111,20 +106,18 @@ void CrashReporter::createAndSaveCrash(int sig) {
const auto FPATH = std::filesystem::canonical("/proc/self/exe");
#endif
- for (size_t i = 0; i < btSize; ++i) {
- finalCrashReport += getFormat("\t#%lu | %s\n", i, btSymbols[i]);
+ for (size_t i = 0; i < CALLSTACK.size(); ++i) {
+ finalCrashReport += getFormat("\t#%lu | %s\n", i, CALLSTACK[i].desc.c_str());
#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
- 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
const auto ADDR2LINE = replaceInString(execAndGet(CMD.c_str()), "\n", "\n\t\t");
finalCrashReport += "\t\t" + ADDR2LINE.substr(0, ADDR2LINE.length() - 2);
}
- free(btSymbols);
-
finalCrashReport += "\n\nLog tail:\n";
finalCrashReport += execAndGet(("cat \"" + Debug::logFile + "\" | tail -n 50").c_str());
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index d18c8f47..acda2abd 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -6,6 +6,7 @@
#include <sys/utsname.h>
#include <iomanip>
#include <sstream>
+#include <execinfo.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
@@ -696,3 +697,20 @@ std::string replaceInString(std::string subject, const std::string& search, cons
}
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;
+}
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 90ac6d78..c9e1f1b3 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -4,22 +4,29 @@
#include <wayland-server.h>
#include <wlr/util/box.h>
#include "Vector2D.hpp"
+#include <vector>
-std::string absolutePath(const std::string&, const std::string&);
-void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
-std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
-std::string escapeJSONStrings(const std::string& str);
-void scaleBox(wlr_box*, float);
-std::string removeBeginEndSpacesTabs(std::string);
-bool isNumber(const std::string&, bool allowfloat = false);
-bool isDirection(const std::string&);
-int getWorkspaceIDFromString(const std::string&, std::string&);
-float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
-void logSystemInfo();
-std::string execAndGet(const char*);
-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); \ No newline at end of file
+struct SCallstackFrameInfo {
+ void* adr = nullptr;
+ std::string desc;
+};
+
+std::string absolutePath(const std::string&, const std::string&);
+void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
+std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
+std::string escapeJSONStrings(const std::string& str);
+void scaleBox(wlr_box*, float);
+std::string removeBeginEndSpacesTabs(std::string);
+bool isNumber(const std::string&, bool allowfloat = false);
+bool isDirection(const std::string&);
+int getWorkspaceIDFromString(const std::string&, std::string&);
+float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
+void logSystemInfo();
+std::string execAndGet(const char*);
+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(); \ No newline at end of file