2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-07-12 04:08:59 -06:00
|
|
|
#include "DebuggerUIUtil.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
#include "Common.h"
|
2009-09-27 15:28:09 -06:00
|
|
|
#include "Host.h"
|
|
|
|
#include "PowerPC/PowerPC.h"
|
|
|
|
#include "HW/Memmap.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
#include "MemoryView.h"
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/clipbrd.h>
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDM_GOTOINMEMVIEW = 12000,
|
|
|
|
IDM_COPYADDRESS,
|
|
|
|
IDM_COPYHEX,
|
|
|
|
IDM_COPYCODE,
|
|
|
|
IDM_RUNTOHERE,
|
|
|
|
IDM_DYNARECRESULTS,
|
2009-06-17 13:50:59 -06:00
|
|
|
IDM_TOGGLEMEMORY,
|
2009-10-12 10:20:31 -06:00
|
|
|
IDM_VIEWASFP,
|
|
|
|
IDM_VIEWASASCII,
|
2008-12-07 22:30:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CMemoryView, wxControl)
|
|
|
|
EVT_ERASE_BACKGROUND(CMemoryView::OnErase)
|
|
|
|
EVT_PAINT(CMemoryView::OnPaint)
|
2009-10-12 10:20:31 -06:00
|
|
|
EVT_LEFT_DOWN(CMemoryView::OnMouseDownL)
|
2008-12-07 22:30:24 -07:00
|
|
|
EVT_LEFT_UP(CMemoryView::OnMouseUpL)
|
|
|
|
EVT_MOTION(CMemoryView::OnMouseMove)
|
2009-10-12 10:20:31 -06:00
|
|
|
EVT_RIGHT_DOWN(CMemoryView::OnMouseDownR)
|
2008-12-07 22:30:24 -07:00
|
|
|
EVT_MENU(-1, CMemoryView::OnPopupMenu)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
CMemoryView::CMemoryView(DebugInterface* debuginterface, wxWindow* parent, wxWindowID Id, const wxSize& Size)
|
|
|
|
: wxControl(parent, Id, wxDefaultPosition, Size),
|
|
|
|
debugger(debuginterface),
|
|
|
|
rowHeight(13),
|
|
|
|
selection(0),
|
|
|
|
oldSelection(0),
|
|
|
|
selectionChanged(false),
|
|
|
|
selecting(false),
|
|
|
|
hasFocus(false),
|
2009-06-17 13:50:59 -06:00
|
|
|
showHex(false),
|
2009-10-12 10:20:31 -06:00
|
|
|
memory(0),
|
|
|
|
viewAsType(VIEWAS_FP)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
rowHeight = 13;
|
|
|
|
align = debuginterface->getInstructionSize(0);
|
|
|
|
curAddress = debuginterface->getPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxSize CMemoryView::DoGetBestSize() const
|
|
|
|
{
|
|
|
|
wxSize bestSize;
|
|
|
|
bestSize.x = 300;
|
|
|
|
bestSize.y = 300;
|
|
|
|
return(bestSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CMemoryView::YToAddress(int y)
|
|
|
|
{
|
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
int ydiff = y - rc.height / 2 - rowHeight / 2;
|
|
|
|
ydiff = (int)(floorf((float)ydiff / (float)rowHeight)) + 1;
|
|
|
|
return(curAddress + ydiff * align);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 10:20:31 -06:00
|
|
|
void CMemoryView::OnMouseDownL(wxMouseEvent& event)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
int x = event.m_x;
|
|
|
|
int y = event.m_y;
|
|
|
|
|
|
|
|
if (x > 16)
|
|
|
|
{
|
|
|
|
oldSelection = selection;
|
|
|
|
selection = YToAddress(y);
|
|
|
|
// SetCapture(wnd);
|
|
|
|
bool oldselecting = selecting;
|
|
|
|
selecting = true;
|
|
|
|
|
|
|
|
if (!oldselecting || (selection != oldSelection))
|
|
|
|
{
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-27 15:28:09 -06:00
|
|
|
int address = YToAddress(y);
|
|
|
|
if (Memory::AreMemoryBreakpointsActivated() && !PowerPC::memchecks.GetMemCheck(address))
|
|
|
|
{
|
|
|
|
// Add Memory Check
|
|
|
|
TMemCheck MemCheck;
|
|
|
|
MemCheck.StartAddress = address;
|
|
|
|
MemCheck.EndAddress = address;
|
|
|
|
MemCheck.OnRead = true;
|
|
|
|
MemCheck.OnWrite = true;
|
|
|
|
|
|
|
|
MemCheck.Log = true;
|
|
|
|
MemCheck.Break = true;
|
|
|
|
|
|
|
|
PowerPC::memchecks.Add(MemCheck);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PowerPC::memchecks.DeleteByAddress(address);
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
redraw();
|
2009-09-27 15:28:09 -06:00
|
|
|
Host_UpdateBreakPointView();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMemoryView::OnMouseMove(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
wxRect rc = GetClientRect();
|
|
|
|
|
|
|
|
if (event.m_leftDown)
|
|
|
|
{
|
|
|
|
if (event.m_x > 16)
|
|
|
|
{
|
|
|
|
if (event.m_y < 0)
|
|
|
|
{
|
|
|
|
curAddress -= align;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
else if (event.m_y > rc.height)
|
|
|
|
{
|
|
|
|
curAddress += align;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-12 10:20:31 -06:00
|
|
|
OnMouseDownL(event);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMemoryView::OnMouseUpL(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
if (event.m_x > 16)
|
|
|
|
{
|
|
|
|
curAddress = YToAddress(event.m_y);
|
|
|
|
selecting = false;
|
|
|
|
//ReleaseCapture();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMemoryView::OnPopupMenu(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
wxTheClipboard->Open();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
case IDM_COPYADDRESS:
|
|
|
|
{
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(wxString::Format(_T("%08x"), selection)));
|
|
|
|
}
|
2009-01-21 04:44:36 -07:00
|
|
|
break;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
case IDM_COPYHEX:
|
|
|
|
{
|
|
|
|
char temp[24];
|
2009-06-17 13:50:59 -06:00
|
|
|
sprintf(temp, "%08x", debugger->readExtraMemory(memory, selection));
|
2008-12-07 22:30:24 -07:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(temp)));
|
|
|
|
}
|
2009-06-17 13:50:59 -06:00
|
|
|
break;
|
2009-10-12 10:20:31 -06:00
|
|
|
#endif
|
|
|
|
case IDM_VIEWASFP:
|
|
|
|
viewAsType = VIEWAS_FP;
|
|
|
|
redraw();
|
|
|
|
break;
|
2009-06-17 13:50:59 -06:00
|
|
|
|
2009-10-12 10:20:31 -06:00
|
|
|
case IDM_VIEWASASCII:
|
|
|
|
viewAsType = VIEWAS_ASCII;
|
2009-06-17 13:50:59 -06:00
|
|
|
redraw();
|
|
|
|
break;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
#endif
|
|
|
|
event.Skip(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 10:20:31 -06:00
|
|
|
void CMemoryView::OnMouseDownR(wxMouseEvent& event)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
// popup menu
|
|
|
|
wxMenu menu;
|
|
|
|
//menu.Append(IDM_GOTOINMEMVIEW, "&Goto in mem view");
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
menu.Append(IDM_COPYADDRESS, wxString::FromAscii("Copy &address"));
|
|
|
|
menu.Append(IDM_COPYHEX, wxString::FromAscii("Copy &hex"));
|
|
|
|
#endif
|
2009-06-17 13:50:59 -06:00
|
|
|
menu.Append(IDM_TOGGLEMEMORY, wxString::FromAscii("Toggle &memory (RAM/ARAM)"));
|
2009-10-12 10:20:31 -06:00
|
|
|
|
|
|
|
wxMenu viewAsSubMenu;
|
|
|
|
viewAsSubMenu.Append(IDM_VIEWASFP, wxString::FromAscii("FP value"));
|
|
|
|
viewAsSubMenu.Append(IDM_VIEWASASCII, wxString::FromAscii("ASCII"));
|
|
|
|
menu.AppendSubMenu(&viewAsSubMenu, wxString::FromAscii("View As:"));
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
PopupMenu(&menu);
|
2009-10-12 10:20:31 -06:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
event.Skip(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMemoryView::OnErase(wxEraseEvent& event)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void CMemoryView::OnPaint(wxPaintEvent& event)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
wxRect rc = GetClientRect();
|
2009-02-06 11:18:20 -07:00
|
|
|
dc.SetFont(DebuggerFont);
|
|
|
|
int fontSize = DebuggerFont.GetPointSize();
|
2008-12-07 22:30:24 -07:00
|
|
|
struct branch
|
|
|
|
{
|
|
|
|
int src, dst, srcAddr;
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: Add any drawing code here...
|
|
|
|
int width = rc.width;
|
|
|
|
int numRows = (rc.height / rowHeight) / 2 + 2;
|
|
|
|
//numRows=(numRows&(~1)) + 1;
|
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
|
|
|
const wxChar* bgColor = _T("#ffffff");
|
|
|
|
wxPen nullPen(bgColor);
|
|
|
|
wxPen currentPen(_T("#000000"));
|
|
|
|
wxPen selPen(_T("#808080")); // gray
|
|
|
|
nullPen.SetStyle(wxTRANSPARENT);
|
|
|
|
|
2009-01-04 20:09:13 -07:00
|
|
|
wxBrush currentBrush(_T("#FFEfE8")); // light gray
|
2008-12-07 22:30:24 -07:00
|
|
|
wxBrush pcBrush(_T("#70FF70")); // green
|
2009-09-27 15:28:09 -06:00
|
|
|
wxBrush mcBrush(_T("#1133FF")); // blue
|
2008-12-07 22:30:24 -07:00
|
|
|
wxBrush bgBrush(bgColor);
|
|
|
|
wxBrush nullBrush(bgColor);
|
|
|
|
nullBrush.SetStyle(wxTRANSPARENT);
|
|
|
|
|
|
|
|
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!!!!!
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = -numRows; i <= numRows; i++)
|
|
|
|
{
|
|
|
|
unsigned int address = curAddress + i * align;
|
|
|
|
|
|
|
|
int rowY1 = rc.height / 2 + rowHeight * i - rowHeight / 2;
|
|
|
|
int rowY2 = rc.height / 2 + rowHeight * i + rowHeight / 2;
|
|
|
|
|
|
|
|
wxString temp = wxString::Format(_T("%08x"), address);
|
|
|
|
u32 col = debugger->getColor(address);
|
|
|
|
wxBrush rowBrush(wxColor(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(i == 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(_T("#600000"));
|
|
|
|
dc.DrawText(temp, 17, rowY1);
|
2008-12-09 14:24:12 -07:00
|
|
|
char mem[256];
|
2009-06-17 13:50:59 -06:00
|
|
|
debugger->getRawMemoryString(memory, address, mem, 256);
|
2008-12-07 22:30:24 -07:00
|
|
|
dc.SetTextForeground(_T("#000080"));
|
|
|
|
dc.DrawText(wxString::FromAscii(mem), 17+fontSize*(8), rowY1);
|
|
|
|
dc.SetTextForeground(_T("#000000"));
|
|
|
|
|
|
|
|
if (debugger->isAlive())
|
|
|
|
{
|
|
|
|
char dis[256] = {0};
|
2009-09-08 15:16:05 -06:00
|
|
|
u32 mem_data = debugger->readExtraMemory(memory, address);
|
2009-10-12 10:20:31 -06:00
|
|
|
|
|
|
|
if (viewAsType == VIEWAS_FP)
|
|
|
|
{
|
|
|
|
float flt = *(float *)(&mem_data);
|
|
|
|
sprintf(dis, "f: %f", flt);
|
|
|
|
}
|
|
|
|
else if (viewAsType == VIEWAS_ASCII)
|
|
|
|
{
|
|
|
|
sprintf(dis, "%c%c%c%c",
|
|
|
|
(mem_data&0xff000000)>>24, (mem_data&0xff0000)>>16,
|
|
|
|
(mem_data&0xff00)>>8, mem_data&0xff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sprintf(dis, "INVALID VIEWAS TYPE");
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
char desc[256] = "";
|
|
|
|
|
2009-06-17 13:50:59 -06:00
|
|
|
dc.DrawText(wxString::FromAscii(dis), 77 + fontSize*(8 + 8), rowY1);
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
if (desc[0] == 0)
|
|
|
|
{
|
|
|
|
strcpy(desc, debugger->getDescription(address).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.SetTextForeground(_T("#0000FF"));
|
|
|
|
|
|
|
|
if (strlen(desc))
|
|
|
|
{
|
|
|
|
dc.DrawText(wxString::FromAscii(desc), 17+fontSize*(8+8+8+30), rowY1);
|
|
|
|
}
|
2009-09-27 15:28:09 -06:00
|
|
|
|
|
|
|
// Show blue memory check dot
|
|
|
|
if (Memory::AreMemoryBreakpointsActivated() && PowerPC::memchecks.GetMemCheck(address))
|
|
|
|
{
|
|
|
|
dc.SetBrush(mcBrush);
|
|
|
|
dc.DrawRectangle(2, rowY1 + 1, 11, 11);
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.SetPen(currentPen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|