Files
qt-creator/src/plugins/debugger/debuggerruncontrol.cpp

1188 lines
41 KiB
C++
Raw Normal View History

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
2008-12-02 15:08:31 +01:00
#include "debuggerruncontrol.h"
#include "debuggermainwindow.h"
#include "debuggertr.h"
2008-12-02 12:01:29 +01:00
#include "console/console.h"
#include "debuggeractions.h"
#include "debuggerengine.h"
#include "debuggerinternalconstants.h"
#include "debuggerkitaspect.h"
#include "debuggerrunconfigurationaspect.h"
#include "breakhandler.h"
#include "enginemanager.h"
2010-06-22 12:28:05 +02:00
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/environmentaspect.h> // For the environment
2008-12-02 12:01:29 +01:00
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/toolchain.h>
2008-12-02 12:01:29 +01:00
#include <remotelinux/remotelinux_constants.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/portlist.h>
#include <utils/qtcprocess.h>
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
#include <utils/temporarydirectory.h>
#include <utils/temporaryfile.h>
#include <utils/url.h>
#include <utils/winutils.h>
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/messagebox.h>
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
#include <qmldebug/qmldebugcommandlinearguments.h>
2008-12-09 15:25:01 +01:00
#include <qtsupport/qtkitaspect.h>
#include <QTcpServer>
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
#include <QTimer>
2008-12-02 12:01:29 +01:00
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
using namespace Core;
using namespace Debugger::Internal;
using namespace ProjectExplorer;
using namespace Utils;
enum { debug = 0 };
namespace Debugger {
namespace Internal {
DebuggerEngine *createCdbEngine();
DebuggerEngine *createGdbEngine();
DebuggerEngine *createPdbEngine();
DebuggerEngine *createQmlEngine();
DebuggerEngine *createLldbEngine();
BareMetal: Long live support for KEIL uVision v5.x debugger This patch adds debugger integration from the KEIL uVision IDE: * http://www2.keil.com/mdk5/uvision/ This IDE has the uVision Socket Interface (UVSC) that allows to the applications configuration, building and debugging: * http://www.keil.com/appnotes/docs/apnt_198.asp Besides, it provides a binary client libraries for Windows, which are implements some API which we are use in this patch. Currently implemented the following features: * Enumeration of a stack frames. * Enumeration of a threads (tasks). * Registers view (read/write). * Local variables view (read/write). * Watchers view (read/write). * Disassembler view. * Current location marker. * Break-points. * Step-in. * Step-over. * Step-out. * Step-by-instruction. * Start/stop/pause/continue debugger. * Auto-detection for the installed uVision instances (as debuggers). * Wizard for choosing and configuring of the UVSC debug providers. At this moment added support only for the 32-bit ARM devices, provided by the STMicroelectronics: https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html For this are implemented two debugger providers: * Simulator - allow to simulate the target device. * ST-Link v2 - it is a HW debugger. This implementation tested only with the QBS using the following target boards: * NUCLEO-F767ZI (based on STM32F767ZIT6 MCU). * STM32F4DISCOVERY (based on STM32F407VG MCU). * STM32F103x (based on STM32F103C8T6 MCU). A more detailed information about this patch can be found in a bug-tracker. Fixes: QTCREATORBUG-23426 Change-Id: Ie36a1f7430b56c33d6665cc35e43fe9bd95d28f1 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2020-01-24 17:08:27 +03:00
DebuggerEngine *createUvscEngine();
DebuggerEngine *createDapEngine(Utils::Id runMode = ProjectExplorer::Constants::NO_RUN_MODE);
static QString noEngineMessage()
{
return Tr::tr("Unable to create a debugging engine.");
}
static QString noDebuggerInKitMessage()
{
return Tr::tr("The kit does not have a debugger set.");
}
class CoreUnpacker final : public RunWorker
{
public:
CoreUnpacker(RunControl *runControl, const FilePath &coreFilePath)
: RunWorker(runControl), m_coreFilePath(coreFilePath)
{}
FilePath coreFileName() const { return m_tempCoreFilePath; }
private:
~CoreUnpacker() final
{
if (m_tempCoreFile.isOpen())
m_tempCoreFile.close();
m_tempCoreFilePath.removeFile();
}
void start() final
{
{
Utils::TemporaryFile tmp("tmpcore-XXXXXX");
tmp.open();
m_tempCoreFilePath = FilePath::fromString(tmp.fileName());
}
m_coreUnpackProcess.setWorkingDirectory(TemporaryDirectory::masterDirectoryFilePath());
connect(&m_coreUnpackProcess, &Process::done, this, [this] {
if (m_coreUnpackProcess.error() == QProcess::UnknownError) {
reportStopped();
return;
}
reportFailure("Error unpacking " + m_coreFilePath.toUserOutput());
});
const QString msg = Tr::tr("Unpacking core file to %1");
appendMessage(msg.arg(m_tempCoreFilePath.toUserOutput()), LogMessageFormat);
if (m_coreFilePath.endsWith(".lzo")) {
m_coreUnpackProcess.setCommand({"lzop", {"-o", m_tempCoreFilePath.path(),
"-x", m_coreFilePath.path()}});
reportStarted();
m_coreUnpackProcess.start();
return;
}
if (m_coreFilePath.endsWith(".gz")) {
appendMessage(msg.arg(m_tempCoreFilePath.toUserOutput()), LogMessageFormat);
m_tempCoreFile.setFileName(m_tempCoreFilePath.path());
m_tempCoreFile.open(QFile::WriteOnly);
connect(&m_coreUnpackProcess, &Process::readyReadStandardOutput, this, [this] {
m_tempCoreFile.write(m_coreUnpackProcess.readAllRawStandardOutput());
});
m_coreUnpackProcess.setCommand({"gzip", {"-c", "-d", m_coreFilePath.path()}});
reportStarted();
m_coreUnpackProcess.start();
return;
}
QTC_CHECK(false);
reportFailure("Unknown file extension in " + m_coreFilePath.toUserOutput());
}
QFile m_tempCoreFile;
FilePath m_coreFilePath;
FilePath m_tempCoreFilePath;
Process m_coreUnpackProcess;
};
class DebuggerRunToolPrivate
{
public:
QPointer<CoreUnpacker> coreUnpacker;
bool addQmlServerInferiorCommandLineArgumentIfNeeded = false;
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
int snapshotCounter = 0;
int engineStartsNeeded = 0;
int engineStopsNeeded = 0;
QString runId;
// Terminal
Process terminalProc;
DebuggerRunTool::AllowTerminal allowTerminal = DebuggerRunTool::DoAllowTerminal;
// DebugServer
Process debuggerServerProc;
Utils::ProcessHandle serverAttachPid;
bool serverUseMulti = true;
bool serverEssential = true;
};
} // namespace Internal
static bool breakOnMainNextTime = false;
void DebuggerRunTool::setBreakOnMainNextTime()
{
breakOnMainNextTime = true;
}
void DebuggerRunTool::setStartMode(DebuggerStartMode startMode)
{
m_runParameters.startMode = startMode;
if (startMode == AttachToQmlServer) {
m_runParameters.cppEngineType = NoEngineType;
m_runParameters.isQmlDebugging = true;
m_runParameters.closeMode = KillAtClose;
// FIXME: This is horribly wrong.
// get files from all the projects in the session
QList<Project *> projects = ProjectManager::projects();
if (Project *startupProject = ProjectManager::startupProject()) {
// startup project first
projects.removeOne(startupProject);
projects.insert(0, startupProject);
}
for (Project *project : std::as_const(projects))
m_runParameters.projectSourceFiles.append(project->files(Project::SourceFiles));
if (!projects.isEmpty())
m_runParameters.projectSourceDirectory = projects.first()->projectDirectory();
}
}
void DebuggerRunTool::setCloseMode(DebuggerCloseMode closeMode)
{
m_runParameters.closeMode = closeMode;
}
void DebuggerRunTool::setAttachPid(ProcessHandle pid)
{
m_runParameters.attachPID = pid;
}
void DebuggerRunTool::setAttachPid(qint64 pid)
{
m_runParameters.attachPID = ProcessHandle(pid);
}
void DebuggerRunTool::setSysRoot(const Utils::FilePath &sysRoot)
{
m_runParameters.sysRoot = sysRoot;
}
void DebuggerRunTool::setSymbolFile(const FilePath &symbolFile)
{
if (symbolFile.isEmpty())
reportFailure(Tr::tr("Cannot debug: Local executable is not set."));
m_runParameters.symbolFile = symbolFile;
}
void DebuggerRunTool::setLldbPlatform(const QString &platform)
{
m_runParameters.platform = platform;
}
void DebuggerRunTool::setRemoteChannel(const QString &channel)
{
m_runParameters.remoteChannel = channel;
}
void DebuggerRunTool::setRemoteChannel(const QUrl &url)
{
m_runParameters.remoteChannel = QString("%1:%2").arg(url.host()).arg(url.port());
}
QString DebuggerRunTool::remoteChannel() const
{
return m_runParameters.remoteChannel;
}
void DebuggerRunTool::setRemoteChannel(const QString &host, int port)
{
m_runParameters.remoteChannel = QString("%1:%2").arg(host).arg(port);
}
void DebuggerRunTool::setUseExtendedRemote(bool on)
{
m_runParameters.useExtendedRemote = on;
}
void DebuggerRunTool::setUseContinueInsteadOfRun(bool on)
{
m_runParameters.useContinueInsteadOfRun = on;
}
void DebuggerRunTool::setUseTargetAsync(bool on)
{
m_runParameters.useTargetAsync = on;
}
void DebuggerRunTool::setContinueAfterAttach(bool on)
{
m_runParameters.continueAfterAttach = on;
}
void DebuggerRunTool::setSkipExecutableValidation(bool on)
{
m_runParameters.skipExecutableValidation = on;
}
void DebuggerRunTool::setUseCtrlCStub(bool on)
{
m_runParameters.useCtrlCStub = on;
}
void DebuggerRunTool::setBreakOnMain(bool on)
{
m_runParameters.breakOnMain = on;
}
void DebuggerRunTool::setUseTerminal(bool on)
{
m_runParameters.useTerminal = on;
}
void DebuggerRunTool::setCommandsAfterConnect(const QString &commands)
{
m_runParameters.commandsAfterConnect = commands;
}
void DebuggerRunTool::setCommandsForReset(const QString &commands)
{
m_runParameters.commandsForReset = commands;
}
void DebuggerRunTool::setDebugInfoLocation(const FilePath &debugInfoLocation)
{
m_runParameters.debugInfoLocation = debugInfoLocation;
}
void DebuggerRunTool::setQmlServer(const QUrl &qmlServer)
{
m_runParameters.qmlServer = qmlServer;
}
void DebuggerRunTool::setIosPlatform(const QString &platform)
{
m_runParameters.platform = platform;
}
void DebuggerRunTool::setDeviceSymbolsRoot(const QString &deviceSymbolsRoot)
{
m_runParameters.deviceSymbolsRoot = deviceSymbolsRoot;
}
void DebuggerRunTool::setTestCase(int testCase)
{
m_runParameters.testCase = testCase;
}
void DebuggerRunTool::setOverrideStartScript(const FilePath &script)
{
m_runParameters.overrideStartScript = script;
}
void DebuggerRunTool::setAbi(const Abi &abi)
{
m_runParameters.toolChainAbi = abi;
}
void DebuggerRunTool::setInferior(const ProcessRunData &runnable)
{
m_runParameters.inferior = runnable;
}
void DebuggerRunTool::setInferiorExecutable(const FilePath &executable)
{
m_runParameters.inferior.command.setExecutable(executable);
}
void DebuggerRunTool::setInferiorEnvironment(const Utils::Environment &env)
{
m_runParameters.inferior.environment = env;
}
void DebuggerRunTool::setRunControlName(const QString &name)
{
m_runParameters.displayName = name;
}
void DebuggerRunTool::setStartMessage(const QString &msg)
{
m_runParameters.startMessage = msg;
}
void DebuggerRunTool::setCoreFilePath(const FilePath &coreFile, bool isSnapshot)
{
if (coreFile.endsWith(".gz") || coreFile.endsWith(".lzo")) {
d->coreUnpacker = new CoreUnpacker(runControl(), coreFile);
addStartDependency(d->coreUnpacker);
}
m_runParameters.coreFile = coreFile;
m_runParameters.isSnapshot = isSnapshot;
}
void DebuggerRunTool::addQmlServerInferiorCommandLineArgumentIfNeeded()
{
d->addQmlServerInferiorCommandLineArgumentIfNeeded = true;
}
void DebuggerRunTool::modifyDebuggerEnvironment(const EnvironmentItems &items)
{
m_runParameters.debugger.environment.modify(items);
}
void DebuggerRunTool::setCrashParameter(const QString &event)
{
m_runParameters.crashParameter = event;
}
void DebuggerRunTool::addExpectedSignal(const QString &signal)
{
m_runParameters.expectedSignals.append(signal);
}
void DebuggerRunTool::addSearchDirectory(const Utils::FilePath &dir)
{
m_runParameters.additionalSearchDirectories.append(dir);
}
void DebuggerRunTool::start()
{
startTerminalIfNeededAndContinueStartup();
}
void DebuggerRunTool::startTerminalIfNeededAndContinueStartup()
{
if (d->allowTerminal == DoNotAllowTerminal)
m_runParameters.useTerminal = false;
// CDB has a built-in console that might be preferred by some.
const bool useCdbConsole = m_runParameters.cppEngineType == CdbEngineType
&& (m_runParameters.startMode == StartInternal
|| m_runParameters.startMode == StartExternal)
&& settings().useCdbConsole();
if (useCdbConsole)
m_runParameters.useTerminal = false;
if (!m_runParameters.useTerminal) {
continueAfterTerminalStart();
return;
}
// Actually start the terminal.
ProcessRunData stub = m_runParameters.inferior;
if (m_runParameters.runAsRoot) {
d->terminalProc.setRunAsRoot(true);
RunControl::provideAskPassEntry(stub.environment);
}
d->terminalProc.setTerminalMode(TerminalMode::Debug);
d->terminalProc.setRunData(stub);
connect(&d->terminalProc, &Process::started, this, [this] {
m_runParameters.applicationPid = d->terminalProc.processId();
m_runParameters.applicationMainThreadId = d->terminalProc.applicationMainThreadId();
continueAfterTerminalStart();
});
connect(&d->terminalProc, &Process::done, this, [this] {
if (d->terminalProc.error() != QProcess::UnknownError)
reportFailure(d->terminalProc.errorString());
if (d->terminalProc.error() != QProcess::FailedToStart)
reportDone();
});
d->terminalProc.start();
}
void DebuggerRunTool::continueAfterTerminalStart()
{
TaskHub::clearTasks(Constants::TASK_CATEGORY_DEBUGGER_RUNTIME);
if (usesDebugChannel())
setRemoteChannel(debugChannel());
if (usesQmlChannel()) {
setQmlServer(qmlChannel());
if (d->addQmlServerInferiorCommandLineArgumentIfNeeded
&& m_runParameters.isQmlDebugging
&& m_runParameters.isCppDebugging()) {
int qmlServerPort = m_runParameters.qmlServer.port();
QTC_ASSERT(qmlServerPort > 0, reportFailure(); return);
QString mode = QString("port:%1").arg(qmlServerPort);
CommandLine cmd{m_runParameters.inferior.command.executable()};
cmd.addArg(qmlDebugCommandLineArguments(QmlDebug::QmlDebuggerServices, mode, true));
cmd.addArgs(m_runParameters.inferior.command.arguments(), CommandLine::Raw);
m_runParameters.inferior.command = cmd;
}
}
// User canceled input dialog asking for executable when working on library project.
if (m_runParameters.startMode == StartInternal
&& m_runParameters.inferior.command.isEmpty()
&& m_runParameters.interpreter.isEmpty()) {
reportFailure(Tr::tr("No executable specified."));
return;
}
// QML and/or mixed are not prepared for it.
// setSupportsReRunning(!m_runParameters.isQmlDebugging);
setSupportsReRunning(false); // FIXME: Broken in general.
// FIXME: Disabled due to Android. Make Android device report available ports instead.
// int portsUsed = portsUsedByDebugger();
// if (portsUsed > device()->freePorts().count()) {
// reportFailure(Tr::tr("Cannot debug: Not enough free ports available."));
// return;
// }
if (d->coreUnpacker)
m_runParameters.coreFile = d->coreUnpacker->coreFileName();
if (!fixupParameters())
return;
if (m_runParameters.cppEngineType == CdbEngineType
&& Utils::is64BitWindowsBinary(m_runParameters.inferior.command.executable())
&& !Utils::is64BitWindowsBinary(m_runParameters.debugger.command.executable())) {
reportFailure(
Tr::tr(
"%1 is a 64 bit executable which can not be debugged by a 32 bit Debugger.\n"
"Please select a 64 bit Debugger in the kit settings for this kit.")
.arg(m_runParameters.inferior.command.executable().toUserOutput()));
return;
}
startDebugServerIfNeededAndContinueStartup();
}
void DebuggerRunTool::continueAfterDebugServerStart()
{
Utils::globalMacroExpander()->registerFileVariables(
"DebuggedExecutable", Tr::tr("Debugged executable"),
[this] { return m_runParameters.inferior.command.executable(); }
);
runControl()->setDisplayName(m_runParameters.displayName);
if (auto dapEngine = createDapEngine(runControl()->runMode()))
m_engines << dapEngine;
if (m_engines.isEmpty()) {
if (m_runParameters.isCppDebugging()) {
switch (m_runParameters.cppEngineType) {
case GdbEngineType:
m_engines << createGdbEngine();
break;
case CdbEngineType:
if (!HostOsInfo::isWindowsHost()) {
reportFailure(Tr::tr("Unsupported CDB host system."));
return;
}
m_engines << createCdbEngine();
break;
case LldbEngineType:
m_engines << createLldbEngine();
break;
case GdbDapEngineType:
m_engines << createDapEngine(ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE);
break;
case LldbDapEngineType:
m_engines << createDapEngine(ProjectExplorer::Constants::DAP_LLDB_DEBUG_RUN_MODE);
break;
BareMetal: Long live support for KEIL uVision v5.x debugger This patch adds debugger integration from the KEIL uVision IDE: * http://www2.keil.com/mdk5/uvision/ This IDE has the uVision Socket Interface (UVSC) that allows to the applications configuration, building and debugging: * http://www.keil.com/appnotes/docs/apnt_198.asp Besides, it provides a binary client libraries for Windows, which are implements some API which we are use in this patch. Currently implemented the following features: * Enumeration of a stack frames. * Enumeration of a threads (tasks). * Registers view (read/write). * Local variables view (read/write). * Watchers view (read/write). * Disassembler view. * Current location marker. * Break-points. * Step-in. * Step-over. * Step-out. * Step-by-instruction. * Start/stop/pause/continue debugger. * Auto-detection for the installed uVision instances (as debuggers). * Wizard for choosing and configuring of the UVSC debug providers. At this moment added support only for the 32-bit ARM devices, provided by the STMicroelectronics: https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html For this are implemented two debugger providers: * Simulator - allow to simulate the target device. * ST-Link v2 - it is a HW debugger. This implementation tested only with the QBS using the following target boards: * NUCLEO-F767ZI (based on STM32F767ZIT6 MCU). * STM32F4DISCOVERY (based on STM32F407VG MCU). * STM32F103x (based on STM32F103C8T6 MCU). A more detailed information about this patch can be found in a bug-tracker. Fixes: QTCREATORBUG-23426 Change-Id: Ie36a1f7430b56c33d6665cc35e43fe9bd95d28f1 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2020-01-24 17:08:27 +03:00
case UvscEngineType:
m_engines << createUvscEngine();
BareMetal: Long live support for KEIL uVision v5.x debugger This patch adds debugger integration from the KEIL uVision IDE: * http://www2.keil.com/mdk5/uvision/ This IDE has the uVision Socket Interface (UVSC) that allows to the applications configuration, building and debugging: * http://www.keil.com/appnotes/docs/apnt_198.asp Besides, it provides a binary client libraries for Windows, which are implements some API which we are use in this patch. Currently implemented the following features: * Enumeration of a stack frames. * Enumeration of a threads (tasks). * Registers view (read/write). * Local variables view (read/write). * Watchers view (read/write). * Disassembler view. * Current location marker. * Break-points. * Step-in. * Step-over. * Step-out. * Step-by-instruction. * Start/stop/pause/continue debugger. * Auto-detection for the installed uVision instances (as debuggers). * Wizard for choosing and configuring of the UVSC debug providers. At this moment added support only for the 32-bit ARM devices, provided by the STMicroelectronics: https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html For this are implemented two debugger providers: * Simulator - allow to simulate the target device. * ST-Link v2 - it is a HW debugger. This implementation tested only with the QBS using the following target boards: * NUCLEO-F767ZI (based on STM32F767ZIT6 MCU). * STM32F4DISCOVERY (based on STM32F407VG MCU). * STM32F103x (based on STM32F103C8T6 MCU). A more detailed information about this patch can be found in a bug-tracker. Fixes: QTCREATORBUG-23426 Change-Id: Ie36a1f7430b56c33d6665cc35e43fe9bd95d28f1 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2020-01-24 17:08:27 +03:00
break;
default:
if (!m_runParameters.isQmlDebugging) {
reportFailure(noEngineMessage() + '\n' +
Tr::tr("Specify Debugger settings in Projects > Run."));
return;
}
// Can happen for pure Qml.
break;
}
}
if (m_runParameters.isPythonDebugging)
m_engines << createPdbEngine();
if (m_runParameters.isQmlDebugging)
m_engines << createQmlEngine();
}
if (m_engines.isEmpty()) {
QString msg = noEngineMessage();
if (!DebuggerKitAspect::debugger(runControl()->kit()))
msg += '\n' + noDebuggerInKitMessage();
reportFailure(msg);
return;
}
if (auto interpreterAspect = runControl()->aspectData<FilePathAspect>()) {
if (auto mainScriptAspect = runControl()->aspectData<MainScriptAspect>()) {
const FilePath mainScript = mainScriptAspect->filePath;
const FilePath interpreter = interpreterAspect->filePath;
if (!interpreter.isEmpty() && mainScript.endsWith(".py")) {
m_runParameters.mainScript = mainScript;
m_runParameters.interpreter = interpreter;
}
}
}
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
bool first = true;
for (auto engine : m_engines) {
engine->setRunParameters(m_runParameters);
engine->setRunId(d->runId);
for (auto companion : m_engines) {
if (companion != engine)
engine->addCompanionEngine(companion);
}
engine->setRunTool(this);
if (!first)
engine->setSecondaryEngine();
auto rc = runControl();
connect(engine, &DebuggerEngine::requestRunControlFinish, rc, [rc] {
rc->setAutoDeleteOnStop(true);
rc->initiateStop();
}, Qt::QueuedConnection);
connect(engine, &DebuggerEngine::requestRunControlStop, rc, &RunControl::initiateStop);
connect(engine, &DebuggerEngine::engineStarted,
this, [this, engine] { handleEngineStarted(engine); });
connect(engine, &DebuggerEngine::engineFinished,
this, [this, engine] { handleEngineFinished(engine); });
connect(engine, &DebuggerEngine::appendMessageRequested,
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
this, &DebuggerRunTool::appendMessage);
++d->engineStartsNeeded;
++d->engineStopsNeeded;
if (first) {
connect(engine, &DebuggerEngine::attachToCoreRequested, this, [this](const QString &coreFile) {
auto rc = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
rc->copyDataFromRunControl(runControl());
rc->resetDataForAttachToCore();
auto name = QString(Tr::tr("%1 - Snapshot %2").arg(runControl()->displayName()).arg(++d->snapshotCounter));
auto debugger = new DebuggerRunTool(rc);
debugger->setStartMode(AttachToCore);
debugger->setCloseMode(DetachAtClose);
debugger->setRunControlName(name);
debugger->setCoreFilePath(FilePath::fromString(coreFile), true);
debugger->startRunControl();
});
first = false;
}
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
}
if (m_runParameters.startMode != AttachToCore) {
QStringList unhandledIds;
bool hasQmlBreakpoints = false;
for (const GlobalBreakpoint &gbp : BreakpointManager::globalBreakpoints()) {
if (gbp->isEnabled()) {
const BreakpointParameters &bp = gbp->requestedParameters();
hasQmlBreakpoints = hasQmlBreakpoints || bp.isQmlFileAndLineBreakpoint();
auto engineAcceptsBp = [bp](const DebuggerEngine *engine) {
return engine->acceptsBreakpoint(bp);
};
if (!Utils::anyOf(m_engines, engineAcceptsBp))
unhandledIds.append(gbp->displayName());
}
}
if (!unhandledIds.isEmpty()) {
QString warningMessage = Tr::tr("Some breakpoints cannot be handled by the debugger "
"languages currently active, and will be ignored.<p>"
"Affected are breakpoints %1")
.arg(unhandledIds.join(", "));
if (hasQmlBreakpoints) {
warningMessage += "<p>"
+ Tr::tr("QML debugging needs to be enabled both in the Build "
"and the Run settings.");
}
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
showMessage(warningMessage, LogWarning);
if (settings().showUnsupportedBreakpointWarning()) {
bool doNotAskAgain = false;
CheckableDecider decider(&doNotAskAgain);
CheckableMessageBox::information(
Core::ICore::dialogParent(),
Tr::tr("Debugger"),
warningMessage,
decider,
QMessageBox::Ok);
if (doNotAskAgain) {
settings().showUnsupportedBreakpointWarning.setValue(false);
settings().showUnsupportedBreakpointWarning.writeSettings();
}
}
}
}
appendMessage(Tr::tr("Debugging %1 ...").arg(m_runParameters.inferior.command.toUserOutput()),
NormalMessageFormat);
const QString debuggerName = Utils::transform<QStringList>(m_engines, &DebuggerEngine::objectName).join(" ");
const QString message = Tr::tr("Starting debugger \"%1\" for ABI \"%2\"...")
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
.arg(debuggerName).arg(m_runParameters.toolChainAbi.toString());
DebuggerMainWindow::showStatusMessage(message, 10000);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
showMessage(m_engines.first()->formatStartParameters(), LogDebug);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
showMessage(DebuggerSettings::dump(), LogDebug);
Utils::reverseForeach(m_engines, [](DebuggerEngine *engine) { engine->start(); });
}
void DebuggerRunTool::kickoffTerminalProcess()
{
d->terminalProc.kickoffProcess();
}
void DebuggerRunTool::interruptTerminal()
{
d->terminalProc.interrupt();
}
void DebuggerRunTool::stop()
{
QTC_ASSERT(!m_engines.isEmpty(), reportStopped(); return);
Utils::reverseForeach(m_engines, [](DebuggerEngine *engine) { engine->quitDebugger(); });
}
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
void DebuggerRunTool::handleEngineStarted(DebuggerEngine *engine)
{
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
// Correct:
// if (--d->engineStartsNeeded == 0) {
// EngineManager::activateDebugMode();
// reportStarted();
// }
// Feels better, as the QML Engine might attach late or not at all.
if (engine == m_engines.first()) {
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
EngineManager::activateDebugMode();
reportStarted();
}
}
void DebuggerRunTool::handleEngineFinished(DebuggerEngine *engine)
{
engine->prepareForRestart();
if (--d->engineStopsNeeded == 0) {
QString cmd = m_runParameters.inferior.command.toUserOutput();
QString msg = engine->runParameters().exitCode // Main engine.
? Tr::tr("Debugging of %1 has finished with exit code %2.")
.arg(cmd).arg(engine->runParameters().exitCode.value())
: Tr::tr("Debugging of %1 has finished.").arg(cmd);
appendMessage(msg, NormalMessageFormat);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
reportStopped();
}
}
bool DebuggerRunTool::isCppDebugging() const
{
return m_runParameters.isCppDebugging();
}
bool DebuggerRunTool::isQmlDebugging() const
{
return m_runParameters.isQmlDebugging;
}
void DebuggerRunTool::setUsePortsGatherer(bool useCpp, bool useQml)
{
if (useCpp)
runControl()->requestDebugChannel();
if (useQml)
runControl()->requestQmlChannel();
}
void DebuggerRunTool::setSolibSearchPath(const Utils::FilePaths &list)
{
m_runParameters.solibSearchPath = list;
}
bool DebuggerRunTool::fixupParameters()
{
DebuggerRunParameters &rp = m_runParameters;
if (rp.symbolFile.isEmpty())
rp.symbolFile = rp.inferior.command.executable();
// Copy over DYLD_IMAGE_SUFFIX etc
for (const auto &var :
QStringList({"DYLD_IMAGE_SUFFIX", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH"}))
if (rp.inferior.environment.hasKey(var))
rp.debugger.environment.set(var, rp.inferior.environment.expandedValueForKey(var));
// validate debugger if C++ debugging is enabled
if (!rp.validationErrors.isEmpty()) {
reportFailure(rp.validationErrors.join('\n'));
return false;
}
if (rp.isQmlDebugging) {
if (device() && device()->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
if (rp.qmlServer.port() <= 0) {
rp.qmlServer = Utils::urlFromLocalHostAndFreePort();
if (rp.qmlServer.port() <= 0) {
reportFailure(Tr::tr("Not enough free ports for QML debugging."));
return false;
}
}
// Makes sure that all bindings go through the JavaScript engine, so that
// breakpoints are actually hit!
const QString optimizerKey = "QML_DISABLE_OPTIMIZER";
if (!rp.inferior.environment.hasKey(optimizerKey))
rp.inferior.environment.set(optimizerKey, "1");
}
}
if (settings().autoEnrichParameters()) {
const FilePath sysroot = rp.sysRoot;
if (rp.debugInfoLocation.isEmpty())
rp.debugInfoLocation = sysroot / "/usr/lib/debug";
if (rp.debugSourceLocation.isEmpty()) {
QString base = sysroot.toString() + "/usr/src/debug/";
rp.debugSourceLocation.append(base + "qt5base/src/corelib");
rp.debugSourceLocation.append(base + "qt5base/src/gui");
rp.debugSourceLocation.append(base + "qt5base/src/network");
}
}
if (rp.isQmlDebugging) {
QmlDebug::QmlDebugServicesPreset service;
if (rp.isCppDebugging()) {
if (rp.nativeMixedEnabled) {
service = QmlDebug::QmlNativeDebuggerServices;
} else {
service = QmlDebug::QmlDebuggerServices;
}
} else {
service = QmlDebug::QmlDebuggerServices;
}
if (rp.startMode != AttachToLocalProcess && rp.startMode != AttachToCrashedProcess) {
QString qmlarg = rp.isCppDebugging() && rp.nativeMixedEnabled
? QmlDebug::qmlDebugNativeArguments(service, false)
: QmlDebug::qmlDebugTcpArguments(service, rp.qmlServer);
rp.inferior.command.addArg(qmlarg);
}
}
if (rp.startMode == NoStartMode)
rp.startMode = StartInternal;
if (breakOnMainNextTime) {
rp.breakOnMain = true;
breakOnMainNextTime = false;
}
if (HostOsInfo::isWindowsHost()) {
// Otherwise command lines with '> tmp.log' hang.
ProcessArgs::SplitError perr;
ProcessArgs::prepareArgs(rp.inferior.command.arguments(), &perr,
HostOsInfo::hostOs(), nullptr,
&rp.inferior.workingDirectory).toWindowsArgs();
if (perr != ProcessArgs::SplitOk) {
// perr == BadQuoting is never returned on Windows
// FIXME? QTCREATORBUG-2809
reportFailure(Tr::tr("Debugging complex command lines "
"is currently not supported on Windows."));
return false;
}
}
if (rp.isNativeMixedDebugging())
rp.inferior.environment.set("QV4_FORCE_INTERPRETER", "1");
if (settings().forceLoggingToConsole())
rp.inferior.environment.set("QT_LOGGING_TO_CONSOLE", "1");
return true;
}
DebuggerEngineType DebuggerRunTool::cppEngineType() const
{
return m_runParameters.cppEngineType;
}
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, AllowTerminal allowTerminal)
: RunWorker(runControl), d(new DebuggerRunToolPrivate)
{
setId("DebuggerRunTool");
static int toolRunCount = 0;
// Reset once all are gone.
if (EngineManager::engines().isEmpty())
toolRunCount = 0;
d->runId = QString::number(++toolRunCount);
d->allowTerminal = allowTerminal;
runControl->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
runControl->setPromptToStop([](bool *optionalPrompt) {
return RunControl::showPromptToStopDialog(
Tr::tr("Close Debugging Session"),
Tr::tr("A debugging session is still in progress. "
"Terminating the session in the current"
" state can leave the target in an inconsistent state."
" Would you still like to terminate it?"),
QString(), QString(), optionalPrompt);
});
m_runParameters.displayName = runControl->displayName();
if (auto symbolsAspect = runControl->aspectData<SymbolFileAspect>())
m_runParameters.symbolFile = symbolsAspect->filePath;
if (auto terminalAspect = runControl->aspectData<TerminalAspect>())
m_runParameters.useTerminal = terminalAspect->useTerminal;
if (auto runAsRootAspect = runControl->aspectData<RunAsRootAspect>())
m_runParameters.runAsRoot = runAsRootAspect->value;
Kit *kit = runControl->kit();
QTC_ASSERT(kit, return);
m_runParameters.sysRoot = SysRootKitAspect::sysRoot(kit);
m_runParameters.macroExpander = runControl->macroExpander();
m_runParameters.debugger = DebuggerKitAspect::runnable(kit);
m_runParameters.cppEngineType = DebuggerKitAspect::engineType(kit);
m_runParameters.version = DebuggerKitAspect::version(kit);
if (QtSupport::QtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(kit))
m_runParameters.qtSourceLocation = qtVersion->sourcePath();
if (auto aspect = runControl->aspectData<DebuggerRunConfigurationAspect>()) {
if (!aspect->useCppDebugger)
m_runParameters.cppEngineType = NoEngineType;
m_runParameters.isQmlDebugging = aspect->useQmlDebugger;
m_runParameters.isPythonDebugging = aspect->usePythonDebugger;
m_runParameters.multiProcess = aspect->useMultiProcess;
m_runParameters.additionalStartupCommands = aspect->overrideStartup;
if (aspect->useCppDebugger) {
if (DebuggerKitAspect::debugger(kit)) {
const Tasks tasks = DebuggerKitAspect::validateDebugger(kit);
for (const Task &t : tasks) {
if (t.type != Task::Warning)
m_runParameters.validationErrors.append(t.description());
}
} else {
m_runParameters.validationErrors.append(noDebuggerInKitMessage());
}
}
}
ProcessRunData inferior = runControl->runnable();
// Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...)
inferior.workingDirectory = inferior.workingDirectory.normalizedPathName();
m_runParameters.inferior = inferior;
const QString envBinary = qtcEnvironmentVariable("QTC_DEBUGGER_PATH");
if (!envBinary.isEmpty())
m_runParameters.debugger.command.setExecutable(FilePath::fromString(envBinary));
if (Project *project = runControl->project()) {
m_runParameters.projectSourceDirectory = project->projectDirectory();
m_runParameters.projectSourceFiles = project->files(Project::SourceFiles);
} else {
m_runParameters.projectSourceDirectory = m_runParameters.debugger.command.executable().parentDir();
m_runParameters.projectSourceFiles.clear();
}
m_runParameters.toolChainAbi = ToolchainKitAspect::targetAbi(kit);
bool ok = false;
const int nativeMixedOverride = qtcEnvironmentVariableIntValue("QTC_DEBUGGER_NATIVE_MIXED", &ok);
if (ok)
m_runParameters.nativeMixedEnabled = bool(nativeMixedOverride);
if (QtSupport::QtVersion *baseQtVersion = QtSupport::QtKitAspect::qtVersion(kit)) {
const QVersionNumber qtVersion = baseQtVersion->qtVersion();
m_runParameters.qtVersion = 0x10000 * qtVersion.majorVersion()
+ 0x100 * qtVersion.minorVersion()
+ qtVersion.microVersion();
}
}
void DebuggerRunTool::startRunControl()
{
ProjectExplorerPlugin::startRunControl(runControl());
}
void DebuggerRunTool::addSolibSearchDir(const QString &str)
{
QString path = str;
path.replace("%{sysroot}", m_runParameters.sysRoot.toString());
m_runParameters.solibSearchPath.append(FilePath::fromString(path));
}
DebuggerRunTool::~DebuggerRunTool()
{
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
if (m_runParameters.isSnapshot && !m_runParameters.coreFile.isEmpty())
m_runParameters.coreFile.removeFile();
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
qDeleteAll(m_engines);
m_engines.clear();
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
delete d;
}
void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout)
{
if (channel == ConsoleOutput)
debuggerConsole()->printItem(ConsoleItem::DefaultType, msg);
QTC_ASSERT(!m_engines.isEmpty(), qDebug() << msg; return);
for (auto engine : m_engines)
engine->showMessage(msg, channel, timeout);
switch (channel) {
case AppOutput:
appendMessage(msg, StdOutFormat);
break;
case AppError:
appendMessage(msg, StdErrFormat);
break;
case AppStuff:
appendMessage(msg, DebugFormat);
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////
//
// Externally visible helper.
//
////////////////////////////////////////////////////////////////////////
/*!
\class Debugger::SubChannelProvider
The class implements a \c RunWorker to provide a url
indicating usable connection end
points for 'server-using' tools (typically one, like plain
gdbserver and the Qml tooling, but two for mixed debugging).
Urls can describe local or tcp servers that are directly
accessible to the host tools.
By default it is assumed that no forwarding is needed, i.e.
end points provided by the shared endpoint resource provider
are directly accessible.
The tool implementations can assume that any needed port
forwarding setup is setup and handled transparently by
a \c SubChannelProvider instance.
If there are multiple subchannels needed that need to share a
common set of resources on the remote side, a device implementation
can provide a "SharedEndpointGatherer" RunWorker.
If none is provided, it is assumed that the shared resource
is open TCP ports, provided by the device's PortGatherer i
implementation.
FIXME: The current implementation supports only the case
of "any number of TCP channels that do not need actual
forwarding.
*/
void DebuggerRunTool::startDebugServerIfNeededAndContinueStartup()
{
if (!usesDebugChannel()) {
continueAfterDebugServerStart();
return;
}
// FIXME: Indentation intentionally wrong to keep diff in gerrit small. Will fix later.
CommandLine commandLine = m_runParameters.inferior.command;
CommandLine cmd;
if (usesQmlChannel() && !usesDebugChannel()) {
// FIXME: Case should not happen?
cmd.setExecutable(commandLine.executable());
cmd.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, qmlChannel()));
cmd.addArgs(commandLine.arguments(), CommandLine::Raw);
} else {
cmd.setExecutable(device()->debugServerPath());
if (cmd.isEmpty()) {
if (device()->osType() == Utils::OsTypeMac) {
const FilePath debugServerLocation = device()->filePath(
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/"
"Resources/debugserver");
if (debugServerLocation.isExecutableFile()) {
cmd.setExecutable(debugServerLocation);
} else {
// TODO: In the future it is expected that the debugserver will be
// replaced by lldb-server. Remove the check for debug server at that point.
const FilePath lldbserver
= device()->filePath("lldb-server").searchInPath();
if (lldbserver.isExecutableFile())
cmd.setExecutable(lldbserver);
}
} else {
const FilePath gdbServerPath
= device()->filePath("gdbserver").searchInPath();
FilePath lldbServerPath
= device()->filePath("lldb-server").searchInPath();
// TODO: Which one should we prefer?
if (gdbServerPath.isExecutableFile())
cmd.setExecutable(gdbServerPath);
else if (lldbServerPath.isExecutableFile()) {
// lldb-server will fail if we start it through a link.
// see: https://github.com/llvm/llvm-project/issues/61955
//
// So we first search for the real executable.
// This is safe because we already checked that the file is executable.
while (lldbServerPath.isSymLink())
lldbServerPath = lldbServerPath.symLinkTarget();
cmd.setExecutable(lldbServerPath);
}
}
}
QTC_ASSERT(usesDebugChannel(), reportFailure({}));
if (cmd.executable().baseName().contains("lldb-server")) {
cmd.addArg("platform");
cmd.addArg("--listen");
cmd.addArg(QString("*:%1").arg(debugChannel().port()));
cmd.addArg("--server");
} else if (cmd.executable().baseName() == "debugserver") {
const QString ipAndPort("`echo $SSH_CLIENT | cut -d ' ' -f 1`:%1");
cmd.addArgs(ipAndPort.arg(debugChannel().port()), CommandLine::Raw);
if (d->serverAttachPid.isValid())
cmd.addArgs({"--attach", QString::number(d->serverAttachPid.pid())});
else
cmd.addCommandLineAsArgs(runControl()->runnable().command);
} else {
// Something resembling gdbserver
if (d->serverUseMulti)
cmd.addArg("--multi");
if (d->serverAttachPid.isValid())
cmd.addArg("--attach");
const auto port = debugChannel().port();
cmd.addArg(QString(":%1").arg(port));
if (device()->extraData(ProjectExplorer::Constants::SSH_FORWARD_DEBUGSERVER_PORT).toBool()) {
QVariantHash extraData;
extraData[RemoteLinux::Constants::SshForwardPort] = port;
extraData[RemoteLinux::Constants::DisableSharing] = true;
d->debuggerServerProc.setExtraData(extraData);
}
if (d->serverAttachPid.isValid())
cmd.addArg(QString::number(d->serverAttachPid.pid()));
}
}
d->debuggerServerProc.setCommand(cmd);
connect(&d->debuggerServerProc, &Process::started, this, [this] {
continueAfterDebugServerStart();
});
connect(&d->debuggerServerProc, &Process::done, this, [this] {
if (d->terminalProc.error() != QProcess::UnknownError)
reportFailure(d->terminalProc.errorString());
if (d->terminalProc.error() != QProcess::FailedToStart && d->serverEssential)
reportDone();
});
d->debuggerServerProc.start();
}
void DebuggerRunTool::setUseDebugServer(ProcessHandle attachPid, bool essential, bool useMulti)
{
runControl()->requestDebugChannel();
d->serverAttachPid = attachPid;
d->serverEssential = essential;
d->serverUseMulti = useMulti;
}
// DebuggerRunWorkerFactory
DebuggerRunWorkerFactory::DebuggerRunWorkerFactory()
{
setProduct<DebuggerRunTool>();
setId(Constants::DEBUGGER_RUN_FACTORY);
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);
addSupportedRunMode(ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE);
addSupportedRunMode(ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE);
addSupportedRunMode(ProjectExplorer::Constants::DAP_LLDB_DEBUG_RUN_MODE);
addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
addSupportedDeviceType("DockerDeviceType");
addSupportForLocalRunConfigs();
}
} // Debugger