diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-07-15 12:01:05 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-08-04 13:34:35 +0000 |
commit | e7a709044e75004075e62c1c3a665b19c47947af (patch) | |
tree | ee46c26bfad465cc9581862bd7a160c451e967dd /src/qml/debugger | |
parent | 32d17754cbaf40e55cb62a420da1db5e95af5516 (diff) |
Simplify QQmlDebugServer::enableFromArguments
We can use the command line arguments already retrieved by
QQmlDebugConnector and we can return early in error conditions.
Also, make sure we don't pass QStringLiterals to QRegExp.
Change-Id: I06ce6eec9ea3adeabb9f4d35de8024eab8729d35
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/debugger')
-rw-r--r-- | src/qml/debugger/qqmldebugconnector.cpp | 8 | ||||
-rw-r--r-- | src/qml/debugger/qqmldebugconnector_p.h | 3 | ||||
-rw-r--r-- | src/qml/debugger/qqmldebugserver.cpp | 94 |
3 files changed, 58 insertions, 47 deletions
diff --git a/src/qml/debugger/qqmldebugconnector.cpp b/src/qml/debugger/qqmldebugconnector.cpp index 3157c0912c..b31e61749b 100644 --- a/src/qml/debugger/qqmldebugconnector.cpp +++ b/src/qml/debugger/qqmldebugconnector.cpp @@ -80,6 +80,14 @@ void QQmlDebugConnector::setPluginKey(const QString &key) } } +QString QQmlDebugConnector::commandLineArguments() +{ + QQmlDebugConnectorParams *params = qmlDebugConnectorParams(); + if (!params) + return QString(); + return params->arguments; +} + QQmlDebugConnector *QQmlDebugConnector::instance() { QQmlDebugConnectorParams *params = qmlDebugConnectorParams(); diff --git a/src/qml/debugger/qqmldebugconnector_p.h b/src/qml/debugger/qqmldebugconnector_p.h index 91f898bd4b..a45da4cae0 100644 --- a/src/qml/debugger/qqmldebugconnector_p.h +++ b/src/qml/debugger/qqmldebugconnector_p.h @@ -78,6 +78,9 @@ public: QQmlDebugConnector *inst = instance(); return inst ? static_cast<Service *>(inst->service(Service::s_key)) : 0; } + +protected: + static QString commandLineArguments(); }; QT_END_NAMESPACE diff --git a/src/qml/debugger/qqmldebugserver.cpp b/src/qml/debugger/qqmldebugserver.cpp index 60c54676ce..a2aab9e1b6 100644 --- a/src/qml/debugger/qqmldebugserver.cpp +++ b/src/qml/debugger/qqmldebugserver.cpp @@ -425,10 +425,12 @@ bool QQmlDebugServerImpl::open(const QVariantHash &configuration = QVariantHash( bool QQmlDebugServerImpl::enableFromArguments() { - if (qApp == 0) - return false; - QCoreApplicationPrivate *appD = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp)); + // format: qmljsdebugger=port:<port_from>[,port_to],host:<ip address>][,block] + const QString args = commandLineArguments(); #ifndef QT_NO_QML_DEBUGGER + if (args.isEmpty()) + return false; // Manual initialization, through QQmlDebugServer::open() + // ### remove port definition when protocol is changed int portFrom = 0; int portTo = 0; @@ -437,57 +439,55 @@ bool QQmlDebugServerImpl::enableFromArguments() QString hostAddress; QString fileName; - // format: qmljsdebugger=port:<port_from>[,port_to],host:<ip address>][,block] - if (!appD->qmljsDebugArgumentsString().isEmpty()) { - QStringList lstjsDebugArguments = appD->qmljsDebugArgumentsString() - .split(QLatin1Char(',')); - QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend(); - QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin(); - for (; argsIt != argsItEnd; ++argsIt) { - const QString strArgument = *argsIt; - if (strArgument.startsWith(QLatin1String("port:"))) { - portFrom = strArgument.mid(5).toInt(&ok); - portTo = portFrom; - QStringList::const_iterator argsNext = argsIt + 1; - if (argsNext == argsItEnd) - break; - const QString nextArgument = *argsNext; - if (ok && nextArgument.contains(QRegExp(QStringLiteral("^\\s*\\d+\\s*$")))) { - portTo = nextArgument.toInt(&ok); - ++argsIt; - } - } else if (strArgument.startsWith(QLatin1String("host:"))) { - hostAddress = strArgument.mid(5); - } else if (strArgument == QLatin1String("block")) { - block = true; - } else if (strArgument.startsWith(QLatin1String("file:"))) { - fileName = strArgument.mid(5); - ok = !fileName.isEmpty(); - } else { - qWarning() << QString::fromLatin1("QML Debugger: Invalid argument '%1' " - "detected. Ignoring the same.") - .arg(strArgument); + const QStringList lstjsDebugArguments = args.split(QLatin1Char(',')); + QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend(); + QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin(); + for (; argsIt != argsItEnd; ++argsIt) { + const QString strArgument = *argsIt; + if (strArgument.startsWith(QLatin1String("port:"))) { + portFrom = strArgument.mid(5).toInt(&ok); + portTo = portFrom; + QStringList::const_iterator argsNext = argsIt + 1; + if (argsNext == argsItEnd) + break; + const QString nextArgument = *argsNext; + + // Don't use QStringLiteral here. QRegExp has a global cache and will save an implicitly + // shared copy of the passed string. That copy isn't properly detached when the library + // is unloaded if the original string lives in the library's .rodata + if (ok && nextArgument.contains(QRegExp(QLatin1String("^\\s*\\d+\\s*$")))) { + portTo = nextArgument.toInt(&ok); + ++argsIt; } - } - - if (ok) { - if (!fileName.isEmpty()) - return enable(ConnectToLocalAction(fileName, block)); - else - return enable(StartTcpServerAction(portFrom, portTo, block, hostAddress)); + } else if (strArgument.startsWith(QLatin1String("host:"))) { + hostAddress = strArgument.mid(5); + } else if (strArgument == QLatin1String("block")) { + block = true; + } else if (strArgument.startsWith(QLatin1String("file:"))) { + fileName = strArgument.mid(5); + ok = !fileName.isEmpty(); } else { - qWarning() << QString(QLatin1String( - "QML Debugger: Ignoring \"-qmljsdebugger=%1\". " - "Format is qmljsdebugger=port:<port_from>[,port_to],host:" - "<ip address>][,block]")).arg(appD->qmljsDebugArgumentsString()); + qWarning() << QString::fromLatin1("QML Debugger: Invalid argument '%1' " + "detected. Ignoring the same.") + .arg(strArgument); } } + + if (ok) { + if (!fileName.isEmpty()) + return enable(ConnectToLocalAction(fileName, block)); + else + return enable(StartTcpServerAction(portFrom, portTo, block, hostAddress)); + } else { + qWarning() << QString::fromLatin1("QML Debugger: Ignoring \"-qmljsdebugger=%1\". " + "Format is qmljsdebugger=port:<port_from>[,port_to],host:" + "<ip address>][,block]").arg(args); + } #else - if (!appD->qmljsDebugArgumentsString().isEmpty()) { + if (!args.isEmpty()) { qWarning() << QString(QLatin1String( "QML Debugger: Ignoring \"-qmljsdebugger=%1\". " - "QtQml is not configured for debugging.")).arg( - appD->qmljsDebugArgumentsString()); + "QtQml is not configured for debugging.")).arg(args); } #endif return false; |