Prevent lldb from enabling os_log mirroring to stderr

lldb will normally set OS_ACTIVITY_DT_MODE, so that NSLog is mirrored
to stderr, but this also affects os_log, which we use in the Apple
unified logging backend.

When we detect this situation in the unified logging backend, we disable
Qt's own stderr logging, to avoid duplicate messages.

As the Qt stderr logging is preferable to the stderr logging that os_log
gives, we override lldb's choice, using the same environment variable
opt out that Xcode uses: IDE_DISABLED_OS_ACTIVITY_DT_MODE.

This makes console output in Qt Creator the same, regardless of whether
the user is debugging the app or not.

Change-Id: I5544bde803671258cede918705388c9283885e30
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tor Arne Vestbø
2023-11-21 14:59:32 +01:00
parent 61e9a7fe16
commit d7545f9bf5

View File

@@ -266,7 +266,13 @@ void LldbEngine::handleLldbStarted()
cmd2.arg("startmode", rp.startMode); cmd2.arg("startmode", rp.startMode);
cmd2.arg("nativemixed", isNativeMixedActive()); cmd2.arg("nativemixed", isNativeMixedActive());
cmd2.arg("workingdirectory", rp.inferior.workingDirectory.path()); cmd2.arg("workingdirectory", rp.inferior.workingDirectory.path());
cmd2.arg("environment", rp.inferior.environment.toStringList()); QStringList environment = rp.inferior.environment.toStringList();
// Prevent lldb from automatically setting OS_ACTIVITY_DT_MODE to mirror
// NSLog to stderr, as that will also mirror os_log, which we pick up in
// AppleUnifiedLogger::preventsStderrLogging(), and end up disabling Qt's
// default stderr logger. We prefer Qt's own stderr logging if we can.
environment << "IDE_DISABLED_OS_ACTIVITY_DT_MODE=1";
cmd2.arg("environment", environment);
cmd2.arg("processargs", toHex(ProcessArgs::splitArgs(rp.inferior.command.arguments(), cmd2.arg("processargs", toHex(ProcessArgs::splitArgs(rp.inferior.command.arguments(),
HostOsInfo::hostOs()).join(QChar(0)))); HostOsInfo::hostOs()).join(QChar(0))));
cmd2.arg("platform", rp.platform); cmd2.arg("platform", rp.platform);