summaryrefslogtreecommitdiff
path: root/src/core/arm/arm_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/arm/arm_interface.cpp')
-rw-r--r--src/core/arm/arm_interface.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp
index 372612c9b..7e846ddd5 100644
--- a/src/core/arm/arm_interface.cpp
+++ b/src/core/arm/arm_interface.cpp
@@ -13,7 +13,6 @@
13#include "core/memory.h" 13#include "core/memory.h"
14 14
15namespace Core { 15namespace Core {
16
17namespace { 16namespace {
18 17
19constexpr u64 ELF_DYNAMIC_TAG_NULL = 0; 18constexpr u64 ELF_DYNAMIC_TAG_NULL = 0;
@@ -61,15 +60,15 @@ static_assert(sizeof(ELFSymbol) == 0x18, "ELFSymbol has incorrect size.");
61 60
62using Symbols = std::vector<std::pair<ELFSymbol, std::string>>; 61using Symbols = std::vector<std::pair<ELFSymbol, std::string>>;
63 62
64Symbols GetSymbols(VAddr text_offset) { 63Symbols GetSymbols(VAddr text_offset, Memory::Memory& memory) {
65 const auto mod_offset = text_offset + Memory::Read32(text_offset + 4); 64 const auto mod_offset = text_offset + memory.Read32(text_offset + 4);
66 65
67 if (mod_offset < text_offset || (mod_offset & 0b11) != 0 || 66 if (mod_offset < text_offset || (mod_offset & 0b11) != 0 ||
68 Memory::Read32(mod_offset) != Common::MakeMagic('M', 'O', 'D', '0')) { 67 memory.Read32(mod_offset) != Common::MakeMagic('M', 'O', 'D', '0')) {
69 return {}; 68 return {};
70 } 69 }
71 70
72 const auto dynamic_offset = Memory::Read32(mod_offset + 0x4) + mod_offset; 71 const auto dynamic_offset = memory.Read32(mod_offset + 0x4) + mod_offset;
73 72
74 VAddr string_table_offset{}; 73 VAddr string_table_offset{};
75 VAddr symbol_table_offset{}; 74 VAddr symbol_table_offset{};
@@ -77,8 +76,8 @@ Symbols GetSymbols(VAddr text_offset) {
77 76
78 VAddr dynamic_index = dynamic_offset; 77 VAddr dynamic_index = dynamic_offset;
79 while (true) { 78 while (true) {
80 const auto tag = Memory::Read64(dynamic_index); 79 const u64 tag = memory.Read64(dynamic_index);
81 const auto value = Memory::Read64(dynamic_index + 0x8); 80 const u64 value = memory.Read64(dynamic_index + 0x8);
82 dynamic_index += 0x10; 81 dynamic_index += 0x10;
83 82
84 if (tag == ELF_DYNAMIC_TAG_NULL) { 83 if (tag == ELF_DYNAMIC_TAG_NULL) {
@@ -106,11 +105,11 @@ Symbols GetSymbols(VAddr text_offset) {
106 VAddr symbol_index = symbol_table_address; 105 VAddr symbol_index = symbol_table_address;
107 while (symbol_index < string_table_address) { 106 while (symbol_index < string_table_address) {
108 ELFSymbol symbol{}; 107 ELFSymbol symbol{};
109 Memory::ReadBlock(symbol_index, &symbol, sizeof(ELFSymbol)); 108 memory.ReadBlock(symbol_index, &symbol, sizeof(ELFSymbol));
110 109
111 VAddr string_offset = string_table_address + symbol.name_index; 110 VAddr string_offset = string_table_address + symbol.name_index;
112 std::string name; 111 std::string name;
113 for (u8 c = Memory::Read8(string_offset); c != 0; c = Memory::Read8(++string_offset)) { 112 for (u8 c = memory.Read8(string_offset); c != 0; c = memory.Read8(++string_offset)) {
114 name += static_cast<char>(c); 113 name += static_cast<char>(c);
115 } 114 }
116 115
@@ -142,28 +141,28 @@ constexpr u64 SEGMENT_BASE = 0x7100000000ull;
142 141
143std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const { 142std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const {
144 std::vector<BacktraceEntry> out; 143 std::vector<BacktraceEntry> out;
144 auto& memory = system.Memory();
145 145
146 auto fp = GetReg(29); 146 auto fp = GetReg(29);
147 auto lr = GetReg(30); 147 auto lr = GetReg(30);
148
149 while (true) { 148 while (true) {
150 out.push_back({"", 0, lr, 0}); 149 out.push_back({"", 0, lr, 0});
151 if (!fp) { 150 if (!fp) {
152 break; 151 break;
153 } 152 }
154 lr = Memory::Read64(fp + 8) - 4; 153 lr = memory.Read64(fp + 8) - 4;
155 fp = Memory::Read64(fp); 154 fp = memory.Read64(fp);
156 } 155 }
157 156
158 std::map<VAddr, std::string> modules; 157 std::map<VAddr, std::string> modules;
159 auto& loader{System::GetInstance().GetAppLoader()}; 158 auto& loader{system.GetAppLoader()};
160 if (loader.ReadNSOModules(modules) != Loader::ResultStatus::Success) { 159 if (loader.ReadNSOModules(modules) != Loader::ResultStatus::Success) {
161 return {}; 160 return {};
162 } 161 }
163 162
164 std::map<std::string, Symbols> symbols; 163 std::map<std::string, Symbols> symbols;
165 for (const auto& module : modules) { 164 for (const auto& module : modules) {
166 symbols.insert_or_assign(module.second, GetSymbols(module.first)); 165 symbols.insert_or_assign(module.second, GetSymbols(module.first, memory));
167 } 166 }
168 167
169 for (auto& entry : out) { 168 for (auto& entry : out) {