2008-07-21 15:56:14 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
2008-07-17 20:08:01 +00:00
|
|
|
|
|
|
|
#include "Debugger.h"
|
2008-07-20 11:02:41 +00:00
|
|
|
#include "BreakpointWindow.h"
|
2008-07-17 20:08:01 +00:00
|
|
|
#include "BreakpointView.h"
|
2008-07-17 21:46:34 +00:00
|
|
|
#include "CodeWindow.h"
|
2008-07-17 22:19:57 +00:00
|
|
|
#include "HW/Memmap.h"
|
2008-07-21 15:56:14 +00:00
|
|
|
#include "BreakPointDlg.h"
|
|
|
|
#include "MemoryCheckDlg.h"
|
2008-07-24 13:40:07 +00:00
|
|
|
#include "IniFile.h"
|
2008-10-18 02:21:59 +00:00
|
|
|
#include "Debugger/Debugger_BreakPoints.h" // for TMemCheck
|
2008-07-17 20:08:01 +00:00
|
|
|
|
2008-08-26 23:32:54 +00:00
|
|
|
#include <wx/mstream.h>
|
2008-07-17 20:08:01 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "../resources/toolbar_add_breakpoint.c"
|
|
|
|
#include "../resources/toolbar_add_memorycheck.c"
|
|
|
|
#include "../resources/toolbar_delete.c"
|
|
|
|
}
|
|
|
|
|
|
|
|
static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT;
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CBreakPointWindow, wxFrame)
|
|
|
|
EVT_CLOSE(CBreakPointWindow::OnClose)
|
|
|
|
EVT_MENU(IDM_DELETE, CBreakPointWindow::OnDelete)
|
2008-10-18 02:21:59 +00:00
|
|
|
EVT_MENU(IDM_CLEAR, CBreakPointWindow::OnClear)
|
2008-07-17 20:08:01 +00:00
|
|
|
EVT_MENU(IDM_ADD_BREAKPOINT, CBreakPointWindow::OnAddBreakPoint)
|
2008-10-18 02:21:59 +00:00
|
|
|
EVT_MENU(IDM_ADD_BREAKPOINTMANY, CBreakPointWindow::OnAddBreakPointMany)
|
2008-07-17 20:08:01 +00:00
|
|
|
EVT_MENU(IDM_ADD_MEMORYCHECK, CBreakPointWindow::OnAddMemoryCheck)
|
2008-10-18 02:21:59 +00:00
|
|
|
EVT_MENU(IDM_ADD_MEMORYCHECKMANY, CBreakPointWindow::OnAddMemoryCheckMany)
|
2008-07-17 21:46:34 +00:00
|
|
|
EVT_LIST_ITEM_ACTIVATED(ID_BPS, CBreakPointWindow::OnActivated)
|
2008-07-17 20:08:01 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
#define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name, sizeof(name))
|
|
|
|
inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
|
|
|
|
{
|
|
|
|
wxMemoryInputStream is(data, length);
|
|
|
|
return(wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-17 21:46:34 +00:00
|
|
|
CBreakPointWindow::CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
|
2008-07-17 20:08:01 +00:00
|
|
|
: wxFrame(parent, id, title, position, size, style)
|
|
|
|
, m_BreakPointListView(NULL)
|
2008-07-17 21:46:34 +00:00
|
|
|
, m_pCodeWindow(_pCodeWindow)
|
2008-07-17 20:08:01 +00:00
|
|
|
{
|
|
|
|
InitBitmaps();
|
|
|
|
|
|
|
|
CreateGUIControls();
|
|
|
|
|
|
|
|
// Create the toolbar
|
|
|
|
RecreateToolbar();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBreakPointWindow::~CBreakPointWindow()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-07-24 13:40:07 +00:00
|
|
|
void
|
|
|
|
CBreakPointWindow::Save(IniFile& _IniFile) const
|
|
|
|
{
|
|
|
|
_IniFile.Set("BreakPoint", "x", GetPosition().x);
|
|
|
|
_IniFile.Set("BreakPoint", "y", GetPosition().y);
|
|
|
|
_IniFile.Set("BreakPoint", "w", GetSize().GetWidth());
|
|
|
|
_IniFile.Set("BreakPoint", "h", GetSize().GetHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::Load(IniFile& _IniFile)
|
|
|
|
{
|
|
|
|
int x,y,w,h;
|
|
|
|
_IniFile.Get("BreakPoint", "x", &x, GetPosition().x);
|
|
|
|
_IniFile.Get("BreakPoint", "y", &y, GetPosition().y);
|
|
|
|
_IniFile.Get("BreakPoint", "w", &w, GetSize().GetWidth());
|
|
|
|
_IniFile.Get("BreakPoint", "h", &h, GetSize().GetHeight());
|
|
|
|
SetSize(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-17 20:08:01 +00:00
|
|
|
void
|
|
|
|
CBreakPointWindow::CreateGUIControls()
|
|
|
|
{
|
|
|
|
SetTitle(wxT("Breakpoints"));
|
|
|
|
SetIcon(wxNullIcon);
|
|
|
|
SetSize(8, 8, 400, 370);
|
|
|
|
Center();
|
|
|
|
|
|
|
|
m_BreakPointListView = new CBreakPointView(this, ID_BPS, wxDefaultPosition, GetSize(),
|
|
|
|
wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL | wxLC_SORT_ASCENDING);
|
|
|
|
|
|
|
|
NotifyUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::PopulateToolbar(wxToolBar* toolBar)
|
|
|
|
{
|
|
|
|
int w = m_Bitmaps[Toolbar_Delete].GetWidth(),
|
|
|
|
h = m_Bitmaps[Toolbar_Delete].GetHeight();
|
|
|
|
|
|
|
|
toolBar->SetToolBitmapSize(wxSize(w, h));
|
2008-07-17 22:19:57 +00:00
|
|
|
toolBar->AddTool(IDM_DELETE, _T("Delete"), m_Bitmaps[Toolbar_Delete], _T("Delete the selected BreakPoint or MemoryCheck"));
|
2008-10-18 02:21:59 +00:00
|
|
|
toolBar->AddTool(IDM_CLEAR, _T("Clear all"), m_Bitmaps[Toolbar_Delete], _T("Clear all BreakPoints and MemoryChecks"));
|
|
|
|
|
2008-07-17 20:08:01 +00:00
|
|
|
toolBar->AddSeparator();
|
2008-10-18 02:21:59 +00:00
|
|
|
|
2008-07-17 22:19:57 +00:00
|
|
|
toolBar->AddTool(IDM_ADD_BREAKPOINT, _T("BP"), m_Bitmaps[Toolbar_Add_BreakPoint], _T("Add BreakPoint..."));
|
2008-10-18 02:21:59 +00:00
|
|
|
toolBar->AddTool(IDM_ADD_BREAKPOINTMANY, _T("BPs"), m_Bitmaps[Toolbar_Add_BreakPoint], _T("Add BreakPoints..."));
|
2008-07-17 22:19:57 +00:00
|
|
|
|
|
|
|
// just add memory breakpoints if you can use them
|
|
|
|
if (Memory::AreMemoryBreakpointsActivated())
|
|
|
|
{
|
|
|
|
toolBar->AddTool(IDM_ADD_MEMORYCHECK, _T("MC"), m_Bitmaps[Toolbar_Add_Memcheck], _T("Add MemoryCheck..."));
|
2008-10-18 02:21:59 +00:00
|
|
|
toolBar->AddTool(IDM_ADD_MEMORYCHECKMANY, _T("MCs"), m_Bitmaps[Toolbar_Add_Memcheck], _T("Add MemoryChecks..."));
|
2008-07-17 22:19:57 +00:00
|
|
|
}
|
2008-07-17 20:08:01 +00:00
|
|
|
|
|
|
|
// after adding the buttons to the toolbar, must call Realize() to reflect
|
|
|
|
// the changes
|
|
|
|
toolBar->Realize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::RecreateToolbar()
|
|
|
|
{
|
|
|
|
// delete and recreate the toolbar
|
|
|
|
wxToolBarBase* toolBar = GetToolBar();
|
|
|
|
long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE;
|
|
|
|
|
|
|
|
delete toolBar;
|
|
|
|
SetToolBar(NULL);
|
|
|
|
|
|
|
|
style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_HORZ_LAYOUT | wxTB_TOP);
|
|
|
|
wxToolBar* theToolBar = CreateToolBar(style, ID_TOOLBAR);
|
|
|
|
|
|
|
|
PopulateToolbar(theToolBar);
|
|
|
|
SetToolBar(theToolBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::InitBitmaps()
|
|
|
|
{
|
|
|
|
// load orignal size 48x48
|
|
|
|
m_Bitmaps[Toolbar_Delete] = wxGetBitmapFromMemory(toolbar_delete_png);
|
|
|
|
m_Bitmaps[Toolbar_Add_BreakPoint] = wxGetBitmapFromMemory(toolbar_add_breakpoint_png);
|
|
|
|
m_Bitmaps[Toolbar_Add_Memcheck] = wxGetBitmapFromMemory(toolbar_add_memcheck_png);
|
|
|
|
|
|
|
|
// scale to 24x24 for toolbar
|
|
|
|
for (size_t n = Toolbar_Delete; n < WXSIZEOF(m_Bitmaps); n++)
|
|
|
|
{
|
|
|
|
m_Bitmaps[n] = wxBitmap(m_Bitmaps[n].ConvertToImage().Scale(16, 16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::OnClose(wxCloseEvent& /*event*/)
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBreakPointWindow::NotifyUpdate()
|
|
|
|
{
|
|
|
|
if (m_BreakPointListView != NULL)
|
|
|
|
{
|
|
|
|
m_BreakPointListView->Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBreakPointWindow::OnDelete(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
if (m_BreakPointListView)
|
|
|
|
{
|
|
|
|
m_BreakPointListView->DeleteCurrentSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-18 02:21:59 +00:00
|
|
|
// ==========================================================================================
|
|
|
|
// Clear all breakpoints
|
|
|
|
// ------------
|
|
|
|
void
|
|
|
|
CBreakPointWindow::OnClear(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
CBreakPoints::ClearAllBreakPoints();
|
|
|
|
}
|
|
|
|
// ============
|
|
|
|
|
|
|
|
|
2008-07-17 20:08:01 +00:00
|
|
|
void
|
|
|
|
CBreakPointWindow::OnAddBreakPoint(wxCommandEvent& event)
|
|
|
|
{
|
2008-07-21 15:56:14 +00:00
|
|
|
BreakPointDlg bpDlg(this);
|
|
|
|
bpDlg.ShowModal();
|
2008-07-17 20:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-18 02:21:59 +00:00
|
|
|
// ==========================================================================================
|
|
|
|
// Load breakpoints from file
|
|
|
|
// --------------
|
|
|
|
void
|
|
|
|
CBreakPointWindow::OnAddBreakPointMany(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
// load ini
|
|
|
|
IniFile ini;
|
|
|
|
std::string filename = std::string("GameIni/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(_T("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))
|
|
|
|
{
|
|
|
|
CBreakPoints::AddBreakPoint(Address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// only update after we are done with the loop
|
|
|
|
CBreakPoints::UpdateBreakPointView();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("You have no GameIni/BreakPoints.ini file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// =================
|
|
|
|
|
|
|
|
|
2008-07-17 20:08:01 +00:00
|
|
|
void
|
|
|
|
CBreakPointWindow::OnAddMemoryCheck(wxCommandEvent& event)
|
|
|
|
{
|
2008-07-21 15:56:14 +00:00
|
|
|
MemoryCheckDlg memDlg(this);
|
|
|
|
memDlg.ShowModal();
|
2008-07-17 20:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-18 02:21:59 +00:00
|
|
|
// ==========================================================================================
|
|
|
|
// Load memory checks from file
|
|
|
|
// --------------
|
|
|
|
void
|
|
|
|
CBreakPointWindow::OnAddMemoryCheckMany(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
// load ini
|
|
|
|
IniFile ini;
|
|
|
|
std::string filename = std::string("GameIni/MemoryChecks.ini");
|
|
|
|
|
|
|
|
if (ini.Load(filename.c_str()))
|
|
|
|
{
|
|
|
|
// get lines from a certain section
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
if (!ini.GetLines("MemoryChecks", lines))
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("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);
|
2008-10-18 03:01:28 +00:00
|
|
|
std::vector<std::string> pieces;
|
2008-10-18 03:04:08 +00:00
|
|
|
SplitString(line, " ", pieces); // split string
|
2008-10-18 03:01:28 +00:00
|
|
|
|
|
|
|
TMemCheck MemCheck;
|
|
|
|
u32 sAddress = 0;
|
|
|
|
u32 eAddress = 0;
|
|
|
|
bool doCommon = false;
|
|
|
|
|
2008-10-18 03:04:08 +00:00
|
|
|
// ------------------------------------------------------------------------------------------
|
2008-10-20 07:39:40 +00:00
|
|
|
// Decide if we have a range or just one address, and if we should break or not
|
2008-10-18 03:04:08 +00:00
|
|
|
// --------------
|
2008-10-18 03:01:28 +00:00
|
|
|
if (
|
|
|
|
pieces.size() == 1
|
|
|
|
&& AsciiToHex(pieces[0].c_str(), sAddress)
|
|
|
|
&& pieces[0].size() == 8
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// address range
|
|
|
|
MemCheck.StartAddress = sAddress;
|
|
|
|
MemCheck.EndAddress = sAddress;
|
|
|
|
doCommon = true;
|
2008-10-20 07:39:40 +00:00
|
|
|
MemCheck.Break = false;
|
2008-10-18 03:01:28 +00:00
|
|
|
}
|
|
|
|
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;
|
2008-10-20 07:39:40 +00:00
|
|
|
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;
|
2008-10-18 03:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(doCommon)
|
2008-10-18 02:21:59 +00:00
|
|
|
{
|
2008-10-18 03:01:28 +00:00
|
|
|
// settings for the memory check
|
2008-10-18 02:21:59 +00:00
|
|
|
MemCheck.OnRead = true;
|
|
|
|
MemCheck.OnWrite = true;
|
|
|
|
MemCheck.Log = true;
|
2008-10-20 07:39:40 +00:00
|
|
|
//MemCheck.Break = false; // this is also what sets Active "on" in the breakpoint window
|
2008-10-18 02:21:59 +00:00
|
|
|
// so don't think it's off because we are only writing this to the log
|
2008-10-18 03:01:28 +00:00
|
|
|
CBreakPoints::AddMemoryCheck(MemCheck);
|
2008-10-18 02:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// update after we are done with the loop
|
|
|
|
CBreakPoints::UpdateBreakPointView();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("You have no GameIni/MemoryChecks.ini file"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// =================
|
|
|
|
|
|
|
|
|
2008-07-17 21:46:34 +00:00
|
|
|
void
|
|
|
|
CBreakPointWindow::OnActivated(wxListEvent& event)
|
|
|
|
{
|
|
|
|
long Index = event.GetIndex();
|
|
|
|
if (Index >= 0)
|
|
|
|
{
|
|
|
|
u32 Address = (u32)m_BreakPointListView->GetItemData(Index);
|
|
|
|
if (m_pCodeWindow != NULL)
|
|
|
|
{
|
|
|
|
m_pCodeWindow->JumpToAddress(Address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-17 20:08:01 +00:00
|
|
|
|