1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 | #include <cinttypes>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include "codeview.hpp"
#include "udb_cpp.hpp"
using namespace finalcut;
CodeView::CodeView(finalcut::FWidget *parent)
: FDialog{ parent }
{
setResizeable();
scrolltext.ignorePadding();
scrolltext.setFocus();
FString instrStr;
char asmStr[40];
FTextView::FTextViewList::size_type line = 0;
for (uint64_t addr = 0; addr < ulm_brk; addr += 4, ++line) {
uint32_t instr;
ulm_fetch32(addr, &instr);
ulm_asm(instr, asmStr, sizeof(asmStr));
instrStr.sprintf(" 0x%016" PRIX64 ": %02X %02X %02X %02X # %s\n",
addr, int(instr >> 24 & 0xFF), int(instr >> 16 & 0xFF),
int(instr >> 8 & 0xFF), int(instr >> 0 & 0xFF),
asmStr);
scrolltext.append(instrStr);
auto &highlight = scrolltext.getLine(line).highlight;
highlight = { hideBP, normInstr };
if (udb_breakpoint.find(addr) != udb_breakpoint.end()) {
highlight[0] = showBP;
scrolltext.getLine(line).text.wc_str()[1] = 'B';
}
}
notify();
}
void
CodeView::notify()
{
update(true);
}
void
CodeView::update(bool scrollToIP)
{
static std::uint64_t prevInstrPtr, currInstrPtr;
scrolltext.getLine(prevInstrPtr).highlight[1] = normInstr;
scrolltext.getLine(currInstrPtr).highlight[1] = normInstr;
prevInstrPtr = udb_getPrevIP() / 4;
currInstrPtr = udb_getIP() / 4;
const auto &l = scrolltext.getLines();
if (currInstrPtr >= l.size()) {
return;
}
scrolltext.getLine(prevInstrPtr).highlight[1] = prevInstr;
scrolltext.getLine(currInstrPtr).highlight[1] = currInstr;
int offsetIP = currInstrPtr - scrolltext.getScrollPos().getY();
if (scrollToIP &&
(offsetIP < 0 ||
offsetIP > int(scrolltext.getTextVisibleSize().getHeight())))
{
scrolltext.scrollBy(0, offsetIP);
} else {
scrolltext.redraw();
}
}
void
CodeView::initLayout()
{
FDialog::setText("Program (Stage D: %IP points to next instruction)");
setMinimumSize(FSize{ 51, 6 });
auto x = 1 + int((getDesktopWidth() - 72));
auto y = 1;
auto window_size = FSize{ 72, getDesktopHeight() - y -1 };
FDialog::setGeometry(FPoint{ x, y }, window_size);
scrolltext.setGeometry(FPoint{ 1, 2 },
FSize{ getWidth(), getHeight() - 1 });
FDialog::initLayout();
}
void
CodeView::adjustSize()
{
finalcut::FDialog::adjustSize();
if (!isZoomed()) {
auto desktop_size = FSize{ getDesktopWidth(), getDesktopHeight() };
FRect screen(FPoint{ 1, 1 }, desktop_size);
bool center = false;
if (getWidth() > getDesktopWidth()) {
setWidth(getDesktopWidth() * 9 / 10);
center = true;
}
if (getHeight() > getDesktopHeight()) {
setHeight(getDesktopHeight() * 7 / 8);
center = true;
}
// Centering the window when it is no longer
// in the visible area of the terminal
if (!screen.contains(getPos()) || center) {
int x = 1 + int((getDesktopWidth() - getWidth()) / 2);
int y = 1 + int((getDesktopHeight() - getHeight()) / 2);
setPos(FPoint{ x, y });
}
}
scrolltext.setGeometry(FPoint{ 1, 2 }, FSize(getWidth(), getHeight() - 1));
}
void
CodeView::onAccel(finalcut::FAccelEvent *ev)
{
close();
ev->accept();
}
CodeView::TextView::TextView(CodeView *codeView)
: FTextView{ codeView }
, codeView{ codeView }
{
}
void
CodeView::TextView::onMouseDown(FMouseEvent *ev)
{
FTextView::onMouseDown(ev);
if (ev->getButton() == MouseButton::Left && ev->getX() < int(getWidth())) {
std::size_t line =
codeView->scrolltext.getScrollPos().getY() + ev->getY() - 2;
const auto &l = codeView->scrolltext.getLines();
if (line >= l.size()) {
return;
}
std::uint64_t addr = line * 4;
if (udb_breakpoint.find(addr) != udb_breakpoint.end()) {
udb_breakpoint.erase(addr);
codeView->scrolltext.addHighlight(line, codeView->hideBP);
codeView->scrolltext.getLine(line).text.wc_str()[1] = ' ';
} else {
udb_breakpoint[addr] = addr;
codeView->scrolltext.addHighlight(line, codeView->showBP);
codeView->scrolltext.getLine(line).text.wc_str()[1] = 'B';
}
codeView->update(false);
}
}
|