2018-09-07 15:00:13 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2018-09-07 15:00:13 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-06-25 16:22:37 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2018-06-25 06:42:26 +00:00
|
|
|
#include "creport_crash_report.hpp"
|
2019-07-12 12:31:00 +00:00
|
|
|
#include "creport_utils.hpp"
|
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::creport {
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Convenience definitions. */
|
|
|
|
constexpr size_t DyingMessageAddressOffset = 0x1C0;
|
2020-01-18 04:11:03 +00:00
|
|
|
static_assert(DyingMessageAddressOffset == OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address));
|
|
|
|
static_assert(DyingMessageAddressOffset == OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address));
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Helper functions. */
|
|
|
|
bool TryGetCurrentTimestamp(u64 *out) {
|
|
|
|
/* Clear output. */
|
|
|
|
*out = 0;
|
|
|
|
|
|
|
|
/* Check if we have time service. */
|
|
|
|
{
|
|
|
|
bool has_time_service = false;
|
|
|
|
if (R_FAILED(sm::HasService(&has_time_service, sm::ServiceName::Encode("time:s"))) || !has_time_service) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to get the current time. */
|
|
|
|
{
|
2019-07-13 01:18:31 +00:00
|
|
|
sm::ScopedServiceHolder<timeInitialize, timeExit> time_holder;
|
|
|
|
return time_holder && R_SUCCEEDED(timeGetCurrentTime(TimeType_LocalSystemClock, out));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2018-11-12 03:52:19 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-13 01:18:31 +00:00
|
|
|
void TryCreateReportDirectories() {
|
2020-03-08 09:45:12 +00:00
|
|
|
fs::EnsureDirectoryRecursively("sdmc:/atmosphere/crash_reports/dumps");
|
|
|
|
fs::EnsureDirectoryRecursively("sdmc:/atmosphere/fatal_reports/dumps");
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-18 04:11:03 +00:00
|
|
|
constexpr const char *GetDebugExceptionString(const svc::DebugException type) {
|
2019-07-12 12:31:00 +00:00
|
|
|
switch (type) {
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedInstruction:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Undefined Instruction";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_InstructionAbort:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Instruction Abort";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DataAbort:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Data Abort";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_AlignmentFault:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Alignment Fault";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DebuggerAttached:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Debugger Attached";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_BreakPoint:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Break Point";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UserBreak:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "User Break";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DebuggerBreak:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Debugger Break";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedSystemCall:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "Undefined System Call";
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_MemorySystemError:
|
2019-07-12 12:31:00 +00:00
|
|
|
return "System Memory Error";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 06:42:26 +00:00
|
|
|
}
|
2019-01-20 00:32:33 +00:00
|
|
|
|
2019-10-18 02:48:28 +00:00
|
|
|
void CrashReport::BuildReport(os::ProcessId process_id, bool has_extra_info) {
|
2019-07-12 12:31:00 +00:00
|
|
|
this->has_extra_info = has_extra_info;
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
if (this->OpenProcess(process_id)) {
|
|
|
|
ON_SCOPE_EXIT { this->Close(); };
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Parse info from the crashed process. */
|
|
|
|
this->ProcessExceptions();
|
|
|
|
this->module_list.FindModulesFromThreadInfo(this->debug_handle, this->crashed_thread);
|
|
|
|
this->thread_list.ReadFromProcess(this->debug_handle, this->thread_tls_map, this->Is64Bit());
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Associate module list to threads. */
|
|
|
|
this->crashed_thread.SetModuleList(&this->module_list);
|
|
|
|
this->thread_list.SetModuleList(&this->module_list);
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Process dying message for applications. */
|
|
|
|
if (this->IsApplication()) {
|
|
|
|
this->ProcessDyingMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nintendo's creport finds extra modules by looking at all threads if application, */
|
|
|
|
/* but there's no reason for us not to always go looking. */
|
|
|
|
for (size_t i = 0; i < this->thread_list.GetThreadCount(); i++) {
|
|
|
|
this->module_list.FindModulesFromThreadInfo(this->debug_handle, this->thread_list.GetThreadInfo(i));
|
|
|
|
}
|
|
|
|
|
2019-07-13 01:18:31 +00:00
|
|
|
/* Nintendo's creport saves the report to erpt here, but we'll save to SD card later. */
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2018-11-14 04:22:54 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-10-27 22:57:30 +00:00
|
|
|
void CrashReport::GetFatalContext(::FatalCpuContext *_out) const {
|
2019-10-24 09:30:10 +00:00
|
|
|
static_assert(sizeof(*_out) == sizeof(ams::fatal::CpuContext));
|
|
|
|
ams::fatal::CpuContext *out = reinterpret_cast<ams::fatal::CpuContext *>(_out);
|
2019-07-12 12:31:00 +00:00
|
|
|
std::memset(out, 0, sizeof(*out));
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-13 01:18:31 +00:00
|
|
|
/* TODO: Support generating 32-bit fatal contexts? */
|
2019-07-19 02:09:35 +00:00
|
|
|
out->architecture = fatal::CpuContext::Architecture_Aarch64;
|
2019-07-12 12:31:00 +00:00
|
|
|
out->type = static_cast<u32>(this->exception_info.type);
|
|
|
|
|
2019-07-19 02:09:35 +00:00
|
|
|
for (size_t i = 0; i < fatal::aarch64::RegisterName_FP; i++) {
|
|
|
|
out->aarch64_ctx.SetRegisterValue(static_cast<fatal::aarch64::RegisterName>(i), this->crashed_thread.GetGeneralPurposeRegister(i));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2019-07-19 02:09:35 +00:00
|
|
|
out->aarch64_ctx.SetRegisterValue(fatal::aarch64::RegisterName_FP, this->crashed_thread.GetFP());
|
|
|
|
out->aarch64_ctx.SetRegisterValue(fatal::aarch64::RegisterName_LR, this->crashed_thread.GetLR());
|
|
|
|
out->aarch64_ctx.SetRegisterValue(fatal::aarch64::RegisterName_SP, this->crashed_thread.GetSP());
|
|
|
|
out->aarch64_ctx.SetRegisterValue(fatal::aarch64::RegisterName_PC, this->crashed_thread.GetPC());
|
2019-01-20 00:32:33 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
out->aarch64_ctx.stack_trace_size = this->crashed_thread.GetStackTraceSize();
|
|
|
|
for (size_t i = 0; i < out->aarch64_ctx.stack_trace_size; i++) {
|
|
|
|
out->aarch64_ctx.stack_trace[i] = this->crashed_thread.GetStackTrace(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->module_list.GetModuleCount()) {
|
2019-07-19 02:09:35 +00:00
|
|
|
out->aarch64_ctx.SetBaseAddress(this->module_list.GetModuleStartAddress(0));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 04:43:01 +00:00
|
|
|
/* For ams fatal, which doesn't use afsr0, pass program_id instead. */
|
|
|
|
out->aarch64_ctx.SetProgramIdForAtmosphere(ncm::ProgramId{this->process_info.program_id});
|
2018-06-25 07:45:25 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::ProcessExceptions() {
|
|
|
|
/* Loop all debug events. */
|
|
|
|
svc::DebugEventInfo d;
|
|
|
|
while (R_SUCCEEDED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), this->debug_handle))) {
|
|
|
|
switch (d.type) {
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugEvent_AttachProcess:
|
2019-07-12 12:31:00 +00:00
|
|
|
this->HandleDebugEventInfoAttachProcess(d);
|
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugEvent_AttachThread:
|
2019-07-12 12:31:00 +00:00
|
|
|
this->HandleDebugEventInfoAttachThread(d);
|
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugEvent_Exception:
|
2019-07-12 12:31:00 +00:00
|
|
|
this->HandleDebugEventInfoException(d);
|
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugEvent_ExitProcess:
|
|
|
|
case svc::DebugEvent_ExitThread:
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-25 07:45:25 +00:00
|
|
|
}
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Parse crashed thread info. */
|
|
|
|
this->crashed_thread.ReadFromProcess(this->debug_handle, this->thread_tls_map, this->crashed_thread_id, this->Is64Bit());
|
2018-06-25 07:45:25 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::HandleDebugEventInfoAttachProcess(const svc::DebugEventInfo &d) {
|
|
|
|
this->process_info = d.info.attach_process;
|
|
|
|
|
|
|
|
/* On 5.0.0+, we want to parse out a dying message from application crashes. */
|
2019-10-18 02:48:28 +00:00
|
|
|
if (hos::GetVersion() < hos::Version_500 || !IsApplication()) {
|
2019-07-12 12:31:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-20 00:32:33 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Parse out user data. */
|
2019-07-12 12:31:00 +00:00
|
|
|
const u64 address = this->process_info.user_exception_context_address + DyingMessageAddressOffset;
|
2018-06-25 07:45:25 +00:00
|
|
|
u64 userdata_address = 0;
|
|
|
|
u64 userdata_size = 0;
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Read userdata address. */
|
|
|
|
if (R_FAILED(svcReadDebugProcessMemory(&userdata_address, this->debug_handle, address, sizeof(userdata_address)))) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Validate userdata address. */
|
|
|
|
if (userdata_address == 0 || userdata_address & 0xFFF) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Read userdata size. */
|
|
|
|
if (R_FAILED(svcReadDebugProcessMemory(&userdata_size, this->debug_handle, address + sizeof(userdata_address), sizeof(userdata_size)))) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Cap userdata size. */
|
2019-07-12 12:31:00 +00:00
|
|
|
userdata_size = std::min(size_t(userdata_size), sizeof(this->dying_message));
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2018-06-25 09:40:32 +00:00
|
|
|
this->dying_message_address = userdata_address;
|
|
|
|
this->dying_message_size = userdata_size;
|
2018-06-25 07:45:25 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::HandleDebugEventInfoAttachThread(const svc::DebugEventInfo &d) {
|
|
|
|
/* Save info on the thread's TLS address for later. */
|
|
|
|
this->thread_tls_map[d.info.attach_thread.thread_id] = d.info.attach_thread.tls_address;
|
2018-06-25 08:18:26 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::HandleDebugEventInfoException(const svc::DebugEventInfo &d) {
|
|
|
|
switch (d.info.exception.type) {
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedInstruction:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultUndefinedInstruction();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_InstructionAbort:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultInstructionAbort();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DataAbort:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultDataAbort();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_AlignmentFault:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultAlignmentFault();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UserBreak:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultUserBreak();
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Try to parse out the user break result. */
|
2019-10-18 02:48:28 +00:00
|
|
|
if (hos::GetVersion() >= hos::Version_500) {
|
2019-07-13 01:18:31 +00:00
|
|
|
svcReadDebugProcessMemory(&this->result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedSystemCall:
|
2019-10-24 08:40:44 +00:00
|
|
|
this->result = ResultUndefinedSystemCall();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_MemorySystemError:
|
|
|
|
this->result = ResultMemorySystemError();
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DebuggerAttached:
|
|
|
|
case svc::DebugException_BreakPoint:
|
|
|
|
case svc::DebugException_DebuggerBreak:
|
2019-07-12 12:31:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Save exception info. */
|
|
|
|
this->exception_info = d.info.exception;
|
|
|
|
this->crashed_thread_id = d.thread_id;
|
2018-06-25 08:18:26 +00:00
|
|
|
}
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::ProcessDyingMessage() {
|
|
|
|
/* Dying message is only stored starting in 5.0.0. */
|
2019-10-18 02:48:28 +00:00
|
|
|
if (hos::GetVersion() < hos::Version_500) {
|
2019-07-12 12:31:00 +00:00
|
|
|
return;
|
2018-06-25 16:22:37 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Validate address/size. */
|
|
|
|
if (this->dying_message_address == 0 || this->dying_message_address & 0xFFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this->dying_message_size > sizeof(this->dying_message)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-20 00:32:33 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Validate that the current report isn't garbage. */
|
|
|
|
if (!IsOpen() || !IsComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Read the dying message. */
|
|
|
|
svcReadDebugProcessMemory(this->dying_message, this->debug_handle, this->dying_message_address, this->dying_message_size);
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void CrashReport::SaveReport() {
|
2019-07-13 01:18:31 +00:00
|
|
|
/* Try to ensure path exists. */
|
|
|
|
TryCreateReportDirectories();
|
2019-01-20 00:32:33 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Get a timestamp. */
|
|
|
|
u64 timestamp;
|
|
|
|
if (!TryGetCurrentTimestamp(×tamp)) {
|
|
|
|
timestamp = svcGetSystemTick();
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Save files. */
|
|
|
|
{
|
2020-03-08 09:45:12 +00:00
|
|
|
char file_path[fs::EntryNameLengthMax + 1];
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Save crash report. */
|
2019-10-28 04:43:01 +00:00
|
|
|
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, this->process_info.program_id);
|
2020-03-08 09:45:12 +00:00
|
|
|
{
|
|
|
|
ScopedFile file(file_path);
|
|
|
|
if (file.IsOpen()) {
|
|
|
|
this->SaveToFile(file);
|
|
|
|
}
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Dump threads. */
|
2019-10-28 04:43:01 +00:00
|
|
|
std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/dumps/%011lu_%016lx_thread_info.bin", timestamp, this->process_info.program_id);
|
2020-03-08 09:45:12 +00:00
|
|
|
{
|
|
|
|
ScopedFile file(file_path);
|
|
|
|
if (file.IsOpen()) {
|
|
|
|
this->thread_list.DumpBinary(file, this->crashed_thread.GetThreadId());
|
|
|
|
}
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2018-06-26 06:51:53 +00:00
|
|
|
}
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2020-03-08 09:45:12 +00:00
|
|
|
void CrashReport::SaveToFile(ScopedFile &file) {
|
2020-03-08 10:08:39 +00:00
|
|
|
file.WriteFormat(u8"Atmosphère Crash Report (v1.5):\n");
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Result: 0x%X (2%03d-%04d)\n\n", this->result.GetValue(), this->result.GetModule(), this->result.GetDescription());
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Process Info. */
|
|
|
|
char name_buf[0x10] = {};
|
|
|
|
static_assert(sizeof(name_buf) >= sizeof(this->process_info.name), "buffer overflow!");
|
|
|
|
std::memcpy(name_buf, this->process_info.name, sizeof(this->process_info.name));
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Process Info:\n");
|
|
|
|
file.WriteFormat(" Process Name: %s\n", name_buf);
|
|
|
|
file.WriteFormat(" Program ID: %016lx\n", this->process_info.program_id);
|
|
|
|
file.WriteFormat(" Process ID: %016lx\n", this->process_info.process_id);
|
|
|
|
file.WriteFormat(" Process Flags: %08x\n", this->process_info.flags);
|
2019-10-18 02:48:28 +00:00
|
|
|
if (hos::GetVersion() >= hos::Version_500) {
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat(" User Exception Address: %s\n", this->module_list.GetFormattedAddressString(this->process_info.user_exception_context_address));
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Exception Info. */
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Exception Info:\n");
|
|
|
|
file.WriteFormat(" Type: %s\n", GetDebugExceptionString(this->exception_info.type));
|
|
|
|
file.WriteFormat(" Address: %s\n", this->module_list.GetFormattedAddressString(this->exception_info.address));
|
2019-07-12 12:31:00 +00:00
|
|
|
switch (this->exception_info.type) {
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedInstruction:
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat(" Opcode: %08x\n", this->exception_info.specific.undefined_instruction.insn);
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_DataAbort:
|
|
|
|
case svc::DebugException_AlignmentFault:
|
2019-07-12 12:31:00 +00:00
|
|
|
if (this->exception_info.specific.raw != this->exception_info.address) {
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat(" Fault Address: %s\n", this->module_list.GetFormattedAddressString(this->exception_info.specific.raw));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UndefinedSystemCall:
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat(" Svc Id: 0x%02x\n", this->exception_info.specific.undefined_system_call.id);
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
2020-01-18 04:11:03 +00:00
|
|
|
case svc::DebugException_UserBreak:
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat(" Break Reason: 0x%x\n", this->exception_info.specific.user_break.break_reason);
|
|
|
|
file.WriteFormat(" Break Address: %s\n", this->module_list.GetFormattedAddressString(this->exception_info.specific.user_break.address));
|
|
|
|
file.WriteFormat(" Break Size: 0x%lx\n", this->exception_info.specific.user_break.size);
|
2019-07-12 12:31:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Crashed Thread Info. */
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Crashed Thread Info:\n");
|
|
|
|
this->crashed_thread.SaveToFile(file);
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Dying Message. */
|
2019-10-18 02:48:28 +00:00
|
|
|
if (hos::GetVersion() >= hos::Version_500 && this->dying_message_size != 0) {
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Dying Message Info:\n");
|
|
|
|
file.WriteFormat(" Address: 0x%s\n", this->module_list.GetFormattedAddressString(this->dying_message_address));
|
|
|
|
file.WriteFormat(" Size: 0x%016lx\n", this->dying_message_size);
|
|
|
|
file.DumpMemory( " Dying Message: ", this->dying_message, this->dying_message_size);
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Module Info. */
|
2020-03-08 09:45:12 +00:00
|
|
|
file.WriteFormat("Module Info:\n");
|
|
|
|
this->module_list.SaveToFile(file);
|
2019-01-20 00:35:40 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
/* Thread Info. */
|
2020-03-08 10:08:39 +00:00
|
|
|
file.WriteFormat("Thread Report:\n");
|
2020-03-08 09:45:12 +00:00
|
|
|
this->thread_list.SaveToFile(file);
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|
2019-07-12 12:31:00 +00:00
|
|
|
|
2018-06-26 06:44:58 +00:00
|
|
|
}
|