mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-09 17:14:47 -06:00
debugger: fix various issues
This commit is contained in:
parent
1d0819109c
commit
630198b344
@ -536,6 +536,10 @@ bool RPLLoader_LoadSections(sint32 aProcId, RPLModule* rplLoaderContext)
|
||||
rplLoaderContext->regionSize_loaderInfo = regionLoaderinfoSize;
|
||||
rplLoaderContext->regionSize_text = regionTextSize;
|
||||
|
||||
// set original base addresses
|
||||
rplLoaderContext->regionOrigAddr_text = regionMappingTable.region[RPL_MAPPING_REGION_TEXT].baseAddress;
|
||||
rplLoaderContext->regionOrigAddr_data = regionMappingTable.region[RPL_MAPPING_REGION_DATA].baseAddress;
|
||||
|
||||
// load data sections
|
||||
for (sint32 i = 0; i < (sint32)rplLoaderContext->rplHeader.sectionTableEntryCount; i++)
|
||||
{
|
||||
|
||||
@ -171,7 +171,9 @@ struct RPLModule
|
||||
uint32 tlsStartAddress;
|
||||
uint32 tlsEndAddress;
|
||||
uint32 regionSize_text;
|
||||
uint32 regionOrigAddr_text;
|
||||
uint32 regionSize_data;
|
||||
uint32 regionOrigAddr_data;
|
||||
uint32 regionSize_loaderInfo;
|
||||
|
||||
uint32 patchCRC; // Cemuhook style module crc for patches.txt
|
||||
|
||||
@ -84,10 +84,7 @@ RPLStoredSymbol* rplSymbolStorage_store(const char* libName, const char* symbolN
|
||||
RPLStoredSymbol* rplSymbolStorage_getByAddress(MPTR address)
|
||||
{
|
||||
std::unique_lock<std::mutex> lck(rplSymbolStorage.m_symbolStorageMutex);
|
||||
auto it = rplSymbolStorage.map_symbolByAddress.find(address);
|
||||
if (it == rplSymbolStorage.map_symbolByAddress.end())
|
||||
return nullptr;
|
||||
return it->second;
|
||||
return rplSymbolStorage.map_symbolByAddress[address];
|
||||
}
|
||||
|
||||
RPLStoredSymbol* rplSymbolStorage_getByClosestAddress(MPTR address)
|
||||
@ -96,8 +93,7 @@ RPLStoredSymbol* rplSymbolStorage_getByClosestAddress(MPTR address)
|
||||
std::unique_lock<std::mutex> lck(rplSymbolStorage.m_symbolStorageMutex);
|
||||
for(uint32 i=0; i<4096; i++)
|
||||
{
|
||||
auto it = rplSymbolStorage.map_symbolByAddress.find(address);
|
||||
RPLStoredSymbol* symbol = (it == rplSymbolStorage.map_symbolByAddress.end()) ? nullptr : it->second;
|
||||
RPLStoredSymbol* symbol = rplSymbolStorage.map_symbolByAddress[address];
|
||||
if(symbol)
|
||||
return symbol;
|
||||
address -= 4;
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
|
||||
#include "wxHelper.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "Common/FileStream.h"
|
||||
#include "config/ActiveSettings.h"
|
||||
#include "Cafe/HW/MMU/MMU.h"
|
||||
@ -88,10 +86,11 @@ DebuggerModuleInfo::DebuggerModuleInfo(RPLModule* module)
|
||||
moduleName = module->moduleName2;
|
||||
patchCRC = module->patchCRC;
|
||||
textArea.base = module->regionMappingBase_text.GetMPTR();
|
||||
textArea.origBase = module->regionOrigAddr_text;
|
||||
textArea.size = module->regionSize_text;
|
||||
dataArea.base = module->regionMappingBase_data;
|
||||
dataArea.origBase = module->regionOrigAddr_data;
|
||||
dataArea.size = module->regionSize_data;
|
||||
|
||||
}
|
||||
|
||||
struct DebuggerModuleInfoNotify : public wxClientData
|
||||
@ -129,89 +128,36 @@ static bool TryParseMapSymbolLine(std::string_view rawLine, uint32& address, std
|
||||
{
|
||||
auto line = rawLine;
|
||||
trim(line);
|
||||
if (line.empty() || line.front() == '#' || line.front() == ';')
|
||||
if (line.empty())
|
||||
return false;
|
||||
|
||||
bool foundAddress = false;
|
||||
bool foundPreferredAddress = false;
|
||||
uint32 fallbackAddress = 0;
|
||||
symbolName.clear();
|
||||
while (!line.empty())
|
||||
{
|
||||
trim(line);
|
||||
if (line.empty())
|
||||
break;
|
||||
|
||||
const auto splitIndex = line.find_first_of(" \t");
|
||||
auto token = splitIndex == std::string_view::npos ? line : line.substr(0, splitIndex);
|
||||
line = splitIndex == std::string_view::npos ? std::string_view{} : line.substr(splitIndex + 1);
|
||||
trim(token, "\t\n\v\f\r ,:;()[]");
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
if (!foundAddress)
|
||||
{
|
||||
if (TryParseMapAddress(token, address))
|
||||
{
|
||||
foundAddress = true;
|
||||
fallbackAddress = address;
|
||||
if (address >= MEMORY_CODEAREA_ADDR)
|
||||
foundPreferredAddress = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32 parsedAddress = 0;
|
||||
if (TryParseMapAddress(token, parsedAddress))
|
||||
{
|
||||
if (parsedAddress >= MEMORY_CODEAREA_ADDR)
|
||||
{
|
||||
address = parsedAddress;
|
||||
foundPreferredAddress = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string lowerToken(token);
|
||||
std::transform(lowerToken.begin(), lowerToken.end(), lowerToken.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
if (lowerToken == "load" || lowerToken == "provide" || lowerToken == "assert" || lowerToken == "*fill*" || lowerToken == "=")
|
||||
continue;
|
||||
if (lowerToken.find('/') != std::string::npos || lowerToken.find('\\') != std::string::npos)
|
||||
continue;
|
||||
if (lowerToken.find(".a(") != std::string::npos || lowerToken.find(".o(") != std::string::npos || lowerToken.find(".obj(") != std::string::npos)
|
||||
continue;
|
||||
if (lowerToken.ends_with(".o") || lowerToken.ends_with(".obj") || lowerToken.ends_with(".a") || lowerToken.ends_with(".lib"))
|
||||
continue;
|
||||
|
||||
if (symbolName.empty())
|
||||
symbolName.assign(token);
|
||||
}
|
||||
|
||||
if (!foundAddress || symbolName.empty())
|
||||
const auto addressEnd = line.find_first_of(" \t");
|
||||
if (addressEnd == std::string_view::npos)
|
||||
return false;
|
||||
if (!TryParseMapAddress(line.substr(0, addressEnd), address))
|
||||
return false;
|
||||
|
||||
if (!foundPreferredAddress)
|
||||
address = fallbackAddress;
|
||||
line = line.substr(addressEnd + 1);
|
||||
trim(line);
|
||||
if (line.empty())
|
||||
return false;
|
||||
|
||||
const auto symbolEnd = line.find_first_of(" \t");
|
||||
auto symbolToken = symbolEnd == std::string_view::npos ? line : line.substr(0, symbolEnd);
|
||||
trim(symbolToken);
|
||||
if (symbolToken.empty())
|
||||
return false;
|
||||
|
||||
symbolName.assign(symbolToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::optional<MPTR> GetRelocatedMapAddress(const DebuggerModuleInfo& moduleInfo, uint32 mapAddress)
|
||||
{
|
||||
if (moduleInfo.textArea.ContainsAddress(mapAddress) || moduleInfo.dataArea.ContainsAddress(mapAddress))
|
||||
return mapAddress;
|
||||
|
||||
if (mapAddress < moduleInfo.textArea.size)
|
||||
return moduleInfo.textArea.base + mapAddress;
|
||||
if (mapAddress < moduleInfo.dataArea.size)
|
||||
return moduleInfo.dataArea.base + mapAddress;
|
||||
|
||||
if (mapAddress >= MEMORY_CODEAREA_ADDR && mapAddress < (MEMORY_CODEAREA_ADDR + moduleInfo.textArea.size))
|
||||
return moduleInfo.textArea.base + (mapAddress - MEMORY_CODEAREA_ADDR);
|
||||
|
||||
if (mapAddress >= MEMORY_DATA_AREA_ADDR && mapAddress < (MEMORY_DATA_AREA_ADDR + moduleInfo.dataArea.size))
|
||||
return moduleInfo.dataArea.base + (mapAddress - MEMORY_DATA_AREA_ADDR);
|
||||
|
||||
if (moduleInfo.textArea.ContainsOriginalAddress(mapAddress))
|
||||
return moduleInfo.textArea.base + (mapAddress - moduleInfo.textArea.origBase);
|
||||
if (moduleInfo.dataArea.ContainsOriginalAddress(mapAddress))
|
||||
return moduleInfo.dataArea.base + (mapAddress - moduleInfo.dataArea.origBase);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@ -10,10 +10,6 @@
|
||||
#include <wx/frame.h>
|
||||
#include <wx/mstream.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class BreakpointWindow;
|
||||
class RegisterWindow;
|
||||
class DumpWindow;
|
||||
@ -59,12 +55,18 @@ struct DebuggerModuleInfo
|
||||
struct ModuleArea
|
||||
{
|
||||
MPTR base;
|
||||
MPTR origBase;
|
||||
uint32 size;
|
||||
|
||||
bool ContainsAddress(MPTR addr) const
|
||||
{
|
||||
return addr >= base && (addr < (base+size));
|
||||
}
|
||||
|
||||
bool ContainsOriginalAddress(MPTR addr) const
|
||||
{
|
||||
return addr >= origBase && (addr < (origBase + size));
|
||||
}
|
||||
};
|
||||
|
||||
std::string moduleName;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user