Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/ImDebugger/ImMemView.h
3186 views
1
#pragma once
2
3
4
#include <cstdint>
5
#include <vector>
6
#include "ext/imgui/imgui.h"
7
8
#include "Core/Debugger/DebugInterface.h"
9
#include "Core/Debugger/MemBlockInfo.h"
10
11
enum OffsetSpacing {
12
offsetSpace = 3, // the number of blank lines that should be left to make space for the offsets
13
offsetLine = 1, // the line on which the offsets should be written
14
};
15
16
enum CommonToggles {
17
On,
18
Off,
19
};
20
21
enum MemorySearchStatus {SEARCH_PSP_NOT_INIT=-1, SEARCH_INITIAL, SEARCH_OK, SEARCH_NOTFOUND, SEARCH_CANCEL};
22
enum MemorySearchType {BITS_8, BITS_16, BITS_32, BITS_64, FLOAT_32, STRING, STRING_16, BYTE_SEQ};
23
class ImMemView {
24
public:
25
ImMemView();
26
~ImMemView();
27
28
void setDebugger(MIPSDebugInterface *deb) {
29
debugger_ = deb;
30
}
31
MIPSDebugInterface *getDebugger() {
32
return debugger_;
33
}
34
void Draw(ImDrawList *drawList);
35
// void onVScroll(WPARAM wParam, LPARAM lParam);
36
// void onKeyDown(WPARAM wParam, LPARAM lParam);
37
void onChar(int c);
38
void onMouseDown(float x, float y, int button);
39
void onMouseUp(float x, float y, int button);
40
void onMouseMove(float x, float y, int button);
41
void gotoAddr(unsigned int addr);
42
43
void drawOffsetScale(ImDrawList *drawList);
44
void toggleOffsetScale(CommonToggles toggle);
45
void setHighlightType(MemBlockFlags flags);
46
47
void toggleEditableMemory(bool toggle);
48
void toggleDrawZeroDark(bool toggle);
49
void initSearch(const char* str, MemorySearchType type);
50
void continueSearch();
51
MemorySearchStatus SearchStatus();
52
bool SearchEmpty();
53
uint32_t SearchMatchAddress();
54
55
const std::string &StatusMessage() const {
56
return statusMessage_;
57
}
58
59
private:
60
void ProcessKeyboardShortcuts(bool focused);
61
62
bool ParseSearchString(const char* query, MemorySearchType mode);
63
void updateStatusBarText();
64
MemorySearchStatus search(bool continueSearch);
65
66
enum class GotoMode {
67
RESET,
68
RESET_IF_OUTSIDE,
69
FROM_CUR,
70
EXTEND,
71
};
72
73
static GotoMode GotoModeFromModifiers(bool isRightClick);
74
void UpdateSelectRange(uint32_t target, GotoMode mode);
75
void GotoPoint(int x, int y, GotoMode mode);
76
void ScrollWindow(int lines, GotoMode mdoe);
77
void ScrollCursor(int bytes, GotoMode mdoe);
78
void PopupMenu();
79
80
void EditMemory(int i);
81
struct MemorySearch{
82
// keep search related variables grouped
83
std::vector<u8> data;
84
uint8_t* fast_data;
85
size_t fast_size;
86
u32 searchAddress;
87
u32 matchAddress;
88
u32 segmentStart;
89
u32 segmentEnd;
90
bool searching;
91
MemorySearchStatus status;
92
} memSearch_;
93
94
std::vector<u8> byteClipboard_;
95
void CopyToByteClipboard();
96
void PasteFromByteClipboard();
97
98
static wchar_t szClassName[];
99
MIPSDebugInterface *debugger_ = nullptr;
100
101
MemBlockFlags highlightFlags_ = MemBlockFlags::ALLOC;
102
103
// Current cursor position.
104
uint32_t curAddress_ = 0x08800000;
105
// Selected range, which should always be around the cursor.
106
uint32_t selectRangeStart_ = 0;
107
uint32_t selectRangeEnd_ = 0;
108
// Last select reset position, for selecting ranges.
109
uint32_t lastSelectReset_ = 0;
110
// Address of the first displayed byte.
111
uint32_t windowStart_ = 0x08800000;
112
// Number of bytes displayed per row.
113
int rowSize_ = 16;
114
115
// Width of one monospace character (to maintain grid.)
116
int charWidth_ = 0;
117
// Height of one monospace character (to maintain grid.)
118
int charHeight_ = 0;
119
// Height of one row of bytes.
120
int rowHeight_ = 0;
121
// Y position of offset header (at top.)
122
int offsetPositionY_ = 0;
123
// X position of addresses (at left.)
124
int addressStartX_ = 0;
125
// X position of hex display.
126
int hexStartX_ = 0;
127
// X position of text display.
128
int asciiStartX_ = 0;
129
// Whether cursor is within text display or hex display.
130
bool asciiSelected_ = false;
131
// Which nibble is selected, if in hex display. 0 means leftmost, i.e. most significant.
132
int selectedNibble_ = 0;
133
134
bool displayOffsetScale_ = false;
135
136
// Number of rows visible as of last redraw.
137
int visibleRows_ = 0;
138
139
bool drawZeroDark_ = false;
140
bool editableMemory_ = false;
141
142
std::string statusMessage_;
143
};
144
145
enum class MemDumpMode {
146
Raw = 0,
147
Disassembly = 1,
148
};
149
150
class ImMemDumpWindow {
151
public:
152
ImMemDumpWindow() {
153
filename_[0] = 0;
154
address_ = 0x08800000;
155
size_ = 0x01800000;
156
}
157
static const char *Title() {
158
return "Memory Dumper";
159
}
160
void Draw(ImConfig &cfg, MIPSDebugInterface *debug);
161
void SetRange(uint32_t addr, uint32_t size, MemDumpMode mode) {
162
address_ = addr;
163
size_ = size;
164
mode_ = mode;
165
}
166
167
private:
168
uint32_t address_;
169
uint32_t size_;
170
MemDumpMode mode_ = MemDumpMode::Raw;
171
char filename_[1024];
172
std::string errorMsg_;
173
};
174
175
// Corresponds to the CMemView dialog
176
class ImMemWindow {
177
public:
178
void Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImControl &control, int index);
179
ImMemView &View() {
180
return memView_;
181
}
182
void DirtySymbolMap() {
183
symsDirty_ = true;
184
}
185
void GotoAddr(u32 addr) {
186
gotoAddr_ = addr;
187
memView_.gotoAddr(addr);
188
}
189
static const char *Title(int index);
190
191
private:
192
// We just keep the state directly in the window. Can refactor later.
193
enum {
194
INVALID_ADDR = 0xFFFFFFFF,
195
};
196
void ProcessKeyboardShortcuts();
197
// Symbol cache
198
std::vector<SymbolEntry> symCache_;
199
bool symsDirty_ = true;
200
int selectedSymbol_ = -1;
201
char selectedSymbolName_[128];
202
203
bool drawZeroDark_ = false;
204
bool editableMemory_ = false;
205
206
int searchFormFlags_=0;
207
bool focusSearchValueInput_ = false;
208
MemorySearchType selectedSearchType_ = BITS_8;
209
char searchStr_[512];
210
// store the state of the search form
211
ImMemView memView_;
212
char searchTerm_[64]{};
213
214
u32 gotoAddr_ = 0x08800000;
215
};
216
217