1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-06 04:01:44 +00:00

Merge pull request #548 from Thog/feature/creport-32-stack-frames

creport: Add 32 bits stack frames parsing support
This commit is contained in:
SciresM 2019-05-27 18:11:10 -07:00 committed by GitHub
commit c2cb94062a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 18 deletions

View file

@ -17,9 +17,15 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
struct StackFrame { union StackFrame {
struct {
u64 fp; u64 fp;
u64 lr; u64 lr;
} frame_64;
struct {
u32 fp;
u32 lr;
} frame_32;
}; };
struct AttachProcessInfo { struct AttachProcessInfo {

View file

@ -75,9 +75,11 @@ bool ThreadInfo::ReadFromProcess(std::map<u64, u64> &tls_map, Handle debug_handl
return false; return false;
} }
/* Don't try to parse stack frames if 32-bit. */ /* In AArch32 mode the LR, FP, and SP registers aren't set correctly in the ThreadContext by svcGetDebugThreadParam... */
if (!is_64_bit) { if (!is_64_bit) {
return true; this->context.fp = this->context.cpu_gprs[11].x;
this->context.sp = this->context.cpu_gprs[13].x;
this->context.lr = this->context.cpu_gprs[14].x;
} }
/* Parse information from TLS if present. */ /* Parse information from TLS if present. */
@ -104,6 +106,8 @@ bool ThreadInfo::ReadFromProcess(std::map<u64, u64> &tls_map, Handle debug_handl
TryGetStackInfo(debug_handle); TryGetStackInfo(debug_handle);
u64 cur_fp = this->context.fp; u64 cur_fp = this->context.fp;
if (is_64_bit) {
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. */
if (cur_fp == 0 || (cur_fp & 0xF)) { if (cur_fp == 0 || (cur_fp & 0xF)) {
@ -112,13 +116,31 @@ bool ThreadInfo::ReadFromProcess(std::map<u64, u64> &tls_map, Handle debug_handl
/* Read a new frame. */ /* Read a new frame. */
StackFrame cur_frame; StackFrame cur_frame;
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame)))) { if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(cur_frame.frame_64)))) {
break; break;
} }
/* Advance to the next frame. */ /* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.lr; this->stack_trace[this->stack_trace_size++] = cur_frame.frame_64.lr;
cur_fp = cur_frame.fp; cur_fp = cur_frame.frame_64.fp;
}
} else {
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
/* Validate the current frame. */
if (cur_fp == 0 || (cur_fp & 0x7)) {
break;
}
/* Read a new frame. */
StackFrame cur_frame;
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(cur_frame.frame_32)))) {
break;
}
/* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.frame_32.lr;
cur_fp = cur_frame.frame_32.fp;
}
} }
return true; return true;