Skip to content

Commit

Permalink
Imperfect/broken debuggin
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Ribelotta <[email protected]>
  • Loading branch information
martinribelotta committed Feb 18, 2017
1 parent c8a77ae commit 81d7918
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 11 deletions.
48 changes: 46 additions & 2 deletions debuginterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "qgdb/opendialog.h"

#include <QMimeDatabase>
#include <QStandardItemModel>
#include <QMessageBox>
#include <QtDebug>

struct DebugInterface::Priv_t {
Expand Down Expand Up @@ -55,6 +57,7 @@ void DebugInterface::ICore_onStateChanged(TargetState state)

void DebugInterface::ICore_onSignalReceived(QString signalName)
{
QMessageBox::information(this->window(), tr("Signal recevied"), tr("Signal <<%1>>").arg(signalName));
}

void DebugInterface::ICore_onLocalVarReset()
Expand Down Expand Up @@ -89,12 +92,36 @@ void DebugInterface::ICore_onBreakpointsChanged()

void DebugInterface::ICore_onThreadListChanged()
{
QStandardItemModel *m = new QStandardItemModel(this);
foreach(ThreadInfo thd, Core::getInstance().getThreadList()) {
QStandardItem* thdItem = new QStandardItem(tr("[%3] %1: %2")
.arg(thd.m_name)
.arg(thd.m_func)
.arg(thd.id));
thdItem->setData(QVariant::fromValue(thd), Qt::UserRole);
qDebug() << "create thread" << thd.id;
m->appendRow(thdItem);
}
ui->treeFrame->setModel(m);
}

void DebugInterface::ICore_onCurrentThreadChanged(int threadId)
{
qDebug() << "thread change" << threadId;
Core::getInstance().selectThread(threadId);
auto *m = qobject_cast<QStandardItemModel*>(ui->treeFrame->model());
if (m && threadId > 0 && threadId <= m->invisibleRootItem()->rowCount()) {
Core::getInstance().selectThread(threadId);
QStandardItem *thdItem = m->invisibleRootItem()->child(threadId-1, 0);
if (thdItem) {
ThreadInfo info = thdItem->data(Qt::UserRole).value<ThreadInfo>();
qDebug() << "select thread id" << info.id << info.m_func << info.m_name;
ui->treeFrame->selectionModel()->select(thdItem->index(),
QItemSelectionModel::Rows |
QItemSelectionModel::Select);
} else
qDebug() << "No thread item for " << threadId;
} else
qDebug() << "ignoring it" << threadId;
}

void DebugInterface::ICore_onStackFrameChange(QList<StackFrameEntry> stackFrameList)
Expand All @@ -116,9 +143,26 @@ void DebugInterface::ICore_onTargetOutput(QString message)
void DebugInterface::ICore_onCurrentFrameChanged(int frameIdx)
{
qDebug() << "current frame" << frameIdx << priv->currentStackFrameList.size();
if (frameIdx < priv->currentStackFrameList.size()) {
if (frameIdx >= 0 && frameIdx < priv->currentStackFrameList.size()) {
StackFrameEntry &entry = priv->currentStackFrameList[priv->currentStackFrameList.size()-frameIdx-1];
documentArea->fileOpenAndSetIP(entry.m_sourcePath, entry.m_line, &projectView->makeInfo());
auto *m = qobject_cast<QStandardItemModel*>(ui->treeFrame->model());
if (m) {
QStandardItem *selectThread = nullptr;
foreach(auto i, ui->treeFrame->selectionModel()->selectedIndexes()) {
selectThread = m->itemFromIndex(i);
if (selectThread) {
if (selectThread->data(Qt::UserRole).canConvert<ThreadInfo>()) {
break;
}
}
}
if (selectThread) {
ThreadInfo info = selectThread->data(Qt::UserRole).value<ThreadInfo>();
qDebug() << "inserting frames on" << info.id << info.m_name;

}
}
}
}

Expand Down
56 changes: 49 additions & 7 deletions debuginterface.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
Expand Down Expand Up @@ -213,7 +213,7 @@
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_1">
<property name="spacing">
<number>0</number>
</property>
Expand All @@ -224,13 +224,47 @@
</property>
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>Stack Frame</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="treeFrame">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Watch View</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonWatchAdd">
<widget class="QToolButton" name="buttonWatchAdd_2">
<property name="toolTip">
<string>Add Watch</string>
</property>
Expand All @@ -250,7 +284,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonWatchRemove">
<widget class="QToolButton" name="buttonWatchRemove_2">
<property name="toolTip">
<string>Remove Selected Watch</string>
</property>
Expand All @@ -270,7 +304,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonWatchClear">
<widget class="QToolButton" name="buttonWatchClear_2">
<property name="toolTip">
<string>Clear All Watchs</string>
</property>
Expand All @@ -292,7 +326,11 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="listWatchs"/>
<widget class="QListWidget" name="listWatchs_2">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -356,7 +394,11 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="listBreakpoints"/>
<widget class="QListWidget" name="listBreakpoints">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationDomain("none.unknown.com");
QCoreApplication::setApplicationName("embedded IDE");
MainWindow w;
a.setWindowIcon(QIcon(":/images/embedded-ide.png"));
adjustPath();
w.show();

Expand Down
32 changes: 30 additions & 2 deletions mapviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QProgressBar>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStyledItemDelegate>

Expand Down Expand Up @@ -302,6 +303,27 @@ class BarItemDelegate: public QStyledItemDelegate {
}
};

class SymbolSortFilter: public QSortFilterProxyModel
{
public:
SymbolSortFilter(QObject *parent = 0l) : QSortFilterProxyModel(parent)
{
setSourceModel(new QStandardItemModel(this));
}
QStandardItemModel *itemModel() { return static_cast<QStandardItemModel*>(sourceModel()); }
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
};

bool SymbolSortFilter::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QVariant leftData = sourceModel()->data(left, Qt::UserRole);
QVariant rightData = sourceModel()->data(right, Qt::UserRole);
bool ok1 = false, ok2 = false;
uint32_t l = leftData.toUInt(&ok1);
uint32_t r = rightData.toUInt(&ok2);
return (ok1 && ok2)? (l < r) : false;
}

