creport: update for new-ipc

This commit is contained in:
Michael Scire 2019-10-17 19:48:28 -07:00 committed by SciresM
parent 799c158b86
commit 89c6fc6437
5 changed files with 29 additions and 27 deletions

View file

@ -85,7 +85,7 @@ namespace sts::creport {
} }
void CrashReport::BuildReport(u64 process_id, bool has_extra_info) { void CrashReport::BuildReport(os::ProcessId process_id, bool has_extra_info) {
this->has_extra_info = has_extra_info; this->has_extra_info = has_extra_info;
if (this->OpenProcess(process_id)) { if (this->OpenProcess(process_id)) {
@ -173,7 +173,7 @@ namespace sts::creport {
this->process_info = d.info.attach_process; this->process_info = d.info.attach_process;
/* On 5.0.0+, we want to parse out a dying message from application crashes. */ /* On 5.0.0+, we want to parse out a dying message from application crashes. */
if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 || !IsApplication()) { if (hos::GetVersion() < hos::Version_500 || !IsApplication()) {
return; return;
} }
@ -226,7 +226,7 @@ namespace sts::creport {
case svc::DebugExceptionType::UserBreak: case svc::DebugExceptionType::UserBreak:
this->result = ResultCreportUserBreak; this->result = ResultCreportUserBreak;
/* Try to parse out the user break result. */ /* Try to parse out the user break result. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
svcReadDebugProcessMemory(&this->result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result)); svcReadDebugProcessMemory(&this->result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
} }
break; break;
@ -249,7 +249,7 @@ namespace sts::creport {
void CrashReport::ProcessDyingMessage() { void CrashReport::ProcessDyingMessage() {
/* Dying message is only stored starting in 5.0.0. */ /* Dying message is only stored starting in 5.0.0. */
if (GetRuntimeFirmwareVersion() < FirmwareVersion_500) { if (hos::GetVersion() < hos::Version_500) {
return; return;
} }
@ -317,7 +317,7 @@ namespace sts::creport {
fprintf(f_report, " Title ID: %016lx\n", this->process_info.title_id); fprintf(f_report, " Title ID: %016lx\n", this->process_info.title_id);
fprintf(f_report, " Process ID: %016lx\n", this->process_info.process_id); fprintf(f_report, " Process ID: %016lx\n", this->process_info.process_id);
fprintf(f_report, " Process Flags: %08x\n", this->process_info.flags); fprintf(f_report, " Process Flags: %08x\n", this->process_info.flags);
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
fprintf(f_report, " User Exception Address: %s\n", this->module_list.GetFormattedAddressString(this->process_info.user_exception_context_address)); fprintf(f_report, " User Exception Address: %s\n", this->module_list.GetFormattedAddressString(this->process_info.user_exception_context_address));
} }
@ -352,7 +352,7 @@ namespace sts::creport {
this->crashed_thread.SaveToFile(f_report); this->crashed_thread.SaveToFile(f_report);
/* Dying Message. */ /* Dying Message. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 && this->dying_message_size != 0) { if (hos::GetVersion() >= hos::Version_500 && this->dying_message_size != 0) {
fprintf(f_report, "Dying Message Info:\n"); fprintf(f_report, "Dying Message Info:\n");
fprintf(f_report, " Address: 0x%s\n", this->module_list.GetFormattedAddressString(this->dying_message_address)); fprintf(f_report, " Address: 0x%s\n", this->module_list.GetFormattedAddressString(this->dying_message_address));
fprintf(f_report, " Size: 0x%016lx\n", this->dying_message_size); fprintf(f_report, " Size: 0x%016lx\n", this->dying_message_size);

View file

@ -74,8 +74,8 @@ namespace sts::creport {
return this->exception_info.type == svc::DebugExceptionType::UserBreak; return this->exception_info.type == svc::DebugExceptionType::UserBreak;
} }
bool OpenProcess(u64 process_id) { bool OpenProcess(os::ProcessId process_id) {
return R_SUCCEEDED(svcDebugActiveProcess(&this->debug_handle, process_id)); return R_SUCCEEDED(svcDebugActiveProcess(&this->debug_handle, static_cast<u64>(process_id)));
} }
void Close() { void Close() {
@ -85,7 +85,7 @@ namespace sts::creport {
} }
} }
void BuildReport(u64 process_id, bool has_extra_info); void BuildReport(os::ProcessId process_id, bool has_extra_info);
void GetFatalContext(FatalContext *out) const; void GetFatalContext(FatalContext *out) const;
void SaveReport(); void SaveReport();
private: private:

View file

@ -18,7 +18,6 @@
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <malloc.h>
#include <switch.h> #include <switch.h>
#include <stratosphere.hpp> #include <stratosphere.hpp>
@ -30,8 +29,9 @@ extern "C" {
extern u32 __start__; extern u32 __start__;
u32 __nx_applet_type = AppletType_None; u32 __nx_applet_type = AppletType_None;
u32 __nx_fs_num_sessions = 1;
#define INNER_HEAP_SIZE 0x100000 #define INNER_HEAP_SIZE 0x4000
size_t nx_inner_heap_size = INNER_HEAP_SIZE; size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE]; char nx_inner_heap[INNER_HEAP_SIZE];
@ -65,8 +65,10 @@ void __libnx_initheap(void) {
fake_heap_end = (char*)addr + size; fake_heap_end = (char*)addr + size;
} }
using namespace sts;
void __appInit(void) { void __appInit(void) {
SetFirmwareVersionForLibnx(); hos::SetVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
R_ASSERT(fsInitialize()); R_ASSERT(fsInitialize());
@ -81,7 +83,7 @@ void __appExit(void) {
fsExit(); fsExit();
} }
static sts::creport::CrashReport g_Creport; static creport::CrashReport g_crash_report;
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* Validate arguments. */ /* Validate arguments. */
@ -95,28 +97,28 @@ int main(int argc, char **argv) {
} }
/* Parse crashed PID. */ /* Parse crashed PID. */
u64 crashed_pid = sts::creport::ParseProcessIdArgument(argv[0]); os::ProcessId crashed_pid = creport::ParseProcessIdArgument(argv[0]);
/* Try to debug the crashed process. */ /* Try to debug the crashed process. */
g_Creport.BuildReport(crashed_pid, argv[1][0] == '1'); g_crash_report.BuildReport(crashed_pid, argv[1][0] == '1');
if (!g_Creport.IsComplete()) { if (!g_crash_report.IsComplete()) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Save report to file. */ /* Save report to file. */
g_Creport.SaveReport(); g_crash_report.SaveReport();
/* Try to terminate the process. */ /* Try to terminate the process. */
{ {
sts::sm::ScopedServiceHolder<nsdevInitialize, nsdevExit> ns_holder; sm::ScopedServiceHolder<nsdevInitialize, nsdevExit> ns_holder;
if (ns_holder) { if (ns_holder) {
nsdevTerminateProcess(crashed_pid); nsdevTerminateProcess(static_cast<u64>(crashed_pid));
} }
} }
/* Don't fatal if we have extra info, or if we're 5.0.0+ and an application crashed. */ /* Don't fatal if we have extra info, or if we're 5.0.0+ and an application crashed. */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (hos::GetVersion() >= hos::Version_500) {
if (g_Creport.IsApplication()) { if (g_crash_report.IsApplication()) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} else if (argv[1][0] == '1') { } else if (argv[1][0] == '1') {
@ -124,12 +126,12 @@ int main(int argc, char **argv) {
} }
/* Also don't fatal if we're a user break. */ /* Also don't fatal if we're a user break. */
if (g_Creport.IsUserBreak()) { if (g_crash_report.IsUserBreak()) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* Throw fatal error. */ /* Throw fatal error. */
FatalContext ctx; FatalContext ctx;
g_Creport.GetFatalContext(&ctx); g_crash_report.GetFatalContext(&ctx);
fatalWithContext(g_Creport.GetResult(), FatalType_ErrorScreen, &ctx); fatalWithContext(g_crash_report.GetResult(), FatalType_ErrorScreen, &ctx);
} }

View file

@ -53,7 +53,7 @@ namespace sts::creport {
} }
} }
u64 ParseProcessIdArgument(const char *s) { os::ProcessId ParseProcessIdArgument(const char *s) {
/* Official creport uses this custom parsing logic... */ /* Official creport uses this custom parsing logic... */
u64 out_val = 0; u64 out_val = 0;
@ -66,7 +66,7 @@ namespace sts::creport {
} }
} }
return out_val; return os::ProcessId{out_val};
} }
} }

View file

@ -22,6 +22,6 @@ namespace sts::creport {
/* Utility functions. */ /* Utility functions. */
void DumpMemoryHexToFile(FILE *f, const char *prefix, const void *data, size_t size); void DumpMemoryHexToFile(FILE *f, const char *prefix, const void *data, size_t size);
u64 ParseProcessIdArgument(const char *s); os::ProcessId ParseProcessIdArgument(const char *s);
} }