Skip to content

Commit 398c751

Browse files
committed
[debugserver] Initialize logging earlier in the startup sequence
Prior to setting up logging, we have uses of RNBLogSTDERR and RNBLogSTDOUT. These macros will dump to STDERR and STDOUT respectively if debugserver has a tty. Otherwise, it uses _DNBLog, which will do nothing if a logging function hasn't been set up. For example, if you specify a log file that cannot be opened for any reason and you don't have a tty, you have 0 insight into what happened. rdar://105473133 Differential Revision: https://reviews.llvm.org/D144142 (cherry picked from commit dcf18e4)
1 parent 751b193 commit 398c751

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)