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 06:42:26 +00:00
|
|
|
#pragma once
|
2019-07-12 12:31:00 +00:00
|
|
|
#include "creport_threads.hpp"
|
|
|
|
#include "creport_modules.hpp"
|
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::creport {
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
class CrashReport {
|
|
|
|
private:
|
2019-12-06 07:41:33 +00:00
|
|
|
static constexpr size_t DyingMessageSizeMax = os::MemoryPageSize;
|
2019-07-12 12:31:00 +00:00
|
|
|
private:
|
|
|
|
Handle debug_handle = INVALID_HANDLE;
|
|
|
|
bool has_extra_info = true;
|
2019-10-24 08:40:44 +00:00
|
|
|
Result result = ResultIncompleteReport();
|
2019-07-12 12:31:00 +00:00
|
|
|
|
|
|
|
/* Attach process info. */
|
|
|
|
svc::DebugInfoAttachProcess process_info = {};
|
|
|
|
u64 dying_message_address = 0;
|
|
|
|
u64 dying_message_size = 0;
|
|
|
|
u8 dying_message[DyingMessageSizeMax] = {};
|
|
|
|
|
|
|
|
/* Exception info. */
|
|
|
|
svc::DebugInfoException exception_info = {};
|
|
|
|
u64 crashed_thread_id = 0;
|
|
|
|
ThreadInfo crashed_thread;
|
|
|
|
|
|
|
|
/* Lists. */
|
|
|
|
ModuleList module_list;
|
|
|
|
ThreadList thread_list;
|
|
|
|
|
|
|
|
/* Meta, used for building module/thread list. */
|
|
|
|
std::map<u64, u64> thread_tls_map;
|
|
|
|
public:
|
|
|
|
Result GetResult() const {
|
|
|
|
return this->result;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
bool IsComplete() const {
|
2019-10-24 08:40:44 +00:00
|
|
|
return !ResultIncompleteReport::Includes(this->result);
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
bool IsOpen() const {
|
|
|
|
return this->debug_handle != INVALID_HANDLE;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
bool IsApplication() const {
|
|
|
|
return (this->process_info.flags & svc::CreateProcessFlag_IsApplication) != 0;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
bool Is64Bit() const {
|
|
|
|
return (this->process_info.flags & svc::CreateProcessFlag_Is64Bit) != 0;
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
bool IsUserBreak() const {
|
2020-01-18 04:11:03 +00:00
|
|
|
return this->exception_info.type == svc::DebugException_UserBreak;
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-10-18 02:48:28 +00:00
|
|
|
bool OpenProcess(os::ProcessId process_id) {
|
|
|
|
return R_SUCCEEDED(svcDebugActiveProcess(&this->debug_handle, static_cast<u64>(process_id)));
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void Close() {
|
|
|
|
if (this->IsOpen()) {
|
|
|
|
svcCloseHandle(this->debug_handle);
|
|
|
|
this->debug_handle = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-10-18 02:48:28 +00:00
|
|
|
void BuildReport(os::ProcessId process_id, bool has_extra_info);
|
2019-10-27 22:57:30 +00:00
|
|
|
void GetFatalContext(::FatalCpuContext *out) const;
|
2019-07-12 12:31:00 +00:00
|
|
|
void SaveReport();
|
|
|
|
private:
|
|
|
|
void ProcessExceptions();
|
|
|
|
void ProcessDyingMessage();
|
|
|
|
void HandleDebugEventInfoAttachProcess(const svc::DebugEventInfo &d);
|
|
|
|
void HandleDebugEventInfoAttachThread(const svc::DebugEventInfo &d);
|
|
|
|
void HandleDebugEventInfoException(const svc::DebugEventInfo &d);
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
void SaveToFile(FILE *f_report);
|
|
|
|
};
|
2019-05-25 20:32:34 +00:00
|
|
|
|
2019-07-12 12:31:00 +00:00
|
|
|
}
|