debugger: better saving/loading of breakpoints/memchecks to file

no more softice style :(

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7240 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2011-02-25 09:35:56 +00:00
parent 7d3ad0b1fe
commit d7a9dc7df8
6 changed files with 272 additions and 320 deletions

View File

@ -16,11 +16,164 @@
// http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "DebugInterface.h"
#include "BreakPoints.h"
#include <sstream>
void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr, bool write, int size, u32 pc)
bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
{
for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
if (i->iAddress == _iAddress)
return true;
return false;
}
bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
{
for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
if (i->iAddress == _iAddress && i->bTemporary)
return true;
return false;
}
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
{
TBreakPointsStr bps;
for (TBreakPoints::const_iterator i = m_BreakPoints.begin();
i != m_BreakPoints.end(); ++i)
{
if (!i->bTemporary)
{
std::stringstream bp;
bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : "");
bps.push_back(bp.str());
}
}
return bps;
}
void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
{
for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i)
{
TBreakPoint bp;
std::stringstream bpstr;
bpstr << std::hex << *i;
bpstr >> bp.iAddress;
bp.bOn = i->find("n") != i->npos;
bp.bTemporary = false;
Add(bp);
}
}
void BreakPoints::Add(const TBreakPoint& bp)
{
if (!IsAddressBreakPoint(bp.iAddress))
m_BreakPoints.push_back(bp);
}
void BreakPoints::Add(u32 em_address, bool temp)
{
if (!IsAddressBreakPoint(em_address)) // only add new addresses
{
TBreakPoint pt; // breakpoint settings
pt.bOn = true;
pt.bTemporary = temp;
pt.iAddress = em_address;
m_BreakPoints.push_back(pt);
}
}
void BreakPoints::Remove(u32 _iAddress)
{
for (TBreakPoints::const_iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
{
if (i->iAddress == _iAddress)
{
m_BreakPoints.erase(i);
return;
}
}
}
MemChecks::TMemChecksStr MemChecks::GetStrings() const
{
TMemChecksStr mcs;
for (TMemChecks::const_iterator i = m_MemChecks.begin();
i != m_MemChecks.end(); ++i)
{
std::stringstream mc;
mc << std::hex << i->StartAddress;
mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " <<
(i->bRange ? "n" : "") << (i->OnRead ? "r" : "") <<
(i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : "");
mcs.push_back(mc.str());
}
return mcs;
}
void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
{
for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i)
{
TMemCheck mc;
std::stringstream mcstr;
mcstr << std::hex << *i;
mcstr >> mc.StartAddress;
mc.bRange = i->find("n") != i->npos;
mc.OnRead = i->find("r") != i->npos;
mc.OnWrite = i->find("w") != i->npos;
mc.Log = i->find("l") != i->npos;
mc.Break = i->find("p") != i->npos;
if (mc.bRange)
mcstr >> mc.EndAddress;
else
mc.EndAddress = mc.StartAddress;
Add(mc);
}
}
void MemChecks::Add(const TMemCheck& _rMemoryCheck)
{
if (GetMemCheck(_rMemoryCheck.StartAddress) == 0)
m_MemChecks.push_back(_rMemoryCheck);
}
void MemChecks::Remove(u32 _Address)
{
for (TMemChecks::const_iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
{
if (i->StartAddress == _Address)
{
m_MemChecks.erase(i);
return;
}
}
}
TMemCheck *MemChecks::GetMemCheck(u32 address)
{
for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
{
if (i->bRange)
{
if (address >= i->StartAddress && address <= i->EndAddress)
return &(*i);
}
else if (i->StartAddress == address)
return &(*i);
}
// none found
return 0;
}
void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr,
bool write, int size, u32 pc)
{
if ((write && OnWrite) || (!write && OnRead))
{
@ -36,119 +189,3 @@ void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr, bo
debug_interface->breakNow();
}
}
bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
{
std::vector<TBreakPoint>::iterator iter;
for (iter = m_BreakPoints.begin(); iter != m_BreakPoints.end(); ++iter)
if ((*iter).iAddress == _iAddress)
return true;
return false;
}
bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
{
std::vector<TBreakPoint>::iterator iter;
for (iter = m_BreakPoints.begin(); iter != m_BreakPoints.end(); ++iter)
if ((*iter).iAddress == _iAddress && (*iter).bTemporary)
return true;
return false;
}
bool BreakPoints::Add(u32 em_address, bool temp)
{
if (!IsAddressBreakPoint(em_address)) // only add new addresses
{
TBreakPoint pt; // breakpoint settings
pt.bOn = true;
pt.bTemporary = temp;
pt.iAddress = em_address;
m_BreakPoints.push_back(pt);
return true;
} else {
return false;
}
}
bool BreakPoints::Remove(u32 _iAddress)
{
std::vector<TBreakPoint>::iterator iter;
for (iter = m_BreakPoints.begin(); iter != m_BreakPoints.end(); ++iter)
{
if ((*iter).iAddress == _iAddress)
{
m_BreakPoints.erase(iter);
return true;
}
}
return false;
}
void BreakPoints::Clear()
{
m_BreakPoints.clear();
}
void BreakPoints::DeleteByAddress(u32 _Address)
{
// first check breakpoints
{
std::vector<TBreakPoint>::iterator iter;
for (iter = m_BreakPoints.begin(); iter != m_BreakPoints.end(); ++iter)
{
if ((*iter).iAddress == _Address)
{
m_BreakPoints.erase(iter);
return;
}
}
}
}
void MemChecks::Add(const TMemCheck& _rMemoryCheck)
{
m_MemChecks.push_back(_rMemoryCheck);
}
TMemCheck *MemChecks::GetMemCheck(u32 address)
{
std::vector<TMemCheck>::iterator iter;
for (iter = m_MemChecks.begin(); iter != m_MemChecks.end(); ++iter)
{
if ((*iter).bRange)
{
if (address >= (*iter).StartAddress && address <= (*iter).EndAddress)
return &(*iter);
}
else
{
if ((*iter).StartAddress == address)
return &(*iter);
}
}
//none found
return 0;
}
void MemChecks::Clear()
{
m_MemChecks.clear();
}
void MemChecks::DeleteByAddress(u32 _Address)
{
std::vector<TMemCheck>::iterator iter;
for (iter = m_MemChecks.begin(); iter != m_MemChecks.end(); ++iter)
{
if ((*iter).StartAddress == _Address)
{
m_MemChecks.erase(iter);
return;
}
}
}

