Results: Implement namespaced, type-safe results.
Because I was working on multiple things at once, this commit also:
- Adds wrappers for/linker flags to wrap CXX exceptions to make them
abort. This saves ~0x8000 of memory in every system module.
- Broadly replaces lines of the pattern if (cond) { return ResultX; }
with R_UNLESS(!cond, ResultX());.
- Reworks the R_TRY_CATCH macros (and the result macros in general).
This commit is contained in:
@@ -212,29 +212,29 @@ namespace sts::creport {
|
||||
void CrashReport::HandleDebugEventInfoException(const svc::DebugEventInfo &d) {
|
||||
switch (d.info.exception.type) {
|
||||
case svc::DebugExceptionType::UndefinedInstruction:
|
||||
this->result = ResultCreportUndefinedInstruction;
|
||||
this->result = ResultUndefinedInstruction();
|
||||
break;
|
||||
case svc::DebugExceptionType::InstructionAbort:
|
||||
this->result = ResultCreportInstructionAbort;
|
||||
this->result = ResultInstructionAbort();
|
||||
break;
|
||||
case svc::DebugExceptionType::DataAbort:
|
||||
this->result = ResultCreportDataAbort;
|
||||
this->result = ResultDataAbort();
|
||||
break;
|
||||
case svc::DebugExceptionType::AlignmentFault:
|
||||
this->result = ResultCreportAlignmentFault;
|
||||
this->result = ResultAlignmentFault();
|
||||
break;
|
||||
case svc::DebugExceptionType::UserBreak:
|
||||
this->result = ResultCreportUserBreak;
|
||||
this->result = ResultUserBreak();
|
||||
/* Try to parse out the user break result. */
|
||||
if (hos::GetVersion() >= hos::Version_500) {
|
||||
svcReadDebugProcessMemory(&this->result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
|
||||
}
|
||||
break;
|
||||
case svc::DebugExceptionType::UndefinedSystemCall:
|
||||
this->result = ResultCreportUndefinedSystemCall;
|
||||
this->result = ResultUndefinedSystemCall();
|
||||
break;
|
||||
case svc::DebugExceptionType::SystemMemoryError:
|
||||
this->result = ResultCreportSystemMemoryError;
|
||||
this->result = ResultSystemMemoryError();
|
||||
break;
|
||||
case svc::DebugExceptionType::DebuggerAttached:
|
||||
case svc::DebugExceptionType::BreakPoint:
|
||||
@@ -306,7 +306,7 @@ namespace sts::creport {
|
||||
|
||||
void CrashReport::SaveToFile(FILE *f_report) {
|
||||
fprintf(f_report, "Atmosphère Crash Report (v1.4):\n");
|
||||
fprintf(f_report, "Result: 0x%X (2%03d-%04d)\n\n", this->result, R_MODULE(this->result), R_DESCRIPTION(this->result));
|
||||
fprintf(f_report, "Result: 0x%X (2%03d-%04d)\n\n", this->result.GetValue(), this->result.GetModule(), this->result.GetDescription());
|
||||
|
||||
/* Process Info. */
|
||||
char name_buf[0x10] = {};
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace sts::creport {
|
||||
private:
|
||||
Handle debug_handle = INVALID_HANDLE;
|
||||
bool has_extra_info = true;
|
||||
Result result = ResultCreportIncompleteReport;
|
||||
Result result = ResultIncompleteReport();
|
||||
|
||||
/* Attach process info. */
|
||||
svc::DebugInfoAttachProcess process_info = {};
|
||||
@@ -55,7 +55,7 @@ namespace sts::creport {
|
||||
}
|
||||
|
||||
bool IsComplete() const {
|
||||
return this->result != ResultCreportIncompleteReport;
|
||||
return !ResultIncompleteReport::Includes(this->result);
|
||||
}
|
||||
|
||||
bool IsOpen() const {
|
||||
|
||||
@@ -52,6 +52,12 @@ namespace sts::ams {
|
||||
|
||||
}
|
||||
|
||||
namespace sts::result {
|
||||
|
||||
bool CallFatalOnResultAssertion = true;
|
||||
|
||||
}
|
||||
|
||||
using namespace sts;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
@@ -136,5 +142,5 @@ int main(int argc, char **argv) {
|
||||
/* Throw fatal error. */
|
||||
FatalContext ctx;
|
||||
g_crash_report.GetFatalContext(&ctx);
|
||||
fatalWithContext(g_crash_report.GetResult(), FatalType_ErrorScreen, &ctx);
|
||||
fatalWithContext(g_crash_report.GetResult().GetValue(), FatalType_ErrorScreen, &ctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user