From 3996e63ab93e7284b2ececf0c78f2a03104f814a Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Mon, 31 Jul 2023 11:42:45 -0500 Subject: [PATCH] Debug dialog for "attach" mode now detects executable name and path. --- CHANGELOG.md | 1 + src/QProcessInfo.cpp | 24 ++++++++++++++++------ src/QProcessInfo.h | 4 ++++ src/QProcessInfoWidget.cpp | 41 +++++++++++++++++++++++++------------ src/QProcessInfoWidget.h | 1 + src/QProcessInfoWidget.ui | 9 ++++++-- src/SeerDebugDialog.cpp | 3 +++ src/SeerSlashProcDialog.cpp | 5 +++++ src/SeerSlashProcDialog.h | 1 + 9 files changed, 68 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe31362..0596d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Add a method to add/change a breakpoint's condition command. * Add a method to add/change a breakpoint's ignore count. * Add a method to add/change a breakpoint's command list. +* Debug dialog for "attach" mode now detects executable name and path. ## [2.0] - 2023-03-06 * Seer is Qt6 based. Still compiles with Qt5. diff --git a/src/QProcessInfo.cpp b/src/QProcessInfo.cpp index 9546f9e..13785e4 100644 --- a/src/QProcessInfo.cpp +++ b/src/QProcessInfo.cpp @@ -44,6 +44,7 @@ QProcessList QProcessInfo::populate() { QFileInfo exe(processDir.absoluteFilePath(QStringLiteral("exe"))); exe = QFileInfo(exe.symLinkTarget()); info.setName(exe.completeBaseName()); + info.setPath(exe.absolutePath()); // if we didn't get a name from the symlink, check in the status file if (info.name().isEmpty()) { @@ -62,6 +63,7 @@ QProcessList QProcessInfo::populate() { line.remove(0, 5); // if we're using this name, surround with []s to indicate it's not a file info.setName(QStringLiteral("[%1]").arg(line.trimmed())); + info.setPath(""); break; } } @@ -108,11 +110,13 @@ QProcessList QProcessInfo::populate() { // if name is a truncated form of a filename, replace it if (firstparam.endsWith(info.name()) && QFileInfo::exists(firstparam)) { info.setName(QFileInfo(firstparam).completeBaseName()); + info.setPath(QFileInfo(firstparam).absolutePath()); } // if we don't have a name, replace it but with []s if (info.name().isEmpty()) { info.setName(QStringLiteral("[%1]").arg(firstparam)); + info.setPath(""); } contents.replace('\0', ' '); @@ -143,27 +147,35 @@ void QProcessInfo::setPid(uint32_t pid) { _pid = pid; } -const QString &QProcessInfo::username() const { +const QString& QProcessInfo::username() const { return _username; } -void QProcessInfo::setUsername(const QString &username) { +void QProcessInfo::setUsername(const QString& username) { _username = username; } -const QString &QProcessInfo::name() const { +const QString& QProcessInfo::name() const { return _name; } -void QProcessInfo::setName(const QString &name) { +void QProcessInfo::setName(const QString& name) { _name = name; } -const QString &QProcessInfo::commandLine() const { +const QString& QProcessInfo::path() const { + return _path; +} + +void QProcessInfo::setPath(const QString& path) { + _path = path; +} + +const QString& QProcessInfo::commandLine() const { return _cmdLine; } -void QProcessInfo::setCommandLine(const QString &cmd) { +void QProcessInfo::setCommandLine(const QString& cmd) { _cmdLine = cmd; } diff --git a/src/QProcessInfo.h b/src/QProcessInfo.h index fb87b03..f30f17b 100644 --- a/src/QProcessInfo.h +++ b/src/QProcessInfo.h @@ -21,6 +21,9 @@ class QProcessInfo { const QString& name () const; void setName (const QString& name); + const QString& path () const; + void setPath (const QString& path); + const QString& commandLine () const; void setCommandLine (const QString& cmd); @@ -28,6 +31,7 @@ class QProcessInfo { uint32_t _pid; QString _username; QString _name; + QString _path; QString _cmdLine; }; diff --git a/src/QProcessInfoWidget.cpp b/src/QProcessInfoWidget.cpp index c109d4c..41c8938 100644 --- a/src/QProcessInfoWidget.cpp +++ b/src/QProcessInfoWidget.cpp @@ -41,10 +41,11 @@ QProcessInfoWidget::QProcessInfoWidget (QWidget* parent) : QWidget(parent) { // Setup the widgets processTreeWidget->setMouseTracking(true); - processTreeWidget->resizeColumnToContents(0); - processTreeWidget->resizeColumnToContents(1); - processTreeWidget->resizeColumnToContents(2); - processTreeWidget->resizeColumnToContents(3); + processTreeWidget->resizeColumnToContents(0); // PID + processTreeWidget->resizeColumnToContents(1); // User name + processTreeWidget->resizeColumnToContents(2); // Path name + processTreeWidget->resizeColumnToContents(3); // Program name + //processTreeWidget->resizeColumnToContents(4); // Command line processTreeWidget->setSortingEnabled(true); processTreeWidget->clear(); systemProcessesCheckBox->setChecked(false); @@ -93,7 +94,18 @@ QString QProcessInfoWidget::selectedName () const { return ""; } - return items[0]->text(2); + return items[0]->text(3); +} + +QString QProcessInfoWidget::selectedFullname () const { + + QList items = processTreeWidget->selectedItems(); + + if (items.size() == 0) { + return ""; + } + + return items[0]->text(2) + "/" + items[0]->text(3); } QString QProcessInfoWidget::selectedCommandLine () const { @@ -104,7 +116,7 @@ QString QProcessInfoWidget::selectedCommandLine () const { return ""; } - return items[0]->text(3); + return items[0]->text(4); } void QProcessInfoWidget::refreshList () { @@ -122,8 +134,9 @@ void QProcessInfoWidget::refreshList () { QTreeWidgetItem* item = new QProcessInfoWidgetItem; item->setText(0, QString::number(info.pid())); item->setText(1, info.username()); - item->setText(2, info.name()); - item->setText(3, info.commandLine()); + item->setText(2, info.path()); + item->setText(3, info.name()); + item->setText(4, info.commandLine()); processTreeWidget->addTopLevelItem(item); } @@ -134,6 +147,7 @@ void QProcessInfoWidget::refreshList () { processTreeWidget->resizeColumnToContents(1); processTreeWidget->resizeColumnToContents(2); processTreeWidget->resizeColumnToContents(3); + //processTreeWidget->resizeColumnToContents(4); // Don't clear the line edits. // programNameLineEdit->clear(); @@ -150,13 +164,13 @@ void QProcessInfoWidget::refreshView () { QList programNameMatches; if (programNameLineEdit->text() == "") { - programNameMatches = processTreeWidget->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive, 2); + programNameMatches = processTreeWidget->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive, 3); }else{ if (programNameLineEdit->text().contains('*')) { - programNameMatches = processTreeWidget->findItems(programNameLineEdit->text(), Qt::MatchWildcard | Qt::MatchRecursive, 2); + programNameMatches = processTreeWidget->findItems(programNameLineEdit->text(), Qt::MatchWildcard | Qt::MatchRecursive, 3); }else{ - programNameMatches = processTreeWidget->findItems(programNameLineEdit->text(), Qt::MatchStartsWith | Qt::MatchRecursive, 2); + programNameMatches = processTreeWidget->findItems(programNameLineEdit->text(), Qt::MatchStartsWith | Qt::MatchRecursive, 3); } } @@ -178,13 +192,13 @@ void QProcessInfoWidget::refreshView () { QList processMatches; if (systemProcessesCheckBox->isChecked() == true) { - processMatches = processTreeWidget->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive, 2); + processMatches = processTreeWidget->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive, 3); //qDebug() << "Checkbox is on." << processMatches.size(); }else{ // To find [xxx] processes : "^(\\[).*(\\])$" // To exclude [xxx] processes: "^(?!\\[).*(?!\\])$" - processMatches = processTreeWidget->findItems("^(?!\\[).*(?!\\])$", Qt::MatchRegularExpression | Qt::MatchRecursive, 2); + processMatches = processTreeWidget->findItems("^(?!\\[).*(?!\\])$", Qt::MatchRegularExpression | Qt::MatchRecursive, 3); //qDebug() << "Checkbox is off." << processMatches.size(); } @@ -209,6 +223,7 @@ void QProcessInfoWidget::refreshView () { processTreeWidget->resizeColumnToContents(1); processTreeWidget->resizeColumnToContents(2); processTreeWidget->resizeColumnToContents(3); + //processTreeWidget->resizeColumnToContents(4); } void QProcessInfoWidget::handleDoubleClicked () { diff --git a/src/QProcessInfoWidget.h b/src/QProcessInfoWidget.h index dce48be..f93edbb 100644 --- a/src/QProcessInfoWidget.h +++ b/src/QProcessInfoWidget.h @@ -15,6 +15,7 @@ class QProcessInfoWidget : public QWidget, protected Ui::QProcessInfoWidget { int selectedPid () const; QString selectedUsername () const; QString selectedName () const; + QString selectedFullname () const; QString selectedCommandLine () const; signals: diff --git a/src/QProcessInfoWidget.ui b/src/QProcessInfoWidget.ui index 2638049..f533852 100644 --- a/src/QProcessInfoWidget.ui +++ b/src/QProcessInfoWidget.ui @@ -37,7 +37,7 @@ - :/seer/resources/RelaxLightIcons/view-refresh.svg:/seer/resources/HighContrast/view-refresh.svg + :/seer/resources/RelaxLightIcons/view-refresh.svg:/seer/resources/RelaxLightIcons/view-refresh.svg @@ -47,7 +47,7 @@ true - 4 + 5 @@ -59,6 +59,11 @@ User Name + + + Program Path + + Program Name diff --git a/src/SeerDebugDialog.cpp b/src/SeerDebugDialog.cpp index db6175f..651f67e 100644 --- a/src/SeerDebugDialog.cpp +++ b/src/SeerDebugDialog.cpp @@ -405,6 +405,9 @@ void SeerDebugDialog::handleProgramPidToolButton () { // Execute the dialog and get the result. if (dlg.exec()) { setAttachPid(dlg.selectedPid()); + if (executableName() == "") { + setExecutableName(dlg.selectedFullname()); + } } } diff --git a/src/SeerSlashProcDialog.cpp b/src/SeerSlashProcDialog.cpp index 7b7e190..1110736 100644 --- a/src/SeerSlashProcDialog.cpp +++ b/src/SeerSlashProcDialog.cpp @@ -24,6 +24,11 @@ QString SeerSlashProcDialog::selectedName () const { return processInfoWidget->selectedName(); } +QString SeerSlashProcDialog::selectedFullname () const { + + return processInfoWidget->selectedFullname(); +} + QString SeerSlashProcDialog::selectedCommandLine () const { return processInfoWidget->selectedCommandLine(); diff --git a/src/SeerSlashProcDialog.h b/src/SeerSlashProcDialog.h index c093315..79aec9d 100644 --- a/src/SeerSlashProcDialog.h +++ b/src/SeerSlashProcDialog.h @@ -15,6 +15,7 @@ class SeerSlashProcDialog : public QDialog, protected Ui::SeerSlashProcDialogFor int selectedPid () const; QString selectedName () const; + QString selectedFullname () const; QString selectedCommandLine () const; public slots: