ppsspp/Windows/Debugger/CtrlDisAsmView.h

176 lines
4.7 KiB
C
Raw Normal View History

2012-11-01 15:19:01 +00:00
// NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
#pragma once
//////////////////////////////////////////////////////////////////////////
//CtrlDisAsmView
// CtrlDisAsmView.cpp
//////////////////////////////////////////////////////////////////////////
//This Win32 control is made to be flexible and usable with
//every kind of CPU architechture that has fixed width instruction words.
//Just supply it an instance of a class derived from Debugger, with all methods
//overridden for full functionality. Look at the ppc one for an example.
//
//To add to a dialog box, just draw a User Control in the dialog editor,
//and set classname to "CtrlDisAsmView". you also need to call CtrlDisAsmView::init()
//before opening this dialog, to register the window class.
//
//To get a class instance to be able to access it, just use
// CtrlDisAsmView::getFrom(GetDlgItem(yourdialog, IDC_yourid)).
#include "../../Core/Debugger/DebugInterface.h"
#include "../../Core/Debugger/DisassemblyManager.h"
2012-11-01 15:19:01 +00:00
#include "Common/CommonWindows.h"
#include <vector>
#include <algorithm>
using std::min;
using std::max;
2012-11-01 15:19:01 +00:00
class CtrlDisAsmView
{
HWND wnd;
HFONT font;
HFONT boldfont;
RECT rect;
DisassemblyManager manager;
2013-06-29 17:59:42 +00:00
u32 curAddress;
u32 selectRangeStart;
u32 selectRangeEnd;
2012-11-01 15:19:01 +00:00
int rowHeight;
int charWidth;
2012-11-01 15:19:01 +00:00
bool hasFocus;
bool showHex;
DebugInterface *debugger;
static TCHAR szClassName[];
2013-06-29 17:59:42 +00:00
u32 windowStart;
int visibleRows;
bool whiteBackground;
bool displaySymbols;
struct {
int addressStart;
int opcodeStart;
int argumentsStart;
int arrowsStart;
} pixelPositions;
std::vector<u32> jumpStack;
std::string searchQuery;
int matchAddress;
bool searching;
bool dontRedraw;
2013-08-17 19:20:24 +00:00
bool keyTaken;
void assembleOpcode(u32 address, std::string defaultText);
2013-11-16 11:21:05 +00:00
std::string disassembleRange(u32 start, u32 size);
void disassembleToFile();
void search(bool continueSearch);
void followBranch();
void calculatePixelPositions();
2013-11-27 23:33:21 +00:00
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);
2013-07-30 14:19:05 +00:00
void updateStatusBarText();
2013-11-24 13:46:53 +00:00
void drawBranchLine(HDC hdc, std::map<u32,int>& addressPositions, BranchLine& line);
void copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm);
std::set<std::string> getSelectedLineArguments();
void drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> &currentArguments);
2012-11-01 15:19:01 +00:00
public:
CtrlDisAsmView(HWND _wnd);
~CtrlDisAsmView();
static void init();
static void deinit();
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static CtrlDisAsmView * getFrom(HWND wnd);
2013-08-17 19:20:24 +00:00
void onChar(WPARAM wParam, LPARAM lParam);
2012-11-01 15:19:01 +00:00
void onPaint(WPARAM wParam, LPARAM lParam);
void onVScroll(WPARAM wParam, LPARAM lParam);
void onKeyDown(WPARAM wParam, LPARAM lParam);
void onKeyUp(WPARAM wParam, LPARAM lParam);
2012-11-01 15:19:01 +00:00
void onMouseDown(WPARAM wParam, LPARAM lParam, int button);
void onMouseUp(WPARAM wParam, LPARAM lParam, int button);
void onMouseMove(WPARAM wParam, LPARAM lParam, int button);
void scrollAddressIntoView();
bool curAddressIsVisible();
2012-11-01 15:19:01 +00:00
void redraw();
2013-09-22 09:00:44 +00:00
void scanFunctions();
void clearFunctions() { manager.clear(); };
void getOpcodeText(u32 address, char* dest, int bufsize);
2013-10-18 22:58:42 +00:00
int getRowHeight() { return rowHeight; };
u32 yToAddress(int y);
2012-11-01 15:19:01 +00:00
void setDontRedraw(bool b) { dontRedraw = b; };
2012-11-01 15:19:01 +00:00
void setDebugger(DebugInterface *deb)
{
debugger=deb;
curAddress=debugger->getPC();
manager.setCpu(deb);
2012-11-01 15:19:01 +00:00
}
DebugInterface *getDebugger()
{
return debugger;
}
2013-11-25 18:51:16 +00:00
void scrollStepping(u32 newPc);
u32 getInstructionSizeAt(u32 address);
2012-11-01 15:19:01 +00:00
void gotoAddr(unsigned int addr)
{
2013-11-26 10:38:01 +00:00
u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
u32 newAddress = manager.getStartAddress(addr);
if (newAddress < windowStart || newAddress >= windowEnd)
{
2013-11-26 10:38:01 +00:00
windowStart = manager.getNthPreviousAddress(newAddress,visibleRows/2);
}
setCurAddress(newAddress);
2013-09-22 11:00:25 +00:00
scanFunctions();
2012-11-01 15:19:01 +00:00
redraw();
}
void gotoPC()
{
2013-11-26 10:38:01 +00:00
gotoAddr(debugger->getPC());
2012-11-01 15:19:01 +00:00
}
2013-06-29 17:59:42 +00:00
u32 getSelection()
2012-11-01 15:19:01 +00:00
{
return curAddress;
}
void setShowMode(bool s)
{
showHex=s;
}
void toggleBreakpoint(bool toggleEnabled = false);
void editBreakpoint();
void scrollWindow(int lines)
{
if (lines < 0)
windowStart = manager.getNthPreviousAddress(windowStart,abs(lines));
else
windowStart = manager.getNthNextAddress(windowStart,lines);
2013-09-22 09:00:44 +00:00
scanFunctions();
redraw();
}
void setCurAddress(u32 newAddress, bool extend = false)
{
newAddress = manager.getStartAddress(newAddress);
u32 after = manager.getNthNextAddress(newAddress,1);
curAddress = newAddress;
selectRangeStart = extend ? std::min(selectRangeStart, newAddress) : newAddress;
selectRangeEnd = extend ? std::max(selectRangeEnd, after) : after;
2013-07-30 14:19:05 +00:00
updateStatusBarText();
}
2012-11-01 15:19:01 +00:00
};