diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Commands/CommandObjectPlatform.cpp | |
parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) |
Notes
Diffstat (limited to 'source/Commands/CommandObjectPlatform.cpp')
-rw-r--r-- | source/Commands/CommandObjectPlatform.cpp | 115 |
1 files changed, 42 insertions, 73 deletions
diff --git a/source/Commands/CommandObjectPlatform.cpp b/source/Commands/CommandObjectPlatform.cpp index 8ed003767d58..f822a8b54cb0 100644 --- a/source/Commands/CommandObjectPlatform.cpp +++ b/source/Commands/CommandObjectPlatform.cpp @@ -18,7 +18,6 @@ #include "lldb/Core/PluginManager.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" -#include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandOptionValidators.h" #include "lldb/Interpreter/CommandReturnObject.h" @@ -27,6 +26,7 @@ #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Args.h" #include "lldb/Utility/DataExtractor.h" #include "llvm/ADT/SmallString.h" @@ -178,17 +178,10 @@ public: ~CommandObjectPlatformSelect() override = default; - int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) override { - std::string completion_str(input.GetArgumentAtIndex(cursor_index)); - completion_str.erase(cursor_char_position); - - CommandCompletions::PlatformPluginNames( - GetCommandInterpreter(), completion_str.c_str(), match_start_point, - max_return_elements, nullptr, word_complete, matches); - return matches.GetSize(); + int HandleCompletion(CompletionRequest &request) override { + CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request, + nullptr); + return request.GetMatches().GetSize(); } Options *GetOptions() override { return &m_option_group; } @@ -385,8 +378,8 @@ protected: Status error; if (platform_sp->IsConnected()) { - // Cache the instance name if there is one since we are - // about to disconnect and the name might go with it. + // Cache the instance name if there is one since we are about to + // disconnect and the name might go with it. const char *hostname_cstr = platform_sp->GetHostname(); std::string hostname; if (hostname_cstr) @@ -867,8 +860,8 @@ public: // argument entry. arg2.push_back(file_arg_host); - // Push the data for the first and the second arguments into the m_arguments - // vector. + // Push the data for the first and the second arguments into the + // m_arguments vector. m_arguments.push_back(arg1); m_arguments.push_back(arg2); } @@ -1059,8 +1052,8 @@ protected: if (argc > 0) { if (m_options.launch_info.GetExecutableFile()) { - // We already have an executable file, so we will use this - // and all arguments to this function are extra arguments + // We already have an executable file, so we will use this and all + // arguments to this function are extra arguments m_options.launch_info.GetArguments().AppendArguments(args); } else { // We don't have any file yet, so the first argument is our @@ -1342,32 +1335,32 @@ protected: } break; case 'n': - match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, - false); + match_info.GetProcessInfo().GetExecutableFile().SetFile( + option_arg, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::Equals); break; case 'e': - match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, - false); + match_info.GetProcessInfo().GetExecutableFile().SetFile( + option_arg, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::EndsWith); break; case 's': - match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, - false); + match_info.GetProcessInfo().GetExecutableFile().SetFile( + option_arg, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::StartsWith); break; case 'c': - match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, - false); + match_info.GetProcessInfo().GetExecutableFile().SetFile( + option_arg, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::Contains); break; case 'r': - match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, - false); + match_info.GetProcessInfo().GetExecutableFile().SetFile( + option_arg, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::RegularExpression); break; @@ -1536,7 +1529,8 @@ public: break; case 'n': - attach_info.GetExecutableFile().SetFile(option_arg, false); + attach_info.GetExecutableFile().SetFile(option_arg, false, + FileSpec::Style::native); break; case 'w': @@ -1560,11 +1554,8 @@ public: } bool HandleOptionArgumentCompletion( - Args &input, int cursor_index, int char_pos, - OptionElementVector &opt_element_vector, int opt_element_index, - int match_start_point, int max_return_elements, - CommandInterpreter &interpreter, bool &word_complete, - StringList &matches) override { + CompletionRequest &request, OptionElementVector &opt_element_vector, + int opt_element_index, CommandInterpreter &interpreter) override { int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index; @@ -1574,11 +1565,10 @@ public: // Are we in the name? // Look to see if there is a -P argument provided, and if so use that - // plugin, otherwise - // use the default plugin. + // plugin, otherwise use the default plugin. const char *partial_name = nullptr; - partial_name = input.GetArgumentAtIndex(opt_arg_pos); + partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); PlatformSP platform_sp(interpreter.GetPlatform(true)); if (platform_sp) { @@ -1586,14 +1576,14 @@ public: ProcessInstanceInfoMatch match_info; if (partial_name) { match_info.GetProcessInfo().GetExecutableFile().SetFile( - partial_name, false); + partial_name, false, FileSpec::Style::native); match_info.SetNameMatchType(NameMatch::StartsWith); } platform_sp->FindProcesses(match_info, process_infos); const uint32_t num_matches = process_infos.GetSize(); if (num_matches > 0) { for (uint32_t i = 0; i < num_matches; ++i) { - matches.AppendString( + request.GetMatches().AppendString( process_infos.GetProcessNameAtIndex(i), process_infos.GetProcessNameLengthAtIndex(i)); } @@ -1693,7 +1683,7 @@ class CommandObjectPlatformShell : public CommandObjectRaw { public: class CommandOptions : public Options { public: - CommandOptions() : Options(), timeout(10) {} + CommandOptions() : Options() {} ~CommandOptions() override = default; @@ -1709,11 +1699,13 @@ public: switch (short_option) { case 't': - timeout = 10; - if (option_arg.getAsInteger(10, timeout)) + uint32_t timeout_sec; + if (option_arg.getAsInteger(10, timeout_sec)) error.SetErrorStringWithFormat( "could not convert \"%s\" to a numeric value.", option_arg.str().c_str()); + else + timeout = std::chrono::seconds(timeout_sec); break; default: error.SetErrorStringWithFormat("invalid short option character '%c'", @@ -1726,7 +1718,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override {} - uint32_t timeout; + Timeout<std::micro> timeout = std::chrono::seconds(10); }; CommandObjectPlatformShell(CommandInterpreter &interpreter) @@ -1739,47 +1731,24 @@ public: Options *GetOptions() override { return &m_options; } - bool DoExecute(const char *raw_command_line, + bool DoExecute(llvm::StringRef raw_command_line, CommandReturnObject &result) override { ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_options.NotifyOptionParsingStarting(&exe_ctx); - const char *expr = nullptr; // Print out an usage syntax on an empty command line. - if (raw_command_line[0] == '\0') { + if (raw_command_line.empty()) { result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str()); return true; } - if (raw_command_line[0] == '-') { - // We have some options and these options MUST end with --. - const char *end_options = nullptr; - const char *s = raw_command_line; - while (s && s[0]) { - end_options = ::strstr(s, "--"); - if (end_options) { - end_options += 2; // Get past the "--" - if (::isspace(end_options[0])) { - expr = end_options; - while (::isspace(*expr)) - ++expr; - break; - } - } - s = end_options; - } - - if (end_options) { - Args args( - llvm::StringRef(raw_command_line, end_options - raw_command_line)); - if (!ParseOptions(args, result)) - return false; - } - } + OptionsWithRaw args(raw_command_line); + const char *expr = args.GetRawPart().c_str(); - if (expr == nullptr) - expr = raw_command_line; + if (args.HasArgs()) + if (!ParseOptions(args.GetArgs(), result)) + return false; PlatformSP platform_sp( m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |