Commit 1cc05705 authored by Héctor Mesa Jiménez's avatar Héctor Mesa Jiménez Committed by Christoph Cullmann
Browse files

gdbplugin: fixed interrupt action for DAP backend

When using the GDB backend, the debuggee program can be
interrupted either by clicking on the "interrupt/stop" action
or by clicking "set breakpoint" if the execution is not already
stopped.

This path fix the DAP backend behaviour, so that all backends
do the same.
parent 98a85761
Pipeline #254571 passed with stage
in 18 minutes and 35 seconds
......@@ -133,6 +133,11 @@ bool Backend::canMove() const
return m_debugger && m_debugger->canMove();
}
bool Backend::canContinue() const
{
return m_debugger && m_debugger->canContinue();
}
void Backend::toggleBreakpoint(QUrl const &url, int line)
{
if (m_debugger)
......
......@@ -32,6 +32,7 @@ public:
bool supportsRunToCursor() const override;
bool canSetBreakpoints() const override;
bool canMove() const override;
bool canContinue() const override;
void toggleBreakpoint(QUrl const &url, int line) override;
void movePC(QUrl const &url, int line) override;
void runToCursor(QUrl const &url, int line) override;
......
......@@ -73,6 +73,12 @@ bool DebugView::canMove() const
return debuggerRunning();
}
bool DebugView::canContinue() const
{
// true to preserve the behaviour previous to DAP
return true;
}
void DebugView::runDebugger(const GDBTargetConf &conf, const QStringList &ioFifos)
{
if (conf.executable.isEmpty()) {
......
......@@ -37,6 +37,7 @@ public:
bool supportsRunToCursor() const override;
bool canSetBreakpoints() const override;
bool canMove() const override;
bool canContinue() const override;
void toggleBreakpoint(QUrl const &url, int line) override;
void movePC(QUrl const &url, int line) override;
......
......@@ -50,7 +50,8 @@ void DapDebugView::resetState(State state)
{
m_requests = 0;
m_runToCursor = std::nullopt;
m_currentThread = std::nullopt;
if (state != Running)
m_currentThread = std::nullopt;
m_watchedThread = std::nullopt;
m_currentFrame = std::nullopt;
m_commandQueue.clear();
......@@ -309,14 +310,26 @@ void DapDebugView::onContinuedEvent(const dap::ContinuedEvent &info)
void DapDebugView::onRunning()
{
setState(State::Running);
Q_EMIT outputText(printEvent(i18n("(running)")));
// if there is not thread, request in case pause is called
if (!m_currentThread) {
pushRequest();
m_client->requestThreads();
}
}
void DapDebugView::onThreads(const QList<dap::Thread> &threads)
{
Q_EMIT threadInfo(dap::Thread(-1), false);
for (const auto &thread : threads) {
Q_EMIT threadInfo(thread, thread.id == m_currentThread.value_or(-1));
if (!m_currentThread) {
if (!threads.isEmpty()) {
m_currentThread = threads[0].id;
}
} else {
Q_EMIT threadInfo(dap::Thread(-1), false);
for (const auto &thread : threads) {
Q_EMIT threadInfo(thread, thread.id == m_currentThread.value_or(-1));
}
}
popRequest();
}
......@@ -775,6 +788,11 @@ bool DapDebugView::canMove() const
return isRunningState();
}
bool DapDebugView::canContinue() const
{
return (m_state == Initializing) || (m_state == Stopped);
}
bool DapDebugView::debuggerRunning() const
{
return m_client && (m_state != None);
......@@ -1432,11 +1450,16 @@ void DapDebugView::setFileSearchPaths(const QStringList & /*paths*/)
void DapDebugView::slotInterrupt()
{
if (isRunningState()) {
tryTerminate();
} else {
tryDisconnect();
if (!isRunningState()) {
return;
}
if (!m_currentThread) {
Q_EMIT outputError(newLine(i18n("missing thread id")));
return;
}
m_client->requestPause(*m_currentThread);
}
void DapDebugView::slotStepInto()
......@@ -1517,6 +1540,12 @@ void DapDebugView::slotKill()
Q_EMIT gdbEnded();
return;
}
// if it is running, interrupt instead of killing
if (isRunningState() && !this->canContinue()) {
slotInterrupt();
return;
}
if (!m_shutdown.userAction) {
if (isRunningState()) {
shutdownUntil(PostMortem);
......
......@@ -34,6 +34,7 @@ public:
bool supportsRunToCursor() const override;
bool canSetBreakpoints() const override;
bool canMove() const override;
bool canContinue() const override;
void toggleBreakpoint(QUrl const &url, int line) override;
void movePC(QUrl const &url, int line) override;
......
......@@ -46,6 +46,10 @@ public:
* true if breakpoints can be set/unset
*/
virtual bool canSetBreakpoints() const = 0;
/**
* true if execution can continue
*/
virtual bool canContinue() const = 0;
/**
* true if basic movement actions can be used
*/
......
......@@ -456,7 +456,7 @@ void KatePluginGDBView::enableDebugActions(bool enable)
actionCollection()->action(QStringLiteral("move_pc"))->setEnabled(enable && m_debugView->supportsMovePC());
actionCollection()->action(QStringLiteral("run_to_cursor"))->setEnabled(enable && m_debugView->supportsRunToCursor());
actionCollection()->action(QStringLiteral("popup_gdb"))->setEnabled(enable);
actionCollection()->action(QStringLiteral("continue"))->setEnabled(enable);
actionCollection()->action(QStringLiteral("continue"))->setEnabled(enable && m_debugView->canContinue());
actionCollection()->action(QStringLiteral("print_value"))->setEnabled(enable);
// "toggle breakpoint" doubles as interrupt while the program is running
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment