1
0
Fork 0

mnemonic help in trace and graph, bookmark in graph

This commit is contained in:
torusrxxx 2020-08-19 23:56:39 +08:00 committed by Duncan Ogilvie
parent 392d46bf8c
commit 1f0577ff68
7 changed files with 140 additions and 6 deletions

View File

@ -267,6 +267,11 @@ CPUDisassembly* CPUWidget::getDisasmWidget()
return mDisas; return mDisas;
} }
DisassemblerGraphView* CPUWidget::getGraphWidget()
{
return mGraph;
}
CPUMultiDump* CPUWidget::getDumpWidget() CPUMultiDump* CPUWidget::getDumpWidget()
{ {
return mDump; return mDump;

View File

@ -41,6 +41,7 @@ public:
// Widget getters // Widget getters
CPUSideBar* getSidebarWidget(); CPUSideBar* getSidebarWidget();
CPUDisassembly* getDisasmWidget(); CPUDisassembly* getDisasmWidget();
DisassemblerGraphView* getGraphWidget();
CPUMultiDump* getDumpWidget(); CPUMultiDump* getDumpWidget();
CPUStack* getStackWidget(); CPUStack* getStackWidget();
CPUInfoBox* getInfoBoxWidget(); CPUInfoBox* getInfoBoxWidget();

View File

@ -414,6 +414,7 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
QRectF bpRect(x - rectSize / 3.0, y + (this->charHeight - rectSize) / 2.0, rectSize, rectSize); QRectF bpRect(x - rectSize / 3.0, y + (this->charHeight - rectSize) / 2.0, rectSize, rectSize);
bool isbp = DbgGetBpxTypeAt(instr.addr) != bp_none; bool isbp = DbgGetBpxTypeAt(instr.addr) != bp_none;
bool isbookmark = DbgGetBookmarkAt(instr.addr);
bool isbpdisabled = DbgIsBpDisabled(instr.addr); bool isbpdisabled = DbgIsBpDisabled(instr.addr);
bool iscip = instr.addr == mCip; bool iscip = instr.addr == mCip;
@ -431,6 +432,20 @@ void DisassemblerGraphView::paintNormal(QPainter & p, QRect & viewportRect, int
p.fillRect(bpRect, isbp ? mBreakpointColor : mDisabledBreakpointColor); p.fillRect(bpRect, isbp ? mBreakpointColor : mDisabledBreakpointColor);
} }
else if(isbookmark)
{
if(iscip)
{
// Left half is cip
bpRect.setWidth(bpRect.width() / 2);
p.fillRect(bpRect, mCipColor);
// Right half is breakpoint
bpRect.translate(bpRect.width(), 0);
}
p.fillRect(bpRect, mBookmarkBackgroundColor);
}
else if(iscip) else if(iscip)
p.fillRect(bpRect, mCipColor); p.fillRect(bpRect, mCipColor);
@ -2183,6 +2198,7 @@ void DisassemblerGraphView::setupContextMenu()
mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), zoomActionHelperNonZero); mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), zoomActionHelperNonZero);
mMenuBuilder->addAction(makeShortcutAction(DIcon("label.png"), tr("&Label"), SLOT(setLabelSlot()), "ActionSetLabel"), zoomActionHelperNonZero); mMenuBuilder->addAction(makeShortcutAction(DIcon("label.png"), tr("&Label"), SLOT(setLabelSlot()), "ActionSetLabel"), zoomActionHelperNonZero);
mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(setBookmarkSlot()), "ActionToggleBookmark"));
mMenuBuilder->addAction(makeShortcutAction(DIcon("xrefs.png"), tr("Xrefs..."), SLOT(xrefSlot()), "ActionXrefs"), zoomActionHelperNonZero); mMenuBuilder->addAction(makeShortcutAction(DIcon("xrefs.png"), tr("Xrefs..."), SLOT(xrefSlot()), "ActionXrefs"), zoomActionHelperNonZero);
MenuBuilder* gotoMenu = new MenuBuilder(this); MenuBuilder* gotoMenu = new MenuBuilder(this);
@ -2268,7 +2284,8 @@ void DisassemblerGraphView::setupContextMenu()
gotoMenu->addSeparator(); gotoMenu->addSeparator();
gotoMenu->addBuilder(childrenAndParentMenu); gotoMenu->addBuilder(childrenAndParentMenu);
mMenuBuilder->addMenu(makeMenu(DIcon("goto.png"), tr("Go to")), gotoMenu); mMenuBuilder->addMenu(makeMenu(DIcon("goto.png"), tr("Go to")), gotoMenu);
mMenuBuilder->addAction(makeShortcutAction(DIcon("helpmnemonic.png"), tr("Help on mnemonic"), SLOT(mnemonicHelpSlot()), "ActionHelpOnMnemonic"));
mMenuBuilder->addSeparator();
auto ifgraphZoomMode = [this](QMenu*) auto ifgraphZoomMode = [this](QMenu*)
{ {
return graphZoomMode; return graphZoomMode;
@ -2276,8 +2293,6 @@ void DisassemblerGraphView::setupContextMenu()
mMenuBuilder->addAction(mZoomToCursor = makeShortcutAction(DIcon("zoom.png"), tr("&Zoom 100%"), SLOT(zoomToCursorSlot()), "ActionGraphZoomToCursor"), ifgraphZoomMode); mMenuBuilder->addAction(mZoomToCursor = makeShortcutAction(DIcon("zoom.png"), tr("&Zoom 100%"), SLOT(zoomToCursorSlot()), "ActionGraphZoomToCursor"), ifgraphZoomMode);
mMenuBuilder->addAction(mFitToWindow = makeShortcutAction(DIcon("fit.png"), tr("&Fit to window"), SLOT(fitToWindowSlot()), "ActionGraphFitToWindow"), ifgraphZoomMode); mMenuBuilder->addAction(mFitToWindow = makeShortcutAction(DIcon("fit.png"), tr("&Fit to window"), SLOT(fitToWindowSlot()), "ActionGraphFitToWindow"), ifgraphZoomMode);
mMenuBuilder->addSeparator();
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("graph.png"), tr("&Overview"), SLOT(toggleOverviewSlot()), "ActionGraphToggleOverview"), ifgraphZoomMode); mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("graph.png"), tr("&Overview"), SLOT(toggleOverviewSlot()), "ActionGraphToggleOverview"), ifgraphZoomMode);
mToggleOverview->setCheckable(true); mToggleOverview->setCheckable(true);
mMenuBuilder->addAction(mToggleSummary = makeShortcutAction(DIcon("summary.png"), tr("S&ummary"), SLOT(toggleSummarySlot()), "ActionGraphToggleSummary")); mMenuBuilder->addAction(mToggleSummary = makeShortcutAction(DIcon("summary.png"), tr("S&ummary"), SLOT(toggleSummarySlot()), "ActionGraphToggleSummary"));
@ -2383,6 +2398,7 @@ void DisassemblerGraphView::colorsUpdatedSlot()
mCipColor = ConfigColor("GraphCipColor"); mCipColor = ConfigColor("GraphCipColor");
mBreakpointColor = ConfigColor("GraphBreakpointColor"); mBreakpointColor = ConfigColor("GraphBreakpointColor");
mDisabledBreakpointColor = ConfigColor("GraphDisabledBreakpointColor"); mDisabledBreakpointColor = ConfigColor("GraphDisabledBreakpointColor");
mBookmarkBackgroundColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
fontChanged(); fontChanged();
loadCurrentGraph(); loadCurrentGraph();
@ -2565,6 +2581,28 @@ restart:
this->refreshSlot(); this->refreshSlot();
} }
void DisassemblerGraphView::setBookmarkSlot()
{
if(!DbgIsDebugging())
return;
duint wVA = this->get_cursor_pos();
bool result;
if(DbgGetBookmarkAt(wVA))
result = DbgSetBookmarkAt(wVA, false);
else
result = DbgSetBookmarkAt(wVA, true);
if(!result)
{
QMessageBox msg(QMessageBox::Critical, tr("Error!"), tr("DbgSetBookmarkAt failed!"));
msg.setWindowIcon(DIcon("compile-error.png"));
msg.setParent(this, Qt::Dialog);
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
msg.exec();
}
GuiUpdateAllViews();
}
void DisassemblerGraphView::xrefSlot() void DisassemblerGraphView::xrefSlot()
{ {
if(!DbgIsDebugging()) if(!DbgIsDebugging())
@ -2596,6 +2634,17 @@ void DisassemblerGraphView::followActionSlot()
} }
} }
void DisassemblerGraphView::mnemonicHelpSlot()
{
unsigned char data[16] = { 0xCC };
auto addr = this->get_cursor_pos();
DbgMemRead(addr, data, sizeof(data));
Zydis zydis;
zydis.Disassemble(addr, data);
DbgCmdExecDirect(QString("mnemonichelp %1").arg(zydis.Mnemonic().c_str()).toUtf8().constData());
emit displayLogWidget();
}
void DisassemblerGraphView::fitToWindowSlot() void DisassemblerGraphView::fitToWindowSlot()
{ {
auto areaSize = viewport()->size(); auto areaSize = viewport()->size();

View File

@ -260,6 +260,7 @@ public:
signals: signals:
void selectionChanged(dsint parVA); void selectionChanged(dsint parVA);
void displayLogWidget();
void detachGraph(); void detachGraph();
public slots: public slots:
@ -286,7 +287,9 @@ public slots:
void saveImageSlot(); void saveImageSlot();
void setCommentSlot(); void setCommentSlot();
void setLabelSlot(); void setLabelSlot();
void setBookmarkSlot();
void xrefSlot(); void xrefSlot();
void mnemonicHelpSlot();
void fitToWindowSlot(); void fitToWindowSlot();
void zoomToCursorSlot(); void zoomToCursorSlot();
void getCurrentGraphSlot(BridgeCFGraphList* graphList); void getCurrentGraphSlot(BridgeCFGraphList* graphList);
@ -371,6 +374,7 @@ private:
QColor mCipColor; QColor mCipColor;
QColor mBreakpointColor; QColor mBreakpointColor;
QColor mDisabledBreakpointColor; QColor mDisabledBreakpointColor;
QColor mBookmarkBackgroundColor;
QColor graphNodeColor; QColor graphNodeColor;
QColor graphNodeBackgroundColor; QColor graphNodeBackgroundColor;
QColor graphCurrentShadowColor; QColor graphCurrentShadowColor;

View File

@ -207,6 +207,7 @@ MainWindow::MainWindow(QWidget* parent)
mTraceWidget->setWindowTitle(tr("Trace")); mTraceWidget->setWindowTitle(tr("Trace"));
mTraceWidget->setWindowIcon(DIcon("trace.png")); mTraceWidget->setWindowIcon(DIcon("trace.png"));
connect(mTraceWidget->getTraceBrowser(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget())); connect(mTraceWidget->getTraceBrowser(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));
connect(mTraceWidget->getTraceBrowser(), SIGNAL(displayLogWidget()), this, SLOT(displayLogWidget()));
mTabWidget = new MHTabWidget(this, true, true); mTabWidget = new MHTabWidget(this, true, true);
@ -336,7 +337,7 @@ MainWindow::MainWindow(QWidget* parent)
connect(mCpuWidget->getDisasmWidget(), SIGNAL(displayGraphWidget()), this, SLOT(displayGraphWidget())); connect(mCpuWidget->getDisasmWidget(), SIGNAL(displayGraphWidget()), this, SLOT(displayGraphWidget()));
connect(mCpuWidget->getDisasmWidget(), SIGNAL(displaySymbolsWidget()), this, SLOT(displaySymbolWidget())); connect(mCpuWidget->getDisasmWidget(), SIGNAL(displaySymbolsWidget()), this, SLOT(displaySymbolWidget()));
connect(mCpuWidget->getDisasmWidget(), SIGNAL(showPatches()), this, SLOT(patchWindow())); connect(mCpuWidget->getDisasmWidget(), SIGNAL(showPatches()), this, SLOT(patchWindow()));
connect(mCpuWidget->getGraphWidget(), SIGNAL(displayLogWidget()), this, SLOT(displayLogWidget()));
connect(mCpuWidget->getDumpWidget(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget())); connect(mCpuWidget->getDumpWidget(), SIGNAL(displayReferencesWidget()), this, SLOT(displayReferencesWidget()));

View File

@ -38,6 +38,7 @@ TraceBrowser::TraceBrowser(QWidget* parent) : AbstractTableView(parent)
mHighlightingMode = false; mHighlightingMode = false;
mPermanentHighlightingMode = false; mPermanentHighlightingMode = false;
mShowMnemonicBrief = false;
mMRUList = new MRUList(this, "Recent Trace Files"); mMRUList = new MRUList(this, "Recent Trace Files");
connect(mMRUList, SIGNAL(openFile(QString)), this, SLOT(openSlot(QString))); connect(mMRUList, SIGNAL(openFile(QString)), this, SLOT(openSlot(QString)));
@ -628,6 +629,7 @@ NotDebuggingLabel:
case Comments: case Comments:
{ {
int xinc = 3; int xinc = 3;
int width;
if(DbgIsDebugging()) if(DbgIsDebugging())
{ {
//TODO: draw arguments //TODO: draw arguments
@ -649,7 +651,7 @@ NotDebuggingLabel:
backgroundColor = mCommentBackgroundColor; backgroundColor = mCommentBackgroundColor;
} }
int width = mFontMetrics->width(comment); width = mFontMetrics->width(comment);
if(width > w) if(width > w)
width = w; width = w;
if(width) if(width)
@ -663,13 +665,49 @@ NotDebuggingLabel:
painter->setPen(mLabelColor); painter->setPen(mLabelColor);
backgroundColor = mLabelBackgroundColor; backgroundColor = mLabelBackgroundColor;
int width = mFontMetrics->width(labelText); width = mFontMetrics->width(labelText);
if(width > w) if(width > w)
width = w; width = w;
if(width) if(width)
painter->fillRect(QRect(x + xinc, y, width, h), QBrush(backgroundColor)); //fill comment color painter->fillRect(QRect(x + xinc, y, width, h), QBrush(backgroundColor)); //fill comment color
painter->drawText(QRect(x + xinc, y, width, h), Qt::AlignVCenter | Qt::AlignLeft, labelText); painter->drawText(QRect(x + xinc, y, width, h), Qt::AlignVCenter | Qt::AlignLeft, labelText);
} }
else
width = 0;
x += width + 3;
}
if(mShowMnemonicBrief)
{
char brief[MAX_STRING_SIZE] = "";
QString mnem;
for(const ZydisTokenizer::SingleToken & token : inst.tokens.tokens)
{
if(token.type != ZydisTokenizer::TokenType::Space && token.type != ZydisTokenizer::TokenType::Prefix)
{
mnem = token.text;
break;
}
}
if(mnem.isEmpty())
mnem = inst.instStr;
int index = mnem.indexOf(' ');
if(index != -1)
mnem.truncate(index);
DbgFunctions()->GetMnemonicBrief(mnem.toUtf8().constData(), MAX_STRING_SIZE, brief);
painter->setPen(mMnemonicBriefColor);
QString mnemBrief = brief;
if(mnemBrief.length())
{
width = mFontMetrics->width(mnemBrief);
if(width > w)
width = w;
if(width)
painter->fillRect(QRect(x, y, width, h), QBrush(mMnemonicBriefBackgroundColor)); //mnemonic brief background color
painter->drawText(QRect(x, y, width, h), Qt::AlignVCenter | Qt::AlignLeft, mnemBrief);
}
} }
return ""; return "";
} }
@ -830,6 +868,16 @@ void TraceBrowser::setupRightClickContextMenu()
mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), isDebugging); mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), isDebugging);
mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(setBookmarkSlot()), "ActionToggleBookmark"), isDebugging); mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(setBookmarkSlot()), "ActionToggleBookmark"), isDebugging);
mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid); mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid);
mMenuBuilder->addAction(makeShortcutAction(DIcon("helpmnemonic.png"), tr("Help on mnemonic"), SLOT(mnemonicHelpSlot()), "ActionHelpOnMnemonic"), isValid);
QAction* mnemonicBrief = makeShortcutAction(DIcon("helpbrief.png"), tr("Show mnemonic brief"), SLOT(mnemonicBriefSlot()), "ActionToggleMnemonicBrief");
mMenuBuilder->addAction(mnemonicBrief, [this, mnemonicBrief](QMenu*)
{
if(mShowMnemonicBrief)
mnemonicBrief->setText(tr("Hide mnemonic brief"));
else
mnemonicBrief->setText(tr("Show mnemonic brief"));
return true;
});
MenuBuilder* gotoMenu = new MenuBuilder(this, isValid); MenuBuilder* gotoMenu = new MenuBuilder(this, isValid);
gotoMenu->addAction(makeShortcutAction(DIcon("goto.png"), tr("Expression"), SLOT(gotoSlot()), "ActionGotoExpression"), isValid); gotoMenu->addAction(makeShortcutAction(DIcon("goto.png"), tr("Expression"), SLOT(gotoSlot()), "ActionGotoExpression"), isValid);
gotoMenu->addAction(makeShortcutAction(DIcon("previous.png"), tr("Previous"), SLOT(gotoPreviousSlot()), "ActionGotoPrevious"), [this](QMenu*) gotoMenu->addAction(makeShortcutAction(DIcon("previous.png"), tr("Previous"), SLOT(gotoPreviousSlot()), "ActionGotoPrevious"), [this](QMenu*)
@ -1191,6 +1239,8 @@ void TraceBrowser::updateColors()
mBytesBackgroundColor = ConfigColor("DisassemblyBytesBackgroundColor"); mBytesBackgroundColor = ConfigColor("DisassemblyBytesBackgroundColor");
mAutoCommentColor = ConfigColor("DisassemblyAutoCommentColor"); mAutoCommentColor = ConfigColor("DisassemblyAutoCommentColor");
mAutoCommentBackgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor"); mAutoCommentBackgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor");
mMnemonicBriefColor = ConfigColor("DisassemblyMnemonicBriefColor");
mMnemonicBriefBackgroundColor = ConfigColor("DisassemblyMnemonicBriefBackgroundColor");
mCommentColor = ConfigColor("DisassemblyCommentColor"); mCommentColor = ConfigColor("DisassemblyCommentColor");
mCommentBackgroundColor = ConfigColor("DisassemblyCommentBackgroundColor"); mCommentBackgroundColor = ConfigColor("DisassemblyCommentBackgroundColor");
mConditionalJumpLineTrueColor = ConfigColor("DisassemblyConditionalJumpLineTrueColor"); mConditionalJumpLineTrueColor = ConfigColor("DisassemblyConditionalJumpLineTrueColor");
@ -1307,6 +1357,23 @@ void TraceBrowser::parseFinishedSlot()
emit selectionChanged(getInitialSelection()); emit selectionChanged(getInitialSelection());
} }
void TraceBrowser::mnemonicBriefSlot()
{
mShowMnemonicBrief = !mShowMnemonicBrief;
reloadData();
}
void TraceBrowser::mnemonicHelpSlot()
{
unsigned char data[16] = { 0xCC };
int size;
mTraceFile->OpCode(getInitialSelection(), data, &size);
Zydis zydis;
zydis.Disassemble(mTraceFile->Registers(getInitialSelection()).regcontext.cip, data);
DbgCmdExecDirect(QString("mnemonichelp %1").arg(zydis.Mnemonic().c_str()).toUtf8().constData());
emit displayLogWidget();
}
void TraceBrowser::gotoSlot() void TraceBrowser::gotoSlot()
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100) if(mTraceFile == nullptr || mTraceFile->Progress() < 100)

