1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "debugger_global.h"
29 #include "debuggerconstants.h"
30 #include "debuggerengine.h"
31 #include "terminal.h"
32 
33 #include <projectexplorer/runconfiguration.h>
34 #include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
35 
36 #include <utils/environmentfwd.h>
37 
38 namespace Debugger {
39 
40 namespace Internal {
41 class TerminalRunner;
42 class DebuggerRunToolPrivate;
43 } // Internal
44 
45 class DebugServerPortsGatherer;
46 
47 class DEBUGGER_EXPORT DebuggerRunTool : public ProjectExplorer::RunWorker
48 {
49     Q_OBJECT
50 
51 public:
52     enum AllowTerminal { DoAllowTerminal, DoNotAllowTerminal };
53     explicit DebuggerRunTool(ProjectExplorer::RunControl *runControl,
54                              AllowTerminal allowTerminal = DoAllowTerminal);
55     ~DebuggerRunTool() override;
56 
57     void startRunControl();
58 
59     void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1);
60 
61     void start() override;
62     void stop() override;
63 
64     bool isCppDebugging() const;
65     bool isQmlDebugging() const;
66     int portsUsedByDebugger() const;
67 
68     void setUsePortsGatherer(bool useCpp, bool useQml);
69     DebugServerPortsGatherer *portsGatherer() const;
70 
71     void setSolibSearchPath(const QStringList &list);
72     void addSolibSearchDir(const QString &str);
73 
74     static void setBreakOnMainNextTime();
75 
76     void setInferior(const ProjectExplorer::Runnable &runnable);
77     void setInferiorExecutable(const Utils::FilePath &executable);
78     void setInferiorEnvironment(const Utils::Environment &env); // Used by GammaRay plugin
79     void setInferiorDevice(ProjectExplorer::IDevice::ConstPtr device); // Used by cdbengine
80     void setRunControlName(const QString &name);
81     void setStartMessage(const QString &msg);
82     void addQmlServerInferiorCommandLineArgumentIfNeeded();
83     void modifyDebuggerEnvironment(const Utils::EnvironmentItems &item);
84     void setCrashParameter(const QString &event);
85 
86     void addExpectedSignal(const QString &signal);
87     void addSearchDirectory(const Utils::FilePath &dir);
88 
89     void setStartMode(DebuggerStartMode startMode);
90     void setCloseMode(DebuggerCloseMode closeMode);
91 
92     void setAttachPid(Utils::ProcessHandle pid);
93     void setAttachPid(qint64 pid);
94 
95     void setSysRoot(const Utils::FilePath &sysRoot);
96     void setSymbolFile(const Utils::FilePath &symbolFile);
97     void setLldbPlatform(const QString &platform);
98     void setRemoteChannel(const QString &channel);
99     void setRemoteChannel(const QString &host, int port);
100     void setRemoteChannel(const QUrl &url);
101     QString remoteChannel() const;
102 
103     void setUseExtendedRemote(bool on);
104     void setUseContinueInsteadOfRun(bool on);
105     void setUseTargetAsync(bool on);
106     void setContinueAfterAttach(bool on);
107     void setSkipExecutableValidation(bool on);
108     void setUseCtrlCStub(bool on);
109     void setBreakOnMain(bool on);
110     void setUseTerminal(bool on);
111     void setRunAsRoot(bool on);
112 
113     void setCommandsAfterConnect(const QString &commands);
114     void setCommandsForReset(const QString &commands);
115 
116     void setServerStartScript(const Utils::FilePath &serverStartScript);
117     void setDebugInfoLocation(const QString &debugInfoLocation);
118 
119     void setQmlServer(const QUrl &qmlServer);
120     QUrl qmlServer() const; // Used in GammaRay integration.
121 
122     void setCoreFileName(const QString &core, bool isSnapshot = false);
123 
124     void setIosPlatform(const QString &platform);
125     void setDeviceSymbolsRoot(const QString &deviceSymbolsRoot);
126 
127     void setTestCase(int testCase);
128     void setOverrideStartScript(const QString &script);
129 
130     void setAbi(const ProjectExplorer::Abi &abi);
131 
132     Internal::TerminalRunner *terminalRunner() const;
133     DebuggerEngineType cppEngineType() const;
134 
135 private:
136     bool fixupParameters();
137     void handleEngineStarted(Internal::DebuggerEngine *engine);
138     void handleEngineFinished(Internal::DebuggerEngine *engine);
139 
140     Internal::DebuggerRunToolPrivate *d;
141     QPointer<Internal::DebuggerEngine> m_engine;
142     QPointer<Internal::DebuggerEngine> m_engine2;
143     Internal::DebuggerRunParameters m_runParameters;
144 };
145 
146 class DEBUGGER_EXPORT DebugServerPortsGatherer : public ProjectExplorer::ChannelProvider
147 {
148     Q_OBJECT
149 
150 public:
151     explicit DebugServerPortsGatherer(ProjectExplorer::RunControl *runControl);
152     ~DebugServerPortsGatherer() override;
153 
setUseGdbServer(bool useIt)154     void setUseGdbServer(bool useIt) { m_useGdbServer = useIt; }
useGdbServer()155     bool useGdbServer() const { return m_useGdbServer; }
156     QUrl gdbServer() const;
157 
setUseQmlServer(bool useIt)158     void setUseQmlServer(bool useIt) { m_useQmlServer = useIt; }
useQmlServer()159     bool useQmlServer() const { return m_useQmlServer; }
160     QUrl qmlServer() const;
161 
162 private:
163     bool m_useGdbServer = false;
164     bool m_useQmlServer = false;
165 };
166 
167 class DEBUGGER_EXPORT DebugServerRunner : public ProjectExplorer::SimpleTargetRunner
168 {
169     Q_OBJECT
170 
171 public:
172     explicit DebugServerRunner(ProjectExplorer::RunControl *runControl,
173                                DebugServerPortsGatherer *portsGatherer);
174 
175     ~DebugServerRunner() override;
176 
177     void setUseMulti(bool on);
178     void setAttachPid(Utils::ProcessHandle pid);
179 
180 private:
181     Utils::ProcessHandle m_pid;
182     bool m_useMulti = true;
183 };
184 
185 extern DEBUGGER_EXPORT const char DebugServerRunnerWorkerId[];
186 extern DEBUGGER_EXPORT const char GdbServerPortGathererWorkerId[];
187 
188 } // namespace Debugger
189