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

@@ -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++;
}
}
}