use .txt for crash reports

This commit is contained in:
Vaxry 2023-03-01 09:32:31 +00:00
parent 50a4a74b4e
commit 0905515c40
2 changed files with 28 additions and 29 deletions

View file

@ -59,7 +59,7 @@ coredumpctl info [PID]
where `[PID]` is the PID you remembered. where `[PID]` is the PID you remembered.
## Obtaining the Hyprland Crash Report (v0.22.0beta and up) ## Obtaining the Hyprland Crash Report (v0.22.0beta and up)
Go to `~/.hyprland/` and you should find a file named `.hyprlandCrashReport[XXXX]` where `[XXXX]` is the PID of the process that crashed. Go to `~/.hyprland/` and you should find a file named `hyprlandCrashReport[XXXX].txt` where `[XXXX]` is the PID of the process that crashed.
If you do not see it, make sure you have "show hidden files" enabled in your file manager. If you do not see it, make sure you have "show hidden files" enabled in your file manager.

View file

@ -10,22 +10,21 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
std::string getRandomMessage() { std::string getRandomMessage() {
const std::vector<std::string> MESSAGES = {"Sorry, didn't mean to...", const std::vector<std::string> MESSAGES = {"Sorry, didn't mean to...",
"This was an accident, I swear!", "This was an accident, I swear!",
"Calm down, it was a misinput! MISINPUT!", "Calm down, it was a misinput! MISINPUT!",
"Oops", "Oops",
"Vaxry is going to be upset.", "Vaxry is going to be upset.",
"Who tried dividing by zero?!", "Who tried dividing by zero?!",
"Maybe you should try dusting your PC in the meantime?", "Maybe you should try dusting your PC in the meantime?",
"I tried so hard, and got so far...", "I tried so hard, and got so far...",
"I don't feel so good...", "I don't feel so good...",
"*thud*", "*thud*",
"Well this is awkward.", "Well this is awkward.",
"\"stable\"", "\"stable\"",
"I hope you didn't have any unsaved progress."}; "I hope you didn't have any unsaved progress."};
std::random_device dev; std::random_device dev;
std::mt19937 engine(dev()); std::mt19937 engine(dev());
@ -80,25 +79,25 @@ void CrashReporter::createAndSaveCrash() {
size_t btSize; size_t btSize;
char** btSymbols; char** btSymbols;
btSize = backtrace(bt, 1024); btSize = backtrace(bt, 1024);
btSymbols = backtrace_symbols(bt, btSize); btSymbols = backtrace_symbols(bt, btSize);
#if defined(KERN_PROC_PATHNAME) #if defined(KERN_PROC_PATHNAME)
int mib[] = { int mib[] = {
CTL_KERN, CTL_KERN,
#if defined(__NetBSD__) #if defined(__NetBSD__)
KERN_PROC_ARGS, KERN_PROC_ARGS,
-1, -1,
KERN_PROC_PATHNAME, KERN_PROC_PATHNAME,
#else #else
KERN_PROC, KERN_PROC,
KERN_PROC_PATHNAME, KERN_PROC_PATHNAME,
-1, -1,
#endif #endif
}; };
u_int miblen = sizeof(mib) / sizeof(mib[0]); u_int miblen = sizeof(mib) / sizeof(mib[0]);
char exe[PATH_MAX] = ""; char exe[PATH_MAX] = "";
size_t sz = sizeof(exe); size_t sz = sizeof(exe);
sysctl(mib, miblen, &exe, &sz, NULL, 0); sysctl(mib, miblen, &exe, &sz, NULL, 0);
const auto FPATH = std::filesystem::canonical(exe); const auto FPATH = std::filesystem::canonical(exe);
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
@ -112,9 +111,9 @@ void CrashReporter::createAndSaveCrash() {
finalCrashReport += getFormat("\t#%i | %s\n", i, btSymbols[i]); finalCrashReport += getFormat("\t#%i | %s\n", i, btSymbols[i]);
#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)bt[i]);
#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)bt[i]);
#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);
@ -132,7 +131,7 @@ void CrashReporter::createAndSaveCrash() {
std::filesystem::permissions(std::string(HOME) + "/.hyprland", std::filesystem::perms::all, std::filesystem::perm_options::replace); std::filesystem::permissions(std::string(HOME) + "/.hyprland", std::filesystem::perms::all, std::filesystem::perm_options::replace);
} }
std::ofstream ofs(std::string(HOME) + "/.hyprland/.hyprlandCrashReport" + std::to_string(PID), std::ios::trunc); std::ofstream ofs(std::string(HOME) + "/.hyprland/hyprlandCrashReport" + std::to_string(PID) + ".txt", std::ios::trunc);
ofs << finalCrashReport; ofs << finalCrashReport;