2013-04-17 21:43:35 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstdio>
|
2010-02-18 05:06:13 -07:00
|
|
|
#include <wx/artprov.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/thread.h>
|
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <wx/windowid.h>
|
|
|
|
#include <wx/aui/auibar.h>
|
|
|
|
#include <wx/aui/auibook.h>
|
|
|
|
#include <wx/aui/framemanager.h>
|
2010-02-18 05:06:13 -07:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/SymbolDB.h"
|
2014-07-08 06:29:26 -06:00
|
|
|
#include "Core/Host.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Core/DSP/DSPCore.h"
|
|
|
|
#include "Core/HW/DSPLLE/DSPDebugInterface.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/HW/DSPLLE/DSPSymbols.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
|
|
|
#include "DolphinWX/Debugger/CodeView.h"
|
|
|
|
#include "DolphinWX/Debugger/DSPDebugWindow.h"
|
|
|
|
#include "DolphinWX/Debugger/DSPRegisterView.h"
|
|
|
|
#include "DolphinWX/Debugger/MemoryView.h"
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2014-07-08 14:37:58 -06:00
|
|
|
static DSPDebuggerLLE* m_DebuggerFrame = nullptr;
|
2010-07-28 09:22:27 -06:00
|
|
|
|
2011-01-30 21:36:49 -07:00
|
|
|
DSPDebuggerLLE::DSPDebuggerLLE(wxWindow* parent, wxWindowID id)
|
|
|
|
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize,
|
2013-04-07 23:16:50 -06:00
|
|
|
wxTAB_TRAVERSAL, _("DSP LLE Debugger"))
|
2010-02-18 05:06:13 -07:00
|
|
|
, m_CachedStepCounter(-1)
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
2014-11-05 20:19:52 -07:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, &DSPDebuggerLLE::OnClose, this);
|
|
|
|
Bind(wxEVT_MENU, &DSPDebuggerLLE::OnChangeState, this, ID_RUNTOOL, ID_SHOWPCTOOL);
|
|
|
|
|
2011-01-30 21:36:49 -07:00
|
|
|
m_DebuggerFrame = this;
|
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
// notify wxAUI which frame to use
|
|
|
|
m_mgr.SetManagedWindow(this);
|
2011-01-31 10:15:21 -07:00
|
|
|
m_mgr.SetFlags(wxAUI_MGR_DEFAULT | wxAUI_MGR_LIVE_RESIZE);
|
2010-02-18 05:06:13 -07:00
|
|
|
|
|
|
|
m_Toolbar = new wxAuiToolBar(this, ID_TOOLBAR,
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_TEXT);
|
2014-05-17 11:17:28 -06:00
|
|
|
m_Toolbar->AddTool(ID_RUNTOOL, _("Pause"),
|
2010-02-18 05:06:13 -07:00
|
|
|
wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, wxSize(10,10)));
|
2014-05-17 11:17:28 -06:00
|
|
|
m_Toolbar->AddTool(ID_STEPTOOL, _("Step"),
|
2010-02-18 05:06:13 -07:00
|
|
|
wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_OTHER, wxSize(10,10)));
|
2014-05-17 11:17:28 -06:00
|
|
|
m_Toolbar->AddTool(ID_SHOWPCTOOL, _("Show PC"),
|
2010-02-18 05:06:13 -07:00
|
|
|
wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_OTHER, wxSize(10,10)));
|
2009-07-05 20:10:26 -06:00
|
|
|
m_Toolbar->AddSeparator();
|
2014-11-05 20:19:52 -07:00
|
|
|
|
|
|
|
m_addr_txtctrl = new wxTextCtrl(m_Toolbar, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
|
|
|
|
m_addr_txtctrl->Bind(wxEVT_TEXT_ENTER, &DSPDebuggerLLE::OnAddrBoxChange, this);
|
|
|
|
|
|
|
|
m_Toolbar->AddControl(m_addr_txtctrl);
|
2009-07-05 20:10:26 -06:00
|
|
|
m_Toolbar->Realize();
|
|
|
|
|
2014-11-05 20:19:52 -07:00
|
|
|
m_SymbolList = new wxListBox(this, wxID_ANY, wxDefaultPosition,
|
2014-03-09 14:14:26 -06:00
|
|
|
wxSize(140, 100), 0, nullptr, wxLB_SORT);
|
2014-11-05 20:19:52 -07:00
|
|
|
m_SymbolList->Bind(wxEVT_LISTBOX, &DSPDebuggerLLE::OnSymbolListChange, this);
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
m_MainNotebook = new wxAuiNotebook(this, wxID_ANY,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_MOVE);
|
|
|
|
|
|
|
|
wxPanel *code_panel = new wxPanel(m_MainNotebook, wxID_ANY);
|
|
|
|
wxBoxSizer *code_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
m_CodeView = new CCodeView(&debug_interface, &DSPSymbols::g_dsp_symbol_db, code_panel);
|
2009-07-05 20:10:26 -06:00
|
|
|
m_CodeView->SetPlain();
|
2010-02-18 05:06:13 -07:00
|
|
|
code_sizer->Add(m_CodeView, 1, wxALL | wxEXPAND);
|
|
|
|
code_panel->SetSizer(code_sizer);
|
2014-05-17 11:17:28 -06:00
|
|
|
m_MainNotebook->AddPage(code_panel, _("Disassembly"), true);
|
2010-02-18 05:06:13 -07:00
|
|
|
|
|
|
|
wxPanel *mem_panel = new wxPanel(m_MainNotebook, wxID_ANY);
|
|
|
|
wxBoxSizer *mem_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
// TODO insert memViewer class
|
|
|
|
m_MemView = new CMemoryView(&debug_interface, mem_panel);
|
|
|
|
mem_sizer->Add(m_MemView, 1, wxALL | wxEXPAND);
|
|
|
|
mem_panel->SetSizer(mem_sizer);
|
2014-05-17 11:17:28 -06:00
|
|
|
m_MainNotebook->AddPage(mem_panel, _("Memory"));
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
m_Regs = new DSPRegisterView(this, ID_DSP_REGS);
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
// add the panes to the manager
|
|
|
|
m_mgr.AddPane(m_Toolbar, wxAuiPaneInfo().
|
|
|
|
ToolbarPane().Top().
|
|
|
|
LeftDockable(false).RightDockable(false));
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
m_mgr.AddPane(m_SymbolList, wxAuiPaneInfo().
|
|
|
|
Left().CloseButton(false).
|
2014-05-17 11:17:28 -06:00
|
|
|
Caption(_("Symbols")).Dockable(true));
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
m_mgr.AddPane(m_MainNotebook, wxAuiPaneInfo().
|
2014-05-17 11:17:28 -06:00
|
|
|
Name("m_MainNotebook").Center().
|
2010-02-18 05:06:13 -07:00
|
|
|
CloseButton(false).MaximizeButton(true));
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2010-02-18 05:06:13 -07:00
|
|
|
m_mgr.AddPane(m_Regs, wxAuiPaneInfo().Right().
|
2014-05-17 11:17:28 -06:00
|
|
|
CloseButton(false).Caption(_("Registers")).
|
2010-02-18 05:06:13 -07:00
|
|
|
Dockable(true));
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
UpdateState();
|
2010-02-18 05:06:13 -07:00
|
|
|
|
|
|
|
m_mgr.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSPDebuggerLLE::~DSPDebuggerLLE()
|
|
|
|
{
|
|
|
|
m_mgr.UnInit();
|
2014-03-09 14:14:26 -06:00
|
|
|
m_DebuggerFrame = nullptr;
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2010-07-28 09:22:27 -06:00
|
|
|
event.Skip();
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnChangeState(wxCommandEvent& event)
|
|
|
|
{
|
2010-07-21 20:05:28 -06:00
|
|
|
if (DSPCore_GetState() == DSPCORE_STOP)
|
|
|
|
return;
|
|
|
|
|
2009-07-05 20:10:26 -06:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
2010-07-21 20:05:28 -06:00
|
|
|
case ID_RUNTOOL:
|
|
|
|
if (DSPCore_GetState() == DSPCORE_RUNNING)
|
|
|
|
DSPCore_SetState(DSPCORE_STEPPING);
|
|
|
|
else
|
|
|
|
DSPCore_SetState(DSPCORE_RUNNING);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_STEPTOOL:
|
|
|
|
if (DSPCore_GetState() == DSPCORE_STEPPING)
|
|
|
|
{
|
|
|
|
DSPCore_Step();
|
2012-12-23 04:00:45 -07:00
|
|
|
Update();
|
2010-07-21 20:05:28 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SHOWPCTOOL:
|
|
|
|
FocusOnPC();
|
|
|
|
break;
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateState();
|
2010-02-18 05:06:13 -07:00
|
|
|
m_mgr.Update();
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
2011-01-31 07:25:50 -07:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
if (m_DebuggerFrame)
|
2012-12-23 04:00:45 -07:00
|
|
|
m_DebuggerFrame->Update();
|
2011-01-31 07:25:50 -07:00
|
|
|
}
|
|
|
|
|
2012-12-23 04:00:45 -07:00
|
|
|
void DSPDebuggerLLE::Update()
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
2011-01-31 07:25:50 -07:00
|
|
|
#if defined __WXGTK__
|
2010-08-01 19:52:00 -06:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
wxMutexGuiEnter();
|
|
|
|
#endif
|
2009-07-05 20:10:26 -06:00
|
|
|
UpdateSymbolMap();
|
|
|
|
UpdateDisAsmListView();
|
|
|
|
UpdateRegisterFlags();
|
|
|
|
UpdateState();
|
2010-02-18 05:06:13 -07:00
|
|
|
m_mgr.Update();
|
2011-01-31 07:25:50 -07:00
|
|
|
#if defined __WXGTK__
|
2010-08-01 19:52:00 -06:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
wxMutexGuiLeave();
|
|
|
|
#endif
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::FocusOnPC()
|
|
|
|
{
|
|
|
|
JumpToAddress(g_dsp.pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateState()
|
|
|
|
{
|
2010-07-28 09:22:27 -06:00
|
|
|
if (DSPCore_GetState() == DSPCORE_RUNNING)
|
2013-04-07 23:16:50 -06:00
|
|
|
{
|
2014-05-17 11:17:28 -06:00
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, _("Pause"));
|
2010-02-18 05:06:13 -07:00
|
|
|
m_Toolbar->SetToolBitmap(ID_RUNTOOL,
|
|
|
|
wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, false);
|
2010-07-28 09:22:27 -06:00
|
|
|
}
|
2013-04-07 23:16:50 -06:00
|
|
|
else
|
|
|
|
{
|
2014-05-17 11:17:28 -06:00
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, _("Run"));
|
2010-02-18 05:06:13 -07:00
|
|
|
m_Toolbar->SetToolBitmap(ID_RUNTOOL,
|
|
|
|
wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, true);
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
m_Toolbar->Realize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateDisAsmListView()
|
|
|
|
{
|
|
|
|
if (m_CachedStepCounter == g_dsp.step_counter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// show PC
|
|
|
|
FocusOnPC();
|
|
|
|
m_CachedStepCounter = g_dsp.step_counter;
|
|
|
|
m_Regs->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateSymbolMap()
|
|
|
|
{
|
2014-03-09 14:14:26 -06:00
|
|
|
if (g_dsp.dram == nullptr)
|
2009-07-05 20:10:26 -06:00
|
|
|
return;
|
|
|
|
|
2014-02-16 21:51:41 -07:00
|
|
|
m_SymbolList->Freeze(); // HyperIris: wx style fast filling
|
2009-07-05 20:10:26 -06:00
|
|
|
m_SymbolList->Clear();
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const auto& symbol : DSPSymbols::g_dsp_symbol_db.Symbols())
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
int idx = m_SymbolList->Append(StrToWxStr(symbol.second.name));
|
|
|
|
m_SymbolList->SetClientData(idx, (void*)&symbol.second);
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
m_SymbolList->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnSymbolListChange(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int index = m_SymbolList->GetSelection();
|
2014-08-30 15:01:19 -06:00
|
|
|
if (index >= 0)
|
|
|
|
{
|
2009-07-05 20:10:26 -06:00
|
|
|
Symbol* pSymbol = static_cast<Symbol *>(m_SymbolList->GetClientData(index));
|
2014-03-09 14:14:26 -06:00
|
|
|
if (pSymbol != nullptr)
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
|
|
|
if (pSymbol->type == Symbol::SYMBOL_FUNCTION)
|
|
|
|
{
|
|
|
|
JumpToAddress(pSymbol->address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateRegisterFlags()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event)
|
|
|
|
{
|
2014-11-05 20:19:52 -07:00
|
|
|
wxString txt = m_addr_txtctrl->GetValue();
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2013-02-27 21:37:38 -07:00
|
|
|
auto text = StripSpaces(WxStrToStr(txt));
|
2009-07-05 20:10:26 -06:00
|
|
|
if (text.size())
|
|
|
|
{
|
|
|
|
u32 addr;
|
|
|
|
sscanf(text.c_str(), "%04x", &addr);
|
|
|
|
if (JumpToAddress(addr))
|
2014-11-05 20:19:52 -07:00
|
|
|
m_addr_txtctrl->SetBackgroundColour(*wxWHITE);
|
2009-07-05 20:10:26 -06:00
|
|
|
else
|
2014-11-05 20:19:52 -07:00
|
|
|
m_addr_txtctrl->SetBackgroundColour(*wxRED);
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
2010-02-18 05:06:13 -07:00
|
|
|
event.Skip();
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DSPDebuggerLLE::JumpToAddress(u16 addr)
|
|
|
|
{
|
2010-02-18 05:06:13 -07:00
|
|
|
int page = m_MainNotebook->GetSelection();
|
|
|
|
if (page == 0)
|
|
|
|
{
|
|
|
|
// Center on valid instruction in IRAM/IROM
|
|
|
|
int new_line = DSPSymbols::Addr2Line(addr);
|
2014-08-30 15:01:19 -06:00
|
|
|
if (new_line >= 0)
|
|
|
|
{
|
2010-02-18 05:06:13 -07:00
|
|
|
m_CodeView->Center(new_line);
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
2010-02-18 05:06:13 -07:00
|
|
|
else if (page == 1)
|
|
|
|
{
|
|
|
|
// Center on any location in any valid ROM/RAM
|
|
|
|
int seg = addr >> 12;
|
|
|
|
if (seg == 0 || seg == 1 ||
|
|
|
|
seg == 8 || seg == 0xf)
|
|
|
|
{
|
|
|
|
m_MemView->Center(addr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|