diff options
Diffstat (limited to 'source/Commands/CommandObjectLog.cpp')
-rw-r--r-- | source/Commands/CommandObjectLog.cpp | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/source/Commands/CommandObjectLog.cpp b/source/Commands/CommandObjectLog.cpp index 2ad61de1a3e9..31a876c3430e 100644 --- a/source/Commands/CommandObjectLog.cpp +++ b/source/Commands/CommandObjectLog.cpp @@ -31,20 +31,23 @@ using namespace lldb; using namespace lldb_private; -static constexpr OptionDefinition g_log_options[] = { - // clang-format off - { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeFilename, "Set the destination file to log to." }, - { LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." }, - { LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Enable verbose logging." }, - { LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." }, - { LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Prepend all log lines with a timestamp." }, - { LLDB_OPT_SET_1, false, "pid-tid", 'p', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Prepend all log lines with the process and thread ID that generates the log line." }, - { LLDB_OPT_SET_1, false, "thread-name",'n', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Prepend all log lines with the thread name for the thread that generates the log line." }, - { LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Append a stack backtrace to each log line." }, - { LLDB_OPT_SET_1, false, "append", 'a', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Append to the log file instead of overwriting." }, - { LLDB_OPT_SET_1, false, "file-function",'F',OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Prepend the names of files and function that generate the logs." }, - // clang-format on -}; +#define LLDB_OPTIONS_log +#include "CommandOptions.inc" + +/// Common completion logic for log enable/disable. +static void CompleteEnableDisable(CompletionRequest &request) { + size_t arg_index = request.GetCursorIndex(); + if (arg_index == 0) { // We got: log enable/disable x[tab] + for (llvm::StringRef channel : Log::ListChannels()) + request.TryCompleteCurrentArg(channel); + } else if (arg_index >= 1) { // We got: log enable/disable channel x[tab] + llvm::StringRef channel = request.GetParsedLine().GetArgumentAtIndex(0); + Log::ForEachChannelCategory( + channel, [&request](llvm::StringRef name, llvm::StringRef desc) { + request.TryCompleteCurrentArg(name, desc); + }); + } +} class CommandObjectLogEnable : public CommandObjectParsed { public: @@ -125,9 +128,7 @@ public: log_options |= LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION; break; default: - error.SetErrorStringWithFormat("unrecognized option '%c'", - short_option); - break; + llvm_unreachable("Unimplemented option"); } return error; @@ -148,17 +149,24 @@ public: uint32_t log_options; }; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CompleteEnableDisable(request); + } + protected: bool DoExecute(Args &args, CommandReturnObject &result) override { if (args.GetArgumentCount() < 2) { result.AppendErrorWithFormat( "%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); + result.SetStatus(eReturnStatusFailed); return false; } // Store into a std::string since we're about to shift the channel off. - const std::string channel = args[0].ref; + const std::string channel = args[0].ref(); args.Shift(); // Shift off the channel char log_file[PATH_MAX]; if (m_options.log_file) @@ -215,16 +223,23 @@ public: ~CommandObjectLogDisable() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + CompleteEnableDisable(request); + } + protected: bool DoExecute(Args &args, CommandReturnObject &result) override { if (args.empty()) { result.AppendErrorWithFormat( "%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); + result.SetStatus(eReturnStatusFailed); return false; } - const std::string channel = args[0].ref; + const std::string channel = args[0].ref(); args.Shift(); // Shift off the channel if (channel == "all") { Log::DisableAllLogChannels(); @@ -266,6 +281,13 @@ public: ~CommandObjectLogList() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + for (llvm::StringRef channel : Log::ListChannels()) + request.TryCompleteCurrentArg(channel); + } + protected: bool DoExecute(Args &args, CommandReturnObject &result) override { std::string output; @@ -277,7 +299,7 @@ protected: bool success = true; for (const auto &entry : args.entries()) success = - success && Log::ListChannelCategories(entry.ref, output_stream); + success && Log::ListChannelCategories(entry.ref(), output_stream); if (success) result.SetStatus(eReturnStatusSuccessFinishResult); } @@ -303,7 +325,7 @@ protected: result.SetStatus(eReturnStatusFailed); if (args.GetArgumentCount() == 1) { - auto sub_command = args[0].ref; + auto sub_command = args[0].ref(); if (sub_command.equals_lower("enable")) { Timer::SetDisplayDepth(UINT32_MAX); @@ -320,8 +342,8 @@ protected: result.SetStatus(eReturnStatusSuccessFinishResult); } } else if (args.GetArgumentCount() == 2) { - auto sub_command = args[0].ref; - auto param = args[1].ref; + auto sub_command = args[0].ref(); + auto param = args[1].ref(); if (sub_command.equals_lower("enable")) { uint32_t depth; |