forked from qt-creator/qt-creator
LLDB-DAP: Handle source mapping and additional debugger startup commands
This way we can step into Qt source code, and run startup commands like `process handle SIGSEGV --notify true --pass true --stop true` Change-Id: I495c1ef1554157989f4013473c22217e2d980053 Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
|
#include <debugger/debuggeractions.h>
|
||||||
#include <debugger/debuggermainwindow.h>
|
#include <debugger/debuggermainwindow.h>
|
||||||
|
#include <debugger/debuggersourcepathmappingwidget.h>
|
||||||
|
|
||||||
#include <utils/mimeconstants.h>
|
#include <utils/mimeconstants.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
|
|
||||||
@@ -112,22 +115,68 @@ LldbDapEngine::LldbDapEngine()
|
|||||||
setDebuggerType("DAP");
|
setDebuggerType("DAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonArray LldbDapEngine::sourceMap() const
|
||||||
|
{
|
||||||
|
QJsonArray sourcePathMapping;
|
||||||
|
const SourcePathMap sourcePathMap
|
||||||
|
= mergePlatformQtPath(runParameters(), settings().sourcePathMap());
|
||||||
|
for (auto it = sourcePathMap.constBegin(), cend = sourcePathMap.constEnd(); it != cend; ++it) {
|
||||||
|
sourcePathMapping.append(QJsonArray{
|
||||||
|
{it.key(), expand(it.value())},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return sourcePathMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray LldbDapEngine::preRunCommands() const
|
||||||
|
{
|
||||||
|
const QStringList lines = settings().gdbStartupCommands().split('\n')
|
||||||
|
+ runParameters().additionalStartupCommands.split('\n');
|
||||||
|
QJsonArray result;
|
||||||
|
for (const QString &line : lines) {
|
||||||
|
const QString trimmed = line.trimmed();
|
||||||
|
if (!trimmed.isEmpty() && !trimmed.startsWith('#'))
|
||||||
|
result.append(trimmed);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void LldbDapEngine::handleDapInitialize()
|
void LldbDapEngine::handleDapInitialize()
|
||||||
{
|
{
|
||||||
|
// Documentation at:
|
||||||
|
// * https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-dap#lldb-dap
|
||||||
|
// * https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/package.json
|
||||||
|
|
||||||
|
const DebuggerRunParameters &rp = runParameters();
|
||||||
|
|
||||||
if (!isLocalAttachEngine()) {
|
if (!isLocalAttachEngine()) {
|
||||||
DapEngine::handleDapInitialize();
|
m_dapClient->postRequest(
|
||||||
|
"launch",
|
||||||
|
QJsonObject{
|
||||||
|
{"noDebug", false},
|
||||||
|
{"program", rp.inferior.command.executable().path()},
|
||||||
|
{"args", rp.inferior.command.arguments()},
|
||||||
|
{"cwd", rp.inferior.workingDirectory.path()},
|
||||||
|
{"sourceMap", sourceMap()},
|
||||||
|
{"preRunCommands", preRunCommands()},
|
||||||
|
{"__restart", ""},
|
||||||
|
});
|
||||||
|
|
||||||
|
qCDebug(logCategory()) << "handleDapLaunch";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
|
QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
|
||||||
|
|
||||||
const DebuggerRunParameters &rp = runParameters();
|
|
||||||
m_dapClient->postRequest(
|
m_dapClient->postRequest(
|
||||||
"attach",
|
"attach",
|
||||||
QJsonObject{
|
QJsonObject{
|
||||||
{"program", rp.inferior.command.executable().path()},
|
{"program", rp.inferior.command.executable().path()},
|
||||||
{"pid", QString::number(rp.attachPID.pid())},
|
{"pid", QString::number(rp.attachPID.pid())},
|
||||||
{"__restart", ""}});
|
{"sourceMap", sourceMap()},
|
||||||
|
{"preRunCommands", preRunCommands()},
|
||||||
|
{"__restart", ""},
|
||||||
|
});
|
||||||
|
|
||||||
qCDebug(logCategory()) << "handleDapAttach";
|
qCDebug(logCategory()) << "handleDapAttach";
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,9 @@ private:
|
|||||||
bool isLocalAttachEngine() const;
|
bool isLocalAttachEngine() const;
|
||||||
bool acceptsBreakpoint(const BreakpointParameters &bp) const override;
|
bool acceptsBreakpoint(const BreakpointParameters &bp) const override;
|
||||||
const QLoggingCategory &logCategory() override;
|
const QLoggingCategory &logCategory() override;
|
||||||
|
|
||||||
|
QJsonArray sourceMap() const;
|
||||||
|
QJsonArray preRunCommands() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Debugger::Internal
|
} // Debugger::Internal
|
||||||
|
Reference in New Issue
Block a user