From dd76ba2fe13e086a8891ff43d9d1c7e63275f726 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 20 Nov 2021 13:34:47 +0200 Subject: [PATCH] CrashReporter: Add "Inspect in Hack Studio" button This allows the user to open the crash coredump in Hack Studio and inspect it in the Debug tab. --- .../CrashReporter/CrashReporterWindow.gml | 7 ++++++ Userland/Applications/CrashReporter/main.cpp | 24 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/CrashReporter/CrashReporterWindow.gml b/Userland/Applications/CrashReporter/CrashReporterWindow.gml index 5bf6d547f6..8ebb958222 100644 --- a/Userland/Applications/CrashReporter/CrashReporterWindow.gml +++ b/Userland/Applications/CrashReporter/CrashReporterWindow.gml @@ -82,6 +82,13 @@ layout: @GUI::HorizontalBoxLayout + @GUI::Button { + name: "inspect_button" + text: "Inspect in Hack Studio" + fixed_width: 150 + fixed_height: 22 + } + // HACK: We need something like Layout::add_spacer() in GML! :^) @GUI::Widget diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index 97f98102a2..e1aeee7e64 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -164,7 +166,7 @@ static void unlink_coredump(StringView const& coredump_path) int main(int argc, char** argv) { - if (pledge("stdio recvfd sendfd cpath rpath unix", nullptr) < 0) { + if (pledge("stdio recvfd sendfd cpath rpath unix proc exec", nullptr) < 0) { perror("pledge"); return 1; } @@ -211,7 +213,7 @@ int main(int argc, char** argv) termination_signal = coredump->process_termination_signal(); } - if (pledge("stdio recvfd sendfd rpath unix cpath", nullptr) < 0) { + if (pledge("stdio recvfd sendfd rpath unix cpath proc exec", nullptr) < 0) { perror("pledge"); return 1; } @@ -238,6 +240,11 @@ int main(int argc, char** argv) } } + if (unveil("/bin/HackStudio", "rx") < 0) { + perror("unveil"); + return 1; + } + if (unveil(nullptr, nullptr) < 0) { perror("unveil"); return 1; @@ -344,6 +351,19 @@ int main(int argc, char** argv) app->quit(); }; + auto& inspect_button = *widget.find_descendant_of_type_named("inspect_button"); + inspect_button.set_icon(MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png"))); + inspect_button.on_click = [&](int) { + pid_t child; + const char* argv[4] = { "HackStudio", "-c", coredump_path, nullptr }; + if ((errno = posix_spawn(&child, "/bin/HackStudio", nullptr, nullptr, const_cast(argv), environ))) { + perror("posix_spawn"); + } else { + if (disown(child) < 0) + perror("disown"); + } + }; + window->show(); return app->exec();