1
0
mirror of synced 2024-09-27 04:58:26 +02:00

sys: Trigger breakpoint in debug mode when a signal is raised

This commit is contained in:
WerWolv 2022-01-11 20:28:57 +01:00
parent b9034523b5
commit 1b853c6a84
2 changed files with 17 additions and 2 deletions

View File

@ -319,10 +319,14 @@
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * 6);
#if defined(DEBUG)
if (ImGui::TitleBarButton(ICON_VS_DEBUG, buttonSize)) {
if (ImGui::GetIO().KeyCtrl && ImGui::GetIO().KeyShift) {
if (ImGui::GetIO().KeyCtrl) {
// Explicitly trigger a segfault by writing to an invalid memory location
// Used for debugging crashes
*reinterpret_cast<u8*>(0x10) = 0x10;
} else if (ImGui::GetIO().KeyShift) {
// Explicitly trigger an abort by throwing an uncaught exception
// Used for debugging exception errors
throw std::runtime_error("Debug Error");
} else {
hex::openWebpage("https://imhex.werwolv.net/debug");
}

View File

@ -12,6 +12,7 @@
#include <iostream>
#include <numeric>
#include <thread>
#include <assert.h>
#include <romfs/romfs.hpp>
@ -259,9 +260,19 @@ namespace hex {
auto signalHandler = [](int signalNumber) {
EventManager::post<EventAbnormalTermination>(signalNumber);
if (std::uncaught_exceptions() > 0) {
log::fatal("Uncaught exception thrown!");
}
// Let's not loop on this...
std::signal(signalNumber, nullptr);
std::raise(signalNumber);
#if defined(DEBUG)
assert(false);
#else
std::raise(signalNumber);
#endif
};
std::signal(SIGTERM, signalHandler);