Merge pull request #4316 from lioncash/debug

DebugInterface: Make GetRawMemoryString return a std::string
This commit is contained in:
Markus Wick 2016-10-08 10:48:45 +02:00 committed by GitHub
commit 0e5fc56bc9
6 changed files with 30 additions and 44 deletions

View File

@ -13,10 +13,9 @@ protected:
virtual ~DebugInterface() {} virtual ~DebugInterface() {}
public: public:
virtual std::string Disassemble(unsigned int /*address*/) { return "NODEBUGGER"; } virtual std::string Disassemble(unsigned int /*address*/) { return "NODEBUGGER"; }
virtual void GetRawMemoryString(int /*memory*/, unsigned int /*address*/, char* dest, virtual std::string GetRawMemoryString(int /*memory*/, unsigned int /*address*/)
int /*max_size*/)
{ {
strcpy(dest, "NODEBUGGER"); return "NODEBUGGER";
} }
virtual int GetInstructionSize(int /*instruction*/) { return 1; } virtual int GetInstructionSize(int /*instruction*/) { return 1; }
virtual bool IsAlive() { return true; } virtual bool IsAlive() { return true; }

View File

@ -2,16 +2,15 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/Debugger/PPCDebugInterface.h"
#include <string> #include <string>
#include "Common/GekkoDisassembler.h" #include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Debugger/Debugger_SymbolMap.h"
#include "Core/Debugger/PPCDebugInterface.h"
#include "Core/HW/DSP.h" #include "Core/HW/DSP.h"
#include "Core/HW/Memmap.h"
#include "Core/Host.h"
#include "Core/PowerPC/JitCommon/JitBase.h" #include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
@ -48,24 +47,19 @@ std::string PPCDebugInterface::Disassemble(unsigned int address)
} }
} }
void PPCDebugInterface::GetRawMemoryString(int memory, unsigned int address, char* dest, std::string PPCDebugInterface::GetRawMemoryString(int memory, unsigned int address)
int max_size)
{ {
if (IsAlive()) if (IsAlive())
{ {
if (memory || PowerPC::HostIsRAMAddress(address)) const bool is_aram = memory != 0;
{
snprintf(dest, max_size, "%08X%s", ReadExtraMemory(memory, address), memory ? " (ARAM)" : ""); if (is_aram || PowerPC::HostIsRAMAddress(address))
} return StringFromFormat("%08X%s", ReadExtraMemory(memory, address), is_aram ? " (ARAM)" : "");
else
{ return is_aram ? "--ARAM--" : "--------";
strcpy(dest, memory ? "--ARAM--" : "--------");
}
}
else
{
strcpy(dest, "<unknwn>"); // bad spelling - 8 chars
} }
return "<unknwn>"; // bad spelling - 8 chars
} }
unsigned int PPCDebugInterface::ReadMemory(unsigned int address) unsigned int PPCDebugInterface::ReadMemory(unsigned int address)

View File

@ -15,7 +15,7 @@ class PPCDebugInterface final : public DebugInterface
public: public:
PPCDebugInterface() {} PPCDebugInterface() {}
std::string Disassemble(unsigned int address) override; std::string Disassemble(unsigned int address) override;
void GetRawMemoryString(int memory, unsigned int address, char* dest, int max_size) override; std::string GetRawMemoryString(int memory, unsigned int address) override;
int GetInstructionSize(int /*instruction*/) override { return 4; } int GetInstructionSize(int /*instruction*/) override { return 4; }
bool IsAlive() override; bool IsAlive() override;
bool IsBreakpoint(unsigned int address) override; bool IsBreakpoint(unsigned int address) override;

View File

@ -2,12 +2,14 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/DSPLLE/DSPDebugInterface.h"
#include <string> #include <string>
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Core/DSP/DSPCore.h" #include "Core/DSP/DSPCore.h"
#include "Core/DSP/DSPMemoryMap.h" #include "Core/DSP/DSPMemoryMap.h"
#include "Core/HW/DSPLLE/DSPDebugInterface.h"
#include "Core/HW/DSPLLE/DSPSymbols.h" #include "Core/HW/DSPLLE/DSPSymbols.h"
std::string DSPDebugInterface::Disassemble(unsigned int address) std::string DSPDebugInterface::Disassemble(unsigned int address)
@ -16,14 +18,10 @@ std::string DSPDebugInterface::Disassemble(unsigned int address)
return DSPSymbols::GetLineText(address); return DSPSymbols::GetLineText(address);
} }
void DSPDebugInterface::GetRawMemoryString(int memory, unsigned int address, char* dest, std::string DSPDebugInterface::GetRawMemoryString(int memory, unsigned int address)
int max_size)
{ {
if (DSPCore_GetState() == DSPCORE_STOP) if (DSPCore_GetState() == DSPCORE_STOP)
{ return "";
dest[0] = 0;
return;
}
switch (memory) switch (memory)
{ {
@ -32,29 +30,25 @@ void DSPDebugInterface::GetRawMemoryString(int memory, unsigned int address, cha
{ {
case 0: case 0:
case 0x8: case 0x8:
sprintf(dest, "%04x", dsp_imem_read(address)); return StringFromFormat("%04x", dsp_imem_read(address));
break;
default: default:
sprintf(dest, "--IMEM--"); return "--IMEM--";
break;
} }
break;
case 1: // DMEM case 1: // DMEM
switch (address >> 12) switch (address >> 12)
{ {
case 0: case 0:
case 1: case 1:
sprintf(dest, "%04x (DMEM)", dsp_dmem_read(address)); return StringFromFormat("%04x (DMEM)", dsp_dmem_read(address));
break;
case 0xf: case 0xf:
sprintf(dest, "%04x (MMIO)", g_dsp.ifx_regs[address & 0xFF]); return StringFromFormat("%04x (MMIO)", g_dsp.ifx_regs[address & 0xFF]);
break;
default: default:
sprintf(dest, "--DMEM--"); return "--DMEM--";
break;
} }
break;
} }
return "";
} }
unsigned int DSPDebugInterface::ReadMemory(unsigned int address) unsigned int DSPDebugInterface::ReadMemory(unsigned int address)

View File

@ -14,7 +14,7 @@ class DSPDebugInterface final : public DebugInterface
public: public:
DSPDebugInterface() {} DSPDebugInterface() {}
std::string Disassemble(unsigned int address) override; std::string Disassemble(unsigned int address) override;
void GetRawMemoryString(int memory, unsigned int address, char* dest, int max_size) override; std::string GetRawMemoryString(int memory, unsigned int address) override;
int GetInstructionSize(int instruction) override { return 1; } int GetInstructionSize(int instruction) override { return 1; }
bool IsAlive() override; bool IsAlive() override;
bool IsBreakpoint(unsigned int address) override; bool IsBreakpoint(unsigned int address) override;

View File

@ -332,8 +332,7 @@ void CMemoryView::OnPaint(wxPaintEvent& event)
if (!IsHexMode()) if (!IsHexMode())
{ {
char mem[256]; const std::string mem = debugger->GetRawMemoryString(memory, address);
debugger->GetRawMemoryString(memory, address, mem, 256);
dc.SetTextForeground(navy_color); dc.SetTextForeground(navy_color);
draw_text(StrToWxStr(mem), 2); draw_text(StrToWxStr(mem), 2);
} }