CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/Debugger/CtrlDisAsmView.h
Views: 1401
1
#pragma once
2
3
// CtrlDisAsmView
4
//
5
// This Win32 control is made to be flexible and usable with
6
// every kind of CPU architecture that has fixed width instruction words.
7
// Just supply it an instance of a class derived from Debugger, with all methods
8
// overridden for full functionality. Look at the ppc one for an example.
9
//
10
// To add to a dialog box, just draw a User Control in the dialog editor,
11
// and set classname to "CtrlDisAsmView". you also need to call CtrlDisAsmView::init()
12
// before opening this dialog, to register the window class.
13
//
14
// To get a class instance to be able to access it, just use
15
// CtrlDisAsmView::getFrom(GetDlgItem(yourdialog, IDC_yourid)).
16
17
#include <vector>
18
#include <algorithm>
19
20
#include "Common/CommonWindows.h"
21
#include "Common/Log.h"
22
#include "Core/Debugger/DebugInterface.h"
23
#include "Core/Debugger/DisassemblyManager.h"
24
25
class CtrlDisAsmView
26
{
27
HWND wnd;
28
HFONT font;
29
HFONT boldfont;
30
RECT rect;
31
32
DisassemblyManager manager;
33
u32 curAddress;
34
u32 selectRangeStart;
35
u32 selectRangeEnd;
36
int rowHeight;
37
int charWidth;
38
39
bool hasFocus;
40
bool showHex;
41
DebugInterface *debugger;
42
static TCHAR szClassName[];
43
44
u32 windowStart;
45
int visibleRows;
46
bool whiteBackground;
47
bool displaySymbols;
48
49
struct {
50
int addressStart;
51
int opcodeStart;
52
int argumentsStart;
53
int arrowsStart;
54
} pixelPositions;
55
56
std::vector<u32> jumpStack;
57
58
std::string searchQuery;
59
int matchAddress;
60
bool searching;
61
bool dontRedraw;
62
bool keyTaken;
63
64
enum class CopyInstructionsMode {
65
OPCODES,
66
DISASM,
67
ADDRESSES,
68
};
69
70
void assembleOpcode(u32 address, const std::string &defaultText);
71
std::string disassembleRange(u32 start, u32 size);
72
void disassembleToFile();
73
void search(bool continueSearch);
74
void followBranch();
75
void calculatePixelPositions();
76
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);
77
void updateStatusBarText();
78
void drawBranchLine(HDC hdc, std::map<u32, int> &addressPositions, const BranchLine &line);
79
void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode);
80
void NopInstructions(u32 startAddr, u32 endAddr);
81
std::set<std::string> getSelectedLineArguments();
82
void drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> &currentArguments);
83
84
public:
85
CtrlDisAsmView(HWND _wnd);
86
~CtrlDisAsmView();
87
static void init();
88
static void deinit();
89
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
90
static CtrlDisAsmView * getFrom(HWND wnd);
91
92
void onChar(WPARAM wParam, LPARAM lParam);
93
void onPaint(WPARAM wParam, LPARAM lParam);
94
void onVScroll(WPARAM wParam, LPARAM lParam);
95
void onKeyDown(WPARAM wParam, LPARAM lParam);
96
void onKeyUp(WPARAM wParam, LPARAM lParam);
97
void onMouseDown(WPARAM wParam, LPARAM lParam, int button);
98
void onMouseUp(WPARAM wParam, LPARAM lParam, int button);
99
void onMouseMove(WPARAM wParam, LPARAM lParam, int button);
100
void scrollAddressIntoView();
101
bool curAddressIsVisible();
102
void redraw();
103
void scanFunctions();
104
void clearFunctions() { manager.clear(); };
105
106
void getOpcodeText(u32 address, char* dest, int bufsize);
107
int getRowHeight() { return rowHeight; };
108
u32 yToAddress(int y);
109
110
void setDontRedraw(bool b) { dontRedraw = b; };
111
void setDebugger(DebugInterface *deb)
112
{
113
debugger=deb;
114
curAddress=debugger->getPC();
115
manager.setCpu(deb);
116
}
117
DebugInterface *getDebugger()
118
{
119
return debugger;
120
}
121
122
void scrollStepping(u32 newPc);
123
u32 getInstructionSizeAt(u32 address);
124
125
void gotoAddr(unsigned int addr)
126
{
127
if (positionLocked_ != 0)
128
return;
129
u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
130
u32 newAddress = manager.getStartAddress(addr);
131
132
if (newAddress < windowStart || newAddress >= windowEnd)
133
{
134
windowStart = manager.getNthPreviousAddress(newAddress,visibleRows/2);
135
}
136
137
setCurAddress(newAddress);
138
scanFunctions();
139
redraw();
140
}
141
void gotoPC()
142
{
143
gotoAddr(debugger->getPC());
144
}
145
u32 getSelection()
146
{
147
return curAddress;
148
}
149
150
void setShowMode(bool s)
151
{
152
showHex=s;
153
}
154
155
void toggleBreakpoint(bool toggleEnabled = false);
156
void editBreakpoint();
157
158
void scrollWindow(int lines)
159
{
160
if (lines < 0)
161
windowStart = manager.getNthPreviousAddress(windowStart,abs(lines));
162
else
163
windowStart = manager.getNthNextAddress(windowStart,lines);
164
165
scanFunctions();
166
redraw();
167
}
168
169
void setCurAddress(u32 newAddress, bool extend = false)
170
{
171
newAddress = manager.getStartAddress(newAddress);
172
u32 after = manager.getNthNextAddress(newAddress,1);
173
curAddress = newAddress;
174
selectRangeStart = extend ? std::min(selectRangeStart, newAddress) : newAddress;
175
selectRangeEnd = extend ? std::max(selectRangeEnd, after) : after;
176
updateStatusBarText();
177
}
178
179
void LockPosition() {
180
positionLocked_++;
181
}
182
void UnlockPosition() {
183
positionLocked_--;
184
_assert_(positionLocked_ >= 0);
185
}
186
187
private:
188
bool redrawScheduled_ = false;
189
int positionLocked_ = 0;
190
};
191
192