Skip to content

Commit 062dee2

Browse files
committed
fix crashes in trace viewer when pressing hotkeys
1 parent 4cf0844 commit 062dee2

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/gui/Src/Tracer/TraceBrowser.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ void TraceBrowser::setupRightClickContextMenu()
478478
return (duint)0;
479479
});
480480
mBreakpointMenu->build(mMenuBuilder);
481+
mMenuBuilder->addAction(makeShortcutAction(DIcon("label.png"), tr("Label Current Address"), SLOT(setLabelSlot()), "ActionSetLabel"), isDebugging);
481482
mMenuBuilder->addAction(makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionSetComment"), isDebugging);
482483
mMenuBuilder->addAction(makeShortcutAction(DIcon("highlight.png"), tr("&Highlighting mode"), SLOT(enableHighlightingModeSlot()), "ActionHighlightingMode"), isValid);
483484
MenuBuilder* gotoMenu = new MenuBuilder(this, isValid);
@@ -854,7 +855,7 @@ void TraceBrowser::updateColors()
854855

855856
void TraceBrowser::openFileSlot()
856857
{
857-
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);
858+
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);
858859
if(browse.exec() != QDialog::Accepted)
859860
return;
860861
emit openSlot(browse.path);
@@ -936,6 +937,8 @@ void TraceBrowser::parseFinishedSlot()
936937

937938
void TraceBrowser::gotoSlot()
938939
{
940+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
941+
return;
939942
GotoDialog gotoDlg(this, false, true); // Problem: Cannot use when not debugging
940943
if(gotoDlg.exec() == QDialog::Accepted)
941944
{
@@ -1090,6 +1093,9 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
10901093

10911094
void TraceBrowser::copySelectionSlot(bool copyBytes)
10921095
{
1096+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1097+
return;
1098+
10931099
QString selectionString = "";
10941100
QString selectionHtmlString = "";
10951101
QTextStream stream(&selectionString);
@@ -1100,6 +1106,9 @@ void TraceBrowser::copySelectionSlot(bool copyBytes)
11001106

11011107
void TraceBrowser::copySelectionToFileSlot(bool copyBytes)
11021108
{
1109+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1110+
return;
1111+
11031112
QString fileName = QFileDialog::getSaveFileName(this, tr("Open File"), "", tr("Text Files (*.txt)"));
11041113
if(fileName != "")
11051114
{
@@ -1138,6 +1147,9 @@ void TraceBrowser::copySelectionToFileNoBytesSlot()
11381147

11391148
void TraceBrowser::copyDisassemblySlot()
11401149
{
1150+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1151+
return;
1152+
11411153
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
11421154
QString clipboard = "";
11431155
for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++)
@@ -1162,6 +1174,9 @@ void TraceBrowser::copyDisassemblySlot()
11621174
void TraceBrowser::copyRvaSlot()
11631175
{
11641176
QString text;
1177+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1178+
return;
1179+
11651180
for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++)
11661181
{
11671182
duint cip = mTraceFile->Registers(i).regcontext.cip;
@@ -1184,6 +1199,9 @@ void TraceBrowser::copyRvaSlot()
11841199
void TraceBrowser::copyFileOffsetSlot()
11851200
{
11861201
QString text;
1202+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1203+
return;
1204+
11871205
for(unsigned long long i = getSelectionStart(); i <= getSelectionEnd(); i++)
11881206
{
11891207
duint cip = mTraceFile->Registers(i).regcontext.cip;
@@ -1205,7 +1223,7 @@ void TraceBrowser::copyFileOffsetSlot()
12051223

12061224
void TraceBrowser::setCommentSlot()
12071225
{
1208-
if(!DbgIsDebugging())
1226+
if(!DbgIsDebugging() || mTraceFile == nullptr || mTraceFile->Progress() < 100)
12091227
return;
12101228
duint wVA = mTraceFile->Registers(getInitialSelection()).regcontext.cip;
12111229
LineEditDialog mLineEdit(this);
@@ -1240,6 +1258,39 @@ void TraceBrowser::setCommentSlot()
12401258
GuiUpdateAllViews();
12411259
}
12421260

1261+
void TraceBrowser::setLabelSlot()
1262+
{
1263+
if(!DbgIsDebugging() || mTraceFile == nullptr || mTraceFile->Progress() < 100)
1264+
return;
1265+
duint wVA = mTraceFile->Registers(getInitialSelection()).regcontext.cip;
1266+
LineEditDialog mLineEdit(this);
1267+
mLineEdit.setTextMaxLength(MAX_LABEL_SIZE - 2);
1268+
QString addr_text = ToPtrString(wVA);
1269+
char label_text[MAX_COMMENT_SIZE] = "";
1270+
if(DbgGetLabelAt((duint)wVA, SEG_DEFAULT, label_text))
1271+
mLineEdit.setText(QString(label_text));
1272+
mLineEdit.setWindowTitle(tr("Add label at ") + addr_text);
1273+
restart:
1274+
if(mLineEdit.exec() != QDialog::Accepted)
1275+
return;
1276+
QByteArray utf8data = mLineEdit.editText.toUtf8();
1277+
if(!utf8data.isEmpty() && DbgIsValidExpression(utf8data.constData()) && DbgValFromString(utf8data.constData()) != wVA)
1278+
{
1279+
QMessageBox msg(QMessageBox::Warning, tr("The label may be in use"),
1280+
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),
1281+
QMessageBox::Yes | QMessageBox::No, this);
1282+
msg.setWindowIcon(DIcon("compile-warning.png"));
1283+
msg.setParent(this, Qt::Dialog);
1284+
msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
1285+
if(msg.exec() == QMessageBox::No)
1286+
goto restart;
1287+
}
1288+
if(!DbgSetLabelAt(wVA, utf8data.constData()))
1289+
SimpleErrorBox(this, tr("Error!"), tr("DbgSetLabelAt failed!"));
1290+
1291+
GuiUpdateAllViews();
1292+
}
1293+
12431294
void TraceBrowser::enableHighlightingModeSlot()
12441295
{
12451296
if(mHighlightingMode)
@@ -1251,6 +1302,9 @@ void TraceBrowser::enableHighlightingModeSlot()
12511302

12521303
void TraceBrowser::followDisassemblySlot()
12531304
{
1305+
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
1306+
return;
1307+
12541308
DbgCmdExec(QString("dis ").append(ToPtrString(mTraceFile->Registers(getInitialSelection()).regcontext.cip)).toUtf8().constData());
12551309
}
12561310

src/gui/Src/Tracer/TraceBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public slots:
115115
void gotoNextSlot();
116116
void followDisassemblySlot();
117117
void enableHighlightingModeSlot();
118+
void setLabelSlot();
118119
void setCommentSlot();
119120
void copyDisassemblySlot();
120121
void copyCipSlot();

0 commit comments

Comments
 (0)