work save

This commit is contained in:
royqh1979@gmail.com 2021-07-31 14:04:43 +08:00
parent 66da8f2df8
commit ffadc81dff
5 changed files with 322 additions and 6 deletions

View File

@ -41,7 +41,7 @@ void Debugger::start()
} }
mReader = new DebugReader(this); mReader = new DebugReader(this);
mReader->setDebuggerPath(debuggerPath); mReader->setDebuggerPath(debuggerPath);
connect(mReader, &QThread::finished,this,&Debugger::stop); connect(mReader, &QThread::finished,this,&Debugger::clearUpReader);
connect(mReader, &DebugReader::parseFinished,this,&Debugger::syncFinishedParsing,Qt::BlockingQueuedConnection); connect(mReader, &DebugReader::parseFinished,this,&Debugger::syncFinishedParsing,Qt::BlockingQueuedConnection);
connect(mReader, &DebugReader::changeDebugConsoleLastLine,this,&Debugger::onChangeDebugConsoleLastline,Qt::BlockingQueuedConnection); connect(mReader, &DebugReader::changeDebugConsoleLastLine,this,&Debugger::onChangeDebugConsoleLastline,Qt::BlockingQueuedConnection);
mReader->start(); mReader->start();
@ -65,16 +65,20 @@ void Debugger::start()
//Application.HintHidePause := 5000; //Application.HintHidePause := 5000;
} }
void Debugger::stop() {
void Debugger::stop() if (mExecuting) {
mReader->stopDebug();
}
}
void Debugger::clearUpReader()
{ {
if (mExecuting) { if (mExecuting) {
mExecuting = false; mExecuting = false;
//stop debugger //stop debugger
mReader->stopDebug();
mReader->deleteLater(); mReader->deleteLater();
mReader=nullptr; mReader=nullptr;
// if WatchVarList.Count = 0 then // nothing worth showing, restore view // if WatchVarList.Count = 0 then // nothing worth showing, restore view
// MainForm.LeftPageControl.ActivePageIndex := LeftPageIndexBackup; // MainForm.LeftPageControl.ActivePageIndex := LeftPageIndexBackup;
@ -1229,6 +1233,7 @@ void DebugReader::run()
} }
if (mStop) { if (mStop) {
mProcess->terminate(); mProcess->terminate();
break;
} }
if (errorOccurred) if (errorOccurred)
break; break;
@ -1430,3 +1435,124 @@ const QList<PTrace> &BacktraceModel::backtraces() const
{ {
return mList; return mList;
} }
QModelIndex WatchModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row,column,parent))
return QModelIndex();
WatchVar* parentItem;
PWatchVar pChild;
if (!parent.isValid()) {
parentItem = nullptr;
pChild = mWatchVars[row];
} else {
parentItem = static_cast<WatchVar*>(parent.internalPointer());
pChild = parentItem->children[row];
}
if (pChild)
return createIndex(row,column,pChild.get());
return QModelIndex();
}
static int getWatchIndex(WatchVar* var, const QList<PWatchVar> list) {
for (int i=0;i<list.size();i++) {
PWatchVar v = list[i];
if (v.get() == var) {
return i;
}
}
}
QModelIndex WatchModel::parent(const QModelIndex &index) const
{
if (!index.isValid()) {
return QModelIndex();
}
WatchVar* childItem = static_cast<WatchVar*>(index.internalPointer());
WatchVar* parentItem =childItem->parent;
//parent is root
if (parentItem == nullptr) {
return QModelIndex();
}
int row;
WatchVar* grandItem = parentItem->parent;
if (grandItem == nullptr) {
row = getWatchIndex(parentItem,mWatchVars);
} else {
row = getWatchIndex(parentItem,grandItem->children);
}
return createIndex(row,0,parentItem);
}
int WatchModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return mWatchVars.count();
} else {
WatchVar* parentItem = static_cast<WatchVar*>(parent.internalPointer());
return parentItem->children.count();
}
}
int WatchModel::columnCount(const QModelIndex &parent) const
{
return 1;
}
void WatchModel::addWatchVar(PWatchVar watchVar)
{
for (PWatchVar var:mWatchVars) {
if (watchVar->name == var->name) {
return;
}
}
mWatchVars.append(watchVar);
}
void WatchModel::removeWatchVar(const QString &name)
{
for (PWatchVar var:mWatchVars) {
if (name == var->name) {
mWatchVars.removeOne(var);
}
}
}
void WatchModel::removeWatchVar(int gdbIndex)
{
for (PWatchVar var:mWatchVars) {
if (gdbIndex == var->gdbIndex) {
mWatchVars.removeOne(var);
}
}
}
void WatchModel::clear()
{
mWatchVars.clear();
}
QList<PWatchVar> &WatchModel::watchVars()
{
return mWatchVars;
}
PWatchVar WatchModel::findWatchVar(const QString &name)
{
for (PWatchVar var:mWatchVars) {
if (name == var->name) {
return var;
}
}
}
PWatchVar WatchModel::findWatchVar(int gdbIndex)
{
for (PWatchVar var:mWatchVars) {
if (gdbIndex == var->gdbIndex) {
return var;
}
}
}

View File

@ -48,13 +48,17 @@ struct DebugCommand{
}; };
using PDebugCommand = std::shared_ptr<DebugCommand>; using PDebugCommand = std::shared_ptr<DebugCommand>;
struct WatchVar;
using PWatchVar = std::shared_ptr<WatchVar>;
struct WatchVar { struct WatchVar {
QString name; QString name;
QString text;
QString value;
int gdbIndex; int gdbIndex;
QList<PWatchVar> children;
WatchVar * parent; //use raw point to prevent circular-reference
}; };
using PWatchVar = std::shared_ptr<WatchVar>;
struct Breakpoint { struct Breakpoint {
int line; int line;
@ -99,6 +103,7 @@ private:
}; };
class BacktraceModel : public QAbstractTableModel { class BacktraceModel : public QAbstractTableModel {
Q_OBJECT
// QAbstractItemModel interface // QAbstractItemModel interface
public: public:
explicit BacktraceModel(QObject *parent = nullptr); explicit BacktraceModel(QObject *parent = nullptr);
@ -114,6 +119,31 @@ private:
QList<PTrace> mList; QList<PTrace> mList;
}; };
class WatchModel: public QAbstractItemModel {
Q_OBJECT
public:
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
void addWatchVar(PWatchVar watchVar);
void removeWatchVar(const QString& name);
void removeWatchVar(int gdbIndex);
void clear();
const QList<PWatchVar>& watchVars();
PWatchVar findWatchVar(const QString& name);
PWatchVar findWatchVar(int gdbIndex);
private:
QList<PWatchVar> mWatchVars;
};
class DebugReader; class DebugReader;
class Editor; class Editor;
@ -181,6 +211,7 @@ private:
private slots: private slots:
void syncFinishedParsing(); void syncFinishedParsing();
void onChangeDebugConsoleLastline(const QString& text); void onChangeDebugConsoleLastline(const QString& text);
void clearUpReader();
private: private:
bool mExecuting; bool mExecuting;
bool mCommandChanged; bool mCommandChanged;

View File

