diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp')
| -rw-r--r-- | contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp | 78 | 
1 files changed, 45 insertions, 33 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp index 2ad61de1a3e9..9bf0b30bc152 100644 --- a/contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp +++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectLog.cpp @@ -8,43 +8,36 @@  #include "CommandObjectLog.h"  #include "lldb/Core/Debugger.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/StreamFile.h"  #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandInterpreter.h"  #include "lldb/Interpreter/CommandReturnObject.h"  #include "lldb/Interpreter/OptionArgParser.h"  #include "lldb/Interpreter/Options.h" -#include "lldb/Symbol/LineTable.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/SymbolVendor.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/Target.h"  #include "lldb/Utility/Args.h"  #include "lldb/Utility/FileSpec.h"  #include "lldb/Utility/Log.h" -#include "lldb/Utility/RegularExpression.h"  #include "lldb/Utility/Stream.h"  #include "lldb/Utility/Timer.h"  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 +118,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 +139,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 +213,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 +271,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 +289,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 +315,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 +332,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;  | 
