Highlight arguments from the selected range.

For example, if "lui v0,0x8000" is selected, highlight "v0" or "0x8000"
used as arguments on other lines.  Makes it a bit easier to follow.
This commit is contained in:
Unknown W. Brackets 2014-03-02 16:48:21 -08:00
parent 374e12afc3
commit f70f70925d
2 changed files with 69 additions and 4 deletions

View File

@ -406,6 +406,68 @@ void CtrlDisAsmView::drawBranchLine(HDC hdc, std::map<u32,int>& addressPositions
DeleteObject(pen);
}
std::set<std::string> CtrlDisAsmView::getSelectedLineArguments() {
std::set<std::string> args;
DisassemblyLineInfo line;
for (u32 addr = selectRangeStart; addr < selectRangeEnd; addr += 4) {
manager.getLine(addr, displaySymbols, line);
size_t p = 0, nextp = line.params.find(',');
while (nextp != line.params.npos) {
args.insert(line.params.substr(p, nextp - p));
p = nextp + 1;
nextp = line.params.find(',', p);
}
if (p < line.params.size()) {
args.insert(line.params.substr(p));
}
}
return args;
}
void CtrlDisAsmView::drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> &currentArguments) {
if (line.params.empty()) {
return;
}
// Don't highlight the selected lines.
if (isInInterval(selectRangeStart, selectRangeEnd - selectRangeStart, line.info.opcodeAddress)) {
TextOutA(hdc, x, y, line.params.c_str(), (int)line.params.size());
return;
}
int highlightedColor = 0xaabb00;
if (textColor == 0x0000ff) {
highlightedColor = 0xaabb77;
}
UINT prevAlign = SetTextAlign(hdc, TA_UPDATECP);
MoveToEx(hdc, x, y, NULL);
size_t p = 0, nextp = line.params.find(',');
while (nextp != line.params.npos) {
const std::string arg = line.params.substr(p, nextp - p);
if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xffffff) {
SetTextColor(hdc, highlightedColor);
}
TextOutA(hdc, 0, 0, arg.c_str(), (int)arg.size());
SetTextColor(hdc,textColor);
p = nextp + 1;
nextp = line.params.find(',', p);
TextOutA(hdc, 0, 0, ",", 1);
}
if (p < line.params.size()) {
const std::string arg = line.params.substr(p);
if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xffffff) {
SetTextColor(hdc, highlightedColor);
}
TextOutA(hdc, 0, 0, arg.c_str(), (int)arg.size());
SetTextColor(hdc,textColor);
}
SetTextAlign(hdc, prevAlign);
}
void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
{
if (!debugger->isAlive()) return;
@ -420,7 +482,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
HPEN nullPen=CreatePen(0,0,0xffffff);
HBRUSH nullBrush=CreateSolidBrush(0xffffff);
HBRUSH currentBrush=CreateSolidBrush(0xFFEfE8);
HBRUSH currentBrush=CreateSolidBrush(0xffefe8);
HPEN oldPen=(HPEN)SelectObject(hdc,nullPen);
HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush);
@ -431,6 +493,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
unsigned int address = windowStart;
std::map<u32,int> addressPositions;
const std::set<std::string> currentArguments = getSelectedLineArguments();
DisassemblyLineInfo line;
for (int i = 0; i < visibleRows; i++)
{
@ -466,7 +529,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
SelectObject(hdc,backgroundBrush);
SelectObject(hdc,backgroundPen);
Rectangle(hdc,0,rowY1,rect.right,rowY1+rowHeight);
SelectObject(hdc,currentBrush);
SelectObject(hdc,nullPen);
@ -499,8 +562,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
line.params += line.info.conditionMet ? " ; true" : " ; false";
}
if (line.params.size() != 0)
TextOutA(hdc,pixelPositions.argumentsStart,rowY1+2,line.params.c_str(),(int)line.params.size());
drawArguments(hdc, line, pixelPositions.argumentsStart, rowY1 + 2, textColor, currentArguments);
SelectObject(hdc,boldfont);
TextOutA(hdc,pixelPositions.opcodeStart,rowY1+2,line.name.c_str(),(int)line.name.size());

View File

@ -78,6 +78,9 @@ class CtrlDisAsmView
void updateStatusBarText();
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);
public:
CtrlDisAsmView(HWND _wnd);
~CtrlDisAsmView();