Merge pull request #8235 from lioncash/move

Common/DebugInterface: Minor cleanup changes
This commit is contained in:
Anthony 2019-07-22 15:07:14 -07:00 committed by GitHub
commit 66e7a11139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 172 additions and 155 deletions

View File

@ -9,12 +9,12 @@
namespace Common::Debug namespace Common::Debug
{ {
Watch::Watch(u32 address_, const std::string& name_, Watch::State is_enabled_) Watch::Watch(u32 address_, std::string name_, State is_enabled_)
: address(address_), name(name_), is_enabled(is_enabled_) : address(address_), name(std::move(name_)), is_enabled(is_enabled_)
{ {
} }
std::size_t Watches::SetWatch(u32 address, const std::string& name) std::size_t Watches::SetWatch(u32 address, std::string name)
{ {
const std::size_t size = m_watches.size(); const std::size_t size = m_watches.size();
for (std::size_t index = 0; index < size; index++) for (std::size_t index = 0; index < size; index++)
@ -25,7 +25,7 @@ std::size_t Watches::SetWatch(u32 address, const std::string& name)
return index; return index;
} }
} }
m_watches.emplace_back(address, name, Watch::State::Enabled); m_watches.emplace_back(address, std::move(name), Watch::State::Enabled);
return size; return size;
} }
@ -46,10 +46,10 @@ void Watches::UnsetWatch(u32 address)
m_watches.end()); m_watches.end());
} }
void Watches::UpdateWatch(std::size_t index, u32 address, const std::string& name) void Watches::UpdateWatch(std::size_t index, u32 address, std::string name)
{ {
m_watches[index].address = address; m_watches[index].address = address;
m_watches[index].name = name; m_watches[index].name = std::move(name);
} }
void Watches::UpdateWatchAddress(std::size_t index, u32 address) void Watches::UpdateWatchAddress(std::size_t index, u32 address)
@ -57,9 +57,9 @@ void Watches::UpdateWatchAddress(std::size_t index, u32 address)
m_watches[index].address = address; m_watches[index].address = address;
} }
void Watches::UpdateWatchName(std::size_t index, const std::string& name) void Watches::UpdateWatchName(std::size_t index, std::string name)
{ {
m_watches[index].name = name; m_watches[index].name = std::move(name);
} }
void Watches::EnableWatch(std::size_t index) void Watches::EnableWatch(std::size_t index)

View File

