diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-05-27 09:45:38 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-06-08 16:10:36 +0000 |
commit | 3baef2b73b9bfecd618572535343ba2195378e61 (patch) | |
tree | 075eab3f3107578f3eefdc5968fd58149c3b603f /src/qml/debugger | |
parent | e70d6e6b4543d91dc9b4eac466146bde1487ba6f (diff) |
QQmlDebug: reliably print the debugger warning
When an executable contains some TUs that pass printWarning and some
that don't, the warning could have been lost if static initialization
first initialized one that had printWarning=false and only then moved
to initializing one that had printWarning=true. Typically, a DLL might
pass false here, in which case the user application, initialized
later, wouldn't have a say in whether the warning was printed.
Use an atomic_flag to independently track whether the warning was
printed, so that we reliably print the warning when at least one TU in
the final executable requested it.
[ChangeLog][QtQml][QQmlDebug] The warning about enabled
debuggers is now printed when at least one translation unit in the
final executable requests it, independent of the order in which
translation units are linked/initialized.
Manual conflict resolutions:
- removed Q_CONSTEXPR (which doesn't exist in 6.3)
Change-Id: I10af0a46ecb82a8b1a1373eb9332d913c03b20f3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit c98c2c08a5f926b67c40b6363274d23066bfe341)
Diffstat (limited to 'src/qml/debugger')
-rw-r--r-- | src/qml/debugger/qqmldebug.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp index 58b8ea2c4f..f065f27c92 100644 --- a/src/qml/debugger/qqmldebug.cpp +++ b/src/qml/debugger/qqmldebug.cpp @@ -44,15 +44,24 @@ #include <private/qqmlengine_p.h> #include <private/qv4compileddata_p.h> +#include <atomic> #include <cstdio> QT_REQUIRE_CONFIG(qml_debug); QT_BEGIN_NAMESPACE +#if __cplusplus >= 202002L +# define Q_ATOMIC_FLAG_INIT {} +#else +# define Q_ATOMIC_FLAG_INIT ATOMIC_FLAG_INIT // deprecated in C++20 +#endif + +static std::atomic_flag s_printedWarning = Q_ATOMIC_FLAG_INIT; + QQmlDebuggingEnabler::QQmlDebuggingEnabler(bool printWarning) { - if (!QQmlEnginePrivate::qml_debugging_enabled && printWarning) + if (printWarning && !s_printedWarning.test_and_set(std::memory_order_relaxed)) fprintf(stderr, "QML debugging is enabled. Only use this in a safe environment.\n"); QQmlEnginePrivate::qml_debugging_enabled = true; } |