2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
#include "Common.h"
|
|
|
|
#include <iostream>
|
2009-07-06 02:10:26 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
#include <wx/artprov.h>
|
|
|
|
|
2009-07-12 12:22:39 +00:00
|
|
|
#include "DSPDebugWindow.h"
|
2009-07-06 02:10:26 +00:00
|
|
|
#include "DSPRegisterView.h"
|
|
|
|
#include "CodeView.h"
|
2010-02-18 12:06:13 +00:00
|
|
|
#include "MemoryView.h"
|
2009-07-06 02:10:26 +00:00
|
|
|
#include "../DSPSymbols.h"
|
|
|
|
|
2009-09-27 21:28:09 +00:00
|
|
|
// Define these here to avoid undefined symbols while still saving functionality
|
|
|
|
void Host_NotifyMapLoaded() {}
|
|
|
|
void Host_UpdateBreakPointView() {}
|
|
|
|
|
2009-07-06 02:10:26 +00:00
|
|
|
BEGIN_EVENT_TABLE(DSPDebuggerLLE, wxFrame)
|
|
|
|
EVT_CLOSE(DSPDebuggerLLE::OnClose)
|
|
|
|
EVT_MENU_RANGE(ID_RUNTOOL, ID_STEPTOOL, DSPDebuggerLLE::OnChangeState)
|
|
|
|
EVT_MENU(ID_SHOWPCTOOL, DSPDebuggerLLE::OnShowPC)
|
2010-02-18 12:06:13 +00:00
|
|
|
EVT_TEXT_ENTER(ID_ADDRBOX, DSPDebuggerLLE::OnAddrBoxChange)
|
|
|
|
EVT_LISTBOX(ID_SYMBOLLIST, DSPDebuggerLLE::OnSymbolListChange)
|
2009-07-06 02:10:26 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
DSPDebuggerLLE::DSPDebuggerLLE(wxWindow* parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, _("DSP LLE Debugger"),
|
|
|
|
wxDefaultPosition, wxSize(700, 800),
|
|
|
|
wxDEFAULT_FRAME_STYLE)
|
|
|
|
, m_CachedStepCounter(-1)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-02-18 12:06:13 +00:00
|
|
|
// notify wxAUI which frame to use
|
|
|
|
m_mgr.SetManagedWindow(this);
|
|
|
|
|
|
|
|
m_Toolbar = new wxAuiToolBar(this, ID_TOOLBAR,
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_TEXT);
|
|
|
|
m_Toolbar->AddTool(ID_RUNTOOL, wxT("Pause"),
|
|
|
|
wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->AddTool(ID_STEPTOOL, wxT("Step"),
|
|
|
|
wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->AddTool(ID_SHOWPCTOOL, wxT("Show PC"),
|
|
|
|
wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_OTHER, wxSize(10,10)));
|
2009-07-06 02:10:26 +00:00
|
|
|
m_Toolbar->AddSeparator();
|
2010-02-18 12:06:13 +00:00
|
|
|
m_Toolbar->AddControl(new wxTextCtrl(m_Toolbar, ID_ADDRBOX, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER));
|
2009-07-06 02:10:26 +00:00
|
|
|
m_Toolbar->Realize();
|
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
m_SymbolList = new wxListBox(this, ID_SYMBOLLIST, wxDefaultPosition,
|
|
|
|
wxSize(140, 100), 0, NULL, wxLB_SORT);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00: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-06 02:10:26 +00:00
|
|
|
m_CodeView->SetPlain();
|
2010-02-18 12:06:13 +00:00
|
|
|
code_sizer->Add(m_CodeView, 1, wxALL | wxEXPAND);
|
|
|
|
code_panel->SetSizer(code_sizer);
|
|
|
|
code_sizer->SetSizeHints(code_panel);
|
|
|
|
m_MainNotebook->AddPage(code_panel, wxT("Disasm"), true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
mem_sizer->SetSizeHints(mem_panel);
|
|
|
|
m_MainNotebook->AddPage(mem_panel, wxT("Mem"));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
m_Regs = new DSPRegisterView(this, ID_DSP_REGS);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
// add the panes to the manager
|
|
|
|
m_mgr.AddPane(m_Toolbar, wxAuiPaneInfo().
|
|
|
|
ToolbarPane().Top().
|
|
|
|
LeftDockable(false).RightDockable(false));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
m_mgr.AddPane(m_SymbolList, wxAuiPaneInfo().
|
|
|
|
Left().CloseButton(false).
|
|
|
|
Caption(wxT("Symbols")).Dockable(true));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
m_mgr.AddPane(m_MainNotebook, wxAuiPaneInfo().
|
|
|
|
Name(wxT("m_MainNotebook")).Center().
|
|
|
|
CloseButton(false).MaximizeButton(true));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-02-18 12:06:13 +00:00
|
|
|
m_mgr.AddPane(m_Regs, wxAuiPaneInfo().Right().
|
|
|
|
CloseButton(false).Caption(wxT("Registers")).
|
|
|
|
Dockable(true));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
UpdateState();
|
2010-02-18 12:06:13 +00:00
|
|
|
|
|
|
|
m_mgr.Update();
|
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSPDebuggerLLE::~DSPDebuggerLLE()
|
|
|
|
{
|
|
|
|
m_mgr.UnInit();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnChangeState(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
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)
|
2009-07-24 02:15:04 +00:00
|
|
|
{
|
2009-07-06 02:10:26 +00:00
|
|
|
DSPCore_Step();
|
2009-07-24 02:15:04 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SHOWPCTOOL:
|
|
|
|
FocusOnPC();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateState();
|
2010-02-18 12:06:13 +00:00
|
|
|
m_mgr.Update();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnShowPC(wxCommandEvent& event)
|
|
|
|
{
|
2009-07-24 02:15:04 +00:00
|
|
|
// UpdateDisAsmListView will focus on PC
|
2009-07-06 02:10:26 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::Refresh()
|
|
|
|
{
|
|
|
|
UpdateSymbolMap();
|
|
|
|
UpdateDisAsmListView();
|
|
|
|
UpdateRegisterFlags();
|
|
|
|
UpdateState();
|
2010-02-18 12:06:13 +00:00
|
|
|
m_mgr.Update();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::FocusOnPC()
|
|
|
|
{
|
|
|
|
JumpToAddress(g_dsp.pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateState()
|
|
|
|
{
|
|
|
|
if (DSPCore_GetState() == DSPCORE_RUNNING) {
|
2010-02-18 12:06:13 +00:00
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, wxT("Pause"));
|
|
|
|
m_Toolbar->SetToolBitmap(ID_RUNTOOL,
|
|
|
|
wxArtProvider::GetBitmap(wxART_TICK_MARK, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, false);
|
|
|
|
} else {
|
|
|
|
m_Toolbar->SetToolLabel(ID_RUNTOOL, wxT("Run"));
|
|
|
|
m_Toolbar->SetToolBitmap(ID_RUNTOOL,
|
|
|
|
wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_OTHER, wxSize(10,10)));
|
|
|
|
m_Toolbar->EnableTool(ID_STEPTOOL, true);
|
2009-07-06 02:10:26 +00: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()
|
|
|
|
{
|
|
|
|
if (g_dsp.dram == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_SymbolList->Freeze(); // HyperIris: wx style fast filling
|
|
|
|
m_SymbolList->Clear();
|
|
|
|
for (SymbolDB::XFuncMap::iterator iter = DSPSymbols::g_dsp_symbol_db.GetIterator();
|
|
|
|
iter != DSPSymbols::g_dsp_symbol_db.End(); iter++)
|
|
|
|
{
|
|
|
|
int idx = m_SymbolList->Append(wxString::FromAscii(iter->second.name.c_str()));
|
|
|
|
m_SymbolList->SetClientData(idx, (void*)&iter->second);
|
|
|
|
}
|
|
|
|
m_SymbolList->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnSymbolListChange(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int index = m_SymbolList->GetSelection();
|
|
|
|
if (index >= 0) {
|
|
|
|
Symbol* pSymbol = static_cast<Symbol *>(m_SymbolList->GetClientData(index));
|
|
|
|
if (pSymbol != NULL)
|
|
|
|
{
|
|
|
|
if (pSymbol->type == Symbol::SYMBOL_FUNCTION)
|
|
|
|
{
|
|
|
|
JumpToAddress(pSymbol->address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::UpdateRegisterFlags()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event)
|
|
|
|
{
|
2010-02-18 12:06:13 +00:00
|
|
|
wxTextCtrl* pAddrCtrl = (wxTextCtrl*)m_Toolbar->FindControl(ID_ADDRBOX);
|
2009-07-06 02:10:26 +00:00
|
|
|
wxString txt = pAddrCtrl->GetValue();
|
|
|
|
|
|
|
|
std::string text(txt.mb_str());
|
|
|
|
text = StripSpaces(text);
|
|
|
|
if (text.size())
|
|
|
|
{
|
|
|
|
u32 addr;
|
|
|
|
sscanf(text.c_str(), "%04x", &addr);
|
|
|
|
if (JumpToAddress(addr))
|
|
|
|
pAddrCtrl->SetBackgroundColour(*wxWHITE);
|
|
|
|
else
|
|
|
|
pAddrCtrl->SetBackgroundColour(*wxRED);
|
|
|
|
}
|
2010-02-18 12:06:13 +00:00
|
|
|
event.Skip();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DSPDebuggerLLE::JumpToAddress(u16 addr)
|
|
|
|
{
|
2010-02-18 12:06:13 +00:00
|
|
|
int page = m_MainNotebook->GetSelection();
|
|
|
|
if (page == 0)
|
|
|
|
{
|
|
|
|
// Center on valid instruction in IRAM/IROM
|
|
|
|
int new_line = DSPSymbols::Addr2Line(addr);
|
|
|
|
if (new_line >= 0) {
|
|
|
|
m_CodeView->Center(new_line);
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
2010-02-18 12:06:13 +00: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-06 02:10:26 +00:00
|
|
|
}
|