Skip to content

Commit 93633bd

Browse files
committed
Support GDB and QML debugging
--debug option removed. Instead there are --debug-gdb and --debug-qml now --start option removed. The first non-recognized argument is treated as binary to execute and following arguments as its parameters. --port-range has to be specified if any --debug-* option is used Change-Id: I851ab2b36a73adfb6a1fbc14da3462c9d27cd620 Reviewed-by: Christian Kandeler <[email protected]>
1 parent 8495323 commit 93633bd

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

main.cpp

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void stop()
9999
connectSocket();
100100
}
101101

102-
static int findFirstFreePort(Utils::PortList range)
102+
static int findFirstFreePort(Utils::PortList &range)
103103
{
104104
QTcpServer s;
105105

@@ -156,8 +156,10 @@ int main(int argc, char **argv)
156156

157157
QCoreApplication app(argc, argv);
158158
QStringList defaultArgs;
159-
QString binary;
160-
bool debug = false;
159+
quint16 gdbDebugPort = 0;
160+
bool useGDB = false;
161+
bool useQML = false;
162+
Utils::PortList range;
161163

162164
if (args.size() == 0) {
163165
qWarning("No arguments given.");
@@ -167,45 +169,23 @@ int main(int argc, char **argv)
167169
Config config = parseConfigFile();
168170

169171
while (!args.isEmpty()) {
170-
if (args[0] == "--start") {
172+
if (args[0] == "--port-range") {
171173
if (args.size() < 2) {
172-
qWarning("--start requires an argument");
174+
qWarning("--port-range requires a range specification");
173175
return 1;
174176
}
175-
binary = args[1];
177+
range = Utils::PortList::fromString(args[1]);
176178
args.removeFirst();
177-
if (binary.isEmpty()) {
178-
qWarning("App path is empty");
179+
if (!range.hasMore()) {
180+
qWarning("Invalid port range");
179181
return 1;
180182
}
181-
defaultArgs.append(args);
182-
break;
183-
} else if (args[0] == "--debug") {
184-
debug = true;
185-
if (args.size() < 3) {
186-
qWarning("--debug requires arguments: port-range and executable");
187-
return 1;
188-
}
189-
Utils::PortList range = Utils::PortList::fromString(args[1]);
190-
binary = args[2];
191-
args.removeFirst();
192-
args.removeFirst();
193-
if (binary.isEmpty()) {
194-
qWarning("App path is empty");
195-
return 1;
196-
}
197-
198-
int port = findFirstFreePort(range);
199-
if (port < 0) {
200-
qWarning("Could not find an unused port in range");
201-
return 1;
202-
}
203-
defaultArgs.push_front("localhost:" + QString::number(port));
204-
defaultArgs.push_front("gdbserver");
205-
defaultArgs.append(args);
183+
} else if (args[0] == "--debug-gdb") {
184+
useGDB = true;
206185
setpgid(0,0); // must be called before setsid()
207186
setsid();
208-
break;
187+
} else if (args[0] == "--debug-qml") {
188+
useQML = true;
209189
} else if (args[0] == "--stop") {
210190
stop();
211191
return 0;
@@ -215,20 +195,55 @@ int main(int argc, char **argv)
215195
config.platform.toLocal8Bit().constData());
216196
return 0;
217197
} else {
218-
qWarning("unknown argument: %s", args.first().toLocal8Bit().constData());
219-
return 1;
198+
break;
220199
}
221200
args.removeFirst();
222201
}
223202

203+
if (args.isEmpty()) {
204+
qWarning("No binary to execute.");
205+
return 1;
206+
}
207+
208+
if ((useGDB || useQML) && !range.hasMore()) {
209+
qWarning("--port-range is mandatory");
210+
return 1;
211+
}
212+
213+
if (useGDB) {
214+
int port = findFirstFreePort(range);
215+
if (port < 0) {
216+
qWarning("Could not find an unused port in range");
217+
return 1;
218+
}
219+
gdbDebugPort = port;
220+
}
221+
if (useQML) {
222+
int port = findFirstFreePort(range);
223+
if (port < 0) {
224+
qWarning("Could not find an unused port in range");
225+
return 1;
226+
}
227+
defaultArgs.push_front("-qmljsdebugger=port:" + QString::number(port) + ",block");
228+
printf("QML Debugger: Going to wait for connection on port %d...\n", port);
229+
}
230+
231+
defaultArgs.push_front(args.takeFirst());
232+
defaultArgs.append(args);
233+
234+
if (useGDB) {
235+
defaultArgs.push_front("localhost:" + QString::number(gdbDebugPort));
236+
defaultArgs.push_front("gdbserver");
237+
}
238+
224239
if (createServerSocket() != 0) {
225240
fprintf(stderr, "Could not create serversocket\n");
226241
return 1;
227242
}
228243

229244
Process process;
230245
process.setConfig(config);
231-
if (debug)
246+
if (gdbDebugPort)
232247
process.setDebug();
233248
process.setSocketNotifier(new QSocketNotifier(serverSocket, QSocketNotifier::Read, &process));
234249
process.start(defaultArgs);

process.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ void Process::startup(QStringList args)
9393
}
9494

9595
args.append(mConfig.args);
96-
qDebug() << args;
9796

9897
mProcess->setProcessEnvironment(pe);
9998
QString binary = args.first();
100-
qDebug() << binary << args;
10199
args.removeFirst();
100+
qDebug() << binary << args;
102101
mProcess->start(binary, args);
103102
}
104103

0 commit comments

Comments
 (0)