Skip to content

Commit

Permalink
feat: [debugger] add functional of "run to line"
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Aug 14, 2024
1 parent 529b658 commit e292385
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/common/util/eventdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ OPI_OBJECT(editor,
//right-cliked menu, Related to debugging
OPI_INTERFACE(setBreakpointCondition, "fileName", "line")
OPI_INTERFACE(jumpToLine, "fileName", "line")
OPI_INTERFACE(runToLine, "fileName", "line")
OPI_INTERFACE(contextMenu, "menu")
OPI_INTERFACE(marginMenu, "menu")
)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codeeditor/gui/private/texteditor_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ void TextEditorPrivate::showMarginMenu()
if (debuggerService->getDebugState() == AbstractDebugger::RunState::kStopped) {
menu.addSeparator();
menu.addAction(tr("jump to %1 line").arg(line + 1), q, [this, line] { editor.jumpToLine(fileName, line + 1); });
menu.addAction(tr("run to %1 line").arg(line + 1), q, [this, line] { editor.runToLine(fileName, line + 1); });
}

// notify other plugin to add action.
Expand Down
24 changes: 24 additions & 0 deletions src/plugins/debugger/dap/dapdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,25 @@ void DAPDebugger::jumpToLine(const QString &filePath, int lineNumber)
}
}

void DAPDebugger::runToLine(const QString &filePath, int lineNumber)
{
if (!d->currentSession)
return;

if (d->runState == kStopped) {
dap::array<IBreakpointData> rawBreakpoints;
IBreakpointData bpData;
bpData.id = QUuid::createUuid().toString().toStdString();
bpData.lineNumber = lineNumber;
bpData.enabled = true;
bpData.hitCondition = "1";
rawBreakpoints.push_back(bpData);

debugService->addBreakpoints(filePath, rawBreakpoints, d->currentSession);
continueDebug();
}
}

