2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-18 01:33:51 +00:00
|
|
|
#include <algorithm>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2014-08-24 18:59:02 +00:00
|
|
|
#include <memory>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/brush.h>
|
|
|
|
#include <wx/chartype.h>
|
2008-12-08 05:30:24 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/colour.h>
|
|
|
|
#include <wx/control.h>
|
|
|
|
#include <wx/dataobj.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/defs.h>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <wx/event.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/gdicmn.h>
|
2014-08-24 18:59:02 +00:00
|
|
|
#include <wx/graphics.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/menuitem.h>
|
|
|
|
#include <wx/pen.h>
|
|
|
|
#include <wx/setup.h>
|
|
|
|
#include <wx/string.h>
|
2008-12-08 05:30:24 +00:00
|
|
|
#include <wx/textdlg.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <wx/windowid.h>
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/DebugInterface.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Common/SymbolDB.h"
|
2014-07-17 08:49:45 +00:00
|
|
|
#include "Core/Core.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/Host.h"
|
2014-08-05 03:46:37 +00:00
|
|
|
#include "DolphinWX/Globals.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
|
|
|
#include "DolphinWX/Debugger/CodeView.h"
|
|
|
|
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
|
|
|
|
|
2014-08-17 20:18:54 +00:00
|
|
|
wxDEFINE_EVENT(wxEVT_CODEVIEW_CHANGE, wxCommandEvent);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDM_GOTOINMEMVIEW = 12000,
|
|
|
|
IDM_COPYADDRESS,
|
|
|
|
IDM_COPYHEX,
|
|
|
|
IDM_COPYCODE,
|
2009-06-09 05:26:39 +00:00
|
|
|
IDM_INSERTBLR, IDM_INSERTNOP,
|
2008-12-08 05:30:24 +00:00
|
|
|
IDM_RUNTOHERE,
|
|
|
|
IDM_JITRESULTS,
|
|
|
|
IDM_FOLLOWBRANCH,
|
|
|
|
IDM_RENAMESYMBOL,
|
|
|
|
IDM_PATCHALERT,
|
|
|
|
IDM_COPYFUNCTION,
|
2009-01-20 13:13:03 +00:00
|
|
|
IDM_ADDFUNCTION,
|
2008-12-08 05:30:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CCodeView, wxControl)
|
|
|
|
EVT_ERASE_BACKGROUND(CCodeView::OnErase)
|
|
|
|
EVT_PAINT(CCodeView::OnPaint)
|
2014-07-16 01:35:11 +00:00
|
|
|
EVT_MOUSEWHEEL(CCodeView::OnScrollWheel)
|
2008-12-08 05:30:24 +00:00
|
|
|
EVT_LEFT_DOWN(CCodeView::OnMouseDown)
|
|
|
|
EVT_LEFT_UP(CCodeView::OnMouseUpL)
|
|
|
|
EVT_MOTION(CCodeView::OnMouseMove)
|
|
|
|
EVT_RIGHT_DOWN(CCodeView::OnMouseDown)
|
|
|
|
EVT_RIGHT_UP(CCodeView::OnMouseUpR)
|
|
|
|
EVT_MENU(-1, CCodeView::OnPopupMenu)
|
2011-02-24 05:05:25 +00:00
|
|
|
EVT_SIZE(CCodeView::OnResize)
|
2008-12-08 05:30:24 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2011-02-24 05:05:25 +00:00
|
|
|
CCodeView::CCodeView(DebugInterface* debuginterface, SymbolDB *symboldb,
|
|
|
|
wxWindow* parent, wxWindowID Id)
|
|
|
|
: wxControl(parent, Id),
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger(debuginterface),
|
|
|
|
m_symbol_db(symboldb),
|
|
|
|
m_plain(false),
|
|
|
|
m_curAddress(debuginterface->GetPC()),
|
|
|
|
m_align(debuginterface->GetInstructionSize(0)),
|
|
|
|
m_rowHeight(13),
|
|
|
|
m_selection(0),
|
|
|
|
m_oldSelection(0),
|
|
|
|
m_selecting(false),
|
|
|
|
m_lx(-1),
|
|
|
|
m_ly(-1)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCodeView::YToAddress(int y)
|
|
|
|
{
|
|
|
|
wxRect rc = GetClientRect();
|
2014-07-16 03:01:17 +00:00
|
|
|
int ydiff = y - rc.height / 2 - m_rowHeight / 2;
|
|
|
|
ydiff = (int)(floorf((float)ydiff / (float)m_rowHeight)) + 1;
|
|
|
|
return m_curAddress + ydiff * m_align;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeView::OnMouseDown(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
int x = event.m_x;
|
|
|
|
int y = event.m_y;
|
|
|
|
|
|
|
|
if (x > 16)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_oldSelection = m_selection;
|
|
|
|
m_selection = YToAddress(y);
|
2008-12-08 05:30:24 +00:00
|
|
|
// SetCapture(wnd);
|
2014-07-16 03:01:17 +00:00
|
|
|
bool oldselecting = m_selecting;
|
|
|
|
m_selecting = true;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
if (!oldselecting || (m_selection != m_oldSelection))
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
else
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2010-08-08 06:00:22 +00:00
|
|
|
ToggleBreakpoint(YToAddress(y));
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 01:35:11 +00:00
|
|
|
void CCodeView::OnScrollWheel(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
const bool scroll_down = (event.GetWheelRotation() < 0);
|
|
|
|
const int num_lines = event.GetLinesPerAction();
|
|
|
|
|
|
|
|
if (scroll_down)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_curAddress += num_lines;
|
2014-07-16 01:35:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_curAddress -= num_lines;
|
2014-07-16 01:35:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2010-08-08 06:00:22 +00:00
|
|
|
void CCodeView::ToggleBreakpoint(u32 address)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger->ToggleBreakpoint(address);
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2014-08-05 03:46:37 +00:00
|
|
|
|
|
|
|
// Propagate back to the parent window to update the breakpoint list.
|
|
|
|
wxCommandEvent evt(wxEVT_HOST_COMMAND, IDM_UPDATEBREAKPOINTS);
|
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
2010-08-08 06:00:22 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
void CCodeView::OnMouseMove(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
|
2011-02-24 05:05:25 +00:00
|
|
|
if (event.m_leftDown && event.m_x > 16)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-02-24 05:05:25 +00:00
|
|
|
if (event.m_y < 0)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_curAddress -= m_align;
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
else if (event.m_y > rc.height)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_curAddress += m_align;
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2011-02-24 05:05:25 +00:00
|
|
|
else
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2011-02-24 05:05:25 +00:00
|
|
|
OnMouseDown(event);
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeView::RaiseEvent()
|
|
|
|
{
|
|
|
|
wxCommandEvent ev(wxEVT_CODEVIEW_CHANGE, GetId());
|
|
|
|
ev.SetEventObject(this);
|
2014-07-16 03:01:17 +00:00
|
|
|
ev.SetInt(m_selection);
|
2008-12-08 05:30:24 +00:00
|
|
|
GetEventHandler()->ProcessEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeView::OnMouseUpL(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
if (event.m_x > 16)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_curAddress = YToAddress(event.m_y);
|
|
|
|
m_selecting = false;
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2014-07-16 03:01:17 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
RaiseEvent();
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CCodeView::AddrToBranch(u32 addr)
|
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::string disasm = m_debugger->Disassemble(addr);
|
|
|
|
size_t pos = disasm.find("->0x");
|
|
|
|
|
|
|
|
if (pos != std::string::npos)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::string hex = disasm.substr(pos + 2);
|
|
|
|
return std::stoul(hex, nullptr, 16);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2014-07-18 01:33:51 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-09 05:26:39 +00:00
|
|
|
void CCodeView::InsertBlrNop(int Blr)
|
|
|
|
{
|
|
|
|
// Check if this address has been modified
|
2013-04-08 05:16:50 +00:00
|
|
|
int find = -1;
|
2014-07-16 03:01:17 +00:00
|
|
|
for (u32 i = 0; i < m_blrList.size(); i++)
|
2009-06-09 05:26:39 +00:00
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
if (m_blrList.at(i).address == m_selection)
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
|
|
|
find = i;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-09 05:26:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
// Save the old value
|
2009-06-21 08:39:21 +00:00
|
|
|
if (find >= 0)
|
2009-06-09 05:26:39 +00:00
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger->WriteExtraMemory(0, m_blrList.at(find).oldValue, m_selection);
|
|
|
|
m_blrList.erase(m_blrList.begin() + find);
|
2009-06-09 05:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
BlrStruct temp;
|
|
|
|
temp.address = m_selection;
|
|
|
|
temp.oldValue = m_debugger->ReadMemory(m_selection);
|
|
|
|
m_blrList.push_back(temp);
|
2009-06-09 05:26:39 +00:00
|
|
|
if (Blr == 0)
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger->InsertBLR(m_selection, 0x4e800020);
|
2009-06-09 05:26:39 +00:00
|
|
|
else
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger->InsertBLR(m_selection, 0x60000000);
|
2009-06-09 05:26:39 +00:00
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
Refresh();
|
2009-06-09 05:26:39 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
void CCodeView::OnPopupMenu(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
wxTheClipboard->Open();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
2013-04-08 05:16:50 +00:00
|
|
|
case IDM_GOTOINMEMVIEW:
|
|
|
|
// CMemoryDlg::Goto(selection);
|
|
|
|
break;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
2013-04-08 05:16:50 +00:00
|
|
|
case IDM_COPYADDRESS:
|
2014-07-16 03:01:17 +00:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(wxString::Format("%08x", m_selection)));
|
2013-04-08 05:16:50 +00:00
|
|
|
break;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2008-12-09 21:24:12 +00:00
|
|
|
case IDM_COPYCODE:
|
2011-02-24 05:05:25 +00:00
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::string disasm = m_debugger->Disassemble(m_selection);
|
2013-08-31 04:39:19 +00:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(disasm)));
|
2011-02-24 05:05:25 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
case IDM_COPYHEX:
|
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::string temp = StringFromFormat("%08x", m_debugger->ReadInstruction(m_selection));
|
2013-08-31 04:39:19 +00:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-01-20 13:13:03 +00:00
|
|
|
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
case IDM_COPYFUNCTION:
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
Symbol *symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
|
2013-08-31 04:39:19 +00:00
|
|
|
if (symbol)
|
2011-02-24 05:05:25 +00:00
|
|
|
{
|
2013-08-31 04:39:19 +00:00
|
|
|
std::string text;
|
|
|
|
text = text + symbol->name + "\r\n";
|
|
|
|
// we got a function
|
|
|
|
u32 start = symbol->address;
|
|
|
|
u32 end = start + symbol->size;
|
|
|
|
for (u32 addr = start; addr != end; addr += 4)
|
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::string disasm = m_debugger->Disassemble(addr);
|
|
|
|
text += StringFromFormat("%08x: ", addr) + disasm + "\r\n";
|
2013-08-31 04:39:19 +00:00
|
|
|
}
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text)));
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
case IDM_RUNTOHERE:
|
2014-07-16 03:01:17 +00:00
|
|
|
m_debugger->SetBreakpoint(m_selection);
|
|
|
|
m_debugger->RunToBreakpoint();
|
2013-04-08 05:16:50 +00:00
|
|
|
Refresh();
|
|
|
|
break;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
// Insert blr or restore old value
|
|
|
|
case IDM_INSERTBLR:
|
2009-06-09 05:26:39 +00:00
|
|
|
InsertBlrNop(0);
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2009-06-09 05:26:39 +00:00
|
|
|
break;
|
|
|
|
case IDM_INSERTNOP:
|
|
|
|
InsertBlrNop(1);
|
2011-02-24 05:05:25 +00:00
|
|
|
Refresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
break;
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
case IDM_JITRESULTS:
|
2014-08-15 19:10:41 +00:00
|
|
|
{
|
|
|
|
// Propagate back to the parent window and tell it
|
|
|
|
// to flip to the JIT tab for the current address.
|
|
|
|
wxCommandEvent jit_event(wxEVT_HOST_COMMAND, IDM_UPDATEJITPANE);
|
|
|
|
GetEventHandler()->AddPendingEvent(jit_event);
|
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
break;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
case IDM_FOLLOWBRANCH:
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
u32 dest = AddrToBranch(m_selection);
|
2013-08-31 04:39:19 +00:00
|
|
|
if (dest)
|
|
|
|
{
|
|
|
|
Center(dest);
|
|
|
|
RaiseEvent();
|
|
|
|
}
|
2013-08-30 22:29:03 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
break;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2009-01-20 13:13:03 +00:00
|
|
|
case IDM_ADDFUNCTION:
|
2014-07-16 03:01:17 +00:00
|
|
|
m_symbol_db->AddFunction(m_selection);
|
2009-09-27 21:28:09 +00:00
|
|
|
Host_NotifyMapLoaded();
|
2009-01-20 13:13:03 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
case IDM_RENAMESYMBOL:
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
Symbol *symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
|
2013-08-31 04:39:19 +00:00
|
|
|
if (symbol)
|
2011-02-24 05:05:25 +00:00
|
|
|
{
|
2014-05-17 17:17:28 +00:00
|
|
|
wxTextEntryDialog input_symbol(this, _("Rename symbol:"),
|
2013-08-31 04:39:19 +00:00
|
|
|
wxGetTextFromUserPromptStr,
|
|
|
|
StrToWxStr(symbol->name));
|
|
|
|
if (input_symbol.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
symbol->name = WxStrToStr(input_symbol.GetValue());
|
|
|
|
Refresh(); // Redraw to show the renamed symbol
|
|
|
|
}
|
|
|
|
Host_NotifyMapLoaded();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_PATCHALERT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
#endif
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeView::OnMouseUpR(wxMouseEvent& event)
|
|
|
|
{
|
2014-07-16 03:01:17 +00:00
|
|
|
bool isSymbol = m_symbol_db->GetSymbolFromAddr(m_selection) != nullptr;
|
2008-12-08 05:30:24 +00:00
|
|
|
// popup menu
|
2009-11-23 08:05:54 +00:00
|
|
|
wxMenu* menu = new wxMenu;
|
|
|
|
//menu->Append(IDM_GOTOINMEMVIEW, "&Goto in mem view");
|
2014-07-16 03:01:17 +00:00
|
|
|
menu->Append(IDM_FOLLOWBRANCH, _("&Follow branch"))->Enable(AddrToBranch(m_selection) ? true : false);
|
2009-11-23 08:05:54 +00:00
|
|
|
menu->AppendSeparator();
|
2008-12-08 05:30:24 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
2014-05-17 17:17:28 +00:00
|
|
|
menu->Append(IDM_COPYADDRESS, _("Copy &address"));
|
|
|
|
menu->Append(IDM_COPYFUNCTION, _("Copy &function"))->Enable(isSymbol);
|
|
|
|
menu->Append(IDM_COPYCODE, _("Copy &code line"));
|
|
|
|
menu->Append(IDM_COPYHEX, _("Copy &hex"));
|
2009-11-23 08:05:54 +00:00
|
|
|
menu->AppendSeparator();
|
2008-12-08 05:30:24 +00:00
|
|
|
#endif
|
2014-05-17 17:17:28 +00:00
|
|
|
menu->Append(IDM_RENAMESYMBOL, _("Rename &symbol"))->Enable(isSymbol);
|
2009-11-23 08:05:54 +00:00
|
|
|
menu->AppendSeparator();
|
2014-07-17 08:49:45 +00:00
|
|
|
menu->Append(IDM_RUNTOHERE, _("&Run To Here"))->Enable(Core::IsRunning());
|
|
|
|
menu->Append(IDM_ADDFUNCTION, _("&Add function"))->Enable(Core::IsRunning());
|
|
|
|
menu->Append(IDM_JITRESULTS, _("PPC vs X86"))->Enable(Core::IsRunning());
|
|
|
|
menu->Append(IDM_INSERTBLR, _("Insert &blr"))->Enable(Core::IsRunning());
|
|
|
|
menu->Append(IDM_INSERTNOP, _("Insert &nop"))->Enable(Core::IsRunning());
|
|
|
|
menu->Append(IDM_PATCHALERT, _("Patch alert"))->Enable(Core::IsRunning());
|
2009-11-23 08:05:54 +00:00
|
|
|
PopupMenu(menu);
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeView::OnErase(wxEraseEvent& event)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void CCodeView::OnPaint(wxPaintEvent& event)
|
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
// -------------------------
|
2008-12-08 05:30:24 +00:00
|
|
|
// General settings
|
|
|
|
// -------------------------
|
2014-08-24 18:59:02 +00:00
|
|
|
std::unique_ptr<wxGraphicsContext> ctx(wxGraphicsContext::Create(wxPaintDC(this)));
|
2008-12-08 05:30:24 +00:00
|
|
|
wxRect rc = GetClientRect();
|
2009-06-21 08:39:21 +00:00
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetFont(DebuggerFont, *wxBLACK);
|
2009-06-21 08:39:21 +00:00
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
wxDouble w,h;
|
|
|
|
ctx->GetTextExtent("0WJyq", &w, &h);
|
2011-07-01 14:20:33 +00:00
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
if (h > m_rowHeight)
|
|
|
|
m_rowHeight = h;
|
2011-07-01 14:20:33 +00:00
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->GetTextExtent("W", &w, &h);
|
2011-07-01 14:20:33 +00:00
|
|
|
int charWidth = w;
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
struct branch
|
|
|
|
{
|
|
|
|
int src, dst, srcAddr;
|
|
|
|
};
|
|
|
|
|
|
|
|
branch branches[256];
|
|
|
|
int numBranches = 0;
|
|
|
|
// TODO: Add any drawing code here...
|
|
|
|
int width = rc.width;
|
2014-08-24 19:16:20 +00:00
|
|
|
int numRows = ((rc.height / m_rowHeight) / 2) + 2;
|
2008-12-08 05:30:24 +00:00
|
|
|
// ------------
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
// -------------------------
|
2008-12-08 05:30:24 +00:00
|
|
|
// Colors and brushes
|
2013-10-29 05:23:17 +00:00
|
|
|
// -------------------------
|
2014-08-24 18:59:02 +00:00
|
|
|
|
2014-05-17 17:17:28 +00:00
|
|
|
const wxColour bgColor = *wxWHITE;
|
2008-12-08 05:30:24 +00:00
|
|
|
wxPen nullPen(bgColor);
|
2014-05-17 17:17:28 +00:00
|
|
|
wxPen currentPen(*wxBLACK_PEN);
|
|
|
|
wxPen selPen(*wxGREY_PEN);
|
2008-12-08 05:30:24 +00:00
|
|
|
nullPen.SetStyle(wxTRANSPARENT);
|
|
|
|
currentPen.SetStyle(wxSOLID);
|
2014-05-17 17:17:28 +00:00
|
|
|
wxBrush currentBrush(*wxLIGHT_GREY_BRUSH);
|
|
|
|
wxBrush pcBrush(*wxGREEN_BRUSH);
|
|
|
|
wxBrush bpBrush(*wxRED_BRUSH);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
wxBrush bgBrush(bgColor);
|
|
|
|
wxBrush nullBrush(bgColor);
|
|
|
|
nullBrush.SetStyle(wxTRANSPARENT);
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetPen(nullPen);
|
|
|
|
ctx->SetBrush(bgBrush);
|
|
|
|
ctx->DrawRectangle(0, 0, 16, rc.height);
|
|
|
|
ctx->DrawRectangle(0, 0, rc.width, 5);
|
2008-12-08 05:30:24 +00:00
|
|
|
// ------------
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
// -----------------------------
|
2008-12-08 05:30:24 +00:00
|
|
|
// Walk through all visible rows
|
2014-08-24 18:59:02 +00:00
|
|
|
// -----------------------------
|
2008-12-08 05:30:24 +00:00
|
|
|
for (int i = -numRows; i <= numRows; i++)
|
|
|
|
{
|
2014-08-24 19:16:20 +00:00
|
|
|
unsigned int address = m_curAddress + (i * m_align);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-08-24 19:16:20 +00:00
|
|
|
int rowY1 = (rc.height / 2) + (m_rowHeight * i) - (m_rowHeight / 2);
|
|
|
|
int rowY2 = (rc.height / 2) + (m_rowHeight * i) + (m_rowHeight / 2);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-05-17 17:17:28 +00:00
|
|
|
wxString temp = wxString::Format("%08x", address);
|
2014-08-24 19:16:20 +00:00
|
|
|
u32 color = m_debugger->GetColor(address);
|
|
|
|
wxBrush rowBrush(wxColour(color >> 16, color >> 8, color));
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetBrush(nullBrush);
|
|
|
|
ctx->SetPen(nullPen);
|
|
|
|
ctx->DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
if (m_selecting && (address == m_selection))
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetPen(selPen);
|
2008-12-08 05:30:24 +00:00
|
|
|
else
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetPen(i == 0 ? currentPen : nullPen);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
if (address == m_debugger->GetPC())
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetBrush(pcBrush);
|
2008-12-08 05:30:24 +00:00
|
|
|
else
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetBrush(rowBrush);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1);
|
|
|
|
ctx->SetBrush(currentBrush);
|
2014-07-16 03:01:17 +00:00
|
|
|
if (!m_plain)
|
2011-02-24 05:05:25 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
// the address text is dark red
|
|
|
|
ctx->SetFont(DebuggerFont, wxColour("#600000"));
|
|
|
|
ctx->DrawText(temp, 17, rowY1);
|
|
|
|
ctx->SetFont(DebuggerFont, *wxBLACK);
|
2009-06-21 08:39:21 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-09-07 12:40:43 +00:00
|
|
|
// If running
|
2014-07-16 03:01:17 +00:00
|
|
|
if (m_debugger->IsAlive())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
std::vector<std::string> dis;
|
|
|
|
SplitString(m_debugger->Disassemble(address), '\t', dis);
|
2014-08-04 07:06:13 +00:00
|
|
|
dis.resize(2);
|
2014-07-18 01:33:51 +00:00
|
|
|
|
|
|
|
static const size_t VALID_BRANCH_LENGTH = 10;
|
2014-08-04 07:06:13 +00:00
|
|
|
const std::string& opcode = dis[0];
|
2014-07-18 01:33:51 +00:00
|
|
|
const std::string& operands = dis[1];
|
|
|
|
std::string desc;
|
|
|
|
|
|
|
|
// look for hex strings to decode branches
|
|
|
|
std::string hex_str;
|
|
|
|
size_t pos = operands.find("0x8");
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
hex_str = operands.substr(pos);
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-18 01:33:51 +00:00
|
|
|
if (hex_str.length() == VALID_BRANCH_LENGTH)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
u32 offs = std::stoul(hex_str, nullptr, 16);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-08-24 19:16:20 +00:00
|
|
|
branches[numBranches].src = rowY1 + (m_rowHeight / 2);
|
|
|
|
branches[numBranches].srcAddr = (address / m_align);
|
2014-07-18 01:33:51 +00:00
|
|
|
branches[numBranches++].dst = (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align + m_rowHeight / 2);
|
|
|
|
desc = StringFromFormat("-->%s", m_debugger->GetDescription(offs).c_str());
|
2014-08-24 19:16:20 +00:00
|
|
|
|
|
|
|
// the -> arrow illustrations are purple
|
|
|
|
ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("PURPLE"));
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2014-07-18 01:33:51 +00:00
|
|
|
else
|
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetFont(DebuggerFont, *wxBLACK);
|
2014-07-18 01:33:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->DrawText(StrToWxStr(operands), 17 + 17*charWidth, rowY1);
|
2014-07-18 01:33:51 +00:00
|
|
|
// ------------
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
// Show blr as its' own color
|
2014-07-18 01:33:51 +00:00
|
|
|
if (opcode == "blr")
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("DARK GREEN"));
|
2008-12-08 05:30:24 +00:00
|
|
|
else
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("VIOLET"));
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->DrawText(StrToWxStr(opcode), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-18 01:33:51 +00:00
|
|
|
if (desc.empty())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
desc = m_debugger->GetDescription(address);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
if (!m_plain)
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetFont(DebuggerFont, *wxBLUE);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
//char temp[256];
|
|
|
|
//UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
|
2014-07-18 01:33:51 +00:00
|
|
|
if (!desc.empty())
|
2009-06-21 08:39:21 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1);
|
2009-06-21 08:39:21 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show red breakpoint dot
|
2014-07-16 03:01:17 +00:00
|
|
|
if (m_debugger->IsBreakpoint(address))
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetBrush(bpBrush);
|
|
|
|
ctx->DrawRectangle(2, rowY1 + 1, 11, 11);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end of for
|
|
|
|
// ------------
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
// -------------------------
|
2008-12-08 05:30:24 +00:00
|
|
|
// Colors and brushes
|
|
|
|
// -------------------------
|
2014-08-24 18:59:02 +00:00
|
|
|
ctx->SetPen(currentPen);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
for (int i = 0; i < numBranches; i++)
|
|
|
|
{
|
2013-04-08 05:16:50 +00:00
|
|
|
int x = 17 + 49 * charWidth + (branches[i].srcAddr % 9) * 8;
|
2014-07-16 03:01:17 +00:00
|
|
|
MoveTo(x-2, branches[i].src);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
if (branches[i].dst < rc.height + 400 && branches[i].dst > -400)
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
LineTo(ctx, x+2, branches[i].src);
|
|
|
|
LineTo(ctx, x+2, branches[i].dst);
|
|
|
|
LineTo(ctx, x-4, branches[i].dst);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-07-16 03:01:17 +00:00
|
|
|
MoveTo(x, branches[i].dst - 4);
|
2014-08-24 18:59:02 +00:00
|
|
|
LineTo(ctx, x-4, branches[i].dst);
|
|
|
|
LineTo(ctx, x+1, branches[i].dst+5);
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2009-01-05 03:09:13 +00:00
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// This can be re-enabled when there is a scrollbar or
|
|
|
|
// something on the codeview (the lines are too long)
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
//LineTo(ctx, x+4, branches[i].src);
|
2014-07-16 03:01:17 +00:00
|
|
|
//MoveTo(x+2, branches[i].dst-4);
|
2014-08-24 18:59:02 +00:00
|
|
|
//LineTo(ctx, x+6, branches[i].dst);
|
|
|
|
//LineTo(ctx, x+1, branches[i].dst+5);
|
2009-01-05 03:09:13 +00:00
|
|
|
//}
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
//LineTo(ctx, x, branches[i].dst+4);
|
|
|
|
//LineTo(ctx, x-2, branches[i].dst);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
// ------------
|
|
|
|
}
|
|
|
|
|
2014-08-24 18:59:02 +00:00
|
|
|
void CCodeView::LineTo(std::unique_ptr<wxGraphicsContext>& ctx, int x, int y)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-08-24 18:59:02 +00:00
|
|
|
std::vector<wxPoint2DDouble> points { wxPoint2DDouble(m_lx, m_ly), wxPoint2DDouble(x, y) };
|
|
|
|
|
|
|
|
ctx->DrawLines(points.size(), points.data());
|
2014-07-16 03:01:17 +00:00
|
|
|
m_lx = x;
|
|
|
|
m_ly = y;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 05:05:25 +00:00
|
|
|
void CCodeView::OnResize(wxSizeEvent& event)
|
|
|
|
{
|
|
|
|
Refresh();
|
|
|
|
event.Skip();
|
|
|
|
}
|