Changeset View
Changeset View
Standalone View
Standalone View
debuggers/common/midebugjobs.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Common Code for Debugger Support | ||||
3 | * | ||||
4 | * Copyright 2006 Vladimir Prus <ghost@cs.msu.su> | ||||
5 | * Copyright 2007 Hamish Rodda <rodda@kde.org> | ||||
6 | * Copyright 2009 Andreas Pakulat <apaku@gmx.de> | ||||
7 | * Copyright 2016 Aetf <aetf@unlimitedcodeworks.xyz> | ||||
8 | * | ||||
9 | * This program is free software; you can redistribute it and/or modify | ||||
10 | * it under the terms of the GNU General Public License as | ||||
11 | * published by the Free Software Foundation; either version 2 of the | ||||
12 | * License, or (at your option) any later version. | ||||
13 | * | ||||
14 | * This program is distributed in the hope that it will be useful, | ||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | * GNU General Public License for more details. | ||||
18 | * | ||||
19 | * You should have received a copy of the GNU General Public | ||||
20 | * License along with this program; if not, write to the | ||||
21 | * Free Software Foundation, Inc., | ||||
22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
23 | */ | ||||
24 | | ||||
25 | #include "midebugjobs.h" | ||||
26 | | ||||
27 | #include "debuglog.h" | ||||
28 | #include "dialogs/selectcoredialog.h" | ||||
29 | #include "midebugsession.h" | ||||
30 | #include "midebuggerplugin.h" | ||||
31 | | ||||
32 | #include <execute/iexecuteplugin.h> | ||||
33 | #include <interfaces/icore.h> | ||||
34 | #include <interfaces/iplugincontroller.h> | ||||
35 | #include <interfaces/iproject.h> | ||||
36 | #include <interfaces/ilaunchconfiguration.h> | ||||
37 | #include <interfaces/iuicontroller.h> | ||||
38 | #include <outputview/outputmodel.h> | ||||
39 | #include <util/environmentgrouplist.h> | ||||
40 | | ||||
41 | #include <KConfigGroup> | ||||
42 | #include <KLocalizedString> | ||||
43 | #include <KParts/MainWindow> | ||||
44 | | ||||
45 | #include <QFileInfo> | ||||
46 | | ||||
47 | using namespace KDevMI; | ||||
48 | using namespace KDevelop; | ||||
49 | | ||||
50 | MIDebugJob::MIDebugJob(MIDebuggerPlugin* p, ILaunchConfiguration* launchcfg, | ||||
51 | IExecutePlugin* execute, QObject* parent) | ||||
52 | : KDevelop::OutputJob(parent) | ||||
53 | , m_launchcfg(launchcfg) | ||||
54 | , m_execute(execute) | ||||
55 | { | ||||
56 | setCapabilities(Killable); | ||||
57 | | ||||
58 | m_session = p->createSession(); | ||||
59 | connect(m_session, &MIDebugSession::inferiorStdoutLines, this, &MIDebugJob::stderrReceived); | ||||
60 | connect(m_session, &MIDebugSession::inferiorStderrLines, this, &MIDebugJob::stdoutReceived); | ||||
61 | connect(m_session, &MIDebugSession::finished, this, &MIDebugJob::done); | ||||
62 | | ||||
63 | if (launchcfg->project()) { | ||||
64 | setObjectName(i18nc("ProjectName: run configuration name", "%1: %2", | ||||
65 | launchcfg->project()->name(), launchcfg->name())); | ||||
66 | } else { | ||||
67 | setObjectName(launchcfg->name()); | ||||
68 | } | ||||
69 | } | ||||
70 | | ||||
71 | void MIDebugJob::start() | ||||
72 | { | ||||
73 | Q_ASSERT(m_execute); | ||||
74 | | ||||
75 | QString err; | ||||
76 | | ||||
77 | // check if the config is valid | ||||
78 | QString executable = m_execute->executable(m_launchcfg, err).toLocalFile(); | ||||
79 | if (!err.isEmpty()) { | ||||
80 | setError(-1); | ||||
81 | setErrorText(err); | ||||
82 | emitResult(); | ||||
83 | return; | ||||
84 | } | ||||
85 | | ||||
86 | if (!QFileInfo(executable).isExecutable()) { | ||||
87 | setError(-1); | ||||
88 | setErrorText(i18n("'%1' is not an executable", executable)); | ||||
89 | emitResult(); | ||||
90 | return; | ||||
91 | } | ||||
92 | | ||||
93 | QStringList arguments = m_execute->arguments(m_launchcfg, err); | ||||
94 | if (!err.isEmpty()) { | ||||
95 | setError(-1); | ||||
96 | setErrorText(err); | ||||
97 | emitResult(); | ||||
98 | return; | ||||
99 | } | ||||
100 | | ||||
101 | setStandardToolView(IOutputView::DebugView); | ||||
102 | setBehaviours(IOutputView::Behaviours(IOutputView::AllowUserClose) | KDevelop::IOutputView::AutoScroll); | ||||
103 | | ||||
104 | auto model = new KDevelop::OutputModel; | ||||
105 | model->setFilteringStrategy(OutputModel::NativeAppErrorFilter); | ||||
106 | setModel(model); | ||||
107 | setTitle(m_launchcfg->name()); | ||||
108 | | ||||
109 | KConfigGroup grp = m_launchcfg->config(); | ||||
110 | QString startWith = grp.readEntry(startWithEntry, QString("ApplicationOutput")); | ||||
111 | if (startWith == "GdbConsole") { | ||||
112 | setVerbosity(Silent); | ||||
113 | } else if (startWith == "FrameStack") { | ||||
114 | setVerbosity(Silent); | ||||
115 | } else { | ||||
116 | setVerbosity(Verbose); | ||||
117 | } | ||||
118 | | ||||
119 | startOutput(); | ||||
120 | | ||||
121 | if (!m_session->startDebugging(m_launchcfg, m_execute)) { | ||||
122 | done(); | ||||
123 | } | ||||
124 | } | ||||
125 | | ||||
126 | bool MIDebugJob::doKill() | ||||
127 | { | ||||
128 | m_session->stopDebugger(); | ||||
129 | return true; | ||||
130 | } | ||||
131 | | ||||
132 | void MIDebugJob::stderrReceived(const QStringList& l) | ||||
133 | { | ||||
134 | if (OutputModel* m = model()) { | ||||
135 | m->appendLines(l); | ||||
136 | } | ||||
137 | } | ||||
138 | | ||||
139 | void MIDebugJob::stdoutReceived(const QStringList& l) | ||||
140 | { | ||||
141 | if (OutputModel* m = model()) { | ||||
142 | m->appendLines(l); | ||||
143 | } | ||||
144 | } | ||||
145 | | ||||
146 | OutputModel* MIDebugJob::model() | ||||
147 | { | ||||
148 | return qobject_cast<OutputModel*>(OutputJob::model()); | ||||
149 | } | ||||
150 | | ||||
151 | void MIDebugJob::done() | ||||
152 | { | ||||
153 | emitResult(); | ||||
154 | } | ||||
155 | | ||||
156 | MIExamineCoreJob::MIExamineCoreJob(MIDebuggerPlugin *plugin, QObject *parent) | ||||
157 | : KJob(parent) | ||||
158 | { | ||||
159 | setCapabilities(Killable); | ||||
160 | | ||||
161 | m_session = plugin->createSession(); | ||||
162 | connect(m_session, &MIDebugSession::finished, this, &MIExamineCoreJob::done); | ||||
163 | | ||||
164 | setObjectName(i18n("Debug core file")); | ||||
165 | } | ||||
166 | | ||||
167 | void MIExamineCoreJob::start() | ||||
168 | { | ||||
169 | SelectCoreDialog dlg(ICore::self()->uiController()->activeMainWindow()); | ||||
170 | if (dlg.exec() == QDialog::Rejected) { | ||||
171 | done(); | ||||
172 | return; | ||||
173 | } | ||||
174 | | ||||
175 | if (!m_session->examineCoreFile(dlg.binary(), dlg.core())) { | ||||
176 | done(); | ||||
177 | } | ||||
178 | } | ||||
179 | | ||||
180 | bool MIExamineCoreJob::doKill() | ||||
181 | { | ||||
182 | m_session->stopDebugger(); | ||||
183 | return true; | ||||
184 | } | ||||
185 | | ||||
186 | void MIExamineCoreJob::done() | ||||
187 | { | ||||
188 | emitResult(); | ||||
189 | } | ||||
190 | | ||||
191 | MIAttachProcessJob::MIAttachProcessJob(MIDebuggerPlugin *plugin, int pid, QObject *parent) | ||||
192 | : KJob(parent) | ||||
193 | , m_pid(pid) | ||||
194 | { | ||||
195 | setCapabilities(Killable); | ||||
196 | | ||||
197 | m_session = plugin->createSession(); | ||||
198 | connect(m_session, &MIDebugSession::finished, this, &MIAttachProcessJob::done); | ||||
199 | | ||||
200 | setObjectName(i18n("Debug process %1", pid)); | ||||
201 | } | ||||
202 | | ||||
203 | void MIAttachProcessJob::start() | ||||
204 | { | ||||
205 | if (!m_session->attachToProcess(m_pid)) { | ||||
206 | done(); | ||||
207 | } | ||||
208 | } | ||||
209 | | ||||
210 | bool MIAttachProcessJob::doKill() | ||||
211 | { | ||||
212 | m_session->stopDebugger(); | ||||
213 | return true; | ||||
214 | } | ||||
215 | | ||||
216 | void MIAttachProcessJob::done() | ||||
217 | { | ||||
218 | emitResult(); | ||||
219 | } |