2018-09-07 15:00:13 +00:00
|
|
|
/*
|
2019-04-08 02:00:49 +00:00
|
|
|
* Copyright (c) 2018-2019 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 06:42:26 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <switch.h>
|
2019-03-28 21:23:34 +00:00
|
|
|
#include <stratosphere.hpp>
|
2018-06-26 06:44:58 +00:00
|
|
|
#include <cstdio>
|
2018-06-25 06:42:26 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
#include "creport_debug_types.hpp"
|
2018-06-25 09:04:17 +00:00
|
|
|
#include "creport_thread_info.hpp"
|
2018-06-25 10:38:54 +00:00
|
|
|
#include "creport_code_info.hpp"
|
2018-06-25 07:45:25 +00:00
|
|
|
|
2018-06-25 06:42:26 +00:00
|
|
|
class CrashReport {
|
|
|
|
private:
|
2018-07-02 14:26:03 +00:00
|
|
|
Handle debug_handle = INVALID_HANDLE;
|
2018-06-25 06:42:26 +00:00
|
|
|
bool has_extra_info;
|
2019-03-28 21:23:34 +00:00
|
|
|
Result result = ResultCreportIncompleteReport;
|
2018-06-25 06:42:26 +00:00
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
/* Attach Process Info. */
|
2018-07-02 14:26:03 +00:00
|
|
|
AttachProcessInfo process_info{};
|
|
|
|
u64 dying_message_address = 0;
|
|
|
|
u64 dying_message_size = 0;
|
|
|
|
u8 dying_message[0x1000]{};
|
2018-06-25 09:40:32 +00:00
|
|
|
|
|
|
|
static_assert(sizeof(dying_message) == 0x1000, "Incorrect definition for dying message!");
|
2018-06-25 07:45:25 +00:00
|
|
|
|
2018-06-25 08:18:26 +00:00
|
|
|
/* Exception Info. */
|
2018-07-02 14:26:03 +00:00
|
|
|
ExceptionInfo exception_info{};
|
2018-06-25 09:04:17 +00:00
|
|
|
ThreadInfo crashed_thread_info;
|
2018-06-25 08:18:26 +00:00
|
|
|
|
2018-06-25 10:07:44 +00:00
|
|
|
/* Extra Info. */
|
2018-06-25 10:38:54 +00:00
|
|
|
CodeList code_list;
|
2018-06-25 10:07:44 +00:00
|
|
|
ThreadList thread_list;
|
|
|
|
|
2018-07-28 03:34:09 +00:00
|
|
|
public:
|
2018-06-25 06:42:26 +00:00
|
|
|
void BuildReport(u64 pid, bool has_extra_info);
|
2018-11-14 04:22:54 +00:00
|
|
|
FatalContext *GetFatalContext();
|
2018-06-25 07:58:44 +00:00
|
|
|
void SaveReport();
|
2018-06-25 06:42:26 +00:00
|
|
|
|
2018-06-25 08:18:26 +00:00
|
|
|
bool IsAddressReadable(u64 address, u64 size, MemoryInfo *mi = NULL);
|
|
|
|
|
2018-06-26 06:44:58 +00:00
|
|
|
static void Memdump(FILE *f, const char *prefix, const void *data, size_t size);
|
|
|
|
|
2018-06-25 06:42:26 +00:00
|
|
|
Result GetResult() {
|
|
|
|
return this->result;
|
|
|
|
}
|
|
|
|
|
2018-06-25 07:58:44 +00:00
|
|
|
bool WasSuccessful() {
|
2019-03-28 21:23:34 +00:00
|
|
|
return this->result != ResultCreportIncompleteReport;
|
2018-06-25 07:58:44 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 06:42:26 +00:00
|
|
|
bool OpenProcess(u64 pid) {
|
|
|
|
return R_SUCCEEDED(svcDebugActiveProcess(&debug_handle, pid));
|
|
|
|
}
|
|
|
|
|
2018-06-25 07:45:25 +00:00
|
|
|
bool IsOpen() {
|
|
|
|
return this->debug_handle != INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2018-06-25 06:42:26 +00:00
|
|
|
void Close() {
|
2018-06-25 07:45:25 +00:00
|
|
|
if (IsOpen()) {
|
2018-06-25 06:42:26 +00:00
|
|
|
svcCloseHandle(debug_handle);
|
|
|
|
debug_handle = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 07:45:25 +00:00
|
|
|
|
|
|
|
bool IsApplication() {
|
|
|
|
return (process_info.flags & 0x40) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Is64Bit() {
|
|
|
|
return (process_info.flags & 0x01) != 0;
|
|
|
|
}
|
2018-06-25 07:58:44 +00:00
|
|
|
|
|
|
|
bool IsUserBreak() {
|
2018-06-25 08:18:26 +00:00
|
|
|
return this->exception_info.type == DebugExceptionType::UserBreak;
|
2018-06-25 07:58:44 +00:00
|
|
|
}
|
2018-06-25 07:45:25 +00:00
|
|
|
private:
|
2018-06-25 09:40:32 +00:00
|
|
|
void ProcessExceptions();
|
|
|
|
void ProcessDyingMessage();
|
2018-06-25 07:45:25 +00:00
|
|
|
void HandleAttachProcess(DebugEventInfo &d);
|
|
|
|
void HandleException(DebugEventInfo &d);
|
2018-06-25 16:22:37 +00:00
|
|
|
|
2018-06-26 06:44:58 +00:00
|
|
|
void SaveToFile(FILE *f);
|
|
|
|
|
2018-06-25 16:22:37 +00:00
|
|
|
void EnsureReportDirectories();
|
|
|
|
bool GetCurrentTime(u64 *out);
|
2018-07-02 14:26:03 +00:00
|
|
|
};
|