2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstdio>
|
2010-02-18 12:06:13 +00:00
|
|
|
#include <wx/artprov.h>
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <wx/aui/auibook.h>
|
2016-09-12 00:03:10 +00:00
|
|
|
#include <wx/aui/dockart.h>
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <wx/aui/framemanager.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/thread.h>
|
2010-02-18 12:06:13 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/SymbolDB.h"
|
|
|
|
#include "Core/DSP/DSPCore.h"
|
|
|
|
#include "Core/HW/DSPLLE/DSPDebugInterface.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/DSPLLE/DSPSymbols.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/Host.h"
|
2016-07-15 21:59:05 +00:00
|
|
|
#include "DolphinWX/AuiToolBar.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/CodeView.h"
|
|
|
|
#include "DolphinWX/Debugger/DSPDebugWindow.h"
|
|
|
|
#include "DolphinWX/Debugger/DSPRegisterView.h"
|
2016-09-12 00:03:10 +00:00
|
|
|
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/MemoryView.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-07-08 20:37:58 +00:00
|
|
|
static DSPDebuggerLLE* m_DebuggerFrame = nullptr;
|
2010-07-28 15:22:27 +00:00
|
|
|
|
2011-01-31 04:36:49 +00:00
|
|
|
DSPDebuggerLLE::DSPDebuggerLLE(wxWindow* parent, wxWindowID id)
|
2016-06-24 08:43:46 +00:00
|
|
|
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("DSP LLE Debugger")),
|
2017-06-07 11:16:02 +00:00
|
|
|
m_CachedStepCounter(UINT64_MAX), m_toolbar_item_size(FromDIP(wxSize(16, 16)))
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
Bind(wxEVT_MENU, &DSPDebuggerLLE::OnChangeState, this, ID_RUNTOOL, ID_SHOWPCTOOL);
|
|
|
|
|
|
|
|
m_DebuggerFrame = this;
|
|
|
|
|
|
|
|
// notify wxAUI which frame to use
|
|
|
|
m_mgr.SetManagedWindow(this);
|
|
|
|
m_mgr.SetFlags(wxAUI_MGR_DEFAULT | wxAUI_MGR_LIVE_RESIZE);
|
|
|
|
|
|
|
|
m_Toolbar =
|
2016-07-15 21:59:05 +00:00
|
|
|
new DolphinAuiToolBar(this, ID_TOOLBAR, wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_TEXT);
|
2016-06-24 08:43:46 +00:00
|
|
|
m_Toolbar->AddTool(ID_RUNTOOL, _("Pause"),
|
2016-10-03 07:29:50 +00:00
|
|
|
wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, m_toolbar_item_size));
|
2016-10-31 14:06:27 +00:00
|
|
|
// i18n: Here, "Step" is a verb. This function is used for
|
|
|
|
// going through code step by step.
|
2016-06-24 08:43:46 +00:00
|
|
|
m_Toolbar->AddTool(ID_STEPTOOL, _("Step"),
|
2016-10-03 07:29:50 +00:00
|
|
|
wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_OTHER, m_toolbar_item_size));
|
|
|
|
m_Toolbar->AddTool(
|
2016-10-31 14:06:27 +00:00
|
|
|
// i18n: Here, PC is an acronym for program counter, not personal computer.
|
2016-10-03 07:29:50 +00:00
|
|
|
ID_SHOWPCTOOL, _("Show PC"),
|
|
|
|
wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_OTHER, m_toolbar_item_size));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_Toolbar->AddSeparator();
|
|
|
|
|
|
|
|
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);
|
|
|
|
m_Toolbar->Realize();
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
m_SymbolList = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(100, 80)),
|
|
|
|
0, nullptr, wxLB_SORT);
|
2016-06-24 08:43:46 +00:00
|
|
|
m_SymbolList->Bind(wxEVT_LISTBOX, &DSPDebuggerLLE::OnSymbolListChange, this);
|
|
|
|
|
|
|
|
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);
|
2016-12-30 18:25:40 +00:00
|
|
|
m_CodeView = new CCodeView(&debug_interface, &DSP::Symbols::g_dsp_symbol_db, code_panel);
|
2016-06-24 08:43:46 +00:00
|
|
|
m_CodeView->SetPlain();
|
2016-10-03 07:29:50 +00:00
|
|
|
code_sizer->Add(m_CodeView, 1, wxEXPAND);
|
2016-06-24 08:43:46 +00:00
|
|
|
code_panel->SetSizer(code_sizer);
|
|
|
|
m_MainNotebook->AddPage(code_panel, _("Disassembly"), true);
|
|
|
|
|
|
|
|
wxPanel* mem_panel = new wxPanel(m_MainNotebook, wxID_ANY);
|
|
|
|
wxBoxSizer* mem_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
m_MemView = new CMemoryView(&debug_interface, mem_panel);
|
2016-10-03 07:29:50 +00:00
|
|
|
mem_sizer->Add(m_MemView, 1, wxEXPAND);
|
2016-06-24 08:43:46 +00:00
|
|
|
mem_panel->SetSizer(mem_sizer);
|
|
|
|
m_MainNotebook->AddPage(mem_panel, _("Memory"));
|
|
|
|
|
|
|
|
m_Regs = new DSPRegisterView(this);
|
|
|
|
|
|
|
|
// add the panes to the manager
|
|
|
|
m_mgr.AddPane(m_Toolbar,
|
|
|
|
wxAuiPaneInfo().ToolbarPane().Top().LeftDockable(false).RightDockable(false));
|
|
|
|
|
|
|
|
m_mgr.AddPane(m_SymbolList,
|
|
|
|
wxAuiPaneInfo().Left().CloseButton(false).Caption(_("Symbols")).Dockable(true));
|
|
|
|
|
|
|
|
m_mgr.AddPane(
|
|
|
|
m_MainNotebook,
|
|
|
|
wxAuiPaneInfo().Name("m_MainNotebook").Center().CloseButton(false).MaximizeButton(true));
|
|
|
|
|
|
|
|
m_mgr.AddPane(m_Regs,
|
|
|
|
wxAuiPaneInfo().Right().CloseButton(false).Caption(_("Registers")).Dockable(true));
|
|
|
|
|
2016-09-12 00:03:10 +00:00
|
|
|
m_mgr.GetArtProvider()->SetFont(wxAUI_DOCKART_CAPTION_FONT, DebuggerFont);
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateState();
|
|
|
|
|
|
|
|
m_mgr.Update();
|
2010-02-18 12:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DSPDebuggerLLE::~DSPDebuggerLLE()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_mgr.UnInit();
|
|
|
|
m_DebuggerFrame = nullptr;
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnChangeState(wxCommandEvent& event)
|
|
|
|
{
|
2017-02-06 16:44:10 +00:00
|
|
|
const DSP::State dsp_state = DSP::DSPCore_GetState();
|
2016-12-30 18:25:40 +00:00
|
|
|
|
2017-02-06 16:44:10 +00:00
|
|
|
if (dsp_state == DSP::State::Stopped)
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case ID_RUNTOOL:
|
2017-02-06 16:44:10 +00:00
|
|
|
if (dsp_state == DSP::State::Running)
|
|
|
|
DSP::DSPCore_SetState(DSP::State::Stepping);
|
2016-06-24 08:43:46 +00:00
|
|
|
else
|
2017-02-06 16:44:10 +00:00
|
|
|
DSP::DSPCore_SetState(DSP::State::Running);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_STEPTOOL:
|
2017-02-06 16:44:10 +00:00
|
|
|
if (dsp_state == DSP::State::Stepping)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-12-30 18:25:40 +00:00
|
|
|
DSP::DSPCore_Step();
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SHOWPCTOOL:
|
|
|
|
FocusOnPC();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateState();
|
|
|
|
m_mgr.Update();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 14:25:50 +00:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
// FIXME: This should use QueueEvent to post the update request to the UI thread.
|
|
|
|
// Need to check if this can safely be performed asynchronously or if it races.
|
|
|
|
// FIXME: This probably belongs in Main.cpp with the other host functions.
|
|
|
|
// NOTE: The DSP never tells us when it shuts down. It probably should.
|
2016-06-24 08:43:46 +00:00
|
|
|
if (m_DebuggerFrame)
|
2016-10-03 07:29:50 +00:00
|
|
|
m_DebuggerFrame->Repopulate();
|
2011-01-31 14:25:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void DSPDebuggerLLE::Repopulate()
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
wxMutexGuiEnter();
|
|
|
|
UpdateSymbolMap();
|
|
|
|
UpdateDisAsmListView();
|
|
|
|
UpdateRegisterFlags();
|
|
|
|
UpdateState();
|
|
|
|
if (!wxIsMainThread())
|
|
|
|
wxMutexGuiLeave();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::FocusOnPC()
|
|
|
|
{
|
2016-12-30 18:25:40 +00:00
|
|
|
JumpToAddress(DSP::g_dsp.pc);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateState()
|
|
|
|
{
|
2017-02-06 16:44:10 +00:00
|
|
|
if (DSP::DSPCore_GetState() == DSP::State::Running)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, _("Pause"));
|
|
|
|
m_Toolbar->SetToolBitmap(
|
2016-10-03 07:29:50 +00:00
|
|
|
ID_RUNTOOL, wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, m_toolbar_item_size));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, _("Run"));
|
|
|
|
m_Toolbar->SetToolBitmap(
|
2016-10-03 07:29:50 +00:00
|
|
|
ID_RUNTOOL, wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_OTHER, m_toolbar_item_size));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, true);
|
|
|
|
}
|
|
|
|
m_Toolbar->Realize();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateDisAsmListView()
|
|
|
|
{
|
2016-12-30 18:25:40 +00:00
|
|
|
if (m_CachedStepCounter == DSP::g_dsp.step_counter)
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// show PC
|
|
|
|
FocusOnPC();
|
2016-12-30 18:25:40 +00:00
|
|
|
m_CachedStepCounter = DSP::g_dsp.step_counter;
|
2016-10-03 07:29:50 +00:00
|
|
|
m_Regs->Repopulate();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateSymbolMap()
|
|
|
|
{
|
2016-12-30 18:25:40 +00:00
|
|
|
if (DSP::g_dsp.dram == nullptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_SymbolList->Freeze(); // HyperIris: wx style fast filling
|
|
|
|
m_SymbolList->Clear();
|
2016-12-30 18:25:40 +00:00
|
|
|
for (const auto& symbol : DSP::Symbols::g_dsp_symbol_db.Symbols())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
int idx = m_SymbolList->Append(StrToWxStr(symbol.second.name));
|
|
|
|
m_SymbolList->SetClientData(idx, (void*)&symbol.second);
|
|
|
|
}
|
|
|
|
m_SymbolList->Thaw();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnSymbolListChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int index = m_SymbolList->GetSelection();
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
2018-05-27 21:37:52 +00:00
|
|
|
auto* pSymbol = static_cast<Common::Symbol*>(m_SymbolList->GetClientData(index));
|
2016-06-24 08:43:46 +00:00
|
|
|
if (pSymbol != nullptr)
|
|
|
|
{
|
2018-05-27 21:37:52 +00:00
|
|
|
if (pSymbol->type == Common::Symbol::Type::Function)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
JumpToAddress(pSymbol->address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateRegisterFlags()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxString txt = m_addr_txtctrl->GetValue();
|
|
|
|
|
|
|
|
auto text = StripSpaces(WxStrToStr(txt));
|
|
|
|
if (text.size())
|
|
|
|
{
|
|
|
|
u32 addr;
|
|
|
|
sscanf(text.c_str(), "%04x", &addr);
|
|
|
|
if (JumpToAddress(addr))
|
|
|
|
m_addr_txtctrl->SetBackgroundColour(*wxWHITE);
|
|
|
|
else
|
|
|
|
m_addr_txtctrl->SetBackgroundColour(*wxRED);
|
|
|
|
}
|
|
|
|
event.Skip();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DSPDebuggerLLE::JumpToAddress(u16 addr)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int page = m_MainNotebook->GetSelection();
|
|
|
|
if (page == 0)
|
|
|
|
{
|
|
|
|
// Center on valid instruction in IRAM/IROM
|
2016-12-30 18:25:40 +00:00
|
|
|
int new_line = DSP::Symbols::Addr2Line(addr);
|
2016-06-24 08:43:46 +00:00
|
|
|
if (new_line >= 0)
|
|
|
|
{
|
|
|
|
m_CodeView->Center(new_line);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-06 02:10:26 +00:00
|
|
|
}
|