From 00a9c05328b75f06ee0fa6ad10d30ed8499b2ce1 Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Mon, 2 Mar 2009 14:04:03 +0100 Subject: [PATCH] Fixes: debugger: forgot to add these --- src/plugins/debugger/debuggerdialogs.cpp | 323 +++++++++++++++++++++++ src/plugins/debugger/debuggerdialogs.h | 112 ++++++++ 2 files changed, 435 insertions(+) create mode 100644 src/plugins/debugger/debuggerdialogs.cpp create mode 100644 src/plugins/debugger/debuggerdialogs.h diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp new file mode 100644 index 00000000000..0f538d63e60 --- /dev/null +++ b/src/plugins/debugger/debuggerdialogs.cpp @@ -0,0 +1,323 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +**************************************************************************/ + +#include "debuggerdialogs.h" + +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QFile> +#include <QtGui/QStandardItemModel> +#include <QtGui/QHeaderView> +#include <QtGui/QFileDialog> +#include <QtGui/QPushButton> + +#ifdef Q_OS_WINDOWS +#include <windows.h> +#include <tlhelp32.h> +#include <tchar.h> +#include <stdio.h> +#endif + +using namespace Debugger::Internal; + + +/////////////////////////////////////////////////////////////////////// +// +// AttachCoreDialog +// +/////////////////////////////////////////////////////////////////////// + +AttachCoreDialog::AttachCoreDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + //connect(procView, SIGNAL(activated(const QModelIndex &)), + // this, SLOT(procSelected(const QModelIndex &))); +} + + + +/////////////////////////////////////////////////////////////////////// +// +// AttachExternalDialog +// +/////////////////////////////////////////////////////////////////////// + +AttachExternalDialog::AttachExternalDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + m_model = new QStandardItemModel(this); + + procView->setSortingEnabled(true); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + connect(procView, SIGNAL(activated(const QModelIndex &)), + this, SLOT(procSelected(const QModelIndex &))); + + rebuildProcessList(); +} + +static bool isProcessName(const QString &procname) +{ + for (int i = 0; i != procname.size(); ++i) + if (!procname.at(i).isDigit()) + return false; + return true; +} + +struct ProcData +{ + QString ppid; + QString name; + QString state; +}; + +static void insertItem(QStandardItem *root, const QString &pid, + const QMap<QString, ProcData> &procs, QMap<QString, QStandardItem *> &known) +{ + //qDebug() << "HANDLING " << pid; + QStandardItem *parent = 0; + const ProcData &proc = procs[pid]; + if (1 || pid == "0") { // FIXME: a real tree is not-so-nice to search + parent = root; + } else { + if (!known.contains(proc.ppid)) + insertItem(root, proc.ppid, procs, known); + parent = known[proc.ppid]; + } + QList<QStandardItem *> row; + row.append(new QStandardItem(pid)); + row.append(new QStandardItem(proc.name)); + //row.append(new QStandardItem(proc.ppid)); + row.append(new QStandardItem(proc.state)); + parent->appendRow(row); + known[pid] = row[0]; +} + +void AttachExternalDialog::rebuildProcessList() +{ + QStringList procnames = QDir("/proc/").entryList(); + if (procnames.isEmpty()) { + procView->hide(); + return; + } + + typedef QMap<QString, ProcData> Procs; + Procs procs; + + foreach (const QString &procname, procnames) { + if (!isProcessName(procname)) + continue; + QString filename = "/proc/" + procname + "/stat"; + QFile file(filename); + file.open(QIODevice::ReadOnly); + QStringList data = QString::fromLocal8Bit(file.readAll()).split(' '); + //qDebug() << filename << data; + ProcData proc; + proc.name = data.at(1); + if (proc.name.startsWith('(') && proc.name.endsWith(')')) + proc.name = proc.name.mid(1, proc.name.size() - 2); + proc.state = data.at(2); + proc.ppid = data.at(3); + procs[procname] = proc; + } + + m_model->clear(); + QMap<QString, QStandardItem *> known; + for (Procs::const_iterator it = procs.begin(); it != procs.end(); ++it) + insertItem(m_model->invisibleRootItem(), it.key(), procs, known); + m_model->setHeaderData(0, Qt::Horizontal, "Process ID", Qt::DisplayRole); + m_model->setHeaderData(1, Qt::Horizontal, "Name", Qt::DisplayRole); + //model->setHeaderData(2, Qt::Horizontal, "Parent", Qt::DisplayRole); + m_model->setHeaderData(2, Qt::Horizontal, "State", Qt::DisplayRole); + + procView->setModel(m_model); + procView->expandAll(); + procView->resizeColumnToContents(0); + procView->resizeColumnToContents(1); + procView->sortByColumn(1, Qt::AscendingOrder); +} + +void AttachExternalDialog::procSelected(const QModelIndex &index0) +{ + QModelIndex index = index0.sibling(index0.row(), 0); + QStandardItem *item = m_model->itemFromIndex(index); + if (!item) + return; + pidLineEdit->setText(item->text()); + accept(); +} + +int AttachExternalDialog::attachPID() const +{ + return pidLineEdit->text().toInt(); +} + + + +/////////////////////////////////////////////////////////////////////// +// +// AttachRemoteDialog +// +/////////////////////////////////////////////////////////////////////// + +AttachRemoteDialog::AttachRemoteDialog(QWidget *parent, const QString &pid) + : QDialog(parent) +{ + setupUi(this); + buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + m_defaultPID = pid; + m_model = new QStandardItemModel(this); + + procView->setSortingEnabled(true); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + connect(procView, SIGNAL(activated(const QModelIndex &)), + this, SLOT(procSelected(const QModelIndex &))); + + + pidLineEdit->setText(m_defaultPID); + rebuildProcessList(); +} + +void AttachRemoteDialog::rebuildProcessList() +{ + QStringList procnames = QDir("/proc/").entryList(); + if (procnames.isEmpty()) { + procView->hide(); + return; + } + + typedef QMap<QString, ProcData> Procs; + Procs procs; + + foreach (const QString &procname, procnames) { + if (!isProcessName(procname)) + continue; + QString filename = "/proc/" + procname + "/stat"; + QFile file(filename); + file.open(QIODevice::ReadOnly); + QStringList data = QString::fromLocal8Bit(file.readAll()).split(' '); + //qDebug() << filename << data; + ProcData proc; + proc.name = data.at(1); + if (proc.name.startsWith('(') && proc.name.endsWith(')')) + proc.name = proc.name.mid(1, proc.name.size() - 2); + proc.state = data.at(2); + proc.ppid = data.at(3); + procs[procname] = proc; + } + + m_model->clear(); + QMap<QString, QStandardItem *> known; + for (Procs::const_iterator it = procs.begin(); it != procs.end(); ++it) + insertItem(m_model->invisibleRootItem(), it.key(), procs, known); + m_model->setHeaderData(0, Qt::Horizontal, "Process ID", Qt::DisplayRole); + m_model->setHeaderData(1, Qt::Horizontal, "Name", Qt::DisplayRole); + //model->setHeaderData(2, Qt::Horizontal, "Parent", Qt::DisplayRole); + m_model->setHeaderData(2, Qt::Horizontal, "State", Qt::DisplayRole); + + procView->setModel(m_model); + procView->expandAll(); + procView->resizeColumnToContents(0); + procView->resizeColumnToContents(1); +} + +void AttachRemoteDialog::procSelected(const QModelIndex &index0) +{ + QModelIndex index = index0.sibling(index0.row(), 0); + QStandardItem *item = m_model->itemFromIndex(index); + if (!item) + return; + pidLineEdit->setText(item->text()); + accept(); +} + +int AttachRemoteDialog::attachPID() const +{ + return pidLineEdit->text().toInt(); +} + + + +/////////////////////////////////////////////////////////////////////// +// +// StartExternalDialog +// +/////////////////////////////////////////////////////////////////////// + + +StartExternalDialog::StartExternalDialog(QWidget *parent) + : QDialog(parent) +{ + setupUi(this); + execFile->setExpectedKind(Core::Utils::PathChooser::File); + execFile->setPromptDialogTitle(tr("Select Executable")); + buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); + + //execLabel->setHidden(false); + //execEdit->setHidden(false); + //browseButton->setHidden(false); + + execLabel->setText(tr("Executable:")); + argLabel->setText(tr("Arguments:")); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + +void StartExternalDialog::setExecutableFile(const QString &str) +{ + execFile->setPath(str); +} + +void StartExternalDialog::setExecutableArguments(const QString &str) +{ + argsEdit->setText(str); +} + +QString StartExternalDialog::executableFile() const +{ + return execFile->path(); +} + +QString StartExternalDialog::executableArguments() const +{ + return argsEdit->text(); +} diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h new file mode 100644 index 00000000000..0bb07242ae0 --- /dev/null +++ b/src/plugins/debugger/debuggerdialogs.h @@ -0,0 +1,112 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +**************************************************************************/ + +#ifndef DEBUGGER_DIALOGS_H +#define DEBUGGER_DIALOGS_H + +#include "ui_attachcoredialog.h" +#include "ui_attachexternaldialog.h" +#include "ui_attachremotedialog.h" +#include "ui_startexternaldialog.h" + +QT_BEGIN_NAMESPACE +class QStandardItemModel; +QT_END_NAMESPACE + + +namespace Debugger { +namespace Internal { + +class AttachCoreDialog : public QDialog, Ui::AttachCoreDialog +{ + Q_OBJECT + +public: + explicit AttachCoreDialog(QWidget *parent); + + void setExecutableFile(const QString &executable); + void setCoreFile(const QString &core); + + QString executableFile() const; + QString coreFile() const; +}; + +class AttachExternalDialog : public QDialog, Ui::AttachExternalDialog +{ + Q_OBJECT + +public: + explicit AttachExternalDialog(QWidget *parent); + int attachPID() const; + +private slots: + void rebuildProcessList(); + void procSelected(const QModelIndex &); + +private: + QStandardItemModel *m_model; +}; + + +class AttachRemoteDialog : public QDialog, Ui::AttachRemoteDialog +{ + Q_OBJECT + +public: + explicit AttachRemoteDialog(QWidget *parent, const QString &pid); + int attachPID() const; + +private slots: + void rebuildProcessList(); + void procSelected(const QModelIndex &); + +private: + QString m_defaultPID; + QStandardItemModel *m_model; +}; + + +class StartExternalDialog : public QDialog, Ui::StartExternalDialog +{ + Q_OBJECT + +public: + explicit StartExternalDialog(QWidget *parent); + + void setExecutableFile(const QString &executable); + void setExecutableArguments(const QString &args); + + QString executableFile() const; + QString executableArguments() const; +}; + +} // namespace Debugger +} // namespace Internal + +#endif // DEBUGGER_DIALOGS_H -- GitLab