2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 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.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-08-14 19:54:01 +00:00
|
|
|
#include <array>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-06-24 10:16:10 +00:00
|
|
|
|
|
|
|
// clang-format off
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/panel.h>
|
2015-08-03 08:19:52 +00:00
|
|
|
#include <wx/srchctrl.h>
|
2015-02-25 05:06:45 +00:00
|
|
|
#include <wx/stattext.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/textdlg.h>
|
|
|
|
#include <wx/thread.h>
|
2014-08-08 22:02:35 +00:00
|
|
|
#include <wx/toolbar.h>
|
2016-07-15 21:59:05 +00:00
|
|
|
#include <wx/aui/auibar.h>
|
2016-08-27 16:12:13 +00:00
|
|
|
#include <wx/aui/dockart.h>
|
2016-06-24 10:16:10 +00:00
|
|
|
// clang-format on
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/BreakPoints.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Common/SymbolDB.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Debugger/Debugger_SymbolMap.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/Debugger/PPCDebugInterface.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/CPU.h"
|
|
|
|
#include "Core/HW/Memmap.h"
|
2014-10-18 00:02:26 +00:00
|
|
|
#include "Core/HW/SystemTimers.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/Host.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/PowerPC/Gekko.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/PowerPC/JitInterface.h"
|
|
|
|
#include "Core/PowerPC/PPCSymbolDB.h"
|
|
|
|
#include "Core/PowerPC/PPCTables.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/BreakpointWindow.h"
|
|
|
|
#include "DolphinWX/Debugger/CodeView.h"
|
|
|
|
#include "DolphinWX/Debugger/CodeWindow.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
|
2014-08-15 19:10:41 +00:00
|
|
|
#include "DolphinWX/Debugger/JitWindow.h"
|
2016-10-03 07:29:50 +00:00
|
|
|
#include "DolphinWX/Debugger/MemoryWindow.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/RegisterWindow.h"
|
2014-10-19 10:45:40 +00:00
|
|
|
#include "DolphinWX/Debugger/WatchWindow.h"
|
2016-07-15 21:59:05 +00:00
|
|
|
#include "DolphinWX/AuiToolBar.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "DolphinWX/Frame.h"
|
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
CCodeWindow::CCodeWindow(const SConfig& _LocalCoreStartupParameter, CFrame* parent, wxWindowID id,
|
|
|
|
const wxPoint& position, const wxSize& size, long style,
|
|
|
|
const wxString& name)
|
2016-10-03 07:29:50 +00:00
|
|
|
: wxPanel(parent, id, position, size, style, name), m_sibling_panels(), Parent(parent),
|
|
|
|
codeview(nullptr)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
InitBitmaps();
|
|
|
|
|
|
|
|
DebugInterface* di = &PowerPC::debug_interface;
|
|
|
|
|
|
|
|
codeview = new CCodeView(di, &g_symbolDB, this, wxID_ANY);
|
|
|
|
|
|
|
|
callstack = new wxListBox(this, wxID_ANY);
|
|
|
|
callstack->Bind(wxEVT_LISTBOX, &CCodeWindow::OnCallstackListChange, this);
|
|
|
|
|
|
|
|
symbols = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
|
|
|
|
symbols->Bind(wxEVT_LISTBOX, &CCodeWindow::OnSymbolListChange, this);
|
|
|
|
|
|
|
|
calls = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
|
|
|
|
calls->Bind(wxEVT_LISTBOX, &CCodeWindow::OnCallsListChange, this);
|
|
|
|
|
|
|
|
callers = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
|
|
|
|
callers->Bind(wxEVT_LISTBOX, &CCodeWindow::OnCallersListChange, this);
|
|
|
|
|
2016-07-15 21:59:05 +00:00
|
|
|
m_aui_toolbar = new DolphinAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxAUI_TB_HORIZONTAL | wxAUI_TB_PLAIN_BACKGROUND);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
wxSearchCtrl* const address_searchctrl = new wxSearchCtrl(m_aui_toolbar, IDM_ADDRBOX);
|
|
|
|
address_searchctrl->Bind(wxEVT_TEXT, &CCodeWindow::OnAddrBoxChange, this);
|
|
|
|
address_searchctrl->SetDescriptiveText(_("Search Address"));
|
|
|
|
|
|
|
|
m_aui_toolbar->AddControl(address_searchctrl);
|
|
|
|
m_aui_toolbar->Realize();
|
|
|
|
|
|
|
|
m_aui_manager.SetManagedWindow(this);
|
|
|
|
m_aui_manager.SetFlags(wxAUI_MGR_DEFAULT | wxAUI_MGR_LIVE_RESIZE);
|
2016-10-03 07:29:50 +00:00
|
|
|
m_aui_manager.AddPane(m_aui_toolbar, wxAuiPaneInfo().ToolbarPane().Top().Floatable(false));
|
|
|
|
m_aui_manager.AddPane(callstack, wxAuiPaneInfo()
|
|
|
|
.MinSize(FromDIP(wxSize(150, 100)))
|
|
|
|
.Left()
|
|
|
|
.CloseButton(false)
|
|
|
|
.Floatable(false)
|
|
|
|
.Caption(_("Callstack")));
|
|
|
|
m_aui_manager.AddPane(symbols, wxAuiPaneInfo()
|
|
|
|
.MinSize(FromDIP(wxSize(150, 100)))
|
|
|
|
.Left()
|
|
|
|
.CloseButton(false)
|
|
|
|
.Floatable(false)
|
|
|
|
.Caption(_("Symbols")));
|
|
|
|
m_aui_manager.AddPane(calls, wxAuiPaneInfo()
|
|
|
|
.MinSize(FromDIP(wxSize(150, 100)))
|
|
|
|
.Left()
|
|
|
|
.CloseButton(false)
|
|
|
|
.Floatable(false)
|
|
|
|
.Caption(_("Function calls")));
|
|
|
|
m_aui_manager.AddPane(callers, wxAuiPaneInfo()
|
|
|
|
.MinSize(FromDIP(wxSize(150, 100)))
|
|
|
|
.Left()
|
|
|
|
.CloseButton(false)
|
|
|
|
.Floatable(false)
|
|
|
|
.Caption(_("Function callers")));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_aui_manager.AddPane(codeview, wxAuiPaneInfo().CenterPane().CloseButton(false).Floatable(false));
|
|
|
|
m_aui_manager.Update();
|
|
|
|
|
|
|
|
// Menu
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnCPUMode, this, IDM_INTERPRETER, IDM_JIT_SR_OFF);
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnChangeFont, this, IDM_FONT_PICKER);
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnJitMenu, this, IDM_CLEAR_CODE_CACHE, IDM_SEARCH_INSTRUCTION);
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnSymbolsMenu, this, IDM_CLEAR_SYMBOLS, IDM_PATCH_HLE_FUNCTIONS);
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnProfilerMenu, this, IDM_PROFILE_BLOCKS, IDM_WRITE_PROFILE);
|
|
|
|
|
|
|
|
// Toolbar
|
|
|
|
Bind(wxEVT_MENU, &CCodeWindow::OnCodeStep, this, IDM_STEP, IDM_GOTOPC);
|
|
|
|
|
|
|
|
// Other
|
|
|
|
Bind(wxEVT_HOST_COMMAND, &CCodeWindow::OnHostMessage, this);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2015-02-24 15:56:01 +00:00
|
|
|
CCodeWindow::~CCodeWindow()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_aui_manager.UnInit();
|
2015-02-24 15:56:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxMenuBar* CCodeWindow::GetMenuBar()
|
2009-08-25 01:50:27 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return Parent->GetMenuBar();
|
2009-08-25 01:50:27 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxToolBar* CCodeWindow::GetToolBar()
|
2009-08-25 01:50:27 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return Parent->m_ToolBar;
|
2009-08-26 09:19:15 +00:00
|
|
|
}
|
2009-08-25 01:50:27 +00:00
|
|
|
|
2009-09-03 07:56:35 +00:00
|
|
|
// ----------
|
2009-08-27 16:08:43 +00:00
|
|
|
// Events
|
2009-09-03 07:56:35 +00:00
|
|
|
|
2009-01-05 02:52:55 +00:00
|
|
|
void CCodeWindow::OnHostMessage(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_NOTIFY_MAP_LOADED:
|
|
|
|
NotifyMapLoaded();
|
2016-10-03 07:29:50 +00:00
|
|
|
if (HasPanel<CBreakPointWindow>())
|
|
|
|
GetPanel<CBreakPointWindow>()->NotifyUpdate();
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_UPDATE_DISASM_DIALOG:
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
|
|
|
if (HasPanel<CRegisterWindow>())
|
|
|
|
GetPanel<CRegisterWindow>()->NotifyUpdate();
|
|
|
|
if (HasPanel<CWatchWindow>())
|
|
|
|
GetPanel<CWatchWindow>()->NotifyUpdate();
|
|
|
|
if (HasPanel<CMemoryWindow>())
|
|
|
|
GetPanel<CMemoryWindow>()->Refresh();
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_UPDATE_BREAKPOINTS:
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
|
|
|
if (HasPanel<CBreakPointWindow>())
|
|
|
|
GetPanel<CBreakPointWindow>()->NotifyUpdate();
|
|
|
|
if (HasPanel<CMemoryWindow>())
|
|
|
|
GetPanel<CMemoryWindow>()->Refresh();
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_UPDATE_JIT_PANE:
|
2016-10-03 07:29:50 +00:00
|
|
|
RequirePanel<CJitWindow>()->ViewAddr(codeview->GetSelection());
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-05 02:52:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 16:08:43 +00:00
|
|
|
// The Play, Stop, Step, Skip, Go to PC and Show PC buttons go here
|
|
|
|
void CCodeWindow::OnCodeStep(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_STEP:
|
|
|
|
SingleStep();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_STEPOVER:
|
|
|
|
StepOver();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_STEPOUT:
|
|
|
|
StepOut();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_TOGGLE_BREAKPOINT:
|
|
|
|
ToggleBreakpoint();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_SKIP:
|
|
|
|
PC += 4;
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_SETPC:
|
|
|
|
PC = codeview->GetSelection();
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_GOTOPC:
|
|
|
|
JumpToAddress(PC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateButtonStates();
|
|
|
|
// Update all toolbars in the aui manager
|
|
|
|
Parent->UpdateGUI();
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 03:17:38 +00:00
|
|
|
bool CCodeWindow::JumpToAddress(u32 address)
|
2009-08-27 16:08:43 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Jump to anywhere in memory
|
|
|
|
if (address <= 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
codeview->Center(address);
|
|
|
|
UpdateLists();
|
2014-07-11 03:17:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-07-11 03:17:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void CCodeWindow::OnCodeViewChange(wxCommandEvent& event)
|
2009-08-27 16:08:43 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateLists();
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::OnAddrBoxChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxSearchCtrl* pAddrCtrl = (wxSearchCtrl*)m_aui_toolbar->FindControl(IDM_ADDRBOX);
|
2014-07-13 18:29:03 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Trim leading and trailing whitespace.
|
|
|
|
wxString txt = pAddrCtrl->GetValue().Trim().Trim(false);
|
2009-08-27 16:08:43 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
bool success = false;
|
|
|
|
unsigned long addr;
|
|
|
|
if (txt.ToULong(&addr, 16))
|
|
|
|
{
|
|
|
|
if (JumpToAddress(addr))
|
|
|
|
success = true;
|
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (success)
|
|
|
|
pAddrCtrl->SetBackgroundColour(wxNullColour);
|
|
|
|
else if (!txt.empty())
|
|
|
|
pAddrCtrl->SetBackgroundColour(*wxRED);
|
2014-07-11 03:17:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
pAddrCtrl->Refresh();
|
2014-07-11 03:17:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
event.Skip();
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::OnCallstackListChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int index = callstack->GetSelection();
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
u32 address = (u32)(u64)(callstack->GetClientData(index));
|
|
|
|
if (address)
|
|
|
|
JumpToAddress(address);
|
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::OnCallersListChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int index = callers->GetSelection();
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
u32 address = (u32)(u64)(callers->GetClientData(index));
|
|
|
|
if (address)
|
|
|
|
JumpToAddress(address);
|
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::OnCallsListChange(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int index = calls->GetSelection();
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
u32 address = (u32)(u64)(calls->GetClientData(index));
|
|
|
|
if (address)
|
|
|
|
JumpToAddress(address);
|
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 06:00:22 +00:00
|
|
|
void CCodeWindow::SingleStep()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (CPU::IsStepping())
|
|
|
|
{
|
2016-09-16 02:32:28 +00:00
|
|
|
PowerPC::CoreMode old_mode = PowerPC::GetMode();
|
|
|
|
PowerPC::SetMode(PowerPC::MODE_INTERPRETER);
|
2016-06-24 08:43:46 +00:00
|
|
|
PowerPC::breakpoints.ClearAllTemporary();
|
|
|
|
CPU::StepOpcode(&sync_event);
|
2016-09-16 02:32:28 +00:00
|
|
|
sync_event.WaitFor(std::chrono::milliseconds(20));
|
|
|
|
PowerPC::SetMode(old_mode);
|
|
|
|
// Will get a IDM_UPDATE_DISASM_DIALOG. Don't update the GUI here.
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2010-08-08 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::StepOver()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (CPU::IsStepping())
|
|
|
|
{
|
|
|
|
UGeckoInstruction inst = PowerPC::HostRead_Instruction(PC);
|
|
|
|
if (inst.LK)
|
|
|
|
{
|
|
|
|
PowerPC::breakpoints.ClearAllTemporary();
|
|
|
|
PowerPC::breakpoints.Add(PC + 4, true);
|
|
|
|
CPU::EnableStepping(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SingleStep();
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 02:32:28 +00:00
|
|
|
// Returns true on a blr or on a bclr that evaluates to true.
|
|
|
|
static bool WillInstructionReturn(UGeckoInstruction inst)
|
|
|
|
{
|
|
|
|
bool counter = (inst.BO_2 >> 2 & 1) != 0 || (CTR != 0) != ((inst.BO_2 >> 1 & 1) != 0);
|
|
|
|
bool condition = inst.BO_2 >> 4 != 0 || GetCRBit(inst.BI_2) == (inst.BO_2 >> 3 & 1);
|
|
|
|
bool isBclr = inst.OPCD_7 == 0b010011 && (inst.hex >> 1 & 0b10000) != 0;
|
|
|
|
return isBclr && counter && condition && !inst.LK_3;
|
|
|
|
}
|
|
|
|
|
2014-10-15 09:04:23 +00:00
|
|
|
void CCodeWindow::StepOut()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (CPU::IsStepping())
|
|
|
|
{
|
|
|
|
CPU::PauseAndLock(true, false);
|
|
|
|
PowerPC::breakpoints.ClearAllTemporary();
|
|
|
|
|
2016-09-16 02:32:28 +00:00
|
|
|
// Keep stepping until the next return instruction or timeout after one second
|
2016-06-24 08:43:46 +00:00
|
|
|
u64 timeout = SystemTimers::GetTicksPerSecond();
|
|
|
|
u64 steps = 0;
|
2016-09-16 02:32:28 +00:00
|
|
|
PowerPC::CoreMode old_mode = PowerPC::GetMode();
|
2016-06-24 08:43:46 +00:00
|
|
|
PowerPC::SetMode(PowerPC::MODE_INTERPRETER);
|
|
|
|
UGeckoInstruction inst = PowerPC::HostRead_Instruction(PC);
|
2016-09-16 02:32:28 +00:00
|
|
|
// Loop until either the current instruction is a return instruction with no Link flag
|
|
|
|
// or a breakpoint is detected so it can step at the breakpoint.
|
|
|
|
while (!(WillInstructionReturn(inst)) && steps < timeout &&
|
|
|
|
!PowerPC::breakpoints.IsAddressBreakPoint(PC))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
if (inst.LK)
|
|
|
|
{
|
|
|
|
// Step over branches
|
|
|
|
u32 next_pc = PC + 4;
|
|
|
|
while (PC != next_pc && steps < timeout)
|
|
|
|
{
|
|
|
|
PowerPC::SingleStep();
|
|
|
|
++steps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PowerPC::SingleStep();
|
|
|
|
++steps;
|
|
|
|
}
|
|
|
|
inst = PowerPC::HostRead_Instruction(PC);
|
|
|
|
}
|
2016-09-16 02:32:28 +00:00
|
|
|
// If the loop stopped because of a breakpoint, we do not want to step to
|
|
|
|
// an instruction after it.
|
|
|
|
if (!PowerPC::breakpoints.IsAddressBreakPoint(PC))
|
|
|
|
PowerPC::SingleStep();
|
|
|
|
PowerPC::SetMode(old_mode);
|
2016-06-24 08:43:46 +00:00
|
|
|
CPU::PauseAndLock(false, false);
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
JumpToAddress(PC);
|
|
|
|
{
|
|
|
|
wxCommandEvent ev(wxEVT_HOST_COMMAND, IDM_UPDATE_DISASM_DIALOG);
|
|
|
|
GetEventHandler()->ProcessEvent(ev);
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Update all toolbars in the aui manager
|
|
|
|
Parent->UpdateGUI();
|
|
|
|
}
|
2014-10-15 09:04:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 06:00:22 +00:00
|
|
|
void CCodeWindow::ToggleBreakpoint()
|
2009-08-27 16:08:43 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (CPU::IsStepping())
|
|
|
|
{
|
|
|
|
if (codeview)
|
|
|
|
codeview->ToggleBreakpoint(codeview->GetSelection());
|
2016-10-03 07:29:50 +00:00
|
|
|
Repopulate();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::UpdateLists()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
callers->Clear();
|
|
|
|
u32 addr = codeview->GetSelection();
|
|
|
|
Symbol* symbol = g_symbolDB.GetSymbolFromAddr(addr);
|
|
|
|
if (!symbol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (auto& call : symbol->callers)
|
|
|
|
{
|
|
|
|
u32 caller_addr = call.callAddress;
|
|
|
|
Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(caller_addr);
|
|
|
|
if (caller_symbol)
|
|
|
|
{
|
|
|
|
int idx = callers->Append(StrToWxStr(
|
|
|
|
StringFromFormat("< %s (%08x)", caller_symbol->name.c_str(), caller_addr).c_str()));
|
|
|
|
callers->SetClientData(idx, (void*)(u64)caller_addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
calls->Clear();
|
|
|
|
for (auto& call : symbol->calls)
|
|
|
|
{
|
|
|
|
u32 call_addr = call.function;
|
|
|
|
Symbol* call_symbol = g_symbolDB.GetSymbolFromAddr(call_addr);
|
|
|
|
if (call_symbol)
|
|
|
|
{
|
|
|
|
int idx = calls->Append(StrToWxStr(
|
|
|
|
StringFromFormat("> %s (%08x)", call_symbol->name.c_str(), call_addr).c_str()));
|
|
|
|
calls->SetClientData(idx, (void*)(u64)call_addr);
|
|
|
|
}
|
|
|
|
}
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::UpdateCallstack()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (Core::GetState() == Core::CORE_STOPPING)
|
|
|
|
return;
|
2009-09-07 12:40:43 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
callstack->Clear();
|
2009-08-27 16:08:43 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::vector<Dolphin_Debugger::CallstackEntry> stack;
|
2009-08-27 16:08:43 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
bool ret = Dolphin_Debugger::GetCallstack(stack);
|
2009-10-15 15:43:51 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
for (auto& frame : stack)
|
|
|
|
{
|
|
|
|
int idx = callstack->Append(StrToWxStr(frame.Name));
|
|
|
|
callstack->SetClientData(idx, (void*)(u64)frame.vAddress);
|
|
|
|
}
|
2009-10-15 15:43:51 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!ret)
|
|
|
|
callstack->Append(StrToWxStr("invalid callstack"));
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
2009-09-02 21:00:45 +00:00
|
|
|
|
2009-01-07 07:35:12 +00:00
|
|
|
// CPU Mode and JIT Menu
|
|
|
|
void CCodeWindow::OnCPUMode(wxCommandEvent& event)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_INTERPRETER:
|
|
|
|
PowerPC::SetMode(UseInterpreter() ? PowerPC::MODE_INTERPRETER : PowerPC::MODE_JIT);
|
|
|
|
break;
|
|
|
|
case IDM_BOOT_TO_PAUSE:
|
2016-10-10 22:21:15 +00:00
|
|
|
SConfig::GetInstance().bBootToPause = event.IsChecked();
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
|
|
|
case IDM_AUTOMATIC_START:
|
2016-10-10 22:21:15 +00:00
|
|
|
SConfig::GetInstance().bAutomaticStart = event.IsChecked();
|
2016-06-24 08:43:46 +00:00
|
|
|
return;
|
|
|
|
case IDM_JIT_OFF:
|
|
|
|
SConfig::GetInstance().bJITOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LS_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStoreOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LSLXZ_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStorelXzOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LSLWZ_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStorelwzOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LSLBZX_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStorelbzxOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LSF_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStoreFloatingOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_LSP_OFF:
|
|
|
|
SConfig::GetInstance().bJITLoadStorePairedOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_FP_OFF:
|
|
|
|
SConfig::GetInstance().bJITFloatingPointOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_I_OFF:
|
|
|
|
SConfig::GetInstance().bJITIntegerOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_P_OFF:
|
|
|
|
SConfig::GetInstance().bJITPairedOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
case IDM_JIT_SR_OFF:
|
|
|
|
SConfig::GetInstance().bJITSystemRegistersOff = event.IsChecked();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the JIT cache to enable these changes
|
|
|
|
JitInterface::ClearCache();
|
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateButtonStates();
|
2009-08-27 16:08:43 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
void CCodeWindow::OnJitMenu(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_LOG_INSTRUCTIONS:
|
|
|
|
PPCTables::LogCompiledInstructions();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_CLEAR_CODE_CACHE:
|
|
|
|
JitInterface::ClearCache();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_SEARCH_INSTRUCTION:
|
|
|
|
{
|
|
|
|
wxString str = wxGetTextFromUser("", _("Op?"), wxEmptyString, this);
|
|
|
|
auto const wx_name = WxStrToStr(str);
|
|
|
|
bool found = false;
|
|
|
|
for (u32 addr = 0x80000000; addr < 0x80180000; addr += 4)
|
|
|
|
{
|
|
|
|
const char* name = PPCTables::GetInstructionName(PowerPC::HostRead_U32(addr));
|
|
|
|
if (name && (wx_name == name))
|
|
|
|
{
|
|
|
|
NOTICE_LOG(POWERPC, "Found %s at %08x", wx_name.c_str(), addr);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
NOTICE_LOG(POWERPC, "Opcode %s not found", wx_name.c_str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 23:28:28 +00:00
|
|
|
// Shortcuts
|
|
|
|
bool CCodeWindow::UseInterpreter()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetMenuBar()->IsChecked(IDM_INTERPRETER);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2009-09-03 23:28:28 +00:00
|
|
|
bool CCodeWindow::BootToPause()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetMenuBar()->IsChecked(IDM_BOOT_TO_PAUSE);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2009-09-03 23:28:28 +00:00
|
|
|
bool CCodeWindow::AutomaticStart()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetMenuBar()->IsChecked(IDM_AUTOMATIC_START);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2010-07-05 02:05:47 +00:00
|
|
|
bool CCodeWindow::JITNoBlockCache()
|
2009-09-03 23:28:28 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetMenuBar()->IsChecked(IDM_JIT_NO_BLOCK_CACHE);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
2010-07-23 03:53:18 +00:00
|
|
|
|
2014-10-09 02:02:02 +00:00
|
|
|
bool CCodeWindow::JITNoBlockLinking()
|
2009-09-03 23:28:28 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetMenuBar()->IsChecked(IDM_JIT_NO_BLOCK_LINKING);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 16:08:43 +00:00
|
|
|
// Toolbar
|
|
|
|
void CCodeWindow::InitBitmaps()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-08-14 19:54:01 +00:00
|
|
|
static constexpr std::array<const char* const, Toolbar_Debug_Bitmap_Max> s_image_names{
|
|
|
|
{"toolbar_debugger_step", "toolbar_debugger_step_over", "toolbar_debugger_step_out",
|
|
|
|
"toolbar_debugger_skip", "toolbar_debugger_goto_pc", "toolbar_debugger_set_pc"}};
|
|
|
|
const wxSize tool_size = Parent->GetToolbarBitmapSize();
|
|
|
|
for (std::size_t i = 0; i < s_image_names.size(); ++i)
|
|
|
|
m_Bitmaps[i] =
|
|
|
|
WxUtils::LoadScaledResourceBitmap(s_image_names[i], Parent, tool_size, wxDefaultSize,
|
|
|
|
WxUtils::LSI_SCALE_DOWN | WxUtils::LSI_ALIGN_CENTER);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 10:43:13 +00:00
|
|
|
void CCodeWindow::PopulateToolbar(wxToolBar* toolBar)
|
2009-01-05 02:52:55 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_STEP, _("Step"), m_Bitmaps[Toolbar_Step],
|
|
|
|
_("Step into the next instruction"));
|
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_STEPOVER, _("Step Over"), m_Bitmaps[Toolbar_StepOver],
|
|
|
|
_("Step over the next instruction"));
|
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_STEPOUT, _("Step Out"), m_Bitmaps[Toolbar_StepOut],
|
|
|
|
_("Step out of the current function"));
|
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_SKIP, _("Skip"), m_Bitmaps[Toolbar_Skip],
|
|
|
|
_("Skips the next instruction completely"));
|
|
|
|
toolBar->AddSeparator();
|
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_GOTOPC, _("Show PC"), m_Bitmaps[Toolbar_GotoPC],
|
|
|
|
_("Go to the current instruction"));
|
|
|
|
WxUtils::AddToolbarButton(toolBar, IDM_SETPC, _("Set PC"), m_Bitmaps[Toolbar_SetPC],
|
|
|
|
_("Set the current instruction"));
|
2009-02-23 21:27:58 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-08-27 16:08:43 +00:00
|
|
|
// Update GUI
|
2016-10-03 07:29:50 +00:00
|
|
|
void CCodeWindow::Repopulate()
|
2009-02-23 21:27:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!codeview)
|
|
|
|
return;
|
2009-09-07 12:40:43 +00:00
|
|
|
|
2016-09-16 02:32:28 +00:00
|
|
|
codeview->Center(PC);
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateCallstack();
|
|
|
|
UpdateButtonStates();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Do not automatically show the current PC position when a breakpoint is hit or
|
|
|
|
// when we pause since this can be called at other times too.
|
|
|
|
// codeview->Center(PC);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeWindow::UpdateButtonStates()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
bool Initialized = (Core::GetState() != Core::CORE_UNINITIALIZED);
|
|
|
|
bool Pause = (Core::GetState() == Core::CORE_PAUSE);
|
|
|
|
bool Stepping = CPU::IsStepping();
|
2016-10-03 07:29:50 +00:00
|
|
|
bool can_step = Initialized && Stepping;
|
2016-06-24 08:43:46 +00:00
|
|
|
wxToolBar* ToolBar = GetToolBar();
|
|
|
|
|
|
|
|
// Toolbar
|
|
|
|
if (!ToolBar)
|
|
|
|
return;
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
ToolBar->EnableTool(IDM_STEP, can_step);
|
|
|
|
ToolBar->EnableTool(IDM_STEPOVER, can_step);
|
|
|
|
ToolBar->EnableTool(IDM_STEPOUT, can_step);
|
|
|
|
ToolBar->EnableTool(IDM_SKIP, can_step);
|
|
|
|
ToolBar->EnableTool(IDM_SETPC, Pause);
|
2016-06-24 08:43:46 +00:00
|
|
|
ToolBar->Realize();
|
|
|
|
|
|
|
|
// Menu bar
|
|
|
|
// ------------------
|
|
|
|
GetMenuBar()->Enable(IDM_INTERPRETER, Pause); // CPU Mode
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
GetMenuBar()->Enable(IDM_STEP, can_step);
|
|
|
|
GetMenuBar()->Enable(IDM_STEPOVER, can_step);
|
|
|
|
GetMenuBar()->Enable(IDM_STEPOUT, can_step);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
GetMenuBar()->Enable(IDM_JIT_NO_BLOCK_CACHE, !Initialized);
|
|
|
|
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LS_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LSLXZ_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LSLWZ_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LSLBZX_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LSF_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_LSP_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_FP_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_I_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_P_OFF, Pause);
|
|
|
|
GetMenuBar()->Enable(IDM_JIT_SR_OFF, Pause);
|
|
|
|
|
|
|
|
GetMenuBar()->Enable(IDM_CLEAR_CODE_CACHE, Pause); // JIT Menu
|
|
|
|
GetMenuBar()->Enable(IDM_SEARCH_INSTRUCTION, Initialized);
|
|
|
|
|
|
|
|
GetMenuBar()->Enable(IDM_CLEAR_SYMBOLS, Initialized); // Symbols menu
|
|
|
|
GetMenuBar()->Enable(IDM_SCAN_FUNCTIONS, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_LOAD_MAP_FILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_SAVEMAPFILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_LOAD_MAP_FILE_AS, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_SAVE_MAP_FILE_AS, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_LOAD_BAD_MAP_FILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_SAVE_MAP_FILE_WITH_CODES, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_CREATE_SIGNATURE_FILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_APPEND_SIGNATURE_FILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_COMBINE_SIGNATURE_FILES, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_RENAME_SYMBOLS, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_USE_SIGNATURE_FILE, Initialized);
|
|
|
|
GetMenuBar()->Enable(IDM_PATCH_HLE_FUNCTIONS, Initialized);
|
|
|
|
|
|
|
|
// Update Fonts
|
|
|
|
callstack->SetFont(DebuggerFont);
|
|
|
|
symbols->SetFont(DebuggerFont);
|
|
|
|
callers->SetFont(DebuggerFont);
|
|
|
|
calls->SetFont(DebuggerFont);
|
2016-08-27 16:12:13 +00:00
|
|
|
m_aui_manager.GetArtProvider()->SetFont(wxAUI_DOCKART_CAPTION_FONT, DebuggerFont);
|
2009-08-27 00:54:44 +00:00
|
|
|
}
|