1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-05 19:51:45 +00:00

creport: Add 32 bits stack frames parsing support

Also fix FP, SP and LR registers being set wrongly by svcGetDebugThreadParam for 32 bits processes.
This commit is contained in:
Thomas Guillemard 2019-05-25 12:29:18 +02:00
parent 766097d0b7
commit a33ace8996
No known key found for this signature in database
GPG key ID: 0CD291558FAFDBC6
2 changed files with 43 additions and 16 deletions

View file

@ -17,11 +17,16 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
struct StackFrame { struct StackFrame64 {
u64 fp; u64 fp;
u64 lr; u64 lr;
}; };
struct StackFrame32 {
u32 fp;
u32 lr;
};
struct AttachProcessInfo { struct AttachProcessInfo {
u64 title_id; u64 title_id;
u64 process_id; u64 process_id;

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,21 +106,41 @@ 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;
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
/* Validate the current frame. */
if (cur_fp == 0 || (cur_fp & 0xF)) {
break;
}
/* Read a new frame. */ if (is_64_bit) {
StackFrame cur_frame; for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame)))) { /* Validate the current frame. */
break; if (cur_fp == 0 || (cur_fp & 0xF)) {
} break;
}
/* Advance to the next frame. */ /* Read a new frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.lr; StackFrame64 cur_frame;
cur_fp = cur_frame.fp; if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame64)))) {
break;
}
/* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.lr;
cur_fp = cur_frame.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. */
StackFrame32 cur_frame;
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame32)))) {
break;
}
/* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.lr;
cur_fp = cur_frame.fp;
}
} }
return true; return true;