@ -1294,3 +1294,80 @@ bool MainWindow::debugInferiorhasBreakpoint()
} }
return false; return false;
} }
void MainWindow::on_actionStep_Over_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("next", "");
mDebugger->updateDebugInfo();
// if (CPUForm) then
// CPUForm.UpdateInfo;
//WatchView.Items.EndUpdate();
//fDebugger.RefreshWatchVars;
}
}
void MainWindow::on_actionStep_Into_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("step", "");
mDebugger->updateDebugInfo();
// if (CPUForm) then
// CPUForm.UpdateInfo;
//WatchView.Items.EndUpdate();
//fDebugger.RefreshWatchVars;
}
}
void MainWindow::on_actionStep_Out_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("finish", "");
mDebugger->updateDebugInfo();
// if (CPUForm) then
// CPUForm.UpdateInfo;
//WatchView.Items.EndUpdate();
//fDebugger.RefreshWatchVars;
}
}
void MainWindow::on_actionRun_To_Cursor_triggered()
{
if (mDebugger->executing()) {
Editor *e=mEditorList->getEditor();
if (e!=nullptr) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("tbreak", QString(" %1").arg(e->caretY()));
mDebugger->sendCommand("continue", "");
mDebugger->updateDebugInfo();
// if (CPUForm) then
// CPUForm.UpdateInfo;
//WatchView.Items.EndUpdate();
//fDebugger.RefreshWatchVars;
}
}
}
void MainWindow::on_actionContinue_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("continue", "");
mDebugger->updateDebugInfo();
// if (CPUForm) then
// CPUForm.UpdateInfo;
//WatchView.Items.EndUpdate();
//fDebugger.RefreshWatchVars;
}
}

View File

@ -141,6 +141,16 @@ private slots:
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();
bool debugInferiorhasBreakpoint(); bool debugInferiorhasBreakpoint();
void on_actionStep_Over_triggered();
void on_actionStep_Into_triggered();
void on_actionStep_Out_triggered();
void on_actionRun_To_Cursor_triggered();
void on_actionContinue_triggered();
public slots: public slots:
void onCompileLog(const QString& msg); void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue); void onCompileIssue(PCompileIssue issue);

View File

@ -551,6 +551,11 @@
<addaction name="actionCompile_Run"/> <addaction name="actionCompile_Run"/>
<addaction name="actionRebuild"/> <addaction name="actionRebuild"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDebug"/>
<addaction name="actionStep_Over"/>
<addaction name="actionStep_Into"/>
<addaction name="actionRun_To_Cursor"/>
<addaction name="actionContinue"/>
<addaction name="actionStop_Execution"/> <addaction name="actionStop_Execution"/>
</widget> </widget>
<widget class="QMenu" name="menuEdit"> <widget class="QMenu" name="menuEdit">
@ -631,6 +636,10 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionDebug"/> <addaction name="actionDebug"/>
<addaction name="actionStep_Over"/>
<addaction name="actionStep_Into"/>
<addaction name="actionStep_Out"/>
<addaction name="actionContinue"/>
<addaction name="actionStop_Execution"/> <addaction name="actionStop_Execution"/>
</widget> </widget>
<action name="actionNew"> <action name="actionNew">
@ -915,6 +924,9 @@
<property name="text"> <property name="text">
<string>Stop Execution</string> <string>Stop Execution</string>
</property> </property>
<property name="shortcut">
<string>F6</string>
</property>
</action> </action>
<action name="actionDebug"> <action name="actionDebug">
<property name="icon"> <property name="icon">
@ -931,6 +943,66 @@
<string>F5</string> <string>F5</string>
</property> </property>
</action> </action>
<action name="actionStep_Over">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/028-Debug-StepOver.png</normalon>
</iconset>
</property>
<property name="text">
<string>Step Over</string>
</property>
<property name="shortcut">
<string>F7</string>
</property>
</action>
<action name="actionStep_Into">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/024-Debug-StepInto.png</normalon>
</iconset>
</property>
<property name="text">
<string>Step Into</string>
</property>
<property name="shortcut">
<string>F8</string>
</property>
</action>
<action name="actionStep_Out">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/026-Debug-StepOut.png</normalon>
</iconset>
</property>
<property name="text">
<string>Step Out</string>
</property>
<property name="shortcut">
<string>Ctrl+F8</string>
</property>
</action>
<action name="actionRun_To_Cursor">
<property name="text">
<string>Run To Cursor</string>
</property>
<property name="shortcut">
<string>Ctrl+F5</string>
</property>
</action>
<action name="actionContinue">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/021-Debug-Continue.png</normalon>
</iconset>
</property>
<property name="text">
<string>Continue</string>
</property>
<property name="shortcut">
<string>F4</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>