| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | // Copyright (C) 2003-2009 Dolphin Project.
 | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +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/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Common.h" // Common
 | 
					
						
							|  |  |  | #include <iostream> // System
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Debugger.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | #include "DSPRegisterView.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | #include "CodeView.h"
 | 
					
						
							|  |  |  | #include "../DSPSymbols.h"
 | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Event table and class
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | BEGIN_EVENT_TABLE(DSPDebuggerLLE, wxFrame)	 | 
					
						
							|  |  |  | 	EVT_CLOSE(DSPDebuggerLLE::OnClose) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | 	EVT_MENU_RANGE(ID_RUNTOOL, ID_STEPTOOL, DSPDebuggerLLE::OnChangeState) | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 	EVT_MENU(ID_SHOWPCTOOL, DSPDebuggerLLE::OnShowPC) | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	EVT_TEXT(ID_ADDRBOX,    DSPDebuggerLLE::OnAddrBoxChange) | 
					
						
							|  |  |  |     EVT_LISTBOX(ID_SYMBOLLIST,     DSPDebuggerLLE::OnSymbolListChange) | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | END_EVENT_TABLE() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | DSPDebuggerLLE::DSPDebuggerLLE(wxWindow *parent, wxWindowID id, const wxString &title, | 
					
						
							|  |  |  | 							   const wxPoint &position, const wxSize& size, long style) | 
					
						
							|  |  |  | 							   : wxFrame(parent, id, title, position, size, style) | 
					
						
							|  |  |  | 							   , m_CachedStepCounter(-1) | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	CreateGUIControls(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | DSPDebuggerLLE::~DSPDebuggerLLE() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::CreateGUIControls() | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	// Basic settings
 | 
					
						
							| 
									
										
										
										
											2009-06-28 17:18:52 +00:00
										 |  |  | 	SetSize(700, 800); | 
					
						
							|  |  |  | 	this->SetSizeHints(700, 800); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_Toolbar = CreateToolBar(wxTB_NODIVIDER|wxTB_NOICONS|wxTB_HORZ_TEXT|wxTB_DOCKABLE, ID_TOOLBAR);  | 
					
						
							|  |  |  | 	m_Toolbar->AddTool(ID_RUNTOOL, wxT("Run"), wxNullBitmap, wxEmptyString, wxITEM_NORMAL); | 
					
						
							|  |  |  | 	m_Toolbar->AddTool(ID_STEPTOOL, wxT("Step"), wxNullBitmap, wxT("Step Code "), wxITEM_NORMAL); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	m_Toolbar->AddTool(ID_SHOWPCTOOL, wxT("Show Pc"), wxNullBitmap, wxT("Show where PC is"), wxITEM_NORMAL); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	m_Toolbar->AddTool(ID_JUMPTOTOOL, wxT("Jump"), wxNullBitmap, wxT("Jump to a specific Address"), wxITEM_NORMAL); | 
					
						
							| 
									
										
										
										
											2009-04-03 19:29:15 +00:00
										 |  |  | 	m_Toolbar->AddSeparator(); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m_Toolbar->AddControl(new wxTextCtrl(m_Toolbar, ID_ADDRBOX, _T(""))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	m_Toolbar->Realize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxBoxSizer* sMain = new wxBoxSizer(wxHORIZONTAL); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	wxBoxSizer* sizerLeft  = new wxBoxSizer(wxVERTICAL); | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	sizerLeft->Add(m_SymbolList = new wxListBox(this, ID_SYMBOLLIST, wxDefaultPosition, wxSize(140, 100), 0, NULL, wxLB_SORT), | 
					
						
							|  |  |  | 		1, wxEXPAND); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	m_CodeView = new CCodeView(&debug_interface, &DSPSymbols::g_dsp_symbol_db, this, ID_CODEVIEW); | 
					
						
							|  |  |  | 	m_CodeView->SetPlain(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	sMain->Add(sizerLeft, 0, wxEXPAND, 0); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	sMain->Add(m_CodeView, 4, wxEXPAND, 0); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wxStaticLine* m_staticline = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL); | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	sMain->Add(m_staticline, 0, wxEXPAND|wxALL, 0); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m_Regs = new DSPRegisterView(this, ID_DSP_REGS); | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	sMain->Add(m_Regs, 0, wxEXPAND|wxALL, 5); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this->SetSizer(sMain); | 
					
						
							|  |  |  | 	this->Layout(); | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	UpdateState(); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | void DSPDebuggerLLE::OnClose(wxCloseEvent& event) | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-18 19:06:47 +00:00
										 |  |  | 	Hide(); | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | void DSPDebuggerLLE::OnChangeState(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (event.GetId()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case ID_RUNTOOL: | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 		if (DSPCore_GetState() == DSPCORE_RUNNING) | 
					
						
							|  |  |  | 			DSPCore_SetState(DSPCORE_STEPPING); | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 			DSPCore_SetState(DSPCORE_RUNNING); | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case ID_STEPTOOL: | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 		if (DSPCore_GetState() == DSPCORE_STEPPING) | 
					
						
							|  |  |  | 			DSPCore_Step(); | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	case ID_SHOWPCTOOL: | 
					
						
							|  |  |  | 		FocusOnPC(); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 	UpdateState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::OnShowPC(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Refresh(); | 
					
						
							|  |  |  | 	FocusOnPC(); | 
					
						
							| 
									
										
										
										
											2009-04-03 18:04:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | void DSPDebuggerLLE::Refresh() | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	UpdateSymbolMap(); | 
					
						
							|  |  |  | 	UpdateDisAsmListView(); | 
					
						
							|  |  |  | 	UpdateRegisterFlags(); | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 	UpdateState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::FocusOnPC() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	JumpToAddress(g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::UpdateState() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 	if (DSPCore_GetState() == DSPCORE_RUNNING) { | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 		m_Toolbar->FindById(ID_RUNTOOL)->SetLabel(wxT("Pause")); | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 		m_Toolbar->FindById(ID_STEPTOOL)->Enable(false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 		m_Toolbar->FindById(ID_RUNTOOL)->SetLabel(wxT("Run")); | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 		m_Toolbar->FindById(ID_STEPTOOL)->Enable(true); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 	m_Toolbar->Realize(); | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | void DSPDebuggerLLE::UpdateDisAsmListView() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_CachedStepCounter == g_dsp.step_counter) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// show PC
 | 
					
						
							| 
									
										
										
										
											2009-04-06 20:32:37 +00:00
										 |  |  | 	FocusOnPC(); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	m_CachedStepCounter = g_dsp.step_counter; | 
					
						
							|  |  |  | 	m_Regs->Update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::UpdateSymbolMap() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (g_dsp.dram == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	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++) | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 		int idx = m_SymbolList->Append(wxString::FromAscii(iter->second.name.c_str())); | 
					
						
							|  |  |  | 		m_SymbolList->SetClientData(idx, (void*)&iter->second); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 	m_SymbolList->Thaw(); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DSPDebuggerLLE::UpdateRegisterFlags() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event) | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	wxTextCtrl* pAddrCtrl = (wxTextCtrl*)GetToolBar()->FindControl(ID_ADDRBOX); | 
					
						
							|  |  |  | 	wxString txt = pAddrCtrl->GetValue(); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	event.Skip(1); | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | bool DSPDebuggerLLE::JumpToAddress(u16 addr) | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	int new_line = DSPSymbols::Addr2Line(addr); | 
					
						
							|  |  |  | 	if (new_line >= 0) { | 
					
						
							|  |  |  | 		m_CodeView->Center(new_line); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-04-02 12:50:47 +00:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-30 13:21:22 +00:00
										 |  |  | } |