diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-05-27 09:45:38 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-31 17:23:09 +0200 |
commit | c98c2c08a5f926b67c40b6363274d23066bfe341 (patch) | |
tree | bf735f0a39a74f54d48faf1f5caa9ea96fcb6d8c /src/qml/debugger | |
parent | 7aa9b826bd43c3cdb5f0c2b7cb0b0ec910a18362 (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.
Pick-to: 6.3 6.2 5.15
Change-Id: I10af0a46ecb82a8b1a1373eb9332d913c03b20f3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
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..5619a5fe3e 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 + +Q_CONSTINIT 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; } |