void DAPDebugger::evaluateWatchVariable(const QString &expression)
{
IVariable var;
Expand Down Expand Up @@ -837,6 +856,11 @@ void DAPDebugger::handleEvents(const dpf::Event &event)
int line = event.property("line").toInt();

jumpToLine(filePath, line);
} else if (event.data() == editor.runToLine.name) {
QString filePath = event.property("fileName").toString();
int line = event.property("line").toInt();

runToLine(filePath, line);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/debugger/dap/dapdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public slots:
void switchBreakpointsStatus(const QString &filePath, int lineNumber, bool enabled);
void setBreakpointCondition(const QString &filePath, int lineNumber, const QString &expression);
void jumpToLine(const QString &filePath, int lineNumber);
void runToLine(const QString &filePath, int lineNumber);
void evaluateWatchVariable(const QString &expression);

bool getLocals(dap::integer frameId, IVariables *out);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/debugger/dap/debugsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ void DebugSession::sendBreakpoints(const QString &sourcePath, dap::array<IBreakp
SourceBreakpoint bt;
bt.line = it.lineNumber;
bt.condition = it.condition;
if (it.hitCondition.has_value()) {
bt.hitCondition = it.hitCondition;
model->removeBreakpoint(sourcePath, bt.line);
}
breakpoints.push_back(bt);
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/debugadapter/dapsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ InitializeResponse DapSession::handleInitializeReq(const InitializeRequest &requ
response.supportsCompletionsRequest = true;
response.supportsDisassembleRequest = true;
response.supportsGotoTargetsRequest = true;
response.supportsHitConditionalBreakpoints = true;

Log("--> Server sent initialize response to client\n")
return response;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/debugadapter/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Debugger : public QObject

virtual void updateBreakpoints(const QString &file, const QList<dap::SourceBreakpoint> &sourceBps) = 0;
virtual QString breakRemoveAll() = 0;
virtual QString breakInsert(const QString& path, const QString &condition = "") = 0;
virtual QString breakInsert(const QString& path, const QString &condition = "", bool isTemp = false) = 0;
virtual QString breakRemove(int bpid) = 0;

virtual void pause() = 0;
Expand Down
18 changes: 15 additions & 3 deletions src/tools/debugadapter/debugger/gdbmi/gdbdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ QString GDBDebugger::breakRemoveAll()
return ("-break-delete");
}

QString GDBDebugger::breakInsert(const QString &path, const QString &condition)
QString GDBDebugger::breakInsert(const QString &path, const QString &condition, bool isTemp)
{
if (condition.isEmpty())
if (isTemp)
return QString{"-break-insert -t -f %1"}.arg(path);
else if (condition.isEmpty())
return QString{"-break-insert -f %1"}.arg(path);
else
return QString{"-break-insert -c \"%1\" -f %2"}.arg(condition, path);
Expand Down Expand Up @@ -193,10 +195,14 @@ void GDBDebugger::updateBreakpoints(const QString &file, const QList<dap::Source
{
QSet<int> curLines;
QMap<int, QString> lineConditionMap;
QSet<int> tempBreakPoints;

for (auto bp : sourceBps) {
QString condition = bp.condition.has_value() ? QString::fromStdString(bp.condition.value()) : "";
lineConditionMap.insert(bp.line, condition);
if (bp.hitCondition.has_value() && bp.hitCondition.value() == "1")
tempBreakPoints.insert(bp.line);
else
lineConditionMap.insert(bp.line, condition);
}

//remove canceled bp and bp which have condition (to update)
Expand Down Expand Up @@ -229,6 +235,12 @@ void GDBDebugger::updateBreakpoints(const QString &file, const QList<dap::Source
}
}
}

// append temp breakpoints
for (const auto &bpLine : tempBreakPoints) {
auto filePath = file + ":" + QString::number(bpLine);
DebugManager::instance()->breakInsert(filePath, "", true);
}
}

void GDBDebugger::parseBreakPoint(const QVariant& var)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/debugadapter/debugger/gdbmi/gdbdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GDBDebugger : public Debugger
QString quit() override;
QString kill() override;

QString breakInsert(const QString& path, const QString &condition = "") override;
QString breakInsert(const QString& path, const QString &condition = "", bool isTemp = false) override;
QString breakRemove(int bpid) override;
QString breakRemoveAll() override;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/debugadapter/debugger/javascript/jsdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void JSDebugger::updateBreakpoints(const QString &file, const QList<dap::SourceB
}
}

QString JSDebugger::breakInsert(const QString &path, const QString &condition)
QString JSDebugger::breakInsert(const QString &path, const QString &condition, bool isTemp)
{
Q_UNUSED(condition)
return ".break " + path;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/debugadapter/debugger/javascript/jsdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JSDebugger : public Debugger
QString kill() override;

void updateBreakpoints(const QString &file, const QList<dap::SourceBreakpoint> &sourceBps) override;
QString breakInsert(const QString& path, const QString &condition = "") override;
QString breakInsert(const QString& path, const QString &condition = "", bool isTemp = false) override;
QString breakRemove(int bpid) override;
QString breakRemoveAll() override;

Expand Down
4 changes: 2 additions & 2 deletions src/tools/debugadapter/debugmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ void DebugManager::breakRemoveAll()
}, true);
}

void DebugManager::breakInsert(const QString &path, const QString &condition)
void DebugManager::breakInsert(const QString &path, const QString &condition, bool isTemp)
{
commandAndResponse(d->debugger->breakInsert(path, condition), [this](const QVariant& r) {
commandAndResponse(d->debugger->breakInsert(path, condition, isTemp), [this](const QVariant& r) {
d->debugger->parseBreakPoint(r);
}, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/debugadapter/debugmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DebugManager : public QObject

void updateBreakpoints(const QString &file, const QList<dap::SourceBreakpoint> &sourceBps);
void breakRemoveAll();
void breakInsert(const QString& path, const QString &condition = "");
void breakInsert(const QString& path, const QString &condition = "", bool isTemp = false);
void removeBreakpointInFile(const QString &filePath);
void breakRemove(int bpid);

Expand Down

0 comments on commit e292385

Please sign in to comment.