diff --git a/stratosphere/creport/source/creport_crash_report.cpp b/stratosphere/creport/source/creport_crash_report.cpp new file mode 100644 index 000000000..88b560b77 --- /dev/null +++ b/stratosphere/creport/source/creport_crash_report.cpp @@ -0,0 +1,10 @@ +#include +#include "creport_crash_report.hpp" + +void CrashReport::BuildReport(u64 pid, bool has_extra_info) { + this->has_extra_info = has_extra_info; + if (OpenProcess(pid)) { + /* TODO: Actually generate report... */ + Close(); + } +} \ No newline at end of file diff --git a/stratosphere/creport/source/creport_crash_report.hpp b/stratosphere/creport/source/creport_crash_report.hpp new file mode 100644 index 000000000..0ae64e50c --- /dev/null +++ b/stratosphere/creport/source/creport_crash_report.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +class CrashReport { + private: + Handle debug_handle; + bool has_extra_info; + Result result; + + public: + CrashReport() : debug_handle(INVALID_HANDLE), result(0x4A2) { } + + void BuildReport(u64 pid, bool has_extra_info); + + Result GetResult() { + return this->result; + } + + bool OpenProcess(u64 pid) { + return R_SUCCEEDED(svcDebugActiveProcess(&debug_handle, pid)); + } + + void Close() { + if (debug_handle != INVALID_HANDLE) { + svcCloseHandle(debug_handle); + debug_handle = INVALID_HANDLE; + } + } +}; \ No newline at end of file diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index 7d6ea0538..094414357 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -6,6 +6,8 @@ #include +#include "creport_crash_report.hpp" + extern "C" { extern u32 __start__; @@ -74,6 +76,8 @@ static u64 creport_parse_u64(char *s) { return out_val; } +static CrashReport g_Creport; + int main(int argc, char **argv) { /* Validate arguments. */ if (argc < 2) { @@ -85,12 +89,11 @@ int main(int argc, char **argv) { } } - /* Parse arguments. */ + /* Parse crashed PID. */ u64 crashed_pid = creport_parse_u64(argv[0]); - bool has_extra_info = argv[1][0] == '1'; - /* TODO: Generate report. */ - (void)(has_extra_info); + /* Try to debug the crashed process. */ + g_Creport.BuildReport(crashed_pid, argv[1][0] == '1'); if (R_SUCCEEDED(nsdevInitialize())) { nsdevTerminateProcess(crashed_pid);