mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-01 15:28:21 -04:00
creport: refactor to use sts:: namespace.
This commit is contained in:
parent
fc7f06dc78
commit
227a1d938d
17 changed files with 1239 additions and 1208 deletions
|
@ -21,9 +21,9 @@
|
|||
#include <malloc.h>
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere/firmware_version.hpp>
|
||||
|
||||
#include <stratosphere.hpp>
|
||||
#include "creport_crash_report.hpp"
|
||||
#include "creport_utils.hpp"
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
@ -81,65 +81,55 @@ void __appExit(void) {
|
|||
fsExit();
|
||||
}
|
||||
|
||||
static u64 creport_parse_u64(char *s) {
|
||||
/* Official creport uses this custom parsing logic... */
|
||||
u64 out_val = 0;
|
||||
for (unsigned int i = 0; i < 20 && s[i]; i++) {
|
||||
if ('0' <= s[i] && s[i] <= '9') {
|
||||
out_val *= 10;
|
||||
out_val += (s[i] - '0');
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out_val;
|
||||
}
|
||||
|
||||
static CrashReport g_Creport;
|
||||
static sts::creport::CrashReport g_Creport;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
/* Validate arguments. */
|
||||
if (argc < 2) {
|
||||
return 0;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (argv[i] == NULL) {
|
||||
return 0;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse crashed PID. */
|
||||
u64 crashed_pid = creport_parse_u64(argv[0]);
|
||||
u64 crashed_pid = sts::creport::ParseProcessIdArgument(argv[0]);
|
||||
|
||||
/* Try to debug the crashed process. */
|
||||
g_Creport.BuildReport(crashed_pid, argv[1][0] == '1');
|
||||
if (g_Creport.WasSuccessful()) {
|
||||
g_Creport.SaveReport();
|
||||
|
||||
DoWithSmSession([&]() {
|
||||
if (R_SUCCEEDED(nsdevInitialize())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
nsdevExit();
|
||||
}
|
||||
});
|
||||
|
||||
/* Don't fatal if we have extra info. */
|
||||
if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) {
|
||||
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;
|
||||
}
|
||||
|
||||
FatalContext *ctx = g_Creport.GetFatalContext();
|
||||
|
||||
fatalWithContext(g_Creport.GetResult(), FatalType_ErrorScreen, ctx);
|
||||
if (!g_Creport.IsComplete()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
/* Save report to file. */
|
||||
g_Creport.SaveReport();
|
||||
|
||||
/* Try to terminate the process. */
|
||||
{
|
||||
auto ns_holder = sts::sm::ScopedServiceHolder<nsdevInitialize, nsdevExit>();
|
||||
if (R_SUCCEEDED(ns_holder.GetResult())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't fatal if we have extra info, or if we're 5.0.0+ and an application crashed. */
|
||||
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
|
||||
if (g_Creport.IsApplication()) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
} else if (argv[1][0] == '1') {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Also don't fatal if we're a user break. */
|
||||
if (g_Creport.IsUserBreak()) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Throw fatal error. */
|
||||
FatalContext ctx;
|
||||
g_Creport.GetFatalContext(&ctx);
|
||||
fatalWithContext(g_Creport.GetResult(), FatalType_ErrorScreen, &ctx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue