2018-09-07 17:00:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-06-25 11:04:17 +02:00
|
|
|
#pragma once
|
|
|
|
#include <switch.h>
|
2018-06-26 08:44:58 +02:00
|
|
|
#include <cstdio>
|
2018-06-25 11:04:17 +02:00
|
|
|
|
|
|
|
#include "creport_debug_types.hpp"
|
2018-07-28 05:34:09 +02:00
|
|
|
#include "creport_code_info.hpp"
|
2018-06-25 11:04:17 +02:00
|
|
|
|
|
|
|
class ThreadInfo {
|
|
|
|
private:
|
2018-09-19 15:03:50 +02:00
|
|
|
ThreadContext context{};
|
2018-07-02 16:26:03 +02:00
|
|
|
u64 thread_id = 0;
|
|
|
|
u64 stack_top = 0;
|
|
|
|
u64 stack_bottom = 0;
|
|
|
|
u64 stack_trace[0x20]{};
|
|
|
|
u32 stack_trace_size = 0;
|
2018-07-28 05:34:09 +02:00
|
|
|
CodeList *code_list;
|
2018-07-02 16:26:03 +02:00
|
|
|
public:
|
2018-09-19 15:03:50 +02:00
|
|
|
u64 GetPC() { return context.pc.x; }
|
2018-06-25 12:38:54 +02:00
|
|
|
u64 GetLR() { return context.lr; }
|
2018-06-26 08:44:58 +02:00
|
|
|
u64 GetId() { return thread_id; }
|
2018-06-25 12:38:54 +02:00
|
|
|
|
2018-06-25 11:04:17 +02:00
|
|
|
bool ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_bit);
|
2018-06-26 08:44:58 +02:00
|
|
|
void SaveToFile(FILE *f_report);
|
|
|
|
void DumpBinary(FILE *f_bin);
|
2018-07-28 05:34:09 +02:00
|
|
|
void SetCodeList(CodeList *cl) { this->code_list = cl; }
|
2018-06-25 12:07:44 +02:00
|
|
|
private:
|
|
|
|
void TryGetStackInfo(Handle debug_handle);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ThreadList {
|
|
|
|
private:
|
|
|
|
static const size_t max_thread_count = 0x60;
|
2018-07-02 16:26:03 +02:00
|
|
|
u32 thread_count = 0;
|
2018-06-25 12:07:44 +02:00
|
|
|
ThreadInfo thread_infos[max_thread_count];
|
2018-07-02 16:26:03 +02:00
|
|
|
public:
|
2018-06-26 08:44:58 +02:00
|
|
|
void SaveToFile(FILE *f_report);
|
|
|
|
void DumpBinary(FILE *f_bin, u64 crashed_id);
|
2018-06-25 12:07:44 +02:00
|
|
|
void ReadThreadsFromProcess(Handle debug_handle, bool is_64_bit);
|
2018-07-28 05:34:09 +02:00
|
|
|
void SetCodeList(CodeList *cl) {
|
|
|
|
for (u32 i = 0; i < thread_count; i++) {
|
|
|
|
thread_infos[i].SetCodeList(cl);
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 12:07:44 +02:00
|
|
|
};
|