1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 02:42:09 +00:00

creport: Implement reading info about all threads.

This commit is contained in:
Michael Scire 2018-06-25 04:07:44 -06:00
parent 5268a9f9f3
commit d65255acb8
4 changed files with 66 additions and 2 deletions

View file

@ -12,7 +12,7 @@ void CrashReport::BuildReport(u64 pid, bool has_extra_info) {
ProcessExceptions();
if (kernelAbove500()) {
/* TODO: Process Code Regions. */
/* TODO: Process Threads. */
thread_list.ReadThreadsFromProcess(this->debug_handle, Is64Bit());
}
if (IsApplication()) {

View file

@ -37,6 +37,9 @@ class CrashReport {
ExceptionInfo exception_info;
ThreadInfo crashed_thread_info;
/* Extra Info. */
ThreadList thread_list;
public:
CrashReport() : debug_handle(INVALID_HANDLE), result((Result)CrashReportResult::IncompleteReport), process_info({}), dying_message_address(0),
dying_message_size(0), dying_message{}, exception_info({}) { }

View file

@ -28,6 +28,9 @@ bool ThreadInfo::ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_
return true;
}
/* Try to locate stack top/bottom. */
TryGetStackInfo(debug_handle);
u64 cur_fp = this->context.fp;
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
/* Validate the current frame. */
@ -47,4 +50,49 @@ bool ThreadInfo::ReadFromProcess(Handle debug_handle, u64 thread_id, bool is_64_
}
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++;
}
}
}

View file

@ -42,4 +42,17 @@ class ThreadInfo {
}
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);
};