@ -24,19 +24,19 @@ struct Watch
std::string name; std::string name;
State is_enabled; State is_enabled;
Watch(u32 address, const std::string& name, State is_enabled); Watch(u32 address, std::string name, State is_enabled);
}; };
class Watches class Watches
{ {
public: public:
std::size_t SetWatch(u32 address, const std::string& name); std::size_t SetWatch(u32 address, std::string name);
const Watch& GetWatch(std::size_t index) const; const Watch& GetWatch(std::size_t index) const;
const std::vector<Watch>& GetWatches() const; const std::vector<Watch>& GetWatches() const;
void UnsetWatch(u32 address); void UnsetWatch(u32 address);
void UpdateWatch(std::size_t index, u32 address, const std::string& name); void UpdateWatch(std::size_t index, u32 address, std::string name);
void UpdateWatchAddress(std::size_t index, u32 address); void UpdateWatchAddress(std::size_t index, u32 address);
void UpdateWatchName(std::size_t index, const std::string& name); void UpdateWatchName(std::size_t index, std::string name);
void EnableWatch(std::size_t index); void EnableWatch(std::size_t index);
void DisableWatch(std::size_t index); void DisableWatch(std::size_t index);
bool HasEnabledWatch(u32 address) const; bool HasEnabledWatch(u32 address) const;

View File

@ -5,30 +5,33 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Debug/MemoryPatches.h"
#include "Common/Debug/Watches.h" namespace Common::Debug
{
struct MemoryPatch;
struct Watch;
} // namespace Common::Debug
namespace Common namespace Common
{ {
class DebugInterface class DebugInterface
{ {
protected: protected:
virtual ~DebugInterface() {} virtual ~DebugInterface() = default;
public: public:
// Watches // Watches
virtual std::size_t SetWatch(u32 address, const std::string& name = "") = 0; virtual std::size_t SetWatch(u32 address, std::string name = "") = 0;
virtual const Common::Debug::Watch& GetWatch(std::size_t index) const = 0; virtual const Debug::Watch& GetWatch(std::size_t index) const = 0;
virtual const std::vector<Common::Debug::Watch>& GetWatches() const = 0; virtual const std::vector<Debug::Watch>& GetWatches() const = 0;
virtual void UnsetWatch(u32 address) = 0; virtual void UnsetWatch(u32 address) = 0;
virtual void UpdateWatch(std::size_t index, u32 address, const std::string& name) = 0; virtual void UpdateWatch(std::size_t index, u32 address, std::string name) = 0;
virtual void UpdateWatchAddress(std::size_t index, u32 address) = 0; virtual void UpdateWatchAddress(std::size_t index, u32 address) = 0;
virtual void UpdateWatchName(std::size_t index, const std::string& name) = 0; virtual void UpdateWatchName(std::size_t index, std::string name) = 0;
virtual void EnableWatch(std::size_t index) = 0; virtual void EnableWatch(std::size_t index) = 0;
virtual void DisableWatch(std::size_t index) = 0; virtual void DisableWatch(std::size_t index) = 0;
virtual bool HasEnabledWatch(u32 address) const = 0; virtual bool HasEnabledWatch(u32 address) const = 0;
@ -40,7 +43,7 @@ public:
// Memory Patches // Memory Patches
virtual void SetPatch(u32 address, u32 value) = 0; virtual void SetPatch(u32 address, u32 value) = 0;
virtual void SetPatch(u32 address, std::vector<u8> value) = 0; virtual void SetPatch(u32 address, std::vector<u8> value) = 0;
virtual const std::vector<Common::Debug::MemoryPatch>& GetPatches() const = 0; virtual const std::vector<Debug::MemoryPatch>& GetPatches() const = 0;
virtual void UnsetPatch(u32 address) = 0; virtual void UnsetPatch(u32 address) = 0;
virtual void EnablePatch(std::size_t index) = 0; virtual void EnablePatch(std::size_t index) = 0;
virtual void DisablePatch(std::size_t index) = 0; virtual void DisablePatch(std::size_t index) = 0;
@ -48,33 +51,30 @@ public:
virtual void RemovePatch(std::size_t index) = 0; virtual void RemovePatch(std::size_t index) = 0;
virtual void ClearPatches() = 0; virtual void ClearPatches() = 0;
virtual std::string Disassemble(unsigned int /*address*/) { return "NODEBUGGER"; } virtual std::string Disassemble(u32 /*address*/) const { return "NODEBUGGER"; }
virtual std::string GetRawMemoryString(int /*memory*/, unsigned int /*address*/) virtual std::string GetRawMemoryString(int /*memory*/, u32 /*address*/) const
{ {
return "NODEBUGGER"; return "NODEBUGGER";
} }
virtual int GetInstructionSize(int /*instruction*/) { return 1; } virtual bool IsAlive() const { return true; }
virtual bool IsAlive() { return true; } virtual bool IsBreakpoint(u32 /*address*/) const { return false; }
virtual bool IsBreakpoint(unsigned int /*address*/) { return false; } virtual void SetBreakpoint(u32 /*address*/) {}
virtual void SetBreakpoint(unsigned int /*address*/) {} virtual void ClearBreakpoint(u32 /*address*/) {}
virtual void ClearBreakpoint(unsigned int /*address*/) {}
virtual void ClearAllBreakpoints() {} virtual void ClearAllBreakpoints() {}
virtual void ToggleBreakpoint(unsigned int /*address*/) {} virtual void ToggleBreakpoint(u32 /*address*/) {}
virtual void ClearAllMemChecks() {} virtual void ClearAllMemChecks() {}
virtual bool IsMemCheck(unsigned int /*address*/, size_t /*size*/) { return false; } virtual bool IsMemCheck(u32 /*address*/, size_t /*size*/) const { return false; }
virtual void ToggleMemCheck(unsigned int /*address*/, bool /*read*/, bool /*write*/, bool /*log*/) virtual void ToggleMemCheck(u32 /*address*/, bool /*read*/, bool /*write*/, bool /*log*/) {}
{ virtual u32 ReadMemory(u32 /*address*/) const { return 0; }
} virtual void WriteExtraMemory(int /*memory*/, u32 /*value*/, u32 /*address*/) {}
virtual unsigned int ReadMemory(unsigned int /*address*/) { return 0; } virtual u32 ReadExtraMemory(int /*memory*/, u32 /*address*/) const { return 0; }
virtual void WriteExtraMemory(int /*memory*/, unsigned int /*value*/, unsigned int /*address*/) {} virtual u32 ReadInstruction(u32 /*address*/) const { return 0; }
virtual unsigned int ReadExtraMemory(int /*memory*/, unsigned int /*address*/) { return 0; } virtual u32 GetPC() const { return 0; }
virtual unsigned int ReadInstruction(unsigned int /*address*/) { return 0; } virtual void SetPC(u32 /*address*/) {}
virtual unsigned int GetPC() { return 0; }
virtual void SetPC(unsigned int /*address*/) {}
virtual void Step() {} virtual void Step() {}
virtual void RunToBreakpoint() {} virtual void RunToBreakpoint() {}
virtual int GetColor(unsigned int /*address*/) { return 0xFFFFFFFF; } virtual u32 GetColor(u32 /*address*/) const { return 0xFFFFFFFF; }
virtual std::string GetDescription(unsigned int /*address*/) = 0; virtual std::string GetDescription(u32 /*address*/) const = 0;
virtual void Clear() = 0; virtual void Clear() = 0;
}; };
} // namespace Common } // namespace Common

View File

@ -4,12 +4,14 @@
#include "Core/Debugger/PPCDebugInterface.h" #include "Core/Debugger/PPCDebugInterface.h"
#include <array>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <fmt/format.h>
#include "Common/Align.h" #include "Common/Align.h"
#include "Common/GekkoDisassembler.h" #include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/DSP.h" #include "Core/HW/DSP.h"
@ -44,9 +46,12 @@ void PPCPatches::Patch(std::size_t index)
} }
} }
std::size_t PPCDebugInterface::SetWatch(u32 address, const std::string& name) PPCDebugInterface::PPCDebugInterface() = default;
PPCDebugInterface::~PPCDebugInterface() = default;
std::size_t PPCDebugInterface::SetWatch(u32 address, std::string name)
{ {
return m_watches.SetWatch(address, name); return m_watches.SetWatch(address, std::move(name));
} }
const Common::Debug::Watch& PPCDebugInterface::GetWatch(std::size_t index) const const Common::Debug::Watch& PPCDebugInterface::GetWatch(std::size_t index) const
@ -64,9 +69,9 @@ void PPCDebugInterface::UnsetWatch(u32 address)
m_watches.UnsetWatch(address); m_watches.UnsetWatch(address);
} }
void PPCDebugInterface::UpdateWatch(std::size_t index, u32 address, const std::string& name) void PPCDebugInterface::UpdateWatch(std::size_t index, u32 address, std::string name)
{ {
return m_watches.UpdateWatch(index, address, name); return m_watches.UpdateWatch(index, address, std::move(name));
} }
void PPCDebugInterface::UpdateWatchAddress(std::size_t index, u32 address) void PPCDebugInterface::UpdateWatchAddress(std::size_t index, u32 address)
@ -74,9 +79,9 @@ void PPCDebugInterface::UpdateWatchAddress(std::size_t index, u32 address)
return m_watches.UpdateWatchAddress(index, address); return m_watches.UpdateWatchAddress(index, address);
} }
void PPCDebugInterface::UpdateWatchName(std::size_t index, const std::string& name) void PPCDebugInterface::UpdateWatchName(std::size_t index, std::string name)
{ {
return m_watches.UpdateWatchName(index, name); return m_watches.UpdateWatchName(index, std::move(name));
} }
void PPCDebugInterface::EnableWatch(std::size_t index) void PPCDebugInterface::EnableWatch(std::size_t index)
@ -121,7 +126,7 @@ void PPCDebugInterface::SetPatch(u32 address, u32 value)
void PPCDebugInterface::SetPatch(u32 address, std::vector<u8> value) void PPCDebugInterface::SetPatch(u32 address, std::vector<u8> value)
{ {
m_patches.SetPatch(address, value); m_patches.SetPatch(address, std::move(value));
} }
const std::vector<Common::Debug::MemoryPatch>& PPCDebugInterface::GetPatches() const const std::vector<Common::Debug::MemoryPatch>& PPCDebugInterface::GetPatches() const
@ -159,7 +164,7 @@ void PPCDebugInterface::ClearPatches()
m_patches.ClearPatches(); m_patches.ClearPatches();
} }
std::string PPCDebugInterface::Disassemble(unsigned int address) std::string PPCDebugInterface::Disassemble(u32 address) const
{ {
// PowerPC::HostRead_U32 seemed to crash on shutdown // PowerPC::HostRead_U32 seemed to crash on shutdown
if (!IsAlive()) if (!IsAlive())
@ -189,14 +194,14 @@ std::string PPCDebugInterface::Disassemble(unsigned int address)
} }
} }
std::string PPCDebugInterface::GetRawMemoryString(int memory, unsigned int address) std::string PPCDebugInterface::GetRawMemoryString(int memory, u32 address) const
{ {
if (IsAlive()) if (IsAlive())
{ {
const bool is_aram = memory != 0; const bool is_aram = memory != 0;
if (is_aram || PowerPC::HostIsRAMAddress(address)) if (is_aram || PowerPC::HostIsRAMAddress(address))
return StringFromFormat("%08X%s", ReadExtraMemory(memory, address), is_aram ? " (ARAM)" : ""); return fmt::format("{:08X}{}", ReadExtraMemory(memory, address), is_aram ? " (ARAM)" : "");
return is_aram ? "--ARAM--" : "--------"; return is_aram ? "--ARAM--" : "--------";
} }
@ -204,12 +209,12 @@ std::string PPCDebugInterface::GetRawMemoryString(int memory, unsigned int addre
return "<unknwn>"; // bad spelling - 8 chars return "<unknwn>"; // bad spelling - 8 chars
} }
unsigned int PPCDebugInterface::ReadMemory(unsigned int address) u32 PPCDebugInterface::ReadMemory(u32 address) const
{ {
return PowerPC::HostRead_U32(address); return PowerPC::HostRead_U32(address);
} }
unsigned int PPCDebugInterface::ReadExtraMemory(int memory, unsigned int address) u32 PPCDebugInterface::ReadExtraMemory(int memory, u32 address) const
{ {
switch (memory) switch (memory)
{ {
@ -223,27 +228,27 @@ unsigned int PPCDebugInterface::ReadExtraMemory(int memory, unsigned int address
} }
} }
unsigned int PPCDebugInterface::ReadInstruction(unsigned int address) u32 PPCDebugInterface::ReadInstruction(u32 address) const
{ {
return PowerPC::HostRead_Instruction(address); return PowerPC::HostRead_Instruction(address);
} }
bool PPCDebugInterface::IsAlive() bool PPCDebugInterface::IsAlive() const
{ {
return Core::IsRunningAndStarted(); return Core::IsRunningAndStarted();
} }
bool PPCDebugInterface::IsBreakpoint(unsigned int address) bool PPCDebugInterface::IsBreakpoint(u32 address) const
{ {
return PowerPC::breakpoints.IsAddressBreakPoint(address); return PowerPC::breakpoints.IsAddressBreakPoint(address);
} }
void PPCDebugInterface::SetBreakpoint(unsigned int address) void PPCDebugInterface::SetBreakpoint(u32 address)
{ {
PowerPC::breakpoints.Add(address); PowerPC::breakpoints.Add(address);
} }
void PPCDebugInterface::ClearBreakpoint(unsigned int address) void PPCDebugInterface::ClearBreakpoint(u32 address)
{ {
PowerPC::breakpoints.Remove(address); PowerPC::breakpoints.Remove(address);
} }
@ -253,7 +258,7 @@ void PPCDebugInterface::ClearAllBreakpoints()
PowerPC::breakpoints.Clear(); PowerPC::breakpoints.Clear();
} }
void PPCDebugInterface::ToggleBreakpoint(unsigned int address) void PPCDebugInterface::ToggleBreakpoint(u32 address)
{ {
if (PowerPC::breakpoints.IsAddressBreakPoint(address)) if (PowerPC::breakpoints.IsAddressBreakPoint(address))
PowerPC::breakpoints.Remove(address); PowerPC::breakpoints.Remove(address);
@ -266,12 +271,12 @@ void PPCDebugInterface::ClearAllMemChecks()
PowerPC::memchecks.Clear(); PowerPC::memchecks.Clear();
} }
bool PPCDebugInterface::IsMemCheck(unsigned int address, size_t size) bool PPCDebugInterface::IsMemCheck(u32 address, size_t size) const
{ {
return PowerPC::memchecks.GetMemCheck(address, size) != nullptr; return PowerPC::memchecks.GetMemCheck(address, size) != nullptr;
} }
void PPCDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool write, bool log) void PPCDebugInterface::ToggleMemCheck(u32 address, bool read, bool write, bool log)
{ {
if (!IsMemCheck(address)) if (!IsMemCheck(address))
{ {
@ -296,13 +301,20 @@ void PPCDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool wri
// ======================================================= // =======================================================
// Separate the blocks with colors. // Separate the blocks with colors.
// ------------- // -------------
int PPCDebugInterface::GetColor(unsigned int address) u32 PPCDebugInterface::GetColor(u32 address) const
{ {
if (!IsAlive()) if (!IsAlive())
return 0xFFFFFF; return 0xFFFFFF;
if (!PowerPC::HostIsRAMAddress(address)) if (!PowerPC::HostIsRAMAddress(address))
return 0xeeeeee; return 0xeeeeee;
static const int colors[6] = {
Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF;
static constexpr std::array<u32, 6> colors{
0xd0FFFF, // light cyan 0xd0FFFF, // light cyan
0xFFd0d0, // light red 0xFFd0d0, // light red
0xd8d8FF, // light blue 0xd8d8FF, // light blue
@ -310,26 +322,21 @@ int PPCDebugInterface::GetColor(unsigned int address)
0xd0FFd0, // light green 0xd0FFd0, // light green
0xFFFFd0, // light yellow 0xFFFFd0, // light yellow
}; };
Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address); return colors[symbol->index % colors.size()];
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF;
return colors[symbol->index % 6];
} }
// ============= // =============
std::string PPCDebugInterface::GetDescription(unsigned int address) std::string PPCDebugInterface::GetDescription(u32 address) const
{ {
return g_symbolDB.GetDescription(address); return g_symbolDB.GetDescription(address);
} }
unsigned int PPCDebugInterface::GetPC() u32 PPCDebugInterface::GetPC() const
{ {
return PowerPC::ppcState.pc; return PowerPC::ppcState.pc;
} }
void PPCDebugInterface::SetPC(unsigned int address) void PPCDebugInterface::SetPC(u32 address)
{ {
PowerPC::ppcState.pc = address; PowerPC::ppcState.pc = address;
} }

View File

@ -7,6 +7,8 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include "Common/Debug/MemoryPatches.h"
#include "Common/Debug/Watches.h"
#include "Common/DebugInterface.h" #include "Common/DebugInterface.h"
class PPCPatches : public Common::Debug::MemoryPatches class PPCPatches : public Common::Debug::MemoryPatches
@ -20,15 +22,17 @@ private:
class PPCDebugInterface final : public Common::DebugInterface class PPCDebugInterface final : public Common::DebugInterface
{ {
public: public:
PPCDebugInterface() {} PPCDebugInterface();
~PPCDebugInterface() override;
// Watches // Watches
std::size_t SetWatch(u32 address, const std::string& name = "") override; std::size_t SetWatch(u32 address, std::string name = "") override;
const Common::Debug::Watch& GetWatch(std::size_t index) const override; const Common::Debug::Watch& GetWatch(std::size_t index) const override;
const std::vector<Common::Debug::Watch>& GetWatches() const override; const std::vector<Common::Debug::Watch>& GetWatches() const override;
void UnsetWatch(u32 address) override; void UnsetWatch(u32 address) override;
void UpdateWatch(std::size_t index, u32 address, const std::string& name) override; void UpdateWatch(std::size_t index, u32 address, std::string name) override;
void UpdateWatchAddress(std::size_t index, u32 address) override; void UpdateWatchAddress(std::size_t index, u32 address) override;
void UpdateWatchName(std::size_t index, const std::string& name) override; void UpdateWatchName(std::size_t index, std::string name) override;
void EnableWatch(std::size_t index) override; void EnableWatch(std::size_t index) override;
void DisableWatch(std::size_t index) override; void DisableWatch(std::size_t index) override;
bool HasEnabledWatch(u32 address) const override; bool HasEnabledWatch(u32 address) const override;
@ -48,34 +52,32 @@ public:
void RemovePatch(std::size_t index) override; void RemovePatch(std::size_t index) override;
void ClearPatches() override; void ClearPatches() override;
std::string Disassemble(unsigned int address) override; std::string Disassemble(u32 address) const override;
std::string GetRawMemoryString(int memory, unsigned int address) override; std::string GetRawMemoryString(int memory, u32 address) const override;
int GetInstructionSize(int /*instruction*/) override { return 4; } bool IsAlive() const override;
bool IsAlive() override; bool IsBreakpoint(u32 address) const override;
bool IsBreakpoint(unsigned int address) override; void SetBreakpoint(u32 address) override;
void SetBreakpoint(unsigned int address) override; void ClearBreakpoint(u32 address) override;
void ClearBreakpoint(unsigned int address) override;
void ClearAllBreakpoints() override; void ClearAllBreakpoints() override;
void ToggleBreakpoint(unsigned int address) override; void ToggleBreakpoint(u32 address) override;
void ClearAllMemChecks() override; void ClearAllMemChecks() override;
bool IsMemCheck(unsigned int address, size_t size = 1) override; bool IsMemCheck(u32 address, size_t size = 1) const override;
void ToggleMemCheck(unsigned int address, bool read = true, bool write = true, void ToggleMemCheck(u32 address, bool read = true, bool write = true, bool log = true) override;
bool log = true) override; u32 ReadMemory(u32 address) const override;
unsigned int ReadMemory(unsigned int address) override;
enum enum
{ {
EXTRAMEM_ARAM = 1, EXTRAMEM_ARAM = 1,
}; };
unsigned int ReadExtraMemory(int memory, unsigned int address) override; u32 ReadExtraMemory(int memory, u32 address) const override;
unsigned int ReadInstruction(unsigned int address) override; u32 ReadInstruction(u32 address) const override;
unsigned int GetPC() override; u32 GetPC() const override;
void SetPC(unsigned int address) override; void SetPC(u32 address) override;
void Step() override {} void Step() override {}
void RunToBreakpoint() override; void RunToBreakpoint() override;
int GetColor(unsigned int address) override; u32 GetColor(u32 address) const override;
std::string GetDescription(unsigned int address) override; std::string GetDescription(u32 address) const override;
void Clear() override; void Clear() override;

View File

@ -4,11 +4,13 @@
#include "Core/HW/DSPLLE/DSPDebugInterface.h" #include "Core/HW/DSPLLE/DSPDebugInterface.h"
#include <array>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <fmt/format.h>
#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/DSPSymbols.h" #include "Core/HW/DSPLLE/DSPSymbols.h"
@ -20,9 +22,12 @@ void DSPPatches::Patch(std::size_t index)
PanicAlert("Patch functionality not supported in DSP module."); PanicAlert("Patch functionality not supported in DSP module.");
} }
std::size_t DSPDebugInterface::SetWatch(u32 address, const std::string& name) DSPDebugInterface::DSPDebugInterface() = default;
DSPDebugInterface::~DSPDebugInterface() = default;
std::size_t DSPDebugInterface::SetWatch(u32 address, std::string name)
{ {
return m_watches.SetWatch(address, name); return m_watches.SetWatch(address, std::move(name));
} }
const Common::Debug::Watch& DSPDebugInterface::GetWatch(std::size_t index) const const Common::Debug::Watch& DSPDebugInterface::GetWatch(std::size_t index) const
@ -40,9 +45,9 @@ void DSPDebugInterface::UnsetWatch(u32 address)
m_watches.UnsetWatch(address); m_watches.UnsetWatch(address);
} }
void DSPDebugInterface::UpdateWatch(std::size_t index, u32 address, const std::string& name) void DSPDebugInterface::UpdateWatch(std::size_t index, u32 address, std::string name)
{ {
return m_watches.UpdateWatch(index, address, name); return m_watches.UpdateWatch(index, address, std::move(name));
} }
void DSPDebugInterface::UpdateWatchAddress(std::size_t index, u32 address) void DSPDebugInterface::UpdateWatchAddress(std::size_t index, u32 address)
@ -50,9 +55,9 @@ void DSPDebugInterface::UpdateWatchAddress(std::size_t index, u32 address)
return m_watches.UpdateWatchAddress(index, address); return m_watches.UpdateWatchAddress(index, address);
} }
void DSPDebugInterface::UpdateWatchName(std::size_t index, const std::string& name) void DSPDebugInterface::UpdateWatchName(std::size_t index, std::string name)
{ {
return m_watches.UpdateWatchName(index, name); return m_watches.UpdateWatchName(index, std::move(name));
} }
void DSPDebugInterface::EnableWatch(std::size_t index) void DSPDebugInterface::EnableWatch(std::size_t index)
@ -97,7 +102,7 @@ void DSPDebugInterface::SetPatch(u32 address, u32 value)
void DSPDebugInterface::SetPatch(u32 address, std::vector<u8> value) void DSPDebugInterface::SetPatch(u32 address, std::vector<u8> value)
{ {
m_patches.SetPatch(address, value); m_patches.SetPatch(address, std::move(value));
} }
const std::vector<Common::Debug::MemoryPatch>& DSPDebugInterface::GetPatches() const const std::vector<Common::Debug::MemoryPatch>& DSPDebugInterface::GetPatches() const
@ -135,13 +140,13 @@ void DSPDebugInterface::ClearPatches()
m_patches.ClearPatches(); m_patches.ClearPatches();
} }
std::string DSPDebugInterface::Disassemble(unsigned int address) std::string DSPDebugInterface::Disassemble(u32 address) const
{ {
// we'll treat addresses as line numbers. // we'll treat addresses as line numbers.
return Symbols::GetLineText(address); return Symbols::GetLineText(address);
} }
std::string DSPDebugInterface::GetRawMemoryString(int memory, unsigned int address) std::string DSPDebugInterface::GetRawMemoryString(int memory, u32 address) const
{ {
if (DSPCore_GetState() == State::Stopped) if (DSPCore_GetState() == State::Stopped)
return ""; return "";
@ -153,7 +158,7 @@ std::string DSPDebugInterface::GetRawMemoryString(int memory, unsigned int addre
{ {
case 0: case 0:
case 0x8: case 0x8:
return StringFromFormat("%04x", dsp_imem_read(address)); return fmt::format("{:04x}", dsp_imem_read(address));
default: default:
return "--IMEM--"; return "--IMEM--";
} }
@ -163,9 +168,9 @@ std::string DSPDebugInterface::GetRawMemoryString(int memory, unsigned int addre
{ {
case 0: case 0:
case 1: case 1:
return StringFromFormat("%04x (DMEM)", dsp_dmem_read(address)); return fmt::format("{:04x} (DMEM)", dsp_dmem_read(address));
case 0xf: case 0xf:
return StringFromFormat("%04x (MMIO)", g_dsp.ifx_regs[address & 0xFF]); return fmt::format("{:04x} (MMIO)", g_dsp.ifx_regs[address & 0xFF]);
default: default:
return "--DMEM--"; return "--DMEM--";
} }
@ -174,22 +179,22 @@ std::string DSPDebugInterface::GetRawMemoryString(int memory, unsigned int addre
return ""; return "";
} }
unsigned int DSPDebugInterface::ReadMemory(unsigned int address) u32 DSPDebugInterface::ReadMemory(u32 address) const
{ {
return 0; return 0;
} }
unsigned int DSPDebugInterface::ReadInstruction(unsigned int address) u32 DSPDebugInterface::ReadInstruction(u32 address) const
{ {
return 0; return 0;
} }
bool DSPDebugInterface::IsAlive() bool DSPDebugInterface::IsAlive() const
{ {
return true; return true;
} }
bool DSPDebugInterface::IsBreakpoint(unsigned int address) bool DSPDebugInterface::IsBreakpoint(u32 address) const
{ {
int real_addr = Symbols::Line2Addr(address); int real_addr = Symbols::Line2Addr(address);
if (real_addr >= 0) if (real_addr >= 0)
@ -198,7 +203,7 @@ bool DSPDebugInterface::IsBreakpoint(unsigned int address)
return false; return false;
} }
void DSPDebugInterface::SetBreakpoint(unsigned int address) void DSPDebugInterface::SetBreakpoint(u32 address)
{ {
int real_addr = Symbols::Line2Addr(address); int real_addr = Symbols::Line2Addr(address);
@ -208,7 +213,7 @@ void DSPDebugInterface::SetBreakpoint(unsigned int address)
} }
} }
void DSPDebugInterface::ClearBreakpoint(unsigned int address) void DSPDebugInterface::ClearBreakpoint(u32 address)
{ {
int real_addr = Symbols::Line2Addr(address); int real_addr = Symbols::Line2Addr(address);
@ -223,7 +228,7 @@ void DSPDebugInterface::ClearAllBreakpoints()
g_dsp_breakpoints.Clear(); g_dsp_breakpoints.Clear();
} }
void DSPDebugInterface::ToggleBreakpoint(unsigned int address) void DSPDebugInterface::ToggleBreakpoint(u32 address)
{ {
int real_addr = Symbols::Line2Addr(address); int real_addr = Symbols::Line2Addr(address);
if (real_addr >= 0) if (real_addr >= 0)
@ -235,7 +240,7 @@ void DSPDebugInterface::ToggleBreakpoint(unsigned int address)
} }
} }
bool DSPDebugInterface::IsMemCheck(unsigned int address, size_t size) bool DSPDebugInterface::IsMemCheck(u32 address, size_t size) const
{ {
return false; return false;
} }
@ -245,7 +250,7 @@ void DSPDebugInterface::ClearAllMemChecks()
PanicAlert("MemCheck functionality not supported in DSP module."); PanicAlert("MemCheck functionality not supported in DSP module.");
} }
void DSPDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool write, bool log) void DSPDebugInterface::ToggleMemCheck(u32 address, bool read, bool write, bool log)
{ {
PanicAlert("MemCheck functionality not supported in DSP module."); PanicAlert("MemCheck functionality not supported in DSP module.");
} }
@ -253,17 +258,8 @@ void DSPDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool wri
// ======================================================= // =======================================================
// Separate the blocks with colors. // Separate the blocks with colors.
// ------------- // -------------
int DSPDebugInterface::GetColor(unsigned int address) u32 DSPDebugInterface::GetColor(u32 address) const
{ {
static const int colors[6] = {
0xd0FFFF, // light cyan
0xFFd0d0, // light red
0xd8d8FF, // light blue
0xFFd0FF, // light purple
0xd0FFd0, // light green
0xFFFFd0, // light yellow
};
// Scan backwards so we don't miss it. Hm, actually, let's not - it looks pretty good. // Scan backwards so we don't miss it. Hm, actually, let's not - it looks pretty good.
int addr = -1; int addr = -1;
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
@ -280,21 +276,30 @@ int DSPDebugInterface::GetColor(unsigned int address)
return 0xFFFFFF; return 0xFFFFFF;
if (symbol->type != Common::Symbol::Type::Function) if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF; return 0xEEEEFF;
return colors[symbol->index % 6];
static constexpr std::array<u32, 6> colors{
0xd0FFFF, // light cyan
0xFFd0d0, // light red
0xd8d8FF, // light blue
0xFFd0FF, // light purple
0xd0FFd0, // light green
0xFFFFd0, // light yellow
};
return colors[symbol->index % colors.size()];
} }
// ============= // =============
std::string DSPDebugInterface::GetDescription(unsigned int address) std::string DSPDebugInterface::GetDescription(u32 address) const
{ {
return ""; // g_symbolDB.GetDescription(address); return ""; // g_symbolDB.GetDescription(address);
} }
unsigned int DSPDebugInterface::GetPC() u32 DSPDebugInterface::GetPC() const
{ {
return Symbols::Addr2Line(DSP::g_dsp.pc); return Symbols::Addr2Line(DSP::g_dsp.pc);
} }
void DSPDebugInterface::SetPC(unsigned int address) void DSPDebugInterface::SetPC(u32 address)
{ {
int new_pc = Symbols::Line2Addr(address); int new_pc = Symbols::Line2Addr(address);
if (new_pc > 0) if (new_pc > 0)

View File

@ -8,6 +8,8 @@
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Debug/MemoryPatches.h"
#include "Common/Debug/Watches.h"
#include "Common/DebugInterface.h" #include "Common/DebugInterface.h"
namespace DSP::LLE namespace DSP::LLE
@ -21,15 +23,17 @@ private:
class DSPDebugInterface final : public Common::DebugInterface class DSPDebugInterface final : public Common::DebugInterface
{ {
public: public:
DSPDebugInterface() {} DSPDebugInterface();
~DSPDebugInterface() override;
// Watches // Watches
std::size_t SetWatch(u32 address, const std::string& name = "") override; std::size_t SetWatch(u32 address, std::string name = "") override;
const Common::Debug::Watch& GetWatch(std::size_t index) const override; const Common::Debug::Watch& GetWatch(std::size_t index) const override;
const std::vector<Common::Debug::Watch>& GetWatches() const override; const std::vector<Common::Debug::Watch>& GetWatches() const override;
void UnsetWatch(u32 address) override; void UnsetWatch(u32 address) override;
void UpdateWatch(std::size_t index, u32 address, const std::string& name) override; void UpdateWatch(std::size_t index, u32 address, std::string name) override;
void UpdateWatchAddress(std::size_t index, u32 address) override; void UpdateWatchAddress(std::size_t index, u32 address) override;
void UpdateWatchName(std::size_t index, const std::string& name) override; void UpdateWatchName(std::size_t index, std::string name) override;
void EnableWatch(std::size_t index) override; void EnableWatch(std::size_t index) override;
void DisableWatch(std::size_t index) override; void DisableWatch(std::size_t index) override;
bool HasEnabledWatch(u32 address) const override; bool HasEnabledWatch(u32 address) const override;
@ -49,27 +53,25 @@ public:
bool HasEnabledPatch(u32 address) const override; bool HasEnabledPatch(u32 address) const override;
void ClearPatches() override; void ClearPatches() override;
std::string Disassemble(unsigned int address) override; std::string Disassemble(u32 address) const override;
std::string GetRawMemoryString(int memory, unsigned int address) override; std::string GetRawMemoryString(int memory, u32 address) const override;
int GetInstructionSize(int instruction) override { return 1; } bool IsAlive() const override;
bool IsAlive() override; bool IsBreakpoint(u32 address) const override;
bool IsBreakpoint(unsigned int address) override; void SetBreakpoint(u32 address) override;
void SetBreakpoint(unsigned int address) override; void ClearBreakpoint(u32 address) override;
void ClearBreakpoint(unsigned int address) override;
void ClearAllBreakpoints() override; void ClearAllBreakpoints() override;
void ToggleBreakpoint(unsigned int address) override; void ToggleBreakpoint(u32 address) override;
void ClearAllMemChecks() override; void ClearAllMemChecks() override;
bool IsMemCheck(unsigned int address, size_t size) override; bool IsMemCheck(u32 address, size_t size) const override;
void ToggleMemCheck(unsigned int address, bool read = true, bool write = true, void ToggleMemCheck(u32 address, bool read = true, bool write = true, bool log = true) override;
bool log = true) override; u32 ReadMemory(u32 address) const override;
unsigned int ReadMemory(unsigned int address) override; u32 ReadInstruction(u32 address) const override;
unsigned int ReadInstruction(unsigned int address) override; u32 GetPC() const override;
unsigned int GetPC() override; void SetPC(u32 address) override;
void SetPC(unsigned int address) override;
void Step() override {} void Step() override {}
void RunToBreakpoint() override; void RunToBreakpoint() override;
int GetColor(unsigned int address) override; u32 GetColor(u32 address) const override;
std::string GetDescription(unsigned int address) override; std::string GetDescription(u32 address) const override;
void Clear() override; void Clear() override;

View File

@ -5,6 +5,7 @@
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include <algorithm> #include <algorithm>
#include <cstring>
#include <map> #include <map>
#include <string> #include <string>
#include <utility> #include <utility>

View File

@ -124,8 +124,8 @@ void CodeViewWidget::Update()
for (int i = 0; i < rowCount(); i++) for (int i = 0; i < rowCount(); i++)
{ {
u32 addr = m_address - ((rowCount() / 2) * 4) + i * 4; const u32 addr = m_address - ((rowCount() / 2) * 4) + i * 4;
u32 color = PowerPC::debug_interface.GetColor(addr); const u32 color = PowerPC::debug_interface.GetColor(addr);
auto* bp_item = new QTableWidgetItem; auto* bp_item = new QTableWidgetItem;
auto* addr_item = new QTableWidgetItem(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0'))); auto* addr_item = new QTableWidgetItem(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));