View File

@ -75,6 +75,7 @@ private:
bool mHighlightingMode; bool mHighlightingMode;
bool mPermanentHighlightingMode; bool mPermanentHighlightingMode;
bool mAutoDisassemblyFollowSelection; bool mAutoDisassemblyFollowSelection;
bool mShowMnemonicBrief;
TraceFileReader* mTraceFile; TraceFileReader* mTraceFile;
BreakpointMenu* mBreakpointMenu; BreakpointMenu* mBreakpointMenu;
@ -115,6 +116,9 @@ private:
QColor mCommentBackgroundColor; QColor mCommentBackgroundColor;
QColor mDisassemblyRelocationUnderlineColor; QColor mDisassemblyRelocationUnderlineColor;
QColor mMnemonicBriefColor;
QColor mMnemonicBriefBackgroundColor;
QColor mConditionalJumpLineTrueColor; QColor mConditionalJumpLineTrueColor;
QColor mLoopColor; QColor mLoopColor;
@ -140,6 +144,7 @@ private:
signals: signals:
void displayReferencesWidget(); void displayReferencesWidget();
void displayLogWidget();
void selectionChanged(unsigned long long selection); void selectionChanged(unsigned long long selection);
public slots: public slots:
@ -160,6 +165,8 @@ public slots:
void setLabelSlot(); void setLabelSlot();
void setCommentSlot(); void setCommentSlot();
void setBookmarkSlot(); void setBookmarkSlot();
void mnemonicBriefSlot();
void mnemonicHelpSlot();
void copyDisassemblySlot(); void copyDisassemblySlot();
void copyCipSlot(); void copyCipSlot();
void copyIndexSlot(); void copyIndexSlot();