Skip to content

Commit 5ab7fdb

Browse files
Rainer KellerRainer Keller
Rainer Keller
authored and
Rainer Keller
committed
Allow to set used debugging port via commandline
Change-Id: I6f99e2bf77aed2503119959d46c48e359940600a Reviewed-by: hjk <[email protected]> Reviewed-by: Mikko Gronoff <[email protected]> Reviewed-by: Samuli Piippo <[email protected]>
1 parent d58e21a commit 5ab7fdb

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

main.cpp

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <sys/wait.h>
4040

4141
#define PID_FILE "/data/user/.appcontroller"
42-
#define FEATURES "restart perf eglresize qmldebugservices"
42+
#define FEATURES "restart perf eglresize qmldebugservices explicitdebugports"
4343

4444
#define B2QT_PREFIX "/usr/bin/b2qt"
4545

@@ -49,14 +49,17 @@ static const char socketPath[] = "#Boot2Qt_appcontroller";
4949

5050
static void usage()
5151
{
52-
printf("appcontroller [--debug-gdb] [--debug-qml] [--qml-debug-services <services>]"
52+
printf("appcontroller [--debug-gdb] [--debug-gdb-port <port>]"
53+
" [--debug-qml] [--debug-qml-port <port>] [--qml-debug-services <services>]"
5354
" [--profile-perf <params>] [--port-range <range>] [--stop] [--launch] [--show-platfrom]"
5455
" [--make-default] [--remove-default] [--print-debug] [--version] [--detach]"
5556
" [executable] [arguments]\n"
5657
"\n"
5758
"--port-range <range> Port range to use for debugging connections\n"
5859
"--debug-gdb Start GDB debugging\n"
60+
"--debug-gdb-port <port> Port to be used for GDB debugging\n"
5961
"--debug-qml Start QML debugging or profiling\n"
62+
"--debug-qml-port <port> Port to be used for QML debugging\n"
6063
"--qml-debug-services <services> Specify services to use for QML debugging/profiling\n"
6164
"--profile-perf <params> Start perf profiling\n"
6265
"--stop Stop already running application\n"
@@ -329,6 +332,7 @@ int main(int argc, char **argv)
329332

330333
QStringList defaultArgs;
331334
quint16 gdbDebugPort = 0;
335+
quint16 qmlDebugPort = 0;
332336
bool useGDB = false;
333337
bool useQML = false;
334338
QString qmlDebugServices;
@@ -363,8 +367,28 @@ int main(int argc, char **argv)
363367
useGDB = true;
364368
setpgid(0,0); // must be called before setsid()
365369
setsid();
370+
} else if (arg == "--debug-gdb-port") {
371+
if (args.isEmpty()) {
372+
fprintf(stderr, "--debug-gdb-port requires a port number\n");
373+
return 1;
374+
}
375+
gdbDebugPort = args.takeFirst().toUInt();
376+
if (gdbDebugPort < 1) {
377+
fprintf(stderr, "--debug-gdb-port has invalid port number\n");
378+
return 1;
379+
}
366380
} else if (arg == "--debug-qml") {
367381
useQML = true;
382+
} else if (arg == "--debug-qml-port") {
383+
if (args.isEmpty()) {
384+
fprintf(stderr, "--debug-qml-port requires a port number\n");
385+
return 1;
386+
}
387+
qmlDebugPort = args.takeFirst().toUInt();
388+
if (qmlDebugPort < 1) {
389+
fprintf(stderr, "--debug-qml-port has invalid port number\n");
390+
return 1;
391+
}
368392
} else if (arg == "--qml-debug-services") {
369393
if (args.isEmpty()) {
370394
fprintf(stderr, "--qml-debug-services requires a list of comma-separated service "
@@ -429,8 +453,13 @@ int main(int argc, char **argv)
429453
return 1;
430454
}
431455

432-
if ((useGDB || useQML) && !range.hasMore()) {
433-
fprintf(stderr, "--port-range is mandatory\n");
456+
if (useGDB && !(gdbDebugPort || range.hasMore())) {
457+
fprintf(stderr, "--debug-gdb requires --port-range or --debug-gdb-port\n");
458+
return 1;
459+
}
460+
461+
if (useQML && !(qmlDebugPort || range.hasMore())) {
462+
fprintf(stderr, "--debug-qml requires --port-range or --debug-qml-port\n");
434463
return 1;
435464
}
436465

@@ -439,7 +468,10 @@ int main(int argc, char **argv)
439468
return 1;
440469
}
441470

442-
if (useGDB) {
471+
if (gdbDebugPort && !useGDB)
472+
gdbDebugPort = 0;
473+
474+
if (useGDB && !gdbDebugPort) {
443475
int port = findFirstFreePort(range);
444476
if (port < 0) {
445477
fprintf(stderr, "Could not find an unused port in range\n");
@@ -448,15 +480,18 @@ int main(int argc, char **argv)
448480
gdbDebugPort = port;
449481
}
450482
if (useQML) {
451-
int port = findFirstFreePort(range);
452-
if (port < 0) {
453-
fprintf(stderr, "Could not find an unused port in range\n");
454-
return 1;
483+
if (!qmlDebugPort) {
484+
int port = findFirstFreePort(range);
485+
if (port < 0) {
486+
fprintf(stderr, "Could not find an unused port in range\n");
487+
return 1;
488+
}
489+
qmlDebugPort = port;
455490
}
456-
defaultArgs.push_front("-qmljsdebugger=port:" + QString::number(port) + ",block" +
491+
defaultArgs.push_front("-qmljsdebugger=port:" + QString::number(qmlDebugPort) + ",block" +
457492
(qmlDebugServices.isEmpty() ?
458493
"" : (",services:" + qmlDebugServices)));
459-
printf("QML Debugger: Going to wait for connection on port %d...\n", port);
494+
printf("QML Debugger: Going to wait for connection on port %d...\n", qmlDebugPort);
460495
}
461496

462497
defaultArgs.push_front(args.takeFirst());

0 commit comments

Comments
 (0)