diff options
author | Alex Langford <alangford@apple.com> | 2023-02-15 14:18:31 -0800 |
---|---|---|
committer | Alex Langford <alangford@apple.com> | 2023-02-15 16:35:51 -0800 |
commit | dcf18e4757b2bc2410031e7b69082117d540a1d6 (patch) | |
tree | c36879b659129616e609587246b1e82f8a2bf506 /lldb/tools/debugserver/source/debugserver.cpp | |
parent | c738b430c46a3145f0d454f0134804d0c90d19ac (diff) | |
download | llvm-dcf18e4757b2bc2410031e7b69082117d540a1d6.zip llvm-dcf18e4757b2bc2410031e7b69082117d540a1d6.tar.gz llvm-dcf18e4757b2bc2410031e7b69082117d540a1d6.tar.bz2 |
[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
Diffstat (limited to 'lldb/tools/debugserver/source/debugserver.cpp')
-rw-r--r-- | lldb/tools/debugserver/source/debugserver.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index cbff6ac..cfc9646e 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -945,6 +945,21 @@ int main(int argc, char *argv[]) { sigaddset(&sigset, SIGCHLD); sigprocmask(SIG_BLOCK, &sigset, NULL); + // Set up DNB logging by default. If the user passes different log flags or a + // log file, these settings will be modified after processing the command line + // arguments. + auto log_callback = OsLogger::GetLogFunction(); + if (log_callback) { + // if os_log() support is available, log through that. + DNBLogSetLogCallback(log_callback, nullptr); + DNBLog("debugserver will use os_log for internal logging."); + } else { + // Fall back to ASL support. + DNBLogSetLogCallback(ASLLogCallback, nullptr); + DNBLog("debugserver will use ASL for internal logging."); + } + DNBLogSetLogMask(/*log_flags*/ 0); + g_remoteSP = std::make_shared<RNBRemote>(); RNBRemote *remote = g_remoteSP.get(); @@ -1318,27 +1333,13 @@ int main(int argc, char *argv[]) { // It is ok for us to set NULL as the logfile (this will disable any logging) if (log_file != NULL) { + DNBLog("debugserver is switching to logging to a file."); DNBLogSetLogCallback(FileLogCallback, log_file); // If our log file was set, yet we have no log flags, log everything! if (log_flags == 0) log_flags = LOG_ALL | LOG_RNB_ALL; - - DNBLogSetLogMask(log_flags); - } else { - // Enable DNB logging - - // if os_log() support is available, log through that. - auto log_callback = OsLogger::GetLogFunction(); - if (log_callback) { - DNBLogSetLogCallback(log_callback, nullptr); - DNBLog("debugserver will use os_log for internal logging."); - } else { - // Fall back to ASL support. - DNBLogSetLogCallback(ASLLogCallback, NULL); - DNBLog("debugserver will use ASL for internal logging."); - } - DNBLogSetLogMask(log_flags); } + DNBLogSetLogMask(log_flags); if (DNBLogEnabled()) { for (i = 0; i < argc; i++) |