From 343d1ece115879ea2c8d77abbeadaa8ef3e3de77 Mon Sep 17 00:00:00 2001 From: "fires.gc" Date: Thu, 17 Jul 2008 21:46:34 +0000 Subject: [PATCH] debugger improvments git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@25 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/StringUtil.cpp | 9 +++ Source/Core/Core/Src/Core.cpp | 2 +- .../Src/Debugger/Debugger_BreakPoints.cpp | 37 ++++++++++ .../Core/Src/Debugger/Debugger_BreakPoints.h | 4 +- Source/Core/Core/Src/HW/Memmap.cpp | 2 +- Source/Core/DebuggerWX/src/BreakpointView.cpp | 26 ++++--- .../Core/DebuggerWX/src/BreakpointWindow.cpp | 18 ++++- Source/Core/DebuggerWX/src/BreakpointWindow.h | 7 +- Source/Core/DebuggerWX/src/CodeWindow.cpp | 74 ++++++++++++++++++- Source/Core/DebuggerWX/src/CodeWindow.h | 4 +- Source/Core/DolphinWX/src/BootManager.cpp | 10 +-- Source/Core/DolphinWX/src/Main.cpp | 34 ++++----- 12 files changed, 186 insertions(+), 41 deletions(-) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 4df2c4c05e..001f6f51ee 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -240,6 +240,13 @@ bool TryParseInt(const char* str, int* outVal) { const char* s = str; int value = 0; + bool negativ = false; + + if (*s == '-') + { + negativ = true; + s++; + } while (*s) { @@ -252,6 +259,8 @@ bool TryParseInt(const char* str, int* outVal) value = value * 10 + (c - '0'); } + if (negativ) + value = -value; *outVal = value; return(true); diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index 1d99eb666a..89fb68096d 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -224,7 +224,7 @@ THREAD_RETURN EmuThread(void *pArg) VideoInitialize.pGetMemoryPointer = Memory::GetPointer; VideoInitialize.pSetPEToken = PixelEngine::SetToken; VideoInitialize.pSetPEFinish = PixelEngine::SetFinish; - VideoInitialize.pWindowHandle = NULL; // _CoreParameter.hMainWindow; // NULL; // filled by video_initialize + VideoInitialize.pWindowHandle = _CoreParameter.hMainWindow; // NULL; // filled by video_initialize VideoInitialize.pLog = Callback_VideoLog; VideoInitialize.pRequestWindowSize = NULL; //Callback_VideoRequestWindowSize; VideoInitialize.pCopiedToXFB = Callback_VideoCopiedToXFB; diff --git a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp index fe7477fe75..39ec765c19 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp +++ b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.cpp @@ -18,6 +18,12 @@ // Lame slow breakpoint system // TODO: a real one +// +// [F|RES]: this class isn't really nice... for a better management we should use a base class for +// breakpoints and memory checks. but probably this will be slower too +// + + #include "Common.h" #include "../HW/CPU.h" @@ -154,6 +160,37 @@ void CBreakPoints::AddAutoBreakpoints() AddBreakPoint(symbol.vaddress, false); } } + + Host_UpdateBreakPointView(); #endif #endif } + +void CBreakPoints::DeleteElementByAddress(u32 _Address) +{ + // first check breakpoints + { + std::vector::iterator iter; + for (iter = m_BreakPoints.begin(); iter != m_BreakPoints.end(); ++iter) + { + if ((*iter).iAddress == _Address) + { + m_BreakPoints.erase(iter); + Host_UpdateBreakPointView(); + return; + } + } + } + + // second memory check checkpoint + std::vector::iterator iter; + for (iter = m_MemChecks.begin(); iter != m_MemChecks.end(); ++iter) + { + if ((*iter).iStartAddress == _Address) + { + m_MemChecks.erase(iter); + Host_UpdateBreakPointView(); + return; + } + } +} diff --git a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h index 9c7d287e32..1203ceff26 100644 --- a/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h +++ b/Source/Core/Core/Src/Debugger/Debugger_BreakPoints.h @@ -25,7 +25,7 @@ struct TBreakPoint { - u32 iAddress; + u32 iAddress; bool bOn; bool bTemporary; }; @@ -83,6 +83,8 @@ public: static void AddAutoBreakpoints(); + static void DeleteElementByAddress(u32 _Address); + private: static TBreakPoints m_BreakPoints; diff --git a/Source/Core/Core/Src/HW/Memmap.cpp b/Source/Core/Core/Src/HW/Memmap.cpp index 8452a35ca9..1b2e84e45c 100644 --- a/Source/Core/Core/Src/HW/Memmap.cpp +++ b/Source/Core/Core/Src/HW/Memmap.cpp @@ -46,7 +46,7 @@ namespace Memory // GLOABL DEFINES -// #define NOCHECK +#define NOCHECK static const bool bFakeVMEM = false; diff --git a/Source/Core/DebuggerWX/src/BreakpointView.cpp b/Source/Core/DebuggerWX/src/BreakpointView.cpp index bcb86e2a4a..2c6c79b79a 100644 --- a/Source/Core/DebuggerWX/src/BreakpointView.cpp +++ b/Source/Core/DebuggerWX/src/BreakpointView.cpp @@ -24,6 +24,7 @@ BEGIN_EVENT_TABLE(CBreakPointView, wxListCtrl) + END_EVENT_TABLE() CBreakPointView::CBreakPointView(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style) @@ -43,7 +44,10 @@ CBreakPointView::Update() InsertColumn(0, wxT("Active"), wxLIST_FORMAT_LEFT, 50); InsertColumn(1, wxT("Type"), wxLIST_FORMAT_LEFT, 50); InsertColumn(2, wxT("Function"), wxLIST_FORMAT_CENTER, 200); + InsertColumn(3, wxT("Address"), wxLIST_FORMAT_CENTER, 100); + InsertColumn(4, wxT("Flags"), wxLIST_FORMAT_CENTER, 100); + char szBuffer[32]; const CBreakPoints::TBreakPoints& rBreakPoints = CBreakPoints::GetBreakPoints(); for (size_t i=0; i= 0) + { + u32 Address = GetItemData(Item); + CBreakPoints::DeleteElementByAddress(Address); + } } \ No newline at end of file diff --git a/Source/Core/DebuggerWX/src/BreakpointWindow.cpp b/Source/Core/DebuggerWX/src/BreakpointWindow.cpp index fbcf1ad4bd..e752f1bbdb 100644 --- a/Source/Core/DebuggerWX/src/BreakpointWindow.cpp +++ b/Source/Core/DebuggerWX/src/BreakpointWindow.cpp @@ -5,6 +5,7 @@ #include "Debugger.h" #include "BreakPointWindow.h" #include "BreakpointView.h" +#include "CodeWindow.h" #include "wx/mstream.h" @@ -21,6 +22,7 @@ BEGIN_EVENT_TABLE(CBreakPointWindow, wxFrame) EVT_MENU(IDM_DELETE, CBreakPointWindow::OnDelete) EVT_MENU(IDM_ADD_BREAKPOINT, CBreakPointWindow::OnAddBreakPoint) EVT_MENU(IDM_ADD_MEMORYCHECK, CBreakPointWindow::OnAddMemoryCheck) + EVT_LIST_ITEM_ACTIVATED(ID_BPS, CBreakPointWindow::OnActivated) END_EVENT_TABLE() @@ -32,9 +34,10 @@ inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length) } -CBreakPointWindow::CBreakPointWindow(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style) +CBreakPointWindow::CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style) : wxFrame(parent, id, title, position, size, style) , m_BreakPointListView(NULL) + , m_pCodeWindow(_pCodeWindow) { InitBitmaps(); @@ -157,4 +160,17 @@ CBreakPointWindow::OnAddMemoryCheck(wxCommandEvent& event) } +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); + } + } +} diff --git a/Source/Core/DebuggerWX/src/BreakpointWindow.h b/Source/Core/DebuggerWX/src/BreakpointWindow.h index 6b7caf3f1b..43bbe03f37 100644 --- a/Source/Core/DebuggerWX/src/BreakpointWindow.h +++ b/Source/Core/DebuggerWX/src/BreakpointWindow.h @@ -6,6 +6,8 @@ #define __BREAKPOINTWINDOW_h__ class CBreakPointView; +class CCodeWindow; +class wxListEvent; #undef BREAKPOINT_WINDOW_STYLE #define BREAKPOINT_WINDOW_STYLE wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX | wxRESIZE_BORDER @@ -19,7 +21,7 @@ class CBreakPointWindow public: - CBreakPointWindow(wxWindow* parent, wxWindowID id = 1, const wxString& title = wxT("Breakpoints"), + CBreakPointWindow(CCodeWindow* _pCodeWindow, wxWindow* parent, wxWindowID id = 1, const wxString& title = wxT("Breakpoints"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(400, 250), long style = BREAKPOINT_WINDOW_STYLE); @@ -48,6 +50,8 @@ class CBreakPointWindow }; CBreakPointView* m_BreakPointListView; + CCodeWindow* m_pCodeWindow; + wxBitmap m_Bitmaps[Bitmaps_max]; void OnClose(wxCloseEvent& event); @@ -60,6 +64,7 @@ class CBreakPointWindow void OnDelete(wxCommandEvent& event); void OnAddBreakPoint(wxCommandEvent& event); void OnAddMemoryCheck(wxCommandEvent& event); + void OnActivated(wxListEvent& event); }; #endif diff --git a/Source/Core/DebuggerWX/src/CodeWindow.cpp b/Source/Core/DebuggerWX/src/CodeWindow.cpp index 269917aad0..319f609691 100644 --- a/Source/Core/DebuggerWX/src/CodeWindow.cpp +++ b/Source/Core/DebuggerWX/src/CodeWindow.cpp @@ -20,6 +20,7 @@ #include "RegisterWindow.h" #include "LogWindow.h" #include "BreakpointWindow.h" +#include "IniFile.h" #include "wx/button.h" #include "wx/textctrl.h" @@ -89,7 +90,7 @@ CCodeWindow::CCodeWindow(const SCoreStartupParameter& _LocalCoreStartupParameter : wxFrame(parent, id, title, pos, size, style) , m_RegisterWindow(NULL) , m_logwindow(NULL) -{ +{ CreateMenu(_LocalCoreStartupParameter); wxBoxSizer* sizerBig = new wxBoxSizer(wxHORIZONTAL); @@ -133,11 +134,70 @@ CCodeWindow::CCodeWindow(const SCoreStartupParameter& _LocalCoreStartupParameter m_RegisterWindow = new CRegisterWindow(this); m_RegisterWindow->Show(true); - m_BreakpointWindow = new CBreakPointWindow(this); + m_BreakpointWindow = new CBreakPointWindow(this, this); m_BreakpointWindow->Show(true); UpdateButtonStates(); + + + int x,y,w,h; + + IniFile file; + file.Load("Debugger.ini"); + + file.Get("Code", "x", &x, GetPosition().x); + file.Get("Code", "y", &y, GetPosition().y); + file.Get("Code", "w", &w, GetSize().GetWidth()); + file.Get("Code", "h", &h, GetSize().GetHeight()); + this->SetSize(x, y, w, h); + + file.Get("BreakPoint", "x", &x, m_BreakpointWindow->GetPosition().x); + file.Get("BreakPoint", "y", &y, m_BreakpointWindow->GetPosition().y); + file.Get("BreakPoint", "w", &w, m_BreakpointWindow->GetSize().GetWidth()); + file.Get("BreakPoint", "h", &h, m_BreakpointWindow->GetSize().GetHeight()); + m_BreakpointWindow->SetSize(x, y, w, h); + + file.Get("LogWindow", "x", &x, m_logwindow->GetPosition().x); + file.Get("LogWindow", "y", &y, m_logwindow->GetPosition().y); + file.Get("LogWindow", "w", &w, m_logwindow->GetSize().GetWidth()); + file.Get("LogWindow", "h", &h, m_logwindow->GetSize().GetHeight()); + m_logwindow->SetSize(x, y, w, h); + + file.Get("RegisterWindow", "x", &x, m_RegisterWindow->GetPosition().x); + file.Get("RegisterWindow", "y", &y, m_RegisterWindow->GetPosition().y); + file.Get("RegisterWindow", "w", &w, m_RegisterWindow->GetSize().GetWidth()); + file.Get("RegisterWindow", "h", &h, m_RegisterWindow->GetSize().GetHeight()); + m_RegisterWindow->SetSize(x, y, w, h); +} + + +CCodeWindow::~CCodeWindow() +{ + IniFile file; + file.Load("Debugger.ini"); + + file.Set("Code", "x", GetPosition().x); + file.Set("Code", "y", GetPosition().y); + file.Set("Code", "w", GetSize().GetWidth()); + file.Set("Code", "h", GetSize().GetHeight()); + + file.Set("BreakPoint", "x", m_BreakpointWindow->GetPosition().x); + file.Set("BreakPoint", "y", m_BreakpointWindow->GetPosition().y); + file.Set("BreakPoint", "w", m_BreakpointWindow->GetSize().GetWidth()); + file.Set("BreakPoint", "h", m_BreakpointWindow->GetSize().GetHeight()); + + file.Set("LogWindow", "x", m_logwindow->GetPosition().x); + file.Set("LogWindow", "y", m_logwindow->GetPosition().y); + file.Set("LogWindow", "w", m_logwindow->GetSize().GetWidth()); + file.Set("LogWindow", "h", m_logwindow->GetSize().GetHeight()); + + file.Set("RegisterWindow", "x", m_RegisterWindow->GetPosition().x); + file.Set("RegisterWindow", "y", m_RegisterWindow->GetPosition().y); + file.Set("RegisterWindow", "w", m_RegisterWindow->GetSize().GetWidth()); + file.Set("RegisterWindow", "h", m_RegisterWindow->GetSize().GetHeight()); + + file.Save("Debugger.ini"); } @@ -190,6 +250,12 @@ bool CCodeWindow::UseDualCore() } +void CCodeWindow::JumpToAddress(u32 _Address) +{ + codeview->Center(_Address); +} + + void CCodeWindow::OnCodeStep(wxCommandEvent& event) { switch (event.GetId()) @@ -437,7 +503,7 @@ void CCodeWindow::OnToggleBreakPointWindow(wxCommandEvent& event) { if (!m_BreakpointWindow) { - m_BreakpointWindow = new CBreakPointWindow(this); + m_BreakpointWindow = new CBreakPointWindow(this, this); } m_BreakpointWindow->Show(true); @@ -485,12 +551,12 @@ void CCodeWindow::OnHostMessage(wxCommandEvent& event) break; case IDM_UPDATEBREAKPOINTS: + Update(); if (m_BreakpointWindow) { m_BreakpointWindow->NotifyUpdate(); } - break; } diff --git a/Source/Core/DebuggerWX/src/CodeWindow.h b/Source/Core/DebuggerWX/src/CodeWindow.h index ff711633ac..95db88ece6 100644 --- a/Source/Core/DebuggerWX/src/CodeWindow.h +++ b/Source/Core/DebuggerWX/src/CodeWindow.h @@ -43,12 +43,14 @@ class CCodeWindow const wxSize& size = wxSize(400, 500), long style = wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN | wxNO_FULL_REPAINT_ON_RESIZE); + ~CCodeWindow(); + void Update(); void NotifyMapLoaded(); bool UseInterpreter(); bool UseDualCore(); - + void JumpToAddress(u32 _Address); private: diff --git a/Source/Core/DolphinWX/src/BootManager.cpp b/Source/Core/DolphinWX/src/BootManager.cpp index 87d6b1741d..2cd0296b5f 100644 --- a/Source/Core/DolphinWX/src/BootManager.cpp +++ b/Source/Core/DolphinWX/src/BootManager.cpp @@ -34,7 +34,7 @@ static std::string s_DataBasePath_USA = "Data_USA"; static std::string s_DataBasePath_JAP = "Data_JAP"; extern CFrame* main_frame; -extern CCodeWindow* code_frame; +extern CCodeWindow* g_pCodeWindow; namespace BootManager { @@ -46,10 +46,10 @@ bool BootCore(const std::string& _rFilename) { SCoreStartupParameter StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter; - if (code_frame) + if (g_pCodeWindow) { // StartUp.bUseDualCore = code_frame->UseDualCore(); - StartUp.bUseDynarec = !code_frame->UseInterpreter(); + StartUp.bUseDynarec = !g_pCodeWindow->UseInterpreter(); } else { @@ -62,7 +62,7 @@ bool BootCore(const std::string& _rFilename) StartUp.bHLEBios = true; StartUp.bRunCompareClient = false; StartUp.bRunCompareServer = false; - StartUp.bEnableDebugging = code_frame ? true : false; // RUNNING_DEBUG + StartUp.bEnableDebugging = g_pCodeWindow ? true : false; // RUNNING_DEBUG std::string BaseDataPath; #ifdef _WIN32 StartUp.hInstance = wxGetInstance(); @@ -79,7 +79,7 @@ bool BootCore(const std::string& _rFilename) return(false); } - Core::SetState(code_frame ? Core::CORE_PAUSE : Core::CORE_RUN); + Core::SetState(g_pCodeWindow ? Core::CORE_PAUSE : Core::CORE_RUN); return(true); } diff --git a/Source/Core/DolphinWX/src/Main.cpp b/Source/Core/DolphinWX/src/Main.cpp index 774e9144a0..c154b460e0 100644 --- a/Source/Core/DolphinWX/src/Main.cpp +++ b/Source/Core/DolphinWX/src/Main.cpp @@ -30,7 +30,7 @@ IMPLEMENT_APP(DolphinApp) CFrame * main_frame = NULL; -CCodeWindow* code_frame = NULL; +CCodeWindow* g_pCodeWindow = NULL; // The `main program' equivalent, creating the windows and returning the // main frame @@ -93,8 +93,8 @@ bool DolphinApp::OnInit() // create debugger if (UseDebugger) { - code_frame = new CCodeWindow(SConfig::GetInstance().m_LocalCoreStartupParameter, main_frame); - code_frame->Show(true); + g_pCodeWindow = new CCodeWindow(SConfig::GetInstance().m_LocalCoreStartupParameter, main_frame); + g_pCodeWindow->Show(true); } SetTopWindow(main_frame); @@ -121,9 +121,9 @@ void Host_BootingStarted() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_BOOTING_STARTED); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -133,9 +133,9 @@ void Host_BootingEnded() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_BOOTING_ENDED); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -147,9 +147,9 @@ void Host_NotifyMapLoaded() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_NOTIFYMAPLOADED); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -159,9 +159,9 @@ void Host_UpdateLogDisplay() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATELOGDISPLAY); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -170,9 +170,9 @@ void Host_UpdateDisasmDialog() { wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEDISASMDIALOG); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -182,9 +182,9 @@ void Host_UpdateMainFrame() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEGUI); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } } @@ -193,9 +193,9 @@ void Host_UpdateBreakPointView() wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEBREAKPOINTS); wxPostEvent(main_frame, event); - if (code_frame) + if (g_pCodeWindow) { - wxPostEvent(code_frame, event); + wxPostEvent(g_pCodeWindow, event); } }