Skip to content

Commit 8239934

Browse files
authored
Merge pull request #6293 from bulbazord/alangford/cherrypick/20221013/105473133
[debugserver] Initialize logging earlier in the startup sequence
2 parents 751b193 + 398c751 commit 8239934

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lldb/tools/debugserver/source/debugserver.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,21 @@ int main(int argc, char *argv[]) {
945945
sigaddset(&sigset, SIGCHLD);
946946
sigprocmask(SIG_BLOCK, &sigset, NULL);
947947

948+
// Set up DNB logging by default. If the user passes different log flags or a
949+
// log file, these settings will be modified after processing the command line
950+
// arguments.
951+
auto log_callback = OsLogger::GetLogFunction();
952+
if (log_callback) {
953+
// if os_log() support is available, log through that.
954+
DNBLogSetLogCallback(log_callback, nullptr);
955+
DNBLog("debugserver will use os_log for internal logging.");
956+
} else {
957+
// Fall back to ASL support.
958+
DNBLogSetLogCallback(ASLLogCallback, nullptr);
959+
DNBLog("debugserver will use ASL for internal logging.");
960+
}
961+
DNBLogSetLogMask(/*log_flags*/ 0);
962+
948963
g_remoteSP = std::make_shared<RNBRemote>();
949964

950965
RNBRemote *remote = g_remoteSP.get();
@@ -1318,27 +1333,13 @@ int main(int argc, char *argv[]) {
13181333
// It is ok for us to set NULL as the logfile (this will disable any logging)
13191334

13201335
if (log_file != NULL) {
1336+
DNBLog("debugserver is switching to logging to a file.");
13211337
DNBLogSetLogCallback(FileLogCallback, log_file);
13221338
// If our log file was set, yet we have no log flags, log everything!
13231339
if (log_flags == 0)
13241340
log_flags = LOG_ALL | LOG_RNB_ALL;
1325-
1326-
DNBLogSetLogMask(log_flags);
1327-
} else {
1328-
// Enable DNB logging
1329-
1330-
// if os_log() support is available, log through that.
1331-
auto log_callback = OsLogger::GetLogFunction();
1332-
if (log_callback) {
1333-
DNBLogSetLogCallback(log_callback, nullptr);
1334-
DNBLog("debugserver will use os_log for internal logging.");
1335-
} else {
1336-
// Fall back to ASL support.
1337-
DNBLogSetLogCallback(ASLLogCallback, NULL);
1338-
DNBLog("debugserver will use ASL for internal logging.");
1339-
}
1340-
DNBLogSetLogMask(log_flags);
13411341
}
1342+
DNBLogSetLogMask(log_flags);
13421343

13431344
if (DNBLogEnabled()) {
13441345
for (i = 0; i < argc; i++)

0 commit comments

Comments
 (0)