View File

@ -36,6 +36,8 @@ struct TMemCheck
{
TMemCheck() {
numHits = 0;
StartAddress = EndAddress = 0;
bRange = OnRead = OnWrite = Log = Break = false;
}
u32 StartAddress;
u32 EndAddress;
@ -50,7 +52,8 @@ struct TMemCheck
u32 numHits;
void Action(DebugInterface *dbg_interface, u32 _iValue, u32 addr, bool write, int size, u32 pc);
void Action(DebugInterface *dbg_interface, u32 _iValue, u32 addr,
bool write, int size, u32 pc);
};
// Code breakpoints.
@ -58,19 +61,24 @@ class BreakPoints
{
public:
typedef std::vector<TBreakPoint> TBreakPoints;
typedef std::vector<std::string> TBreakPointsStr;
const TBreakPoints& GetBreakPoints() { return m_BreakPoints; }
TBreakPointsStr GetStrings() const;
void AddFromStrings(const TBreakPointsStr& bps);
// is address breakpoint
bool IsAddressBreakPoint(u32 _iAddress);
bool IsTempBreakPoint(u32 _iAddress);
// AddBreakPoint
bool Add(u32 em_address, bool temp=false);
// Add BreakPoint
void Add(u32 em_address, bool temp=false);
void Add(const TBreakPoint& bp);
// Remove Breakpoint
bool Remove(u32 _iAddress);
void Clear();
void Remove(u32 _iAddress);
void Clear() { m_BreakPoints.clear(); };
void DeleteByAddress(u32 _Address);
@ -85,15 +93,22 @@ class MemChecks
{
public:
typedef std::vector<TMemCheck> TMemChecks;
typedef std::vector<std::string> TMemChecksStr;
TMemChecks m_MemChecks;
const TMemChecks& GetMemChecks() { return m_MemChecks; }
TMemChecksStr GetStrings() const;
void AddFromStrings(const TMemChecksStr& mcs);
void Add(const TMemCheck& _rMemoryCheck);
//memory breakpoint
// memory breakpoint
TMemCheck *GetMemCheck(u32 address);
void DeleteByAddress(u32 _Address);
void Remove(u32 _Address);
void Clear();
void Clear() { m_MemChecks.clear(); };
};
#endif

View File

@ -156,7 +156,7 @@ void PPCDebugInterface::toggleMemCheck(unsigned int address)
}
else
PowerPC::memchecks.DeleteByAddress(address);
PowerPC::memchecks.Remove(address);
}
void PPCDebugInterface::insertBLR(unsigned int address, unsigned int value)

View File

@ -112,6 +112,9 @@ void CBreakPointView::Update()
SetItemData(Item, rMemCheck.StartAddress);
}
SetColumnWidth(2, -1);
SetColumnWidth(3, -1);
Refresh();
}
@ -121,8 +124,8 @@ void CBreakPointView::DeleteCurrentSelection()
if (Item >= 0)
{
u32 Address = (u32)GetItemData(Item);
PowerPC::breakpoints.DeleteByAddress(Address);
PowerPC::memchecks.DeleteByAddress(Address);
PowerPC::breakpoints.Remove(Address);
PowerPC::memchecks.Remove(Address);
Update();
}
}
@ -136,7 +139,7 @@ CBreakPointBar::CBreakPointBar(CBreakPointWindow* parent, const wxWindowID id, c
SetBackgroundColour(wxColour(0x555555));
SetForegroundColour(wxColour(0xffffff));
// load orignal size 48x48
// load original size 48x48
wxMemoryInputStream st1(toolbar_delete_png, sizeof(toolbar_delete_png));
wxMemoryInputStream st2(toolbar_add_breakpoint_png, sizeof(toolbar_add_breakpoint_png));
wxMemoryInputStream st3(toolbar_add_memcheck_png, sizeof(toolbar_add_memcheck_png));
@ -157,15 +160,14 @@ CBreakPointBar::CBreakPointBar(CBreakPointWindow* parent, const wxWindowID id, c
void CBreakPointBar::PopulateBar()
{
InsertItem(IDM_DELETE, _("Delete"), 0);
InsertItem(IDM_CLEAR, _("Clear all"), 0);
InsertItem(IDM_CLEAR, _("Clear"), 0);
InsertItem(IDM_ADD_BREAKPOINT, _("Add BP..."), 1);
InsertItem(IDM_ADD_BREAKPOINTMANY, _("Add BPs..."), 1);
InsertItem(IDM_ADD_BREAKPOINT, _("+BP"), 1);
// just add memory breakpoints if you can use them
if (Memory::AreMemoryBreakpointsActivated())
{
InsertItem(IDM_ADD_MEMORYCHECK, _("Add MC..."), 2);
InsertItem(IDM_ADD_MEMORYCHECKMANY, _("Add MCs..."), 2);
}
InsertItem(IDM_ADD_MEMORYCHECK, _("+MC"), 2);
InsertItem(IDM_SAVEALL, _("Load"));
InsertItem(IDM_SAVEALL, _("Save"));
}

View File

@ -27,8 +27,10 @@
#include "FileUtil.h"
BEGIN_EVENT_TABLE(CBreakPointWindow, wxPanel)
EVT_LIST_ITEM_ACTIVATED(ID_BPS, CBreakPointWindow::OnActivated)
EVT_LIST_ITEM_SELECTED(ID_TOOLBAR, CBreakPointWindow::OnSelectItem)
EVT_CLOSE(CBreakPointWindow::OnClose)
EVT_LIST_ITEM_SELECTED(ID_BPS, CBreakPointWindow::OnSelectBP)
EVT_LIST_ITEM_RIGHT_CLICK(ID_BPS, CBreakPointWindow::OnRightClick)
EVT_LIST_ITEM_SELECTED(ID_TOOLBAR, CBreakPointWindow::OnSelectToolbar)
END_EVENT_TABLE()
CBreakPointWindow::CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent,
@ -41,6 +43,11 @@ CBreakPointWindow::CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent
CreateGUIControls();
}
void CBreakPointWindow::OnClose(wxCloseEvent& WXUNUSED(event))
{
SaveAll();
}
void CBreakPointWindow::CreateGUIControls()
{
SetSize(8, 8, 400, 370);
@ -53,69 +60,65 @@ void CBreakPointWindow::CreateGUIControls()
wxBoxSizer* sizerH = new wxBoxSizer(wxVERTICAL);
sizerH->Add(m_BreakPointBar, 0, wxALL | wxEXPAND);
sizerH->Add((wxListCtrl*)m_BreakPointListView, 1, wxEXPAND);
sizerH->Add(m_BreakPointListView, 1, wxEXPAND);
NotifyUpdate();
SetSizer(sizerH);
}
void CBreakPointWindow::OnSelectItem(wxListEvent& event)
void CBreakPointWindow::OnSelectToolbar(wxListEvent& event)
{
switch(event.GetItem().GetId())
{
case IDM_DELETE:
OnDelete();
m_BreakPointBar->SetItemState(event.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED);
break;
case IDM_CLEAR:
OnClear();
m_BreakPointBar->SetItemState(event.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED);
break;
case IDM_ADD_BREAKPOINT:
OnAddBreakPoint();
break;
case IDM_ADD_BREAKPOINTMANY:
OnAddBreakPointMany();
break;
case IDM_ADD_MEMORYCHECK:
OnAddMemoryCheck();
break;
case IDM_ADD_MEMORYCHECKMANY:
OnAddMemoryCheckMany();
case IDM_LOADALL:
LoadAll();
case IDM_SAVEALL:
SaveAll();
break;
}
}
void CBreakPointWindow::NotifyUpdate()
{
if (m_BreakPointListView != NULL) m_BreakPointListView->Update();
if (m_BreakPointListView)
m_BreakPointListView->Update();
}
void CBreakPointWindow::OnDelete()
{
if (m_BreakPointListView)
{
m_BreakPointListView->DeleteCurrentSelection();
}
}
void CBreakPointWindow::OnActivated(wxListEvent& event)
// jump to begin addr
void CBreakPointWindow::OnSelectBP(wxListEvent& event)
{
long Index = event.GetIndex();
if (Index >= 0)
{
u32 Address = (u32)m_BreakPointListView->GetItemData(Index);
if (m_pCodeWindow != NULL)
{
if (m_pCodeWindow)
m_pCodeWindow->JumpToAddress(Address);
}
}
}
// Breakpoint actions
// ---------------------
// modify
void CBreakPointWindow::OnRightClick(wxListEvent& event)
{
}
// Clear all breakpoints
// Clear all breakpoints and memchecks
void CBreakPointWindow::OnClear()
{
PowerPC::breakpoints.Clear();
@ -123,143 +126,43 @@ void CBreakPointWindow::OnClear()
NotifyUpdate();
}
// Add one breakpoint
void CBreakPointWindow::OnAddBreakPoint()
{
BreakPointDlg bpDlg(this, this);
bpDlg.ShowModal();
}
// Load breakpoints from file
void CBreakPointWindow::OnAddBreakPointMany()
{
// load ini
IniFile ini;
std::string filename = std::string(File::GetUserPath(D_GAMECONFIG_IDX)) + "BreakPoints.ini";
if (ini.Load(filename.c_str())) // check if there is any file there
{
// get lines from a certain section
std::vector<std::string> lines;
if (!ini.GetLines("BreakPoints", lines))
{
wxMessageBox(_("You have no [BreakPoints] line in your file"));
return;
}
for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{
std::string line = StripSpaces(*iter);
u32 Address = 0;
if (AsciiToHex(line.c_str(), Address))
{
PowerPC::breakpoints.Add(Address);
}
}
// Only update after we are done with the loop
NotifyUpdate();
}
else
{
wxMessageBox(_("Couldn't find GameConfig/BreakPoints.ini file"));
}
}
// Memory check actions
// ---------------------
void
CBreakPointWindow::OnAddMemoryCheck()
void CBreakPointWindow::OnAddMemoryCheck()
{
MemoryCheckDlg memDlg(this);
memDlg.ShowModal();
}
// Load memory checks from file
void CBreakPointWindow::OnAddMemoryCheckMany()
void CBreakPointWindow::SaveAll()
{
// load ini
// simply dump all to bp/mc files in a way we can read again
IniFile ini;
std::string filename = std::string(File::GetUserPath(D_GAMECONFIG_IDX)) + "MemoryChecks.ini";
if (ini.Load(filename.c_str()))
if (ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX)))
{
// get lines from a certain section
std::vector<std::string> lines;
if (!ini.GetLines("MemoryChecks", lines))
{
wxMessageBox(_("You have no [MemoryChecks] line in your file"));
return;
}
for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{
std::string line = StripSpaces(*iter);
std::vector<std::string> pieces;
SplitString(line, ' ', pieces); // split string
TMemCheck MemCheck;
u32 sAddress = 0;
u32 eAddress = 0;
bool doCommon = false;
// ------------------------------------------------------------------------------------------
// Decide if we have a range or just one address, and if we should break or not
// --------------
if (
pieces.size() == 1
&& AsciiToHex(pieces[0].c_str(), sAddress)
&& pieces[0].size() == 8
)
{
// address range
MemCheck.StartAddress = sAddress;
MemCheck.EndAddress = sAddress;
doCommon = true;
MemCheck.Break = false;
}
else if(
pieces.size() == 2
&& AsciiToHex(pieces[0].c_str(), sAddress) && AsciiToHex(pieces[1].c_str(), eAddress)
&& pieces[0].size() == 8 && pieces[1].size() == 8
)
{
// address range
MemCheck.StartAddress = sAddress;
MemCheck.EndAddress = eAddress;
doCommon = true;
MemCheck.Break = false;
}
else if(
pieces.size() == 3
&& AsciiToHex(pieces[0].c_str(), sAddress) && AsciiToHex(pieces[1].c_str(), eAddress)
&& pieces[0].size() == 8 && pieces[1].size() == 8 && pieces[2].size() == 1
)
{
// address range
MemCheck.StartAddress = sAddress;
MemCheck.EndAddress = eAddress;
doCommon = true;
MemCheck.Break = true;
}
if (doCommon)
{
// settings for the memory check
MemCheck.OnRead = true;
MemCheck.OnWrite = true;
MemCheck.Log = true;
//MemCheck.Break = false; // this is also what sets Active "on" in the breakpoint window
// so don't think it's off because we are only writing this to the log
PowerPC::memchecks.Add(MemCheck);
}
}
// Update after we are done with the loop
NotifyUpdate();
}
else
{
wxMessageBox(_("You have no ") + wxString::FromAscii(File::GetUserPath(D_GAMECONFIG_IDX)) + _("MemoryChecks.ini file"));
ini.SetLines("BreakPoints", PowerPC::breakpoints.GetStrings());
ini.SetLines("MemoryChecks", PowerPC::memchecks.GetStrings());
ini.Save(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
}
}
void CBreakPointWindow::LoadAll()
{
IniFile ini;
BreakPoints::TBreakPointsStr newbps;
MemChecks::TMemChecksStr newmcs;
if (!ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX)))
return;
if (ini.GetLines("BreakPoints", newbps))
PowerPC::breakpoints.AddFromStrings(newbps);
if (ini.GetLines("MemoryChecks", newmcs, false))
PowerPC::memchecks.AddFromStrings(newmcs);
NotifyUpdate();
}

