mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-13 00:26:35 +00:00
creport: Implement reading info about all threads.
This commit is contained in:
parent
5268a9f9f3
commit
d65255acb8
4 changed files with 66 additions and 2 deletions
|
@ -12,7 +12,7 @@ void CrashReport::BuildReport(u64 pid, bool has_extra_info) {
|
||||||
ProcessExceptions();
|
ProcessExceptions();
|
||||||
if (kernelAbove500()) {
|
if (kernelAbove500()) {
|
||||||
/* TODO: Process Code Regions. */
|
/* TODO: Process Code Regions. */
|
||||||
/* TODO: Process Threads. */
|
thread_list.ReadThreadsFromProcess(this->debug_handle, Is64Bit());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsApplication()) {
|
if (IsApplication()) {
|
||||||
|
|
|
@ -37,6 +37,9 @@ class CrashReport {
|
||||||
ExceptionInfo exception_info;
|
ExceptionInfo exception_info;
|
||||||
ThreadInfo crashed_thread_info;
|
ThreadInfo crashed_thread_info;
|
||||||
|
|
||||||
|
/* Extra Info. */
|
||||||
|
ThreadList thread_list;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CrashReport() : debug_handle(INVALID_HANDLE), result((Result)CrashReportResult::IncompleteReport), process_info({}), dying_message_address(0),
|
CrashReport() : debug_handle(INVALID_HANDLE), result((Result)CrashReportResult::IncompleteReport), process_info({}), dying_message_address(0),
|
||||||
dying_message_size(0), dying_message{}, exception_info({}) { }
|
dying_message_size(0), dying_message{}, exception_info({}) { }
|
||||||
|
|
|
@ -28,6 +28,9 @@ bool ThreadInfo::ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to locate stack top/bottom. */
|
||||||
|
TryGetStackInfo(debug_handle);
|
||||||
|
|
||||||
u64 cur_fp = this->context.fp;
|
u64 cur_fp = this->context.fp;
|
||||||
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
|
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
|
||||||
/* Validate the current frame. */
|
/* Validate the current frame. */
|
||||||
|
@ -47,4 +50,49 @@ bool ThreadInfo::ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadInfo::TryGetStackInfo(Handle debug_handle) {
|
||||||
|
MemoryInfo mi;
|
||||||
|
u32 pi;
|
||||||
|
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, this->context.sp))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if sp points into the stack. */
|
||||||
|
if (mi.type == MemType_MappedMemory) {
|
||||||
|
this->stack_bottom = mi.addr;
|
||||||
|
this->stack_top = mi.addr + mi.size;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It's possible that sp is below the stack... */
|
||||||
|
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr + mi.size))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mi.type == MemType_MappedMemory) {
|
||||||
|
this->stack_bottom = mi.addr;
|
||||||
|
this->stack_top = mi.addr + mi.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadList::ReadThreadsFromProcess(Handle debug_handle, bool is_64_bit) {
|
||||||
|
u32 thread_count;
|
||||||
|
u64 thread_ids[max_thread_count];
|
||||||
|
|
||||||
|
if (R_FAILED(svcGetThreadList(&thread_count, thread_ids, max_thread_count, debug_handle))) {
|
||||||
|
this->thread_count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread_count > max_thread_count) {
|
||||||
|
thread_count = max_thread_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < thread_count; i++) {
|
||||||
|
if (this->thread_infos[this->thread_count].ReadFromProcess(debug_handle, thread_ids[this->thread_count], is_64_bit)) {
|
||||||
|
this->thread_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -42,4 +42,17 @@ class ThreadInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_bit);
|
bool ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_bit);
|
||||||
};
|
private:
|
||||||
|
void TryGetStackInfo(Handle debug_handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ThreadList {
|
||||||
|
private:
|
||||||
|
static const size_t max_thread_count = 0x60;
|
||||||
|
u32 thread_count;
|
||||||
|
ThreadInfo thread_infos[max_thread_count];
|
||||||
|
public:
|
||||||
|
ThreadList() : thread_count(0), thread_infos({}) { }
|
||||||
|
|
||||||
|
void ReadThreadsFromProcess(Handle debug_handle, bool is_64_bit);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue