Skip to content

Commit

Permalink
Merge pull request #8235 from lioncash/move
Browse files Browse the repository at this point in the history
Common/DebugInterface: Minor cleanup changes
  • Loading branch information
Helios747 committed Jul 22, 2019
2 parents 136264d + d2d7bf5 commit 66e7a11
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 155 deletions.
16 changes: 8 additions & 8 deletions Source/Core/Common/Debug/Watches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

namespace Common::Debug
{
Watch::Watch(u32 address_, const std::string& name_, Watch::State is_enabled_)
: address(address_), name(name_), is_enabled(is_enabled_)
Watch::Watch(u32 address_, std::string name_, State 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();
for (std::size_t index = 0; index < size; index++)
Expand All @@ -25,7 +25,7 @@ std::size_t Watches::SetWatch(u32 address, const std::string& name)
return index;
}
}
m_watches.emplace_back(address, name, Watch::State::Enabled);
m_watches.emplace_back(address, std::move(name), Watch::State::Enabled);
return size;
}

Expand All @@ -46,20 +46,20 @@ void Watches::UnsetWatch(u32 address)
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].name = name;
m_watches[index].name = std::move(name);
}

void Watches::UpdateWatchAddress(std::size_t index, u32 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)
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Common/Debug/Watches.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ struct Watch
std::string name;
State is_enabled;

Watch(u32 address, const std::string& name, State is_enabled);
Watch(u32 address, std::string name, State is_enabled);
};

