From 09dea546692f4e9f32bf16f1a9d5d0de52a64691 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 23 Jun 2022 08:06:17 -0700 Subject: [lldb] Support a buffered logging mode This patch adds a buffered logging mode to lldb. A buffer size can be passed to `log enable` with the -b flag. If no buffer size is specified, logging is unbuffered. Differential revision: https://reviews.llvm.org/D127986 --- lldb/source/Commands/CommandObjectLog.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lldb/source/Commands/CommandObjectLog.cpp') diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index c8df308..190b262 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -11,6 +11,7 @@ #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" +#include "lldb/Interpreter/OptionValueUInt64.h" #include "lldb/Interpreter/Options.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/FileSpec.h" @@ -21,7 +22,7 @@ using namespace lldb; using namespace lldb_private; -#define LLDB_OPTIONS_log +#define LLDB_OPTIONS_log_enable #include "CommandOptions.inc" /// Common completion logic for log enable/disable. @@ -89,6 +90,10 @@ public: log_file.SetFile(option_arg, FileSpec::Style::native); FileSystem::Instance().Resolve(log_file); break; + case 'b': + error = + buffer_size.SetValueFromString(option_arg, eVarSetOperationAssign); + break; case 't': log_options |= LLDB_LOG_OPTION_THREADSAFE; break; @@ -125,16 +130,16 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override { log_file.Clear(); + buffer_size.Clear(); log_options = 0; } llvm::ArrayRef GetDefinitions() override { - return llvm::makeArrayRef(g_log_options); + return llvm::makeArrayRef(g_log_enable_options); } - // Instance variables to hold the values for command options. - FileSpec log_file; + OptionValueUInt64 buffer_size; uint32_t log_options = 0; }; @@ -164,9 +169,9 @@ protected: std::string error; llvm::raw_string_ostream error_stream(error); - bool success = - GetDebugger().EnableLog(channel, args.GetArgumentArrayRef(), log_file, - m_options.log_options, error_stream); + bool success = GetDebugger().EnableLog( + channel, args.GetArgumentArrayRef(), log_file, m_options.log_options, + m_options.buffer_size.GetCurrentValue(), error_stream); result.GetErrorStream() << error_stream.str(); if (success) -- cgit v1.1