Commit 3059046a authored by hjk's avatar hjk
Browse files

Fixes: debugger: start work on core file loading

parent f4e875b9
<ui version="4.0" >
<class>AttachCoreDialog</class>
<widget class="QDialog" name="AttachCoreDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>561</width>
<height>866</height>
</rect>
</property>
<property name="windowTitle" >
<string>Start Debugger</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="pidLabel" >
<property name="text" >
<string>Attach to Process ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pidLineEdit" />
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="procView" >
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/**************************************************************************
**
** 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 "attachexternaldialog.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QPushButton>
#include <QStandardItemModel>
#include <QHeaderView>
#ifdef Q_OS_WINDOWS
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
#endif
using namespace Debugger::Internal;
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();
}
/**************************************************************************
**
** 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 ATTACHEXTERNALDIALOG_H
#define ATTACHEXTERNALDIALOG_H
#include "ui_attachexternaldialog.h"
QT_BEGIN_NAMESPACE
class QStandardItemModel;
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
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;
};
} // namespace Debugger
} // namespace Internal
#endif // ATTACHEEXTERNALDIALOG_H
/**************************************************************************
**
** 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 "attachremotedialog.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QPushButton>
#include <QStandardItemModel>
#include <QHeaderView>
using namespace Debugger::Internal;
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();
}
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") {
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 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();
}
/**************************************************************************
**
** 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 ATTACHREMOTE_DIALOG_H
#define ATTACHREMOTE_DIALOG_H
#include "ui_attachremotedialog.h"
QT_BEGIN_NAMESPACE
class QStandardItemModel;
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
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;
};
} // namespace Debugger
} // namespace Internal
#endif // ATTACHREMOTEDIALOG_H
......@@ -14,11 +14,11 @@ INCLUDEPATH += $$PWD/../../libs/utils
QT += gui network script
HEADERS += attachexternaldialog.h \
attachremotedialog.h \
HEADERS += \
breakhandler.h \
breakwindow.h \
debuggerconstants.h \
debuggerdialogs.h \
debuggermanager.h \
debuggeroutputwindow.h \
debuggerplugin.h \
......@@ -39,16 +39,15 @@ HEADERS += attachexternaldialog.h \
stackhandler.h \
stackwindow.h \
sourcefileswindow.h \
startexternaldialog.h \
threadswindow.h \
watchhandler.h \
watchwindow.h
SOURCES += attachexternaldialog.cpp \
attachremotedialog.cpp \
SOURCES += \
breakhandler.cpp \
breakwindow.cpp \
breakwindow.h \
debuggerdialogs.cpp \
debuggermanager.cpp \
debuggeroutputwindow.cpp \
debuggerplugin.cpp \
......@@ -67,13 +66,13 @@ SOURCES += attachexternaldialog.cpp \
stackhandler.cpp \
stackwindow.cpp \
sourcefileswindow.cpp \
startexternaldialog.cpp \
threadswindow.cpp \
watchhandler.cpp \
watchwindow.cpp
FORMS += attachexternaldialog.ui \
attachremotedialog.ui \
attachcoredialog.ui \
breakbyfunction.ui \
breakcondition.ui \
gdboptionpage.ui \
......
......@@ -51,8 +51,7 @@
#include "stackhandler.h"
#include "watchhandler.h"
#include "startexternaldialog.h"
#include "attachexternaldialog.h"
#include "debuggerdialogs.h"
#include <utils/qtcassert.h>
......@@ -294,6 +293,9 @@ void DebuggerManager::init()
m_attachExternalAction = new QAction(this);
m_attachExternalAction->setText(tr("Attach to Running External Application..."));
m_attachCoreAction = new QAction(this);
m_attachCoreAction->setText(tr("Attach to Core..."));
m_continueAction = new QAction(this);
m_continueAction->setText(tr("Continue"));
m_continueAction->setIcon(QIcon(":/gdbdebugger/images/debugger_continue_small.png"));
......@@ -362,6 +364,8 @@ void DebuggerManager::init()
this, SLOT(startExternalApplication()));
connect(m_attachExternalAction, SIGNAL(triggered()),
this, SLOT(attachExternalApplication()));
connect(m_attachCoreAction, SIGNAL(triggered()),
this, SLOT(attachCore()));
connect(m_stopAction, SIGNAL(triggered()),
this, SLOT(interruptDebuggingRequest()));
......@@ -769,6 +773,12 @@ void DebuggerManager::attachExternalApplication()
emit debuggingFinished();
}
void DebuggerManager::attachCore()
{
if (!startNewDebugger(AttachCore))
emit debuggingFinished();
}
bool DebuggerManager::startNewDebugger(StartMode mode)
{
m_startMode = mode;
......@@ -827,6 +837,22 @@ bool DebuggerManager::startNewDebugger(StartMode mode)
//m_processArgs = sd.processArgs.join(QLatin1String(" "));
m_attachedPID = 0;
}
} else if (startMode() == AttachCore) {
StartExternalDialog dlg(mainWindow());
dlg.setExecutableFile(
configValue(QLatin1String("LastExternalExecutableFile")).toString());
dlg.setExecutableArguments(
configValue(QLatin1String("LastExternalExecutableArguments")).toString());
if (dlg.exec() != QDialog::Accepted)
return false;
setConfigValue(QLatin1String("LastExternalExecutableFile"),
dlg.executableFile());
setConfigValue(QLatin1String("LastExternalExecutableArguments"),
dlg.executableArguments());
m_executable = dlg.executableFile();