Atmosphere/stratosphere/creport/source/creport_crash_report.hpp

106 lines
3.7 KiB
C++
Raw Permalink Normal View History

/*
* Copyright (c) Atmosphère-NX
*
* 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/>.
*/
#pragma once
#include "creport_threads.hpp"
#include "creport_modules.hpp"
namespace ams::creport {
class CrashReport {
private:
static constexpr size_t DyingMessageSizeMax = os::MemoryPageSize;
static constexpr size_t MemoryHeapSize = 512_KB;
static_assert(MemoryHeapSize >= DyingMessageSizeMax + sizeof(ModuleList) + sizeof(ThreadList) + os::MemoryPageSize);
private:
2021-10-10 07:14:06 +00:00
os::NativeHandle m_debug_handle = os::InvalidNativeHandle;
bool m_has_extra_info = true;
Result m_result = creport::ResultIncompleteReport();
/* Meta, used for building module/thread list. */
2021-10-10 07:14:06 +00:00
ThreadTlsMap m_thread_tls_map = {};
/* Attach process info. */
2021-10-10 07:14:06 +00:00
svc::DebugInfoCreateProcess m_process_info = {};
u64 m_dying_message_address = 0;
u64 m_dying_message_size = 0;
u8 *m_dying_message = nullptr;
/* Exception info. */
2021-10-10 07:14:06 +00:00
svc::DebugInfoException m_exception_info = {};
u64 m_module_base_address = 0;
u64 m_crashed_thread_id = 0;
ThreadInfo m_crashed_thread;
/* Lists. */
2021-10-10 07:14:06 +00:00
ModuleList *m_module_list = nullptr;
ThreadList *m_thread_list = nullptr;
/* Memory heap. */
2021-10-10 07:14:06 +00:00
lmem::HeapHandle m_heap_handle = nullptr;
u8 m_heap_storage[MemoryHeapSize] = {};
public:
2021-01-19 01:50:40 +00:00
constexpr CrashReport() = default;
Result GetResult() const {
2021-10-10 07:14:06 +00:00
return m_result;
}
bool IsComplete() const {
2021-10-10 07:14:06 +00:00
return !ResultIncompleteReport::Includes(m_result);
}
bool IsOpen() const {
2021-10-10 07:14:06 +00:00
return m_debug_handle != os::InvalidNativeHandle;
}
bool IsApplication() const {
2021-10-10 07:14:06 +00:00
return (m_process_info.flags & svc::CreateProcessFlag_IsApplication) != 0;
}
bool Is64Bit() const {
2021-10-10 07:14:06 +00:00
return (m_process_info.flags & svc::CreateProcessFlag_Is64Bit) != 0;
}
bool IsUserBreak() const {
2021-10-10 07:14:06 +00:00
return m_exception_info.type == svc::DebugException_UserBreak;
}
2019-10-18 02:48:28 +00:00
bool OpenProcess(os::ProcessId process_id) {
2021-10-10 07:14:06 +00:00
return R_SUCCEEDED(svc::DebugActiveProcess(std::addressof(m_debug_handle), process_id.value));
}
void Close() {
2021-10-10 07:14:06 +00:00
os::CloseNativeHandle(m_debug_handle);
m_debug_handle = os::InvalidNativeHandle;
}
void Initialize();
2019-10-18 02:48:28 +00:00
void BuildReport(os::ProcessId process_id, bool has_extra_info);
void GetFatalContext(::FatalCpuContext *out) const;
2020-12-15 03:15:49 +00:00
void SaveReport(bool enable_screenshot);
private:
void ProcessExceptions();
void ProcessDyingMessage();
2020-07-31 08:27:09 +00:00
void HandleDebugEventInfoCreateProcess(const svc::DebugEventInfo &d);
void HandleDebugEventInfoCreateThread(const svc::DebugEventInfo &d);
void HandleDebugEventInfoException(const svc::DebugEventInfo &d);
2020-03-08 09:45:12 +00:00
void SaveToFile(ScopedFile &file);
};
}