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>
|
2016-10-11 13:15:02 +00:00
|
|
|
#include <chrono>
|
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>
|
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-11-11 18:20:47 +00:00
|
|
|
CCodeWindow::CCodeWindow(CFrame* parent, wxWindowID id, const wxPoint& position, const wxSize& size,
|
|
|
|
long style, const wxString& name)
|
2016-11-11 18:31:36 +00:00
|
|
|
: wxPanel(parent, id, position, size, style, name), Parent(parent)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
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"));
|
2016-12-04 13:47:08 +00:00
|
|
|
m_symbol_filter_ctrl = new wxSearchCtrl(m_aui_toolbar, wxID_ANY);
|
|
|
|
m_symbol_filter_ctrl->Bind(wxEVT_TEXT, &CCodeWindow::OnSymbolFilterText, this);
|
|
|
|
m_symbol_filter_ctrl->SetDescriptiveText(_("Filter Symbols"));
|
|
|
|
m_symbol_filter_ctrl->SetToolTip(_("Filter the symbol list by name. This is case-sensitive."));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
m_aui_toolbar->AddControl(address_searchctrl);
|
2016-12-04 13:47:08 +00:00
|
|
|
m_aui_toolbar->AddControl(m_symbol_filter_ctrl);
|
2016-06-24 08:43:46 +00:00
|
|
|
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-11-05 02:02:36 +00:00
|
|
|
wxMenuBar* CCodeWindow::GetParentMenuBar()
|
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
|
|
|
|
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-22 21:20:06 +00:00
|
|
|
codeview->Center(PC);
|
|
|
|
Repopulate(false);
|
2016-10-03 07:29:50 +00:00
|
|
|
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-22 21:20:06 +00:00
|
|
|
codeview->Center(PC);
|
|
|
|
Repopulate(false);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_SETPC:
|
|
|
|
PC = codeview->GetSelection();
|
2016-10-22 21:20:06 +00:00
|
|
|
codeview->Center(PC);
|
|
|
|
Repopulate(false);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_GOTOPC:
|
|
|
|
JumpToAddress(PC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2016-12-04 13:47:08 +00:00
|
|
|
void CCodeWindow::OnSymbolFilterText(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
ReloadSymbolListBox();
|
|
|
|
}
|
|
|
|
|
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);
|
2016-10-11 13:15:02 +00:00
|
|
|
Core::DisplayMessage(_("Step successful!").ToStdString(), 2000);
|
2016-09-16 02:32:28 +00:00
|
|
|
// 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);
|
2016-10-11 13:15:02 +00:00
|
|
|
Core::DisplayMessage(_("Step over in progress...").ToStdString(), 2000);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SingleStep();
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:15:02 +00:00
|
|
|
// Returns true on a rfi, blr or on a bclr that evaluates to true.
|
2016-09-16 02:32:28 +00:00
|
|
|
static bool WillInstructionReturn(UGeckoInstruction inst)
|
|
|
|
{
|
2016-10-11 13:15:02 +00:00
|
|
|
// Is a rfi instruction
|
|
|
|
if (inst.hex == 0x4C000064u)
|
|
|
|
return true;
|
2016-09-16 02:32:28 +00:00
|
|
|
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-10-11 13:15:02 +00:00
|
|
|
// Keep stepping until the next return instruction or timeout after five seconds
|
|
|
|
using clock = std::chrono::steady_clock;
|
|
|
|
clock::time_point timeout = clock::now() + std::chrono::seconds(5);
|
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);
|
2016-10-11 13:15:02 +00:00
|
|
|
|
2016-09-16 02:32:28 +00:00
|
|
|
// Loop until either the current instruction is a return instruction with no Link flag
|
2016-10-11 13:15:02 +00:00
|
|
|
// or a breakpoint is detected so it can step at the breakpoint. If the PC is currently
|
|
|
|
// on a breakpoint, skip it.
|
|
|
|
UGeckoInstruction inst = PowerPC::HostRead_Instruction(PC);
|
|
|
|
do
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-11 13:15:02 +00:00
|
|
|
if (WillInstructionReturn(inst))
|
|
|
|
{
|
|
|
|
PowerPC::SingleStep();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (inst.LK)
|
|
|
|
{
|
|
|
|
// Step over branches
|
|
|
|
u32 next_pc = PC + 4;
|
2016-10-11 13:15:02 +00:00
|
|
|
do
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
PowerPC::SingleStep();
|
2016-10-11 13:15:02 +00:00
|
|
|
} while (PC != next_pc && clock::now() < timeout &&
|
|
|
|
!PowerPC::breakpoints.IsAddressBreakPoint(PC));
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PowerPC::SingleStep();
|
|
|
|
}
|
2016-10-11 13:15:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
inst = PowerPC::HostRead_Instruction(PC);
|
2016-10-11 13:15:02 +00:00
|
|
|
} while (clock::now() < timeout && !PowerPC::breakpoints.IsAddressBreakPoint(PC));
|
|
|
|
|
2016-09-16 02:32:28 +00:00
|
|
|
PowerPC::SetMode(old_mode);
|
2016-06-24 08:43:46 +00:00
|
|
|
CPU::PauseAndLock(false, false);
|
|
|
|
|
2016-10-22 21:20:06 +00:00
|
|
|
wxCommandEvent ev(wxEVT_HOST_COMMAND, IDM_UPDATE_DISASM_DIALOG);
|
|
|
|
GetEventHandler()->ProcessEvent(ev);
|
2016-10-03 07:29:50 +00:00
|
|
|
|
2016-10-11 13:15:02 +00:00
|
|
|
if (PowerPC::breakpoints.IsAddressBreakPoint(PC))
|
|
|
|
Core::DisplayMessage(_("Breakpoint encountered! Step out aborted.").ToStdString(), 2000);
|
|
|
|
else if (clock::now() >= timeout)
|
|
|
|
Core::DisplayMessage(_("Step out timed out!").ToStdString(), 2000);
|
|
|
|
else
|
|
|
|
Core::DisplayMessage(_("Step out successful!").ToStdString(), 2000);
|
|
|
|
|
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();
|
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-11-05 02:02:36 +00:00
|
|
|
return GetParentMenuBar()->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-11-05 02:02:36 +00:00
|
|
|
return GetParentMenuBar()->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-11-05 02:02:36 +00:00
|
|
|
return GetParentMenuBar()->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-11-05 02:02:36 +00:00
|
|
|
return GetParentMenuBar()->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-11-05 02:02:36 +00:00
|
|
|
return GetParentMenuBar()->IsChecked(IDM_JIT_NO_BLOCK_LINKING);
|
2009-09-03 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 16:08:43 +00:00
|
|
|
// Update GUI
|
2016-10-22 21:20:06 +00:00
|
|
|
void CCodeWindow::Repopulate(bool refresh_codeview)
|
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-10-22 21:20:06 +00:00
|
|
|
if (refresh_codeview)
|
|
|
|
codeview->Refresh();
|
2016-11-03 22:02:53 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateCallstack();
|
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
|
|
|
}
|
|
|
|
|
2016-11-03 22:02:53 +00:00
|
|
|
void CCodeWindow::UpdateFonts()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
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);
|
2016-11-03 22:02:53 +00:00
|
|
|
m_aui_manager.Update();
|
2009-08-27 00:54:44 +00:00
|
|
|
}
|