From 4570dd7eeb9033c0e349d3a9f0126f24010b0699 Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 26 Oct 2014 23:23:45 +1100 Subject: [PATCH] Fixed a crash that would occur if a new watch were added by entering a watch name. Code style updates. --- Source/Core/Common/BreakPoints.cpp | 2 +- Source/Core/Common/BreakPoints.h | 2 +- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 2 +- Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp | 2 +- Source/Core/DolphinWX/Debugger/CodeWindow.cpp | 2 +- Source/Core/DolphinWX/Debugger/WatchView.cpp | 38 ++++++++++------- Source/Core/DolphinWX/Debugger/WatchView.h | 4 +- Source/Core/DolphinWX/Debugger/WatchWindow.h | 10 ++--- Source/Core/DolphinWX/FrameTools.cpp | 42 ++++++++----------- 9 files changed, 53 insertions(+), 51 deletions(-) diff --git a/Source/Core/Common/BreakPoints.cpp b/Source/Core/Common/BreakPoints.cpp index ece8add228..8772a2287f 100644 --- a/Source/Core/Common/BreakPoints.cpp +++ b/Source/Core/Common/BreakPoints.cpp @@ -280,7 +280,7 @@ void Watches::Update(int count, u32 em_address) m_Watches.at(count).iAddress = em_address; } -void Watches::UpdateName(int count, std::string name) +void Watches::UpdateName(int count, const std::string name) { m_Watches.at(count).name = name; } diff --git a/Source/Core/Common/BreakPoints.h b/Source/Core/Common/BreakPoints.h index 73854b8167..7534f41400 100644 --- a/Source/Core/Common/BreakPoints.h +++ b/Source/Core/Common/BreakPoints.h @@ -125,7 +125,7 @@ public: void Add(const TWatch& bp); void Update(int count, u32 em_address); - void UpdateName(int count, std::string name); + void UpdateName(int count, const std::string name); // Remove Breakpoint void Remove(u32 _iAddress); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 2a5757d726..021ab386c4 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -867,7 +867,7 @@ void Jit64::EnableBlockLink() { jo.enableBlocklink = true; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bJITNoBlockLinking || - SConfig::GetInstance().m_LocalCoreStartupParameter.bMMU) + SConfig::GetInstance().m_LocalCoreStartupParameter.bMMU) { // TODO: support block linking with MMU jo.enableBlocklink = false; diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index 0f37c63c10..65f86d92cf 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -712,7 +712,7 @@ void JitIL::EnableBlockLink() { jo.enableBlocklink = true; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bJITNoBlockLinking || - SConfig::GetInstance().m_LocalCoreStartupParameter.bMMU) + SConfig::GetInstance().m_LocalCoreStartupParameter.bMMU) { // TODO: support block linking with MMU jo.enableBlocklink = false; diff --git a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp index 481240c498..35678e43dd 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp @@ -342,7 +342,7 @@ void CCodeWindow::StepOut() PowerPC::CoreMode oldMode = PowerPC::GetMode(); PowerPC::SetMode(PowerPC::MODE_INTERPRETER); UGeckoInstruction inst = Memory::Read_Instruction(PC); - GekkoOPInfo *opinfo = GetOpInfo(inst); + GekkoOPInfo* opinfo = GetOpInfo(inst); while (inst.hex != 0x4e800020 && steps < timeout) // check for blr { if (inst.LK) diff --git a/Source/Core/DolphinWX/Debugger/WatchView.cpp b/Source/Core/DolphinWX/Debugger/WatchView.cpp index a66ac40961..ea905a0f71 100644 --- a/Source/Core/DolphinWX/Debugger/WatchView.cpp +++ b/Source/Core/DolphinWX/Debugger/WatchView.cpp @@ -58,9 +58,17 @@ static void UpdateWatchAddr(int count, u32 value) PowerPC::watches.Update(count - 1, value); } -static void SetWatchName(int count, std::string value) +static void SetWatchName(int count, const std::string value) { - PowerPC::watches.UpdateName(count - 1, value); + if ((count - 1) < PowerPC::watches.GetWatches().size()) + { + PowerPC::watches.UpdateName(count - 1, value); + } + else + { + PowerPC::watches.Add(0); + PowerPC::watches.UpdateName(PowerPC::watches.GetWatches().size() - 1, value); + } } static void SetWatchValue(int count, u32 value) @@ -97,7 +105,7 @@ static wxString GetValueByRowCol(int row, int col) { u32 addr = GetWatchAddr(row); if (Memory::IsRAMAddress(addr)) - return Memory::GetString(addr, 32).c_str(); + return Memory::GetString(addr, 32).c_str(); else return wxEmptyString; } @@ -161,9 +169,9 @@ void CWatchTable::UpdateWatch() } } -wxGridCellAttr *CWatchTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind) +wxGridCellAttr* CWatchTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind) { - wxGridCellAttr *attr = new wxGridCellAttr(); + wxGridCellAttr* attr = new wxGridCellAttr(); attr->SetBackgroundColour(*wxWHITE); attr->SetFont(DebuggerFont); @@ -191,10 +199,8 @@ wxGridCellAttr *CWatchTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKin else { bool red = false; - switch (col) - { - case 1: red = m_CachedWatchHasChanged[row]; break; - } + if (col == 1) + red = m_CachedWatchHasChanged[row]; attr->SetTextColour(red ? *wxRED : *wxBLACK); @@ -208,7 +214,7 @@ wxGridCellAttr *CWatchTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKin return attr; } -CWatchView::CWatchView(wxWindow *parent, wxWindowID id) +CWatchView::CWatchView(wxWindow* parent, wxWindowID id) : wxGrid(parent, id) { SetTable(new CWatchTable(), false); @@ -269,11 +275,13 @@ void CWatchView::OnPopupMenu(wxCommandEvent& event) { case IDM_DELETEWATCH: strNewVal = GetValueByRowCol(m_selectedRow, 1); - TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress); - PowerPC::watches.Remove(m_selectedAddress); - if (watch_window) - watch_window->NotifyUpdate(); - Refresh(); + if (TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress)) + { + PowerPC::watches.Remove(m_selectedAddress); + if (watch_window) + watch_window->NotifyUpdate(); + Refresh(); + } break; case IDM_ADDMEMCHECK: MemCheck.StartAddress = m_selectedAddress; diff --git a/Source/Core/DolphinWX/Debugger/WatchView.h b/Source/Core/DolphinWX/Debugger/WatchView.h index dceaa0f3d7..e879696f72 100644 --- a/Source/Core/DolphinWX/Debugger/WatchView.h +++ b/Source/Core/DolphinWX/Debugger/WatchView.h @@ -30,8 +30,8 @@ public: int GetNumberCols() override { return 5; } int GetNumberRows() override { return MAX_SPECIALS; } wxString GetValue(int row, int col) override; - void SetValue(int row, int col, const wxString &) override; - wxGridCellAttr *GetAttr(int, int, wxGridCellAttr::wxAttrKind) override; + void SetValue(int row, int col, const wxString&) override; + wxGridCellAttr* GetAttr(int, int, wxGridCellAttr::wxAttrKind) override; void UpdateWatch(); private: diff --git a/Source/Core/DolphinWX/Debugger/WatchWindow.h b/Source/Core/DolphinWX/Debugger/WatchWindow.h index 360974dcb3..8c070768cd 100644 --- a/Source/Core/DolphinWX/Debugger/WatchWindow.h +++ b/Source/Core/DolphinWX/Debugger/WatchWindow.h @@ -21,11 +21,11 @@ class CWatchWindow { public: CWatchWindow(wxWindow* parent, - wxWindowID id = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxTAB_TRAVERSAL | wxNO_BORDER, - const wxString& name = _("Watch")); + wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = _("Watch")); ~CWatchWindow(); void NotifyUpdate(); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index c4a8009017..0c27b52308 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -661,15 +661,12 @@ void CFrame::BootGame(const std::string& filename) if (!bootfile.empty()) { StartGame(bootfile); - if (UseDebugger) + if (UseDebugger && g_pCodeWindow) { - if (g_pCodeWindow) - { - if (g_pCodeWindow->m_WatchWindow) - g_pCodeWindow->m_WatchWindow->LoadAll(); - if (g_pCodeWindow->m_BreakpointWindow) - g_pCodeWindow->m_BreakpointWindow->LoadAll(); - } + if (g_pCodeWindow->m_WatchWindow) + g_pCodeWindow->m_WatchWindow->LoadAll(); + if (g_pCodeWindow->m_BreakpointWindow) + g_pCodeWindow->m_BreakpointWindow->LoadAll(); } } } @@ -1178,25 +1175,22 @@ void CFrame::DoStop() } } - if (UseDebugger) + if (UseDebugger && g_pCodeWindow) { - if (g_pCodeWindow) + if (g_pCodeWindow->m_WatchWindow) { - if (g_pCodeWindow->m_WatchWindow) - { - g_pCodeWindow->m_WatchWindow->SaveAll(); - PowerPC::watches.Clear(); - } - if (g_pCodeWindow->m_BreakpointWindow) - { - g_pCodeWindow->m_BreakpointWindow->SaveAll(); - PowerPC::breakpoints.Clear(); - PowerPC::memchecks.Clear(); - g_pCodeWindow->m_BreakpointWindow->NotifyUpdate(); - } - g_symbolDB.Clear(); - Host_NotifyMapLoaded(); + g_pCodeWindow->m_WatchWindow->SaveAll(); + PowerPC::watches.Clear(); } + if (g_pCodeWindow->m_BreakpointWindow) + { + g_pCodeWindow->m_BreakpointWindow->SaveAll(); + PowerPC::breakpoints.Clear(); + PowerPC::memchecks.Clear(); + g_pCodeWindow->m_BreakpointWindow->NotifyUpdate(); + } + g_symbolDB.Clear(); + Host_NotifyMapLoaded(); } // TODO: Show the author/description dialog here