mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-25 11:00:18 +00:00
creport: Solidify main() logic.
This commit is contained in:
parent
851d21a276
commit
4e7fcc1a50
3 changed files with 49 additions and 7 deletions
|
@ -2,6 +2,10 @@
|
|||
#include "creport_crash_report.hpp"
|
||||
#include "creport_debug_types.hpp"
|
||||
|
||||
void CrashReport::SaveReport() {
|
||||
/* TODO: Save the report to the SD card. */
|
||||
}
|
||||
|
||||
void CrashReport::BuildReport(u64 pid, bool has_extra_info) {
|
||||
this->has_extra_info = has_extra_info;
|
||||
if (OpenProcess(pid)) {
|
||||
|
|
|
@ -4,6 +4,20 @@
|
|||
|
||||
#include "creport_debug_types.hpp"
|
||||
|
||||
enum class CrashReportResult : Result {
|
||||
UndefinedInstruction = 0x00A8,
|
||||
InstructionAbort = 0x02A8,
|
||||
DataAbort = 0x04A8,
|
||||
AlignmentFault = 0x06A8,
|
||||
DebuggerAttached = 0x08A8,
|
||||
BreakPoint = 0x0AA8,
|
||||
UserBreak = 0x0CA8,
|
||||
DebuggerBreak = 0x0EA8,
|
||||
BadSvc = 0x10A8,
|
||||
UnknownNine = 0x12A8,
|
||||
IncompleteReport = 0xC6A8,
|
||||
};
|
||||
|
||||
class CrashReport {
|
||||
private:
|
||||
Handle debug_handle;
|
||||
|
@ -16,15 +30,20 @@ class CrashReport {
|
|||
u64 userdata_5x_size;
|
||||
|
||||
public:
|
||||
CrashReport() : debug_handle(INVALID_HANDLE), result(0xC6A8), process_info({0}) { }
|
||||
CrashReport() : debug_handle(INVALID_HANDLE), result((Result)CrashReportResult::IncompleteReport), process_info({0}) { }
|
||||
|
||||
void BuildReport(u64 pid, bool has_extra_info);
|
||||
void SaveReport();
|
||||
void ProcessExceptions();
|
||||
|
||||
Result GetResult() {
|
||||
return this->result;
|
||||
}
|
||||
|
||||
bool WasSuccessful() {
|
||||
return this->result != (Result)CrashReportResult::IncompleteReport;
|
||||
}
|
||||
|
||||
bool OpenProcess(u64 pid) {
|
||||
return R_SUCCEEDED(svcDebugActiveProcess(&debug_handle, pid));
|
||||
}
|
||||
|
@ -47,6 +66,10 @@ class CrashReport {
|
|||
bool Is64Bit() {
|
||||
return (process_info.flags & 0x01) != 0;
|
||||
}
|
||||
|
||||
bool IsUserBreak() {
|
||||
return this->result == (Result)CrashReportResult::UserBreak;
|
||||
}
|
||||
private:
|
||||
void HandleAttachProcess(DebugEventInfo &d);
|
||||
void HandleException(DebugEventInfo &d);
|
||||
|
|
|
@ -94,12 +94,27 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Try to debug the crashed process. */
|
||||
g_Creport.BuildReport(crashed_pid, argv[1][0] == '1');
|
||||
|
||||
if (R_SUCCEEDED(nsdevInitialize())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
nsdevExit();
|
||||
if (g_Creport.WasSuccessful()) {
|
||||
if (R_SUCCEEDED(nsdevInitialize())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
nsdevExit();
|
||||
}
|
||||
|
||||
/* Don't fatal if we have extra info. */
|
||||
if (kernelAbove500()) {
|
||||
if (g_Creport.IsApplication()) {
|
||||
return 0;
|
||||
}
|
||||
} else if (argv[1][0] == '1') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Also don't fatal if we're a user break. */
|
||||
if (g_Creport.IsUserBreak()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fatalWithType(g_Creport.GetResult(), FatalType_ErrorScreen);
|
||||
}
|
||||
|
||||
/* TODO: fatalWithType(<report error>, FatalType_ErrorScreen); */
|
||||
fatalWithType(0, FatalType_ErrorScreen);
|
||||
}
|
Loading…
Reference in a new issue