View File

@ -29,19 +29,15 @@ enum
IDM_DELETE = 0,
IDM_CLEAR,
IDM_ADD_BREAKPOINT,
IDM_ADD_BREAKPOINTMANY,
IDM_ADD_MEMORYCHECK,
IDM_ADD_MEMORYCHECKMANY
IDM_LOADALL,
IDM_SAVEALL
};
class CBreakPointWindow
: public wxPanel
{
private:
DECLARE_EVENT_TABLE();
public:
public:
CBreakPointWindow(CCodeWindow* _pCodeWindow,
wxWindow* parent,
@ -52,14 +48,9 @@ class CBreakPointWindow
long style = wxTAB_TRAVERSAL | wxBORDER_NONE);
void NotifyUpdate();
void OnDelete();
void OnClear();
void OnAddBreakPoint();
void OnAddBreakPointMany();
void OnAddMemoryCheck();
void OnAddMemoryCheckMany();
private:
private:
DECLARE_EVENT_TABLE();
enum
{
@ -71,13 +62,17 @@ class CBreakPointWindow
CBreakPointView* m_BreakPointListView;
CCodeWindow* m_pCodeWindow;
// void RecreateToolbar();
// void PopulateToolbar(wxToolBar* toolBar);
// void InitBitmaps();
void OnClose(wxCloseEvent& event);
void OnSelectToolbar(wxListEvent& event);
void OnSelectBP(wxListEvent& event);
void OnRightClick(wxListEvent& event);
void CreateGUIControls();
void OnSelectItem(wxListEvent& event);
void OnActivated(wxListEvent& event);
void OnDelete();
void OnClear();
void OnAddBreakPoint();
void OnAddMemoryCheck();
void SaveAll();
void LoadAll();
};
#endif