2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:43:35 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cmath>
|
|
|
|
#include <string>
|
|
|
|
#include <wx/brush.h>
|
2008-12-07 22:30:24 -07:00
|
|
|
#include <wx/clipbrd.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/colour.h>
|
|
|
|
#include <wx/control.h>
|
|
|
|
#include <wx/dataobj.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/font.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/pen.h>
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/DebugInterface.h"
|
2014-09-07 18:36:02 -06:00
|
|
|
#include "Common/StringUtil.h"
|
2015-01-17 14:17:36 -07:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2014-10-23 07:47:00 -06:00
|
|
|
#include "DolphinWX/Debugger/CodeWindow.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
|
|
|
|
#include "DolphinWX/Debugger/MemoryView.h"
|
2014-10-23 07:47:00 -06:00
|
|
|
#include "DolphinWX/Debugger/WatchWindow.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "DolphinWX/Frame.h"
|
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
enum
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
IDM_GOTOINMEMVIEW = 12000,
|
|
|
|
IDM_COPYADDRESS,
|
|
|
|
IDM_COPYHEX,
|
|
|
|
IDM_COPYCODE,
|
|
|
|
IDM_RUNTOHERE,
|
|
|
|
IDM_DYNARECRESULTS,
|
|
|
|
IDM_WATCHADDRESS,
|
|
|
|
IDM_TOGGLEMEMORY,
|
|
|
|
IDM_VIEWASFP,
|
|
|
|
IDM_VIEWASASCII,
|
|
|
|
IDM_VIEWASHEX,
|
2008-12-07 22:30:24 -07:00
|
|
|
};
|
|
|
|
|
2011-02-23 22:05:25 -07:00
|
|
|
CMemoryView::CMemoryView(DebugInterface* debuginterface, wxWindow* parent)
|
2016-06-24 02:43:46 -06:00
|
|
|
: wxControl(parent, wxID_ANY), debugger(debuginterface),
|
|
|
|
align(debuginterface->GetInstructionSize(0)), rowHeight(13), selection(0), oldSelection(0),
|
|
|
|
selecting(false), memory(0), curAddress(debuginterface->GetPC()),
|
|
|
|
dataType(MemoryDataType::U8), viewAsType(VIEWAS_FP)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Bind(wxEVT_PAINT, &CMemoryView::OnPaint, this);
|
|
|
|
Bind(wxEVT_LEFT_DOWN, &CMemoryView::OnMouseDownL, this);
|
|
|
|
Bind(wxEVT_LEFT_UP, &CMemoryView::OnMouseUpL, this);
|
|
|
|
Bind(wxEVT_MOTION, &CMemoryView::OnMouseMove, this);
|
|
|
|
Bind(wxEVT_RIGHT_DOWN, &CMemoryView::OnMouseDownR, this);
|
|
|
|
Bind(wxEVT_MOUSEWHEEL, &CMemoryView::OnScrollWheel, this);
|
|
|
|
Bind(wxEVT_MENU, &CMemoryView::OnPopupMenu, this);
|
|
|
|
Bind(wxEVT_SIZE, &CMemoryView::OnResize, this);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMemoryView::YToAddress(int y)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
int ydiff = y - rc.height / 2 - rowHeight / 2;
|
|
|
|
ydiff = (int)(floorf((float)ydiff / (float)rowHeight)) + 1;
|
|
|
|
return curAddress + ydiff * align;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2009-10-12 10:20:31 -06:00
|
|
|
void CMemoryView::OnMouseDownL(wxMouseEvent& event)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
int x = event.m_x;
|
|
|
|
int y = event.m_y;
|
|
|
|
|
|
|
|
if (x > 16)
|
|
|
|
{
|
|
|
|
oldSelection = selection;
|
|
|
|
selection = YToAddress(y);
|
|
|
|
bool oldselecting = selecting;
|
|
|
|
selecting = true;
|
|
|
|
|
|
|
|
if (!oldselecting || (selection != oldSelection))
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debugger->ToggleMemCheck(YToAddress(y));
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
|
|
|
// Propagate back to the parent window to update the breakpoint list.
|
|
|
|
wxCommandEvent evt(wxEVT_HOST_COMMAND, IDM_UPDATE_BREAKPOINTS);
|
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryView::OnMouseMove(wxMouseEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
|
|
|
|
if (event.m_leftDown && event.m_x > 16)
|
|
|
|
{
|
|
|
|
if (event.m_y < 0)
|
|
|
|
{
|
|
|
|
curAddress -= align;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
else if (event.m_y > rc.height)
|
|
|
|
{
|
|
|
|
curAddress += align;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
OnMouseDownL(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryView::OnMouseUpL(wxMouseEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (event.m_x > 16)
|
|
|
|
{
|
|
|
|
curAddress = YToAddress(event.m_y);
|
|
|
|
selecting = false;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2014-07-18 20:42:03 -06:00
|
|
|
void CMemoryView::OnScrollWheel(wxMouseEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
const bool scroll_down = (event.GetWheelRotation() < 0);
|
|
|
|
const int num_lines = event.GetLinesPerAction();
|
|
|
|
|
|
|
|
if (scroll_down)
|
|
|
|
{
|
|
|
|
curAddress += num_lines * 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curAddress -= num_lines * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
event.Skip();
|
2014-07-18 20:42:03 -06:00
|
|
|
}
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
void CMemoryView::OnPopupMenu(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
CFrame* main_frame = static_cast<CFrame*>(GetGrandParent()->GetParent());
|
|
|
|
CCodeWindow* code_window = main_frame->g_pCodeWindow;
|
|
|
|
CWatchWindow* watch_window = code_window->m_WatchWindow;
|
2014-10-23 07:47:00 -06:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
#if wxUSE_CLIPBOARD
|
2016-06-24 02:43:46 -06:00
|
|
|
wxTheClipboard->Open();
|
2008-12-07 22:30:24 -07:00
|
|
|
#endif
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
2008-12-07 22:30:24 -07:00
|
|
|
#if wxUSE_CLIPBOARD
|
2016-06-24 02:43:46 -06:00
|
|
|
case IDM_COPYADDRESS:
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(wxString::Format("%08x", selection)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_COPYHEX:
|
|
|
|
{
|
|
|
|
std::string temp = StringFromFormat("%08x", debugger->ReadExtraMemory(memory, selection));
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
|
|
|
|
}
|
|
|
|
break;
|
2009-10-12 10:20:31 -06:00
|
|
|
#endif
|
2009-10-12 10:24:24 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
case IDM_WATCHADDRESS:
|
|
|
|
debugger->AddWatch(selection);
|
|
|
|
if (watch_window)
|
|
|
|
watch_window->NotifyUpdate();
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_TOGGLEMEMORY:
|
|
|
|
memory ^= 1;
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_VIEWASFP:
|
|
|
|
viewAsType = VIEWAS_FP;
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_VIEWASASCII:
|
|
|
|
viewAsType = VIEWAS_ASCII;
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
case IDM_VIEWASHEX:
|
|
|
|
viewAsType = VIEWAS_HEX;
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
2016-06-24 02:43:46 -06:00
|
|
|
wxTheClipboard->Close();
|
2008-12-07 22:30:24 -07:00
|
|
|
#endif
|
2016-06-24 02:43:46 -06:00
|
|
|
event.Skip();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2009-10-12 10:20:31 -06:00
|
|
|
void CMemoryView::OnMouseDownR(wxMouseEvent& event)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
// popup menu
|
|
|
|
wxMenu menu;
|
|
|
|
// menu.Append(IDM_GOTOINMEMVIEW, _("&Goto in mem view"));
|
2008-12-07 22:30:24 -07:00
|
|
|
#if wxUSE_CLIPBOARD
|
2016-06-24 02:43:46 -06:00
|
|
|
menu.Append(IDM_COPYADDRESS, _("Copy &address"));
|
|
|
|
menu.Append(IDM_COPYHEX, _("Copy &hex"));
|
2008-12-07 22:30:24 -07:00
|
|
|
#endif
|
2016-06-24 02:43:46 -06:00
|
|
|
menu.Append(IDM_WATCHADDRESS, _("Add to &watch"));
|
|
|
|
menu.Append(IDM_TOGGLEMEMORY, _("Toggle &memory"));
|
2009-10-12 10:20:31 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
wxMenu* viewAsSubMenu = new wxMenu;
|
|
|
|
viewAsSubMenu->Append(IDM_VIEWASFP, _("FP value"));
|
|
|
|
viewAsSubMenu->Append(IDM_VIEWASASCII, "ASCII");
|
|
|
|
viewAsSubMenu->Append(IDM_VIEWASHEX, _("Hex"));
|
|
|
|
menu.AppendSubMenu(viewAsSubMenu, _("View As:"));
|
2009-10-12 10:20:31 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
PopupMenu(&menu);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryView::OnPaint(wxPaintEvent& event)
|
2009-11-25 03:07:56 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxPaintDC dc(this);
|
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
wxFont hFont("Courier");
|
|
|
|
hFont.SetFamily(wxFONTFAMILY_TELETYPE);
|
|
|
|
|
|
|
|
wxCoord w, h;
|
|
|
|
dc.GetTextExtent("0WJyq", &w, &h, nullptr, nullptr, &hFont);
|
|
|
|
if (h > rowHeight)
|
|
|
|
rowHeight = h;
|
|
|
|
dc.GetTextExtent("0WJyq", &w, &h, nullptr, nullptr, &DebuggerFont);
|
|
|
|
if (h > rowHeight)
|
|
|
|
rowHeight = h;
|
|
|
|
|
|
|
|
if (viewAsType == VIEWAS_HEX)
|
|
|
|
dc.SetFont(hFont);
|
|
|
|
else
|
|
|
|
dc.SetFont(DebuggerFont);
|
|
|
|
|
|
|
|
dc.GetTextExtent("W", &w, &h);
|
|
|
|
int fontSize = w;
|
|
|
|
int textPlacement = 17 + 9 * fontSize;
|
|
|
|
|
|
|
|
// TODO: Add any drawing code here...
|
|
|
|
int width = rc.width;
|
|
|
|
int numRows = (rc.height / rowHeight) / 2 + 2;
|
2016-06-25 23:25:29 -06:00
|
|
|
dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT);
|
2016-06-24 02:43:46 -06:00
|
|
|
const wxColour bgColor = *wxWHITE;
|
|
|
|
wxPen nullPen(bgColor);
|
|
|
|
wxPen currentPen(*wxBLACK_PEN);
|
|
|
|
wxPen selPen(*wxGREY_PEN);
|
2016-06-25 23:25:29 -06:00
|
|
|
nullPen.SetStyle(wxPENSTYLE_TRANSPARENT);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
wxBrush currentBrush(*wxLIGHT_GREY_BRUSH);
|
|
|
|
wxBrush pcBrush(*wxGREEN_BRUSH);
|
|
|
|
wxBrush mcBrush(*wxBLUE_BRUSH);
|
|
|
|
wxBrush bgBrush(bgColor);
|
|
|
|
wxBrush nullBrush(bgColor);
|
2016-06-25 23:25:29 -06:00
|
|
|
nullBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
dc.SetPen(nullPen);
|
|
|
|
dc.SetBrush(bgBrush);
|
|
|
|
dc.DrawRectangle(0, 0, 16, rc.height);
|
|
|
|
dc.DrawRectangle(0, 0, rc.width, 5 + 8);
|
|
|
|
|
|
|
|
// TODO - clean up this freaking mess!!!!!
|
|
|
|
for (int row = -numRows; row <= numRows; row++)
|
|
|
|
{
|
|
|
|
unsigned int address = curAddress + row * align;
|
|
|
|
|
|
|
|
int rowY1 = rc.height / 2 + rowHeight * row - rowHeight / 2;
|
|
|
|
int rowY2 = rc.height / 2 + rowHeight * row + rowHeight / 2;
|
|
|
|
|
|
|
|
wxString temp = wxString::Format("%08x", address);
|
|
|
|
u32 col = debugger->GetColor(address);
|
|
|
|
wxBrush rowBrush(wxColour(col >> 16, col >> 8, col));
|
|
|
|
dc.SetBrush(nullBrush);
|
|
|
|
dc.SetPen(nullPen);
|
|
|
|
dc.DrawRectangle(0, rowY1, 16, rowY2);
|
|
|
|
|
|
|
|
if (selecting && (address == selection))
|
|
|
|
dc.SetPen(selPen);
|
|
|
|
else
|
|
|
|
dc.SetPen(row == 0 ? currentPen : nullPen);
|
|
|
|
|
|
|
|
if (address == debugger->GetPC())
|
|
|
|
dc.SetBrush(pcBrush);
|
|
|
|
else
|
|
|
|
dc.SetBrush(rowBrush);
|
|
|
|
|
|
|
|
dc.DrawRectangle(16, rowY1, width, rowY2 - 1);
|
|
|
|
dc.SetBrush(currentBrush);
|
|
|
|
dc.SetTextForeground("#600000"); // Dark red
|
|
|
|
dc.DrawText(temp, 17, rowY1);
|
|
|
|
|
|
|
|
if (viewAsType != VIEWAS_HEX)
|
|
|
|
{
|
|
|
|
char mem[256];
|
|
|
|
debugger->GetRawMemoryString(memory, address, mem, 256);
|
|
|
|
dc.SetTextForeground(wxTheColourDatabase->Find("NAVY"));
|
|
|
|
dc.DrawText(StrToWxStr(mem), 17 + fontSize * (8), rowY1);
|
|
|
|
dc.SetTextForeground(*wxBLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PowerPC::HostIsRAMAddress(address))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (debugger->IsAlive())
|
|
|
|
{
|
|
|
|
std::string dis;
|
|
|
|
u32 mem_data = debugger->ReadExtraMemory(memory, address);
|
|
|
|
|
|
|
|
if (viewAsType == VIEWAS_FP)
|
|
|
|
{
|
|
|
|
float flt = *(float*)(&mem_data);
|
|
|
|
dis = StringFromFormat("f: %f", flt);
|
|
|
|
}
|
|
|
|
else if (viewAsType == VIEWAS_ASCII)
|
|
|
|
{
|
|
|
|
u32 a[4] = {(mem_data & 0xff000000) >> 24, (mem_data & 0xff0000) >> 16,
|
|
|
|
(mem_data & 0xff00) >> 8, (mem_data & 0xff)};
|
|
|
|
|
|
|
|
for (auto& word : a)
|
|
|
|
{
|
|
|
|
if (word == '\0')
|
|
|
|
word = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
dis = StringFromFormat("%c%c%c%c", a[0], a[1], a[2], a[3]);
|
|
|
|
}
|
|
|
|
else if (viewAsType == VIEWAS_HEX)
|
|
|
|
{
|
|
|
|
u32 mema[8] = {debugger->ReadExtraMemory(memory, address),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 4),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 8),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 12),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 16),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 20),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 24),
|
|
|
|
debugger->ReadExtraMemory(memory, address + 28)};
|
|
|
|
|
|
|
|
for (auto& word : mema)
|
|
|
|
{
|
|
|
|
switch (dataType)
|
|
|
|
{
|
|
|
|
case MemoryDataType::U8:
|
|
|
|
dis += StringFromFormat(" %02X %02X %02X %02X", ((word & 0xff000000) >> 24) & 0xFF,
|
|
|
|
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff00) >> 8) & 0xFF,
|
|
|
|
word & 0xff);
|
|
|
|
break;
|
|
|
|
case MemoryDataType::U16:
|
|
|
|
dis += StringFromFormat(" %02X%02X %02X%02X", ((word & 0xff000000) >> 24) & 0xFF,
|
|
|
|
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff00) >> 8) & 0xFF,
|
|
|
|
word & 0xff);
|
|
|
|
break;
|
|
|
|
case MemoryDataType::U32:
|
|
|
|
dis += StringFromFormat(" %02X%02X%02X%02X", ((word & 0xff000000) >> 24) & 0xFF,
|
|
|
|
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff00) >> 8) & 0xFF,
|
|
|
|
word & 0xff);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dis = "INVALID VIEWAS TYPE";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewAsType != VIEWAS_HEX)
|
|
|
|
dc.DrawText(StrToWxStr(dis), textPlacement + fontSize * (8 + 8), rowY1);
|
|
|
|
else
|
|
|
|
dc.DrawText(StrToWxStr(dis), textPlacement, rowY1);
|
|
|
|
|
|
|
|
dc.SetTextForeground(*wxBLUE);
|
|
|
|
|
|
|
|
std::string desc = debugger->GetDescription(address);
|
|
|
|
if (!desc.empty())
|
|
|
|
dc.DrawText(StrToWxStr(desc), 17 + fontSize * ((8 + 8 + 8 + 30) * 2), rowY1);
|
|
|
|
|
|
|
|
// Show blue memory check dot
|
|
|
|
if (debugger->IsMemCheck(address))
|
|
|
|
{
|
|
|
|
dc.SetBrush(mcBrush);
|
|
|
|
dc.DrawRectangle(8, rowY1 + 1, 11, 11);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.SetPen(currentPen);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
2011-02-23 22:05:25 -07:00
|
|
|
|
|
|
|
void CMemoryView::OnResize(wxSizeEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Refresh();
|
|
|
|
event.Skip();
|
2011-02-23 22:05:25 -07:00
|
|
|
}
|