class Watches
{
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 std::vector<Watch>& GetWatches() const;
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 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 DisableWatch(std::size_t index);
bool HasEnabledWatch(u32 address) const;
Expand Down
60 changes: 30 additions & 30 deletions Source/Core/Common/DebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@
#pragma once

#include <cstddef>
#include <cstring>
#include <string>
#include <vector>

#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
{
class DebugInterface
{
protected:
virtual ~DebugInterface() {}
virtual ~DebugInterface() = default;

public:
// Watches
virtual std::size_t SetWatch(u32 address, const std::string& name = "") = 0;
virtual const Common::Debug::Watch& GetWatch(std::size_t index) const = 0;
virtual const std::vector<Common::Debug::Watch>& GetWatches() const = 0;
virtual std::size_t SetWatch(u32 address, std::string name = "") = 0;
virtual const Debug::Watch& GetWatch(std::size_t index) const = 0;
virtual const std::vector<Debug::Watch>& GetWatches() const = 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 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 DisableWatch(std::size_t index) = 0;
virtual bool HasEnabledWatch(u32 address) const = 0;
Expand All @@ -40,41 +43,38 @@ class DebugInterface
// Memory Patches
virtual void SetPatch(u32 address, u32 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 EnablePatch(std::size_t index) = 0;
virtual void DisablePatch(std::size_t index) = 0;
virtual bool HasEnabledPatch(u32 address) const = 0;
virtual void RemovePatch(std::size_t index) = 0;
virtual void ClearPatches() = 0;

virtual std::string Disassemble(unsigned int /*address*/) { return "NODEBUGGER"; }
virtual std::string GetRawMemoryString(int /*memory*/, unsigned int /*address*/)
virtual std::string Disassemble(u32 /*address*/) const { return "NODEBUGGER"; }
virtual std::string GetRawMemoryString(int /*memory*/, u32 /*address*/) const
{
return "NODEBUGGER";
}
virtual int GetInstructionSize(int /*instruction*/) { return 1; }
virtual bool IsAlive() { return true; }
virtual bool IsBreakpoint(unsigned int /*address*/) { return false; }
virtual void SetBreakpoint(unsigned int /*address*/) {}
virtual void ClearBreakpoint(unsigned int /*address*/) {}
virtual bool IsAlive() const { return true; }
virtual bool IsBreakpoint(u32 /*address*/) const { return false; }
virtual void SetBreakpoint(u32 /*address*/) {}
virtual void ClearBreakpoint(u32 /*address*/) {}
virtual void ClearAllBreakpoints() {}
virtual void ToggleBreakpoint(unsigned int /*address*/) {}
virtual void ToggleBreakpoint(u32 /*address*/) {}
virtual void ClearAllMemChecks() {}
virtual bool IsMemCheck(unsigned int /*address*/, size_t /*size*/) { return false; }
virtual void ToggleMemCheck(unsigned int /*address*/, bool /*read*/, bool /*write*/, bool /*log*/)
{
}
virtual unsigned int ReadMemory(unsigned int /*address*/) { return 0; }
virtual void WriteExtraMemory(int /*memory*/, unsigned int /*value*/, unsigned int /*address*/) {}
virtual unsigned int ReadExtraMemory(int /*memory*/, unsigned int /*address*/) { return 0; }
virtual unsigned int ReadInstruction(unsigned int /*address*/) { return 0; }
virtual unsigned int GetPC() { return 0; }
virtual void SetPC(unsigned int /*address*/) {}
virtual bool IsMemCheck(u32 /*address*/, size_t /*size*/) const { return false; }
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 u32 ReadExtraMemory(int /*memory*/, u32 /*address*/) const { return 0; }
virtual u32 ReadInstruction(u32 /*address*/) const { return 0; }
virtual u32 GetPC() const { return 0; }
virtual void SetPC(u32 /*address*/) {}
virtual void Step() {}
virtual void RunToBreakpoint() {}
virtual int GetColor(unsigned int /*address*/) { return 0xFFFFFFFF; }
virtual std::string GetDescription(unsigned int /*address*/) = 0;
virtual u32 GetColor(u32 /*address*/) const { return 0xFFFFFFFF; }
virtual std::string GetDescription(u32 /*address*/) const = 0;
virtual void Clear() = 0;
};
} // namespace Common
71 changes: 39 additions & 32 deletions Source/Core/Core/Debugger/PPCDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

#include "Core/Debugger/PPCDebugInterface.h"

#include <array>
#include <cstddef>
#include <string>

#include <fmt/format.h>

#include "Common/Align.h"
#include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"

#include "Core/Core.h"
#include "Core/HW/DSP.h"
Expand Down Expand Up @@ -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
Expand All @@ -64,19 +69,19 @@ void PPCDebugInterface::UnsetWatch(u32 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)
{
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)
Expand Down Expand Up @@ -121,7 +126,7 @@ void PPCDebugInterface::SetPatch(u32 address, u32 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
Expand Down Expand Up @@ -159,7 +164,7 @@ void PPCDebugInterface::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
if (!IsAlive())
Expand Down Expand Up @@ -189,27 +194,27 @@ 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())
{
const bool is_aram = memory != 0;

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 "<unknwn>"; // bad spelling - 8 chars
}

unsigned int PPCDebugInterface::ReadMemory(unsigned int address)
u32 PPCDebugInterface::ReadMemory(u32 address) const
{
return PowerPC::HostRead_U32(address);
}

unsigned int PPCDebugInterface::ReadExtraMemory(int memory, unsigned int address)
u32 PPCDebugInterface::ReadExtraMemory(int memory, u32 address) const
{
switch (memory)
{
Expand All @@ -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);
}

bool PPCDebugInterface::IsAlive()
bool PPCDebugInterface::IsAlive() const
{
return Core::IsRunningAndStarted();
}

bool PPCDebugInterface::IsBreakpoint(unsigned int address)
bool PPCDebugInterface::IsBreakpoint(u32 address) const
{
return PowerPC::breakpoints.IsAddressBreakPoint(address);
}

void PPCDebugInterface::SetBreakpoint(unsigned int address)
void PPCDebugInterface::SetBreakpoint(u32 address)
{
PowerPC::breakpoints.Add(address);
}

void PPCDebugInterface::ClearBreakpoint(unsigned int address)
void PPCDebugInterface::ClearBreakpoint(u32 address)
{
PowerPC::breakpoints.Remove(address);
}
Expand All @@ -253,7 +258,7 @@ void PPCDebugInterface::ClearAllBreakpoints()
PowerPC::breakpoints.Clear();
}

void PPCDebugInterface::ToggleBreakpoint(unsigned int address)
void PPCDebugInterface::ToggleBreakpoint(u32 address)
{
if (PowerPC::breakpoints.IsAddressBreakPoint(address))
PowerPC::breakpoints.Remove(address);
Expand All @@ -266,12 +271,12 @@ void PPCDebugInterface::ClearAllMemChecks()
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;
}

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))
{
Expand All @@ -296,40 +301,42 @@ void PPCDebugInterface::ToggleMemCheck(unsigned int address, bool read, bool wri
// =======================================================
// Separate the blocks with colors.
// -------------
int PPCDebugInterface::GetColor(unsigned int address)
u32 PPCDebugInterface::GetColor(u32 address) const
{
if (!IsAlive())
return 0xFFFFFF;
if (!PowerPC::HostIsRAMAddress(address))
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
0xFFd0d0, // light red
0xd8d8FF, // light blue
0xFFd0FF, // light purple
0xd0FFd0, // light green
0xFFFFd0, // light yellow
};
Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF;
return colors[symbol->index % 6];
return colors[symbol->index % colors.size()];
}
// =============

std::string PPCDebugInterface::GetDescription(unsigned int address)
std::string PPCDebugInterface::GetDescription(u32 address) const
{
return g_symbolDB.GetDescription(address);
}

unsigned int PPCDebugInterface::GetPC()
u32 PPCDebugInterface::GetPC() const
{
return PowerPC::ppcState.pc;
}

void PPCDebugInterface::SetPC(unsigned int address)
void PPCDebugInterface::SetPC(u32 address)
{
PowerPC::ppcState.pc = address;
}
Expand Down
Loading

0 comments on commit 66e7a11

Please sign in to comment.