mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-02-16 16:00:29 -05:00
Gekko constistancy changes. Add context item to codeview to show or copy a load/store target memory address from instructions at or near PC when paused.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -375,6 +376,55 @@ std::string PPCDebugInterface::GetDescription(u32 address) const
|
||||
return g_symbolDB.GetDescription(address);
|
||||
}
|
||||
|
||||
std::optional<u32>
|
||||
PPCDebugInterface::GetMemoryAddressFromInstruction(const std::string& instruction) const
|
||||
{
|
||||
std::regex re(",[^r0-]*(-?)(0[xX]?[0-9a-fA-F]*|r\\d+)[^r^s]*.(p|toc|\\d+)");
|
||||
std::smatch match;
|
||||
|
||||
// Instructions should be identified as a load or store before using this function. This error
|
||||
// check should never trigger.
|
||||
if (!std::regex_search(instruction, match, re))
|
||||
return std::nullopt;
|
||||
|
||||
// Output: match.str(1): negative sign for offset or no match. match.str(2): 0xNNNN, 0, or
|
||||
// rNN. Check next for 'r' to see if a gpr needs to be loaded. match.str(3): will either be p,
|
||||
// toc, or NN. Always a gpr.
|
||||
const std::string offset_match = match.str(2);
|
||||
const std::string register_match = match.str(3);
|
||||
constexpr char is_reg = 'r';
|
||||
u32 offset = 0;
|
||||
|
||||
if (is_reg == offset_match[0])
|
||||
{
|
||||
const int register_index = std::stoi(offset_match.substr(1), nullptr, 10);
|
||||
offset = (register_index == 0 ? 0 : GPR(register_index));
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = static_cast<u32>(std::stoi(offset_match, nullptr, 16));
|
||||
}
|
||||
|
||||
// sp and rtoc need to be converted to 1 and 2.
|
||||
constexpr char is_sp = 'p';
|
||||
constexpr char is_rtoc = 't';
|
||||
u32 i = 0;
|
||||
|
||||
if (is_sp == register_match[0])
|
||||
i = 1;
|
||||
else if (is_rtoc == register_match[0])
|
||||
i = 2;
|
||||
else
|
||||
i = std::stoi(register_match, nullptr, 10);
|
||||
|
||||
const u32 base_address = GPR(i);
|
||||
|
||||
if (!match.str(1).empty())
|
||||
return base_address - offset;
|
||||
|
||||
return base_address + offset;
|
||||
}
|
||||
|
||||
u32 PPCDebugInterface::GetPC() const
|
||||
{
|
||||
return PowerPC::ppcState.pc;
|
||||
|
||||
Reference in New Issue
Block a user