BarItemDelegate::~BarItemDelegate()
{
}
Expand All @@ -320,11 +342,12 @@ MapViewer::MapViewer(QWidget *parent) :
ui->memoryTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->memoryTable->setItemDelegateForColumn(4, new BarItemDelegate(this));

ui->symbolsTable->setModel(new QStandardItemModel(this));
ui->symbolsTable->setModel(new SymbolSortFilter(this));
ui->symbolsTable->setEditTriggers(QTableView::NoEditTriggers);
ui->symbolsTable->setAlternatingRowColors(true);
ui->symbolsTable->header()->setStretchLastSection(true);
ui->symbolsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->symbolsTable->setSortingEnabled(true);
}

MapViewer::~MapViewer()
Expand Down Expand Up @@ -360,7 +383,7 @@ bool MapViewer::load(const QString &path)
items[4]->setData((r.used * 100.0) / r.size, Qt::UserRole);
memoryModel->appendRow(items);
}
auto symbolsTree = qobject_cast<QStandardItemModel*>(ui->symbolsTable->model());
auto symbolsTree = static_cast<SymbolSortFilter*>(ui->symbolsTable->model())->itemModel();
symbolsTree->clear();
symbolsTree->setHorizontalHeaderLabels(QStringList({tr("Name"),
tr("Store address"),
Expand All @@ -376,17 +399,22 @@ bool MapViewer::load(const QString &path)
QList<QStandardItem*> items;
items += new QStandardItem(name.isEmpty()? tr("Symbols without section") : name);
items += new QStandardItem(toHex(section.base));
items.last()->setData(section.base, Qt::UserRole);
items += new QStandardItem(toHex(section.load));
items.last()->setData(section.load, Qt::UserRole);
items += new QStandardItem(toHumanReadableSize(section.size));
items.last()->setData(section.size, Qt::UserRole);
symbolsTree->appendRow(items);
foreach(auto tru, section.translationUnits) {
if (tru.symbols.isEmpty())
continue;
QList<QStandardItem*> childItems;
childItems += new QStandardItem(tru.isNull()? tr("No unit") : tru.path);
childItems += new QStandardItem(tru.isNull()? QString() : toHex(tru.addr));
childItems.last()->setData(tru.addr, Qt::UserRole);
childItems += new QStandardItem();
childItems += new QStandardItem(toHumanReadableSize(tru.size));
childItems.last()->setData(tru.size, Qt::UserRole);
items.first()->appendRow(childItems);
foreach(auto symbol,tru.symbols) {
QList<QStandardItem*> symbolItems;
Expand Down
2 changes: 2 additions & 0 deletions qgdb/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct ThreadInfo {
QString m_func;
};

Q_DECLARE_METATYPE(ThreadInfo)

struct StackFrameEntry
{
public:
Expand Down

0 comments on commit 81d7918

Please sign in to comment.