StringUtil cleanup. Nothing seems broken.
[dolphin.git] / Source / Core / DebuggerWX / Src / BreakpointWindow.cpp
blobffa2ffaf98c844dffa34a17b29ae7d37c1f3c11a
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #include "Debugger.h"
19 #include "BreakpointView.h"
20 #include "CodeWindow.h"
21 #include "HW/Memmap.h"
22 #include "BreakpointDlg.h"
23 #include "MemoryCheckDlg.h"
24 #include "Host.h"
25 #include "PowerPC/PowerPC.h"
26 #include "FileUtil.h"
28 BEGIN_EVENT_TABLE(CBreakPointWindow, wxPanel)
29 EVT_LIST_ITEM_ACTIVATED(ID_BPS, CBreakPointWindow::OnActivated)
30 EVT_LIST_ITEM_SELECTED(ID_TOOLBAR, CBreakPointWindow::OnSelectItem)
31 END_EVENT_TABLE()
33 CBreakPointWindow::CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent,
34 wxWindowID id, const wxString& title, const wxPoint& position,
35 const wxSize& size, long style)
36 : wxPanel(parent, id, position, size, style, title)
37 , m_BreakPointListView(NULL)
38 , m_pCodeWindow(_pCodeWindow)
40 CreateGUIControls();
43 void CBreakPointWindow::CreateGUIControls()
45 SetSize(8, 8, 400, 370);
46 Center();
48 m_BreakPointBar = new CBreakPointBar(this, ID_TOOLBAR, wxDefaultPosition, wxSize(0, 55),
49 wxLC_ICON | wxSUNKEN_BORDER | wxLC_SINGLE_SEL);
50 m_BreakPointListView = new CBreakPointView(this, ID_BPS, wxDefaultPosition, wxDefaultSize,
51 wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL | wxLC_SORT_ASCENDING);
53 wxBoxSizer* sizerH = new wxBoxSizer(wxVERTICAL);
54 sizerH->Add(m_BreakPointBar, 0, wxALL | wxEXPAND);
55 sizerH->Add((wxListCtrl*)m_BreakPointListView, 1, wxEXPAND);
57 NotifyUpdate();
58 SetSizer(sizerH);
61 void CBreakPointWindow::OnSelectItem(wxListEvent& event)
63 switch(event.GetItem().GetId())
65 case IDM_DELETE:
66 OnDelete();
67 m_BreakPointBar->SetItemState(event.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED);
68 break;
69 case IDM_CLEAR:
70 OnClear();
71 m_BreakPointBar->SetItemState(event.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED);
72 break;
73 case IDM_ADD_BREAKPOINT:
74 OnAddBreakPoint();
75 break;
76 case IDM_ADD_BREAKPOINTMANY:
77 OnAddBreakPointMany();
78 break;
79 case IDM_ADD_MEMORYCHECK:
80 OnAddMemoryCheck();
81 break;
82 case IDM_ADD_MEMORYCHECKMANY:
83 OnAddMemoryCheckMany();
84 break;
88 void CBreakPointWindow::NotifyUpdate()
90 if (m_BreakPointListView != NULL) m_BreakPointListView->Update();
93 void CBreakPointWindow::OnDelete()
95 if (m_BreakPointListView)
97 m_BreakPointListView->DeleteCurrentSelection();
101 void CBreakPointWindow::OnActivated(wxListEvent& event)
103 long Index = event.GetIndex();
104 if (Index >= 0)
106 u32 Address = (u32)m_BreakPointListView->GetItemData(Index);
107 if (m_pCodeWindow != NULL)
109 m_pCodeWindow->JumpToAddress(Address);
114 // Breakpoint actions
115 // ---------------------
117 // Clear all breakpoints
118 void CBreakPointWindow::OnClear()
120 PowerPC::breakpoints.Clear();
121 PowerPC::memchecks.Clear();
122 NotifyUpdate();
125 // Add one breakpoint
126 void CBreakPointWindow::OnAddBreakPoint()
128 BreakPointDlg bpDlg(this, this);
129 bpDlg.ShowModal();
132 // Load breakpoints from file
133 void CBreakPointWindow::OnAddBreakPointMany()
135 // load ini
136 IniFile ini;
137 std::string filename = std::string(File::GetUserPath(D_GAMECONFIG_IDX)) + "BreakPoints.ini";
139 if (ini.Load(filename.c_str())) // check if there is any file there
141 // get lines from a certain section
142 std::vector<std::string> lines;
143 if (!ini.GetLines("BreakPoints", lines))
145 wxMessageBox(_T("You have no [BreakPoints] line in your file"));
146 return;
149 for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
151 std::string line = StripSpaces(*iter);
152 u32 Address = 0;
153 if (AsciiToHex(line.c_str(), Address))
155 PowerPC::breakpoints.Add(Address);
158 // Only update after we are done with the loop
159 NotifyUpdate();
161 else
163 wxMessageBox(_T("Couldn't find GameConfig/BreakPoints.ini file"));
168 // Memory check actions
169 // ---------------------
170 void
171 CBreakPointWindow::OnAddMemoryCheck()
173 MemoryCheckDlg memDlg(this);
174 memDlg.ShowModal();
177 // Load memory checks from file
178 void CBreakPointWindow::OnAddMemoryCheckMany()
180 // load ini
181 IniFile ini;
182 std::string filename = std::string(File::GetUserPath(D_GAMECONFIG_IDX)) + "MemoryChecks.ini";
184 if (ini.Load(filename.c_str()))
186 // get lines from a certain section
187 std::vector<std::string> lines;
188 if (!ini.GetLines("MemoryChecks", lines))
190 wxMessageBox(_T("You have no [MemoryChecks] line in your file"));
191 return;
194 for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
196 std::string line = StripSpaces(*iter);
197 std::vector<std::string> pieces;
198 SplitString(line, ' ', pieces); // split string
200 TMemCheck MemCheck;
201 u32 sAddress = 0;
202 u32 eAddress = 0;
203 bool doCommon = false;
205 // ------------------------------------------------------------------------------------------
206 // Decide if we have a range or just one address, and if we should break or not
207 // --------------
208 if (
209 pieces.size() == 1
210 && AsciiToHex(pieces[0].c_str(), sAddress)
211 && pieces[0].size() == 8
214 // address range
215 MemCheck.StartAddress = sAddress;
216 MemCheck.EndAddress = sAddress;
217 doCommon = true;
218 MemCheck.Break = false;
220 else if(
221 pieces.size() == 2
222 && AsciiToHex(pieces[0].c_str(), sAddress) && AsciiToHex(pieces[1].c_str(), eAddress)
223 && pieces[0].size() == 8 && pieces[1].size() == 8
226 // address range
227 MemCheck.StartAddress = sAddress;
228 MemCheck.EndAddress = eAddress;
229 doCommon = true;
230 MemCheck.Break = false;
232 else if(
233 pieces.size() == 3
234 && AsciiToHex(pieces[0].c_str(), sAddress) && AsciiToHex(pieces[1].c_str(), eAddress)
235 && pieces[0].size() == 8 && pieces[1].size() == 8 && pieces[2].size() == 1
238 // address range
239 MemCheck.StartAddress = sAddress;
240 MemCheck.EndAddress = eAddress;
241 doCommon = true;
242 MemCheck.Break = true;
245 if (doCommon)
247 // settings for the memory check
248 MemCheck.OnRead = true;
249 MemCheck.OnWrite = true;
250 MemCheck.Log = true;
251 //MemCheck.Break = false; // this is also what sets Active "on" in the breakpoint window
252 // so don't think it's off because we are only writing this to the log
253 PowerPC::memchecks.Add(MemCheck);
256 // Update after we are done with the loop
257 NotifyUpdate();
259 else
261 wxMessageBox(_T("You have no ") + wxString::FromAscii(File::GetUserPath(D_GAMECONFIG_IDX)) + _T("MemoryChecks.ini file"));