1
0
Fork 0

fix crashes in trace viewer when pressing hotkeys

This commit is contained in:
torusrxxx 2017-11-08 17:12:20 +08:00
parent 4cf0844255
commit 062dee26f6
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
2 changed files with 57 additions and 2 deletions

View File

@ -478,6 +478,7 @@ void TraceBrowser::setupRightClickContextMenu()
return (duint)0; return (duint)0;
}); });
mBreakpointMenu->build(mMenuBuilder); mBreakpointMenu->build(mMenuBuilder);
mMenuBuilder->addAction(makeShortcutAction(DIcon("label.png"), tr("Label Current Address"), SLOT(setLabelSlot()), "ActionSetLabel"), isDebugging);
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("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid); mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid);
MenuBuilder* gotoMenu = new MenuBuilder(this, isValid); MenuBuilder* gotoMenu = new MenuBuilder(this, isValid);
@ -854,7 +855,7 @@ void TraceBrowser::updateColors()
void TraceBrowser::openFileSlot() void TraceBrowser::openFileSlot()
{ {
BrowseDialog browse(this, tr("Open run trace file"), tr("Open trace file"), tr("Run trace files (*.%1);;All files (*.*)").arg(ArchValue("trace32", "trace64")), QApplication::applicationDirPath(), false); BrowseDialog browse(this, tr("Open run trace file"), tr("Open trace file"), tr("Run trace files (*.%1);;All files (*.*)").arg(ArchValue("trace32", "trace64")), QApplication::applicationDirPath() + QDir::separator() + "db", false);
if(browse.exec() != QDialog::Accepted) if(browse.exec() != QDialog::Accepted)
return; return;
emit openSlot(browse.path); emit openSlot(browse.path);
@ -936,6 +937,8 @@ void TraceBrowser::parseFinishedSlot()
void TraceBrowser::gotoSlot() void TraceBrowser::gotoSlot()
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
GotoDialog gotoDlg(this, false, true); // Problem: Cannot use when not debugging GotoDialog gotoDlg(this, false, true); // Problem: Cannot use when not debugging
if(gotoDlg.exec() == QDialog::Accepted) if(gotoDlg.exec() == QDialog::Accepted)
{ {
@ -1090,6 +1093,9 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
void TraceBrowser::copySelectionSlot(bool copyBytes) void TraceBrowser::copySelectionSlot(bool copyBytes)
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
QString selectionString = ""; QString selectionString = "";
QString selectionHtmlString = ""; QString selectionHtmlString = "";
QTextStream stream(&selectionString); QTextStream stream(&selectionString);
@ -1100,6 +1106,9 @@ void TraceBrowser::copySelectionSlot(bool copyBytes)
void TraceBrowser::copySelectionToFileSlot(bool copyBytes) void TraceBrowser::copySelectionToFileSlot(bool copyBytes)
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
QString fileName = QFileDialog::getSaveFileName(this, tr("Open File"), "", tr("Text Files (*.txt)")); QString fileName = QFileDialog::getSaveFileName(this, tr("Open File"), "", tr("Text Files (*.txt)"));
if(fileName != "") if(fileName != "")
{ {
@ -1138,6 +1147,9 @@ void TraceBrowser::copySelectionToFileNoBytesSlot()
void TraceBrowser::copyDisassemblySlot() void TraceBrowser::copyDisassemblySlot()
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight()); QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
QString clipboard = ""; QString clipboard = "";
for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++) for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++)
@ -1162,6 +1174,9 @@ void TraceBrowser::copyDisassemblySlot()
void TraceBrowser::copyRvaSlot() void TraceBrowser::copyRvaSlot()
{ {
QString text; QString text;
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++) for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++)
{ {
duint cip = mTraceFile->Registers(i).regcontext.cip; duint cip = mTraceFile->Registers(i).regcontext.cip;
@ -1184,6 +1199,9 @@ void TraceBrowser::copyRvaSlot()
void TraceBrowser::copyFileOffsetSlot() void TraceBrowser::copyFileOffsetSlot()
{ {
QString text; QString text;
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++) for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++)
{ {
duint cip = mTraceFile->Registers(i).regcontext.cip; duint cip = mTraceFile->Registers(i).regcontext.cip;
@ -1205,7 +1223,7 @@ void TraceBrowser::copyFileOffsetSlot()
void TraceBrowser::setCommentSlot() void TraceBrowser::setCommentSlot()
{ {
if(!DbgIsDebugging()) if(!DbgIsDebugging() || mTraceFile == nullptr || mTraceFile->Progress() < 100)
return; return;
duint wVA = mTraceFile->Registers(getInitialSelection()).regcontext.cip; duint wVA = mTraceFile->Registers(getInitialSelection()).regcontext.cip;
LineEditDialog mLineEdit(this); LineEditDialog mLineEdit(this);
@ -1240,6 +1258,39 @@ void TraceBrowser::setCommentSlot()
GuiUpdateAllViews(); GuiUpdateAllViews();
} }
void TraceBrowser::setLabelSlot()
{
if(!DbgIsDebugging() || mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
duint wVA = mTraceFile->Registers(getInitialSelection()).regcontext.cip;
LineEditDialog mLineEdit(this);
mLineEdit.setTextMaxLength(MAX_LABEL_SIZE - 2);
QString addr_text = ToPtrString(wVA);
char label_text[MAX_COMMENT_SIZE] = "";
if(DbgGetLabelAt((duint)wVA, SEG_DEFAULT, label_text))
mLineEdit.setText(QString(label_text));
mLineEdit.setWindowTitle(tr("Add label at ") + addr_text);
restart:
if(mLineEdit.exec() != QDialog::Accepted)
return;
QByteArray utf8data = mLineEdit.editText.toUtf8();
if(!utf8data.isEmpty() && DbgIsValidExpression(utf8data.constData()) && DbgValFromString(utf8data.constData()) != wVA)
{
QMessageBox msg(QMessageBox::Warning, tr("The label may be in use"),
tr("The label \"%1\" may be an existing label or a valid expression. Using such label might have undesired effects. Do you still want to continue?").arg(mLineEdit.editText),
QMessageBox::Yes | QMessageBox::No, this);
msg.setWindowIcon(DIcon("compile-warning.png"));
msg.setParent(this, Qt::Dialog);
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
if(msg.exec() == QMessageBox::No)
goto restart;
}
if(!DbgSetLabelAt(wVA, utf8data.constData()))
SimpleErrorBox(this, tr("Error!"), tr("DbgSetLabelAt failed!"));
GuiUpdateAllViews();
}
void TraceBrowser::enableHighlightingModeSlot() void TraceBrowser::enableHighlightingModeSlot()
{ {
if(mHighlightingMode) if(mHighlightingMode)
@ -1251,6 +1302,9 @@ void TraceBrowser::enableHighlightingModeSlot()
void TraceBrowser::followDisassemblySlot() void TraceBrowser::followDisassemblySlot()
{ {
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
return;
DbgCmdExec(QString("dis ").append(ToPtrString(mTraceFile->Registers(getInitialSelection()).regcontext.cip)).toUtf8().constData()); DbgCmdExec(QString("dis ").append(ToPtrString(mTraceFile->Registers(getInitialSelection()).regcontext.cip)).toUtf8().constData());
} }

View File

@ -115,6 +115,7 @@ public slots:
void gotoNextSlot(); void gotoNextSlot();
void followDisassemblySlot(); void followDisassemblySlot();
void enableHighlightingModeSlot(); void enableHighlightingModeSlot();
void setLabelSlot();
void setCommentSlot(); void setCommentSlot();
void copyDisassemblySlot(); void copyDisassemblySlot();
void copyCipSlot(); void copyCipSlot();