diff options
Diffstat (limited to 'lldb/source/Interpreter')
46 files changed, 399 insertions, 221 deletions
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp index 5139c53a47b3..a5e033937210 100644 --- a/lldb/source/Interpreter/CommandAlias.cpp +++ b/lldb/source/Interpreter/CommandAlias.cpp @@ -1,4 +1,4 @@ -//===-- CommandAlias.cpp -----------------------------------------*- C++-*-===// +//===-- CommandAlias.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -32,7 +32,7 @@ static bool ProcessAliasOptionsArgs(lldb::CommandObjectSP &cmd_obj_sp, std::string options_string(options_args); // TODO: Find a way to propagate errors in this CommandReturnObject up the // stack. - CommandReturnObject result; + CommandReturnObject result(false); // Check to see if the command being aliased can take any command options. Options *options = cmd_obj_sp->GetOptions(); if (options) { @@ -65,7 +65,8 @@ static bool ProcessAliasOptionsArgs(lldb::CommandObjectSP &cmd_obj_sp, else { for (auto &entry : args.entries()) { if (!entry.ref().empty()) - option_arg_vector->emplace_back("<argument>", -1, entry.ref()); + option_arg_vector->emplace_back(std::string("<argument>"), -1, + std::string(entry.ref())); } } } @@ -79,7 +80,7 @@ CommandAlias::CommandAlias(CommandInterpreter &interpreter, llvm::StringRef help, llvm::StringRef syntax, uint32_t flags) : CommandObject(interpreter, name, help, syntax, flags), - m_underlying_command_sp(), m_option_string(options_args), + m_underlying_command_sp(), m_option_string(std::string(options_args)), m_option_args_sp(new OptionArgVector), m_is_dashdash_alias(eLazyBoolCalculate), m_did_set_help(false), m_did_set_help_long(false) { diff --git a/lldb/source/Interpreter/CommandHistory.cpp b/lldb/source/Interpreter/CommandHistory.cpp index 0be61f836e00..9c7919ecc41f 100644 --- a/lldb/source/Interpreter/CommandHistory.cpp +++ b/lldb/source/Interpreter/CommandHistory.cpp @@ -1,4 +1,4 @@ -//===-- CommandHistory.cpp --------------------------------------*- C++ -*-===// +//===-- CommandHistory.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -87,7 +87,7 @@ void CommandHistory::AppendString(llvm::StringRef str, bool reject_if_dupe) { return; } } - m_history.push_back(str); + m_history.push_back(std::string(str)); } void CommandHistory::Clear() { diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 1ee80503f569..e55b25500179 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1,4 +1,4 @@ -//===-- CommandInterpreter.cpp ----------------------------------*- C++ -*-===// +//===-- CommandInterpreter.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -116,8 +116,7 @@ CommandInterpreter::CommandInterpreter(Debugger &debugger, m_skip_lldbinit_files(false), m_skip_app_init_files(false), m_command_io_handler_sp(), m_comment_char('#'), m_batch_command_mode(false), m_truncation_warning(eNoTruncation), - m_command_source_depth(0), m_num_errors(0), m_quit_requested(false), - m_stopped_for_crash(false) { + m_command_source_depth(0), m_result() { SetEventName(eBroadcastBitThreadShouldExit, "thread-should-exit"); SetEventName(eBroadcastBitResetPrompt, "reset-prompt"); SetEventName(eBroadcastBitQuitCommandReceived, "quit"); @@ -210,7 +209,7 @@ void CommandInterpreter::Initialize() { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); - CommandReturnObject result; + CommandReturnObject result(m_debugger.GetUseColor()); LoadCommandDictionary(); @@ -357,7 +356,7 @@ void CommandInterpreter::Initialize() { AddAlias("p", cmd_obj_sp, "--")->SetHelpLong(""); AddAlias("print", cmd_obj_sp, "--")->SetHelpLong(""); AddAlias("call", cmd_obj_sp, "--")->SetHelpLong(""); - if (auto po = AddAlias("po", cmd_obj_sp, "-O --")) { + if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) { po->SetHelp("Evaluate an expression on the current thread. Displays any " "returned value with formatting " "controlled by the type's author."); @@ -382,6 +381,16 @@ void CommandInterpreter::Initialize() { } } + cmd_obj_sp = GetCommandSPExact("platform shell", false); + if (cmd_obj_sp) { + CommandAlias *shell_alias = AddAlias("shell", cmd_obj_sp, " --host --"); + if (shell_alias) { + shell_alias->SetHelp("Run a shell command on the host."); + shell_alias->SetHelpLong(""); + shell_alias->SetSyntax("shell <shell-command>"); + } + } + cmd_obj_sp = GetCommandSPExact("process kill", false); if (cmd_obj_sp) { AddAlias("kill", cmd_obj_sp); @@ -500,7 +509,10 @@ void CommandInterpreter::LoadCommandDictionary() { m_command_dict["language"] = CommandObjectSP(new CommandObjectLanguage(*this)); + // clang-format off const char *break_regexes[][2] = { + {"^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$", + "breakpoint set --file '%1' --line %2 --column %3"}, {"^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$", "breakpoint set --file '%1' --line %2"}, {"^/([^/]+)/$", "breakpoint set --source-pattern-regexp '%1'"}, @@ -515,6 +527,7 @@ void CommandInterpreter::LoadCommandDictionary() { "breakpoint set --name '%1' --skip-prologue=0"}, {"^[\"']?(.*[^[:space:]\"'])[\"']?[[:space:]]*$", "breakpoint set --name '%1'"}}; + // clang-format on size_t num_regexes = llvm::array_lengthof(break_regexes); @@ -523,6 +536,9 @@ void CommandInterpreter::LoadCommandDictionary() { *this, "_regexp-break", "Set a breakpoint using one of several shorthand formats.", "\n" + "_regexp-break <filename>:<linenum>:<colnum>\n" + " main.c:12:21 // Break at line 12 and column " + "21 of main.c\n\n" "_regexp-break <filename>:<linenum>\n" " main.c:12 // Break at line 12 of " "main.c\n\n" @@ -546,7 +562,7 @@ void CommandInterpreter::LoadCommandDictionary() { "current file\n" " // containing text 'break " "here'.\n", - 2, + 3, CommandCompletions::eSymbolCompletion | CommandCompletions::eSourceFileCompletion, false)); @@ -564,7 +580,8 @@ void CommandInterpreter::LoadCommandDictionary() { if (success) { CommandObjectSP break_regex_cmd_sp(break_regex_cmd_up.release()); - m_command_dict[break_regex_cmd_sp->GetCommandName()] = break_regex_cmd_sp; + m_command_dict[std::string(break_regex_cmd_sp->GetCommandName())] = + break_regex_cmd_sp; } } @@ -573,6 +590,9 @@ void CommandInterpreter::LoadCommandDictionary() { *this, "_regexp-tbreak", "Set a one-shot breakpoint using one of several shorthand formats.", "\n" + "_regexp-break <filename>:<linenum>:<colnum>\n" + " main.c:12:21 // Break at line 12 and column " + "21 of main.c\n\n" "_regexp-break <filename>:<linenum>\n" " main.c:12 // Break at line 12 of " "main.c\n\n" @@ -621,7 +641,7 @@ void CommandInterpreter::LoadCommandDictionary() { if (success) { CommandObjectSP tbreak_regex_cmd_sp(tbreak_regex_cmd_up.release()); - m_command_dict[tbreak_regex_cmd_sp->GetCommandName()] = + m_command_dict[std::string(tbreak_regex_cmd_sp->GetCommandName())] = tbreak_regex_cmd_sp; } } @@ -641,7 +661,7 @@ void CommandInterpreter::LoadCommandDictionary() { "process attach --name '%1'") && attach_regex_cmd_up->AddRegexCommand("^$", "process attach")) { CommandObjectSP attach_regex_cmd_sp(attach_regex_cmd_up.release()); - m_command_dict[attach_regex_cmd_sp->GetCommandName()] = + m_command_dict[std::string(attach_regex_cmd_sp->GetCommandName())] = attach_regex_cmd_sp; } } @@ -657,7 +677,8 @@ void CommandInterpreter::LoadCommandDictionary() { down_regex_cmd_up->AddRegexCommand("^([0-9]+)$", "frame select -r -%1")) { CommandObjectSP down_regex_cmd_sp(down_regex_cmd_up.release()); - m_command_dict[down_regex_cmd_sp->GetCommandName()] = down_regex_cmd_sp; + m_command_dict[std::string(down_regex_cmd_sp->GetCommandName())] = + down_regex_cmd_sp; } } @@ -671,7 +692,8 @@ void CommandInterpreter::LoadCommandDictionary() { if (up_regex_cmd_up->AddRegexCommand("^$", "frame select -r 1") && up_regex_cmd_up->AddRegexCommand("^([0-9]+)$", "frame select -r %1")) { CommandObjectSP up_regex_cmd_sp(up_regex_cmd_up.release()); - m_command_dict[up_regex_cmd_sp->GetCommandName()] = up_regex_cmd_sp; + m_command_dict[std::string(up_regex_cmd_sp->GetCommandName())] = + up_regex_cmd_sp; } } @@ -684,7 +706,7 @@ void CommandInterpreter::LoadCommandDictionary() { if (display_regex_cmd_up->AddRegexCommand( "^(.+)$", "target stop-hook add -o \"expr -- %1\"")) { CommandObjectSP display_regex_cmd_sp(display_regex_cmd_up.release()); - m_command_dict[display_regex_cmd_sp->GetCommandName()] = + m_command_dict[std::string(display_regex_cmd_sp->GetCommandName())] = display_regex_cmd_sp; } } @@ -699,7 +721,7 @@ void CommandInterpreter::LoadCommandDictionary() { if (undisplay_regex_cmd_up->AddRegexCommand("^([0-9]+)$", "target stop-hook delete %1")) { CommandObjectSP undisplay_regex_cmd_sp(undisplay_regex_cmd_up.release()); - m_command_dict[undisplay_regex_cmd_sp->GetCommandName()] = + m_command_dict[std::string(undisplay_regex_cmd_sp->GetCommandName())] = undisplay_regex_cmd_sp; } } @@ -718,7 +740,7 @@ void CommandInterpreter::LoadCommandDictionary() { "^([[:digit:]]+)$", "process connect --plugin gdb-remote connect://localhost:%1")) { CommandObjectSP command_sp(connect_gdb_remote_cmd_up.release()); - m_command_dict[command_sp->GetCommandName()] = command_sp; + m_command_dict[std::string(command_sp->GetCommandName())] = command_sp; } } @@ -736,7 +758,7 @@ void CommandInterpreter::LoadCommandDictionary() { connect_kdp_remote_cmd_up->AddRegexCommand( "^(.+)$", "process connect --plugin kdp-remote udp://%1:41139")) { CommandObjectSP command_sp(connect_kdp_remote_cmd_up.release()); - m_command_dict[command_sp->GetCommandName()] = command_sp; + m_command_dict[std::string(command_sp->GetCommandName())] = command_sp; } } @@ -761,7 +783,7 @@ void CommandInterpreter::LoadCommandDictionary() { bt_regex_cmd_up->AddRegexCommand("^all[[:space:]]*$", "thread backtrace all") && bt_regex_cmd_up->AddRegexCommand("^[[:space:]]*$", "thread backtrace")) { CommandObjectSP command_sp(bt_regex_cmd_up.release()); - m_command_dict[command_sp->GetCommandName()] = command_sp; + m_command_dict[std::string(command_sp->GetCommandName())] = command_sp; } } @@ -797,7 +819,8 @@ void CommandInterpreter::LoadCommandDictionary() { "source list --name \"%1\"") && list_regex_cmd_up->AddRegexCommand("^$", "source list")) { CommandObjectSP list_regex_cmd_sp(list_regex_cmd_up.release()); - m_command_dict[list_regex_cmd_sp->GetCommandName()] = list_regex_cmd_sp; + m_command_dict[std::string(list_regex_cmd_sp->GetCommandName())] = + list_regex_cmd_sp; } } @@ -815,7 +838,8 @@ void CommandInterpreter::LoadCommandDictionary() { env_regex_cmd_up->AddRegexCommand("^([A-Za-z_][A-Za-z_0-9]*=.*)$", "settings set target.env-vars %1")) { CommandObjectSP env_regex_cmd_sp(env_regex_cmd_up.release()); - m_command_dict[env_regex_cmd_sp->GetCommandName()] = env_regex_cmd_sp; + m_command_dict[std::string(env_regex_cmd_sp->GetCommandName())] = + env_regex_cmd_sp; } } @@ -838,7 +862,8 @@ void CommandInterpreter::LoadCommandDictionary() { jump_regex_cmd_up->AddRegexCommand("^([+\\-][0-9]+)$", "thread jump --by %1")) { CommandObjectSP jump_regex_cmd_sp(jump_regex_cmd_up.release()); - m_command_dict[jump_regex_cmd_sp->GetCommandName()] = jump_regex_cmd_sp; + m_command_dict[std::string(jump_regex_cmd_sp->GetCommandName())] = + jump_regex_cmd_sp; } } } @@ -863,7 +888,7 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases, StringList *descriptions) const { CommandObjectSP command_sp; - std::string cmd = cmd_str; + std::string cmd = std::string(cmd_str); if (HasCommands()) { auto pos = m_command_dict.find(cmd); @@ -992,18 +1017,18 @@ bool CommandInterpreter::AddUserCommand(llvm::StringRef name, if (CommandExists(name)) { if (!can_replace) return false; - if (!m_command_dict[name]->IsRemovable()) + if (!m_command_dict[std::string(name)]->IsRemovable()) return false; } if (UserCommandExists(name)) { if (!can_replace) return false; - if (!m_user_dict[name]->IsRemovable()) + if (!m_user_dict[std::string(name)]->IsRemovable()) return false; } - m_user_dict[name] = cmd_sp; + m_user_dict[std::string(name)] = cmd_sp; return true; } return false; @@ -1089,14 +1114,15 @@ CommandInterpreter::GetCommandObject(llvm::StringRef cmd_str, } bool CommandInterpreter::CommandExists(llvm::StringRef cmd) const { - return m_command_dict.find(cmd) != m_command_dict.end(); + return m_command_dict.find(std::string(cmd)) != m_command_dict.end(); } bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const { - bool exact_match = (m_alias_dict.find(cmd) != m_alias_dict.end()); + bool exact_match = + (m_alias_dict.find(std::string(cmd)) != m_alias_dict.end()); if (exact_match) { - full_name.assign(cmd); + full_name.assign(std::string(cmd)); return exact_match; } else { StringList matches; @@ -1122,11 +1148,11 @@ bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd, } bool CommandInterpreter::AliasExists(llvm::StringRef cmd) const { - return m_alias_dict.find(cmd) != m_alias_dict.end(); + return m_alias_dict.find(std::string(cmd)) != m_alias_dict.end(); } bool CommandInterpreter::UserCommandExists(llvm::StringRef cmd) const { - return m_user_dict.find(cmd) != m_user_dict.end(); + return m_user_dict.find(std::string(cmd)) != m_user_dict.end(); } CommandAlias * @@ -1141,7 +1167,8 @@ CommandInterpreter::AddAlias(llvm::StringRef alias_name, new CommandAlias(*this, command_obj_sp, args_string, alias_name)); if (command_alias_up && command_alias_up->IsValid()) { - m_alias_dict[alias_name] = CommandObjectSP(command_alias_up.get()); + m_alias_dict[std::string(alias_name)] = + CommandObjectSP(command_alias_up.get()); return command_alias_up.release(); } @@ -1149,7 +1176,7 @@ CommandInterpreter::AddAlias(llvm::StringRef alias_name, } bool CommandInterpreter::RemoveAlias(llvm::StringRef alias_name) { - auto pos = m_alias_dict.find(alias_name); + auto pos = m_alias_dict.find(std::string(alias_name)); if (pos != m_alias_dict.end()) { m_alias_dict.erase(pos); return true; @@ -1158,7 +1185,7 @@ bool CommandInterpreter::RemoveAlias(llvm::StringRef alias_name) { } bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd) { - auto pos = m_command_dict.find(cmd); + auto pos = m_command_dict.find(std::string(cmd)); if (pos != m_command_dict.end()) { if (pos->second->IsRemovable()) { // Only regular expression objects or python commands are removable @@ -1169,7 +1196,8 @@ bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd) { return false; } bool CommandInterpreter::RemoveUser(llvm::StringRef alias_name) { - CommandObject::CommandMap::iterator pos = m_user_dict.find(alias_name); + CommandObject::CommandMap::iterator pos = + m_user_dict.find(std::string(alias_name)); if (pos != m_user_dict.end()) { m_user_dict.erase(pos); return true; @@ -1253,7 +1281,8 @@ CommandObject *CommandInterpreter::GetCommandObjectForCommand( end = command_string.find_first_of(k_white_space, start); if (end == std::string::npos) end = command_string.size(); - std::string cmd_word = command_string.substr(start, end - start); + std::string cmd_word = + std::string(command_string.substr(start, end - start)); if (cmd_obj == nullptr) // Since cmd_obj is NULL we are on our first time through this loop. @@ -1311,10 +1340,10 @@ static size_t FindArgumentTerminator(const std::string &s) { if (pos == std::string::npos) break; if (pos > 0) { - if (isspace(s[pos - 1])) { + if (llvm::isSpace(s[pos - 1])) { // Check if the string ends "\s--" (where \s is a space character) or // if we have "\s--\s". - if ((pos + 2 >= s_len) || isspace(s[pos + 2])) { + if ((pos + 2 >= s_len) || llvm::isSpace(s[pos + 2])) { return pos; } } @@ -1394,7 +1423,7 @@ CommandObject *CommandInterpreter::BuildAliasResult( ((CommandAlias *)alias_cmd_obj)->Desugar(); OptionArgVectorSP option_arg_vector_sp = desugared.second; alias_cmd_obj = desugared.first.get(); - std::string alias_name_str = alias_name; + std::string alias_name_str = std::string(alias_name); if ((cmd_args.GetArgumentCount() == 0) || (alias_name_str != cmd_args.GetArgumentAtIndex(0))) cmd_args.Unshift(alias_name_str); @@ -1402,7 +1431,7 @@ CommandObject *CommandInterpreter::BuildAliasResult( result_str.Printf("%s", alias_cmd_obj->GetCommandName().str().c_str()); if (!option_arg_vector_sp.get()) { - alias_result = result_str.GetString(); + alias_result = std::string(result_str.GetString()); return alias_cmd_obj; } OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); @@ -1443,7 +1472,7 @@ CommandObject *CommandInterpreter::BuildAliasResult( } } - alias_result = result_str.GetString(); + alias_result = std::string(result_str.GetString()); return alias_cmd_obj; } @@ -1527,7 +1556,7 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) { scalar.GetValue(&value_strm, show_type); size_t value_string_size = value_strm.GetSize(); if (value_string_size) { - command.insert(start_backtick, value_strm.GetString()); + command.insert(start_backtick, std::string(value_strm.GetString())); pos = start_backtick + value_string_size; continue; } else { @@ -1591,6 +1620,11 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) { "expression '%s'", expr_str.c_str()); break; + case eExpressionThreadVanished: + error.SetErrorStringWithFormat( + "expression thread vanished for the expression '%s'", + expr_str.c_str()); + break; } } } @@ -1652,8 +1686,8 @@ bool CommandInterpreter::HandleCommand(const char *command_line, search_str = search_str.drop_front(non_space); if (auto hist_str = m_command_history.FindString(search_str)) { add_to_history = false; - command_string = *hist_str; - original_command_string = *hist_str; + command_string = std::string(*hist_str); + original_command_string = std::string(*hist_str); } else { result.AppendErrorWithFormat("Could not find entry: %s in history", command_string.c_str()); @@ -1817,6 +1851,8 @@ void CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) { void CommandInterpreter::HandleCompletion(CompletionRequest &request) { + UpdateExecutionContext(nullptr); + // Don't complete comments, and if the line we are completing is just the // history repeat character, substitute the appropriate history line. llvm::StringRef first_arg = request.GetParsedLine().GetArgumentAtIndex(0); @@ -1854,7 +1890,7 @@ bool CommandInterpreter::Confirm(llvm::StringRef message, bool default_answer) { IOHandlerConfirm *confirm = new IOHandlerConfirm(m_debugger, message, default_answer); IOHandlerSP io_handler_sp(confirm); - m_debugger.RunIOHandler(io_handler_sp); + m_debugger.RunIOHandlerSync(io_handler_sp); return confirm->GetResponse(); } @@ -1862,7 +1898,7 @@ const CommandAlias * CommandInterpreter::GetAlias(llvm::StringRef alias_name) const { OptionArgVectorSP ret_val; - auto pos = m_alias_dict.find(alias_name); + auto pos = m_alias_dict.find(std::string(alias_name)); if (pos != m_alias_dict.end()) return (CommandAlias *)pos->second.get(); @@ -2228,7 +2264,7 @@ void CommandInterpreter::HandleCommands(const StringList &commands, m_debugger.GetPrompt().str().c_str(), cmd); } - CommandReturnObject tmp_result; + CommandReturnObject tmp_result(m_debugger.GetUseColor()); // If override_context is not NULL, pass no_context_switching = true for // HandleCommand() since we updated our context already. @@ -2477,7 +2513,7 @@ void CommandInterpreter::HandleCommandsFromFile( m_command_source_depth++; - debugger.RunIOHandler(io_handler_sp); + debugger.RunIOHandlerSync(io_handler_sp); if (!m_command_source_flags.empty()) m_command_source_flags.pop_back(); m_command_source_depth--; @@ -2756,7 +2792,7 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler, StartHandlingCommand(); - lldb_private::CommandReturnObject result; + lldb_private::CommandReturnObject result(m_debugger.GetUseColor()); HandleCommand(line.c_str(), eLazyBoolCalculate, result); // Now emit the command output text from the command we just executed @@ -2794,23 +2830,26 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler, break; case eReturnStatusFailed: - m_num_errors++; - if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError)) + m_result.IncrementNumberOfErrors(); + if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError)) { + m_result.SetResult(lldb::eCommandInterpreterResultCommandError); io_handler.SetIsDone(true); + } break; case eReturnStatusQuit: - m_quit_requested = true; + m_result.SetResult(lldb::eCommandInterpreterResultQuitRequested); io_handler.SetIsDone(true); break; } // Finally, if we're going to stop on crash, check that here: - if (!m_quit_requested && result.GetDidChangeProcessState() && + if (m_result.IsResult(lldb::eCommandInterpreterResultSuccess) && + result.GetDidChangeProcessState() && io_handler.GetFlags().Test(eHandleCommandFlagStopOnCrash) && DidProcessStopAbnormally()) { io_handler.SetIsDone(true); - m_stopped_for_crash = true; + m_result.SetResult(lldb::eCommandInterpreterResultInferiorCrash); } } @@ -2854,7 +2893,7 @@ void CommandInterpreter::GetLLDBCommandsFromIOHandler( if (io_handler_sp) { io_handler_sp->SetUserData(baton); - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } } @@ -2874,7 +2913,7 @@ void CommandInterpreter::GetPythonCommandsFromIOHandler( if (io_handler_sp) { io_handler_sp->SetUserData(baton); - debugger.PushIOHandler(io_handler_sp); + debugger.RunIOHandlerAsync(io_handler_sp); } } @@ -2928,26 +2967,27 @@ CommandInterpreter::GetIOHandler(bool force_create, return m_command_io_handler_sp; } -void CommandInterpreter::RunCommandInterpreter( - bool auto_handle_events, bool spawn_thread, +CommandInterpreterRunResult CommandInterpreter::RunCommandInterpreter( CommandInterpreterRunOptions &options) { // Always re-create the command interpreter when we run it in case any file // handles have changed. bool force_create = true; - m_debugger.PushIOHandler(GetIOHandler(force_create, &options)); - m_stopped_for_crash = false; + m_debugger.RunIOHandlerAsync(GetIOHandler(force_create, &options)); + m_result = CommandInterpreterRunResult(); - if (auto_handle_events) + if (options.GetAutoHandleEvents()) m_debugger.StartEventHandlerThread(); - if (spawn_thread) { + if (options.GetSpawnThread()) { m_debugger.StartIOHandlerThread(); } else { - m_debugger.ExecuteIOHandlers(); + m_debugger.RunIOHandlers(); - if (auto_handle_events) + if (options.GetAutoHandleEvents()) m_debugger.StopEventHandlerThread(); } + + return m_result; } CommandObject * @@ -3073,7 +3113,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line, std::string gdb_format_option("--gdb-format="); gdb_format_option += (suffix.c_str() + 1); - std::string cmd = revised_command_line.GetString(); + std::string cmd = std::string(revised_command_line.GetString()); size_t arg_terminator_idx = FindArgumentTerminator(cmd); if (arg_terminator_idx != std::string::npos) { // Insert the gdb format option before the "--" that terminates @@ -3114,7 +3154,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line, revised_command_line.Printf(" %s", scratch_command.c_str()); if (cmd_obj != nullptr) - command_line = revised_command_line.GetString(); + command_line = std::string(revised_command_line.GetString()); return cmd_obj; } diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index d666852ee68c..538f7a1ba693 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -1,4 +1,4 @@ -//===-- CommandObject.cpp ---------------------------------------*- C++ -*-===// +//===-- CommandObject.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,6 +18,7 @@ #include "lldb/Core/Address.h" #include "lldb/Interpreter/Options.h" #include "lldb/Utility/ArchSpec.h" +#include "llvm/ADT/ScopeExit.h" // These are for the Sourcename completers. // FIXME: Make a separate file for the completers. @@ -37,14 +38,15 @@ using namespace lldb_private; // CommandObject -CommandObject::CommandObject(CommandInterpreter &interpreter, llvm::StringRef name, - llvm::StringRef help, llvm::StringRef syntax, uint32_t flags) - : m_interpreter(interpreter), m_cmd_name(name), +CommandObject::CommandObject(CommandInterpreter &interpreter, + llvm::StringRef name, llvm::StringRef help, + llvm::StringRef syntax, uint32_t flags) + : m_interpreter(interpreter), m_cmd_name(std::string(name)), m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags), m_arguments(), m_deprecated_command_override_callback(nullptr), m_command_override_callback(nullptr), m_command_override_baton(nullptr) { - m_cmd_help_short = help; - m_cmd_syntax = syntax; + m_cmd_help_short = std::string(help); + m_cmd_syntax = std::string(syntax); } CommandObject::~CommandObject() {} @@ -73,20 +75,28 @@ llvm::StringRef CommandObject::GetSyntax() { syntax_str.PutCString("-- "); GetFormattedCommandArguments(syntax_str); } - m_cmd_syntax = syntax_str.GetString(); + m_cmd_syntax = std::string(syntax_str.GetString()); return m_cmd_syntax; } llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; } -void CommandObject::SetCommandName(llvm::StringRef name) { m_cmd_name = name; } +void CommandObject::SetCommandName(llvm::StringRef name) { + m_cmd_name = std::string(name); +} -void CommandObject::SetHelp(llvm::StringRef str) { m_cmd_help_short = str; } +void CommandObject::SetHelp(llvm::StringRef str) { + m_cmd_help_short = std::string(str); +} -void CommandObject::SetHelpLong(llvm::StringRef str) { m_cmd_help_long = str; } +void CommandObject::SetHelpLong(llvm::StringRef str) { + m_cmd_help_long = std::string(str); +} -void CommandObject::SetSyntax(llvm::StringRef str) { m_cmd_syntax = str; } +void CommandObject::SetSyntax(llvm::StringRef str) { + m_cmd_syntax = std::string(str); +} Options *CommandObject::GetOptions() { // By default commands don't have options unless this virtual function is @@ -258,6 +268,10 @@ void CommandObject::Cleanup() { } void CommandObject::HandleCompletion(CompletionRequest &request) { + + m_exe_ctx = m_interpreter.GetExecutionContext(); + auto reset_ctx = llvm::make_scope_exit([this]() { Cleanup(); }); + // Default implementation of WantsCompletion() is !WantsRawCommandString(). // Subclasses who want raw command string but desire, for example, argument // completion should override WantsCompletion() to return true, instead. @@ -268,7 +282,7 @@ void CommandObject::HandleCompletion(CompletionRequest &request) { } else { // Can we do anything generic with the options? Options *cur_options = GetOptions(); - CommandReturnObject result; + CommandReturnObject result(m_interpreter.GetDebugger().GetUseColor()); OptionElementVector opt_element_vector; if (cur_options != nullptr) { @@ -485,7 +499,7 @@ void CommandObject::GetFormattedCommandArguments(Stream &str, names.Printf("%s", GetArgumentName(arg_entry[j].arg_type)); } - std::string name_str = names.GetString(); + std::string name_str = std::string(names.GetString()); switch (arg_entry[0].arg_repetition) { case eArgRepeatPlain: str.Printf("<%s>", name_str.c_str()); @@ -673,7 +687,7 @@ static llvm::StringRef FormatHelpTextCallback() { sstr.Flush(); - help_text = sstr.GetString(); + help_text = std::string(sstr.GetString()); return help_text; } @@ -691,7 +705,7 @@ static llvm::StringRef LanguageTypeHelpTextCallback() { sstr.Flush(); - help_text = sstr.GetString(); + help_text = std::string(sstr.GetString()); return help_text; } @@ -809,7 +823,7 @@ static llvm::StringRef ExprPathHelpTextCallback() { void CommandObject::FormatLongHelpText(Stream &output_strm, llvm::StringRef long_help) { CommandInterpreter &interpreter = GetCommandInterpreter(); - std::stringstream lineStream(long_help); + std::stringstream lineStream{std::string(long_help)}; std::string line; while (std::getline(lineStream, line)) { if (line.empty()) { @@ -822,8 +836,8 @@ void CommandObject::FormatLongHelpText(Stream &output_strm, } std::string whitespace_prefix = line.substr(0, result); std::string remainder = line.substr(result); - interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(), - remainder.c_str()); + interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix, + remainder); } } @@ -835,13 +849,11 @@ void CommandObject::GenerateHelpText(CommandReturnObject &result) { void CommandObject::GenerateHelpText(Stream &output_strm) { CommandInterpreter &interpreter = GetCommandInterpreter(); + std::string help_text(GetHelp()); if (WantsRawCommandString()) { - std::string help_text(GetHelp()); help_text.append(" Expects 'raw' input (see 'help raw-input'.)"); - interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(), - 1); - } else - interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1); + } + interpreter.OutputFormattedHelpText(output_strm, "", help_text); output_strm << "\nSyntax: " << GetSyntax() << "\n"; Options *options = GetOptions(); if (options != nullptr) { @@ -1066,7 +1078,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." }, { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." }, { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." }, - { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, + { eArgTypePlugin, "plugin", CommandCompletions::eProcessPluginCompletion, { nullptr, false }, "Help text goes here." }, { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." }, { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." }, { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." }, @@ -1077,7 +1089,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." }, { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, - { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, + { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Supported languages are python and lua." }, { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." }, { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." }, { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." }, @@ -1105,7 +1117,8 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." }, { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." }, { eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes. To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." }, - { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." } + { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." }, + { eArgTypeColumnNum, "column", CommandCompletions::eNoCompletion, { nullptr, false }, "Column number in a source file." } // clang-format on }; diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index 693d18ce7bdf..5a0265e58c5c 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -1,4 +1,4 @@ -//===-- CommandObjectRegexCommand.cpp ---------------------------*- C++ -*-===// +//===-- CommandObjectRegexCommand.cpp -------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/CommandObjectScript.cpp b/lldb/source/Interpreter/CommandObjectScript.cpp index d61d0cac9762..5e98c658ebdb 100644 --- a/lldb/source/Interpreter/CommandObjectScript.cpp +++ b/lldb/source/Interpreter/CommandObjectScript.cpp @@ -1,4 +1,4 @@ -//===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===// +//===-- CommandObjectScript.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/CommandObjectScript.h b/lldb/source/Interpreter/CommandObjectScript.h index 4f7a912979bf..a5f659995de3 100644 --- a/lldb/source/Interpreter/CommandObjectScript.h +++ b/lldb/source/Interpreter/CommandObjectScript.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_CommandObjectScript_h_ -#define liblldb_CommandObjectScript_h_ +#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H +#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H #include "lldb/Interpreter/CommandObject.h" @@ -28,4 +28,4 @@ protected: } // namespace lldb_private -#endif // liblldb_CommandObjectScript_h_ +#endif // LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H diff --git a/lldb/source/Interpreter/CommandOptionValidators.cpp b/lldb/source/Interpreter/CommandOptionValidators.cpp index c41c1566aab9..a4b4b57c54b1 100644 --- a/lldb/source/Interpreter/CommandOptionValidators.cpp +++ b/lldb/source/Interpreter/CommandOptionValidators.cpp @@ -1,4 +1,4 @@ -//===-- CommandOptionValidators.cpp -----------------------------*- C++ -*-===// +//===-- CommandOptionValidators.cpp ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index c17390be7311..6f3732e35078 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -1,4 +1,4 @@ -//===-- CommandReturnObject.cpp ---------------------------------*- C++ -*-===// +//===-- CommandReturnObject.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,12 +14,21 @@ using namespace lldb; using namespace lldb_private; -static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s, - bool add_newline_if_empty) { +static llvm::raw_ostream &error(Stream &strm) { + return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Error, + llvm::ColorMode::Enable) + << "error: "; +} + +static llvm::raw_ostream &warning(Stream &strm) { + return llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Warning, + llvm::ColorMode::Enable) + << "warning: "; +} + +static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s) { bool add_newline = false; - if (s.empty()) { - add_newline = add_newline_if_empty; - } else { + if (!s.empty()) { // We already checked for empty above, now make sure there is a newline in // the error, and if there isn't one, add one. strm.Write(s.c_str(), s.size()); @@ -31,9 +40,10 @@ static void DumpStringToStreamWithNewline(Stream &strm, const std::string &s, strm.EOL(); } -CommandReturnObject::CommandReturnObject() - : m_out_stream(), m_err_stream(), m_status(eReturnStatusStarted), - m_did_change_process_state(false), m_interactive(true) {} +CommandReturnObject::CommandReturnObject(bool colors) + : m_out_stream(colors), m_err_stream(colors), + m_status(eReturnStatusStarted), m_did_change_process_state(false), + m_interactive(true) {} CommandReturnObject::~CommandReturnObject() {} @@ -46,11 +56,10 @@ void CommandReturnObject::AppendErrorWithFormat(const char *format, ...) { sstrm.PrintfVarArg(format, args); va_end(args); - const std::string &s = sstrm.GetString(); + const std::string &s = std::string(sstrm.GetString()); if (!s.empty()) { - Stream &error_strm = GetErrorStream(); - error_strm.PutCString("error: "); - DumpStringToStreamWithNewline(error_strm, s, false); + error(GetErrorStream()); + DumpStringToStreamWithNewline(GetErrorStream(), s); } } @@ -75,7 +84,7 @@ void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) { sstrm.PrintfVarArg(format, args); va_end(args); - GetErrorStream() << "warning: " << sstrm.GetString(); + warning(GetErrorStream()) << sstrm.GetString(); } void CommandReturnObject::AppendMessage(llvm::StringRef in_string) { @@ -87,7 +96,7 @@ void CommandReturnObject::AppendMessage(llvm::StringRef in_string) { void CommandReturnObject::AppendWarning(llvm::StringRef in_string) { if (in_string.empty()) return; - GetErrorStream() << "warning: " << in_string << "\n"; + warning(GetErrorStream()) << in_string << '\n'; } // Similar to AppendWarning, but do not prepend 'warning: ' to message, and @@ -102,7 +111,7 @@ void CommandReturnObject::AppendRawWarning(llvm::StringRef in_string) { void CommandReturnObject::AppendError(llvm::StringRef in_string) { if (in_string.empty()) return; - GetErrorStream() << "error: " << in_string << "\n"; + error(GetErrorStream()) << in_string << '\n'; } void CommandReturnObject::SetError(const Status &error, diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp index 56d99a4220f0..3dcb30e846d9 100644 --- a/lldb/source/Interpreter/OptionArgParser.cpp +++ b/lldb/source/Interpreter/OptionArgParser.cpp @@ -1,4 +1,4 @@ -//===-- OptionArgParser.cpp -------------------------------------*- C++ -*-===// +//===-- OptionArgParser.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupArchitecture.cpp b/lldb/source/Interpreter/OptionGroupArchitecture.cpp index 11f786c52c09..baca1c6e8068 100644 --- a/lldb/source/Interpreter/OptionGroupArchitecture.cpp +++ b/lldb/source/Interpreter/OptionGroupArchitecture.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupArchitecture.cpp -----------------------------*- C++ -*-===// +//===-- OptionGroupArchitecture.cpp ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -42,7 +42,7 @@ OptionGroupArchitecture::SetOptionValue(uint32_t option_idx, switch (short_option) { case 'a': - m_arch_str.assign(option_arg); + m_arch_str.assign(std::string(option_arg)); break; default: diff --git a/lldb/source/Interpreter/OptionGroupBoolean.cpp b/lldb/source/Interpreter/OptionGroupBoolean.cpp index 8a6482c8df25..3482e784ca0c 100644 --- a/lldb/source/Interpreter/OptionGroupBoolean.cpp +++ b/lldb/source/Interpreter/OptionGroupBoolean.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupBoolean.cpp ----------------------------------*- C++ -*-===// +//===-- OptionGroupBoolean.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupFile.cpp b/lldb/source/Interpreter/OptionGroupFile.cpp index cda75ec205ec..9d9be5b6f178 100644 --- a/lldb/source/Interpreter/OptionGroupFile.cpp +++ b/lldb/source/Interpreter/OptionGroupFile.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupFile.cpp -------------------------------*- C++ -*-===// +//===-- OptionGroupFile.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp index c25e35f84517..0052f72b0550 100644 --- a/lldb/source/Interpreter/OptionGroupFormat.cpp +++ b/lldb/source/Interpreter/OptionGroupFormat.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupFormat.cpp -----------------------------------*- C++ -*-===// +//===-- OptionGroupFormat.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupOutputFile.cpp b/lldb/source/Interpreter/OptionGroupOutputFile.cpp index 3df75cf86b85..65105c3e0180 100644 --- a/lldb/source/Interpreter/OptionGroupOutputFile.cpp +++ b/lldb/source/Interpreter/OptionGroupOutputFile.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===// +//===-- OptionGroupOutputFile.cpp -----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp index 6ddbbf0e3abb..4242e010fa64 100644 --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupPlatform.cpp ---------------------------------*- C++ -*-===// +//===-- OptionGroupPlatform.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -95,7 +95,7 @@ OptionGroupPlatform::SetOptionValue(uint32_t option_idx, switch (short_option) { case 'p': - m_platform_name.assign(option_arg); + m_platform_name.assign(std::string(option_arg)); break; case 'v': diff --git a/lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp b/lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp index e41f9d7b40ee..217dab2ef63b 100644 --- a/lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp +++ b/lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupPythonClassWithDict.cpp ----------------------------------*- C++ -*-===// +//===-- OptionGroupPythonClassWithDict.cpp --------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -91,13 +91,13 @@ Status OptionGroupPythonClassWithDict::SetOptionValue( switch (option_idx) { case 0: case 3: { - m_name.assign(option_arg); + m_name.assign(std::string(option_arg)); } break; case 1: { if (!m_dict_sp) m_dict_sp = std::make_shared<StructuredData::Dictionary>(); if (m_current_key.empty()) - m_current_key.assign(option_arg); + m_current_key.assign(std::string(option_arg)); else error.SetErrorStringWithFormat("Key: \"%s\" missing value.", m_current_key.c_str()); diff --git a/lldb/source/Interpreter/OptionGroupString.cpp b/lldb/source/Interpreter/OptionGroupString.cpp index c01b7065fbd0..c9f78eb953f4 100644 --- a/lldb/source/Interpreter/OptionGroupString.cpp +++ b/lldb/source/Interpreter/OptionGroupString.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupString.cpp ----------------------------------*- C++ -*-===// +//===-- OptionGroupString.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupUInt64.cpp b/lldb/source/Interpreter/OptionGroupUInt64.cpp index 53e5674d0296..309855d4718c 100644 --- a/lldb/source/Interpreter/OptionGroupUInt64.cpp +++ b/lldb/source/Interpreter/OptionGroupUInt64.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupUInt64.cpp ----------------------------------*- C++ -*-===// +//===-- OptionGroupUInt64.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupUUID.cpp b/lldb/source/Interpreter/OptionGroupUUID.cpp index 8fc330a89391..46f2ff75225a 100644 --- a/lldb/source/Interpreter/OptionGroupUUID.cpp +++ b/lldb/source/Interpreter/OptionGroupUUID.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupUUID.cpp -------------------------------------*- C++ -*-===// +//===-- OptionGroupUUID.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp index da0437ac299c..e0401f8987ad 100644 --- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp +++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===// +//===-- OptionGroupValueObjectDisplay.cpp ---------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp index a9004bf03cd2..9f57dbbd073e 100644 --- a/lldb/source/Interpreter/OptionGroupVariable.cpp +++ b/lldb/source/Interpreter/OptionGroupVariable.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupVariable.cpp -----------------------*- C++ -*-===// +//===-- OptionGroupVariable.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp index 682f99b8c5cc..07013b5b78fe 100644 --- a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp +++ b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp @@ -1,4 +1,4 @@ -//===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===// +//===-- OptionGroupWatchpoint.cpp -----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp index bc929aa9dabf..198be85a7b47 100644 --- a/lldb/source/Interpreter/OptionValue.cpp +++ b/lldb/source/Interpreter/OptionValue.cpp @@ -1,4 +1,4 @@ -//===-- OptionValue.cpp -----------------------------------------*- C++ -*-===// +//===-- OptionValue.cpp ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,10 +7,11 @@ //===----------------------------------------------------------------------===// #include "lldb/Interpreter/OptionValue.h" - #include "lldb/Interpreter/OptionValues.h" #include "lldb/Utility/StringList.h" +#include <memory> + using namespace lldb; using namespace lldb_private; @@ -505,37 +506,37 @@ lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask( lldb::OptionValueSP value_sp; switch (type_mask) { case 1u << eTypeArch: - value_sp.reset(new OptionValueArch()); + value_sp = std::make_shared<OptionValueArch>(); break; case 1u << eTypeBoolean: - value_sp.reset(new OptionValueBoolean(false)); + value_sp = std::make_shared<OptionValueBoolean>(false); break; case 1u << eTypeChar: - value_sp.reset(new OptionValueChar('\0')); + value_sp = std::make_shared<OptionValueChar>('\0'); break; case 1u << eTypeFileSpec: - value_sp.reset(new OptionValueFileSpec()); + value_sp = std::make_shared<OptionValueFileSpec>(); break; case 1u << eTypeFormat: - value_sp.reset(new OptionValueFormat(eFormatInvalid)); + value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid); break; case 1u << eTypeFormatEntity: - value_sp.reset(new OptionValueFormatEntity(nullptr)); + value_sp = std::make_shared<OptionValueFormatEntity>(nullptr); break; case 1u << eTypeLanguage: - value_sp.reset(new OptionValueLanguage(eLanguageTypeUnknown)); + value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown); break; case 1u << eTypeSInt64: - value_sp.reset(new OptionValueSInt64()); + value_sp = std::make_shared<OptionValueSInt64>(); break; case 1u << eTypeString: - value_sp.reset(new OptionValueString()); + value_sp = std::make_shared<OptionValueString>(); break; case 1u << eTypeUInt64: - value_sp.reset(new OptionValueUInt64()); + value_sp = std::make_shared<OptionValueUInt64>(); break; case 1u << eTypeUUID: - value_sp.reset(new OptionValueUUID()); + value_sp = std::make_shared<OptionValueUUID>(); break; } diff --git a/lldb/source/Interpreter/OptionValueArch.cpp b/lldb/source/Interpreter/OptionValueArch.cpp index 7271c1471f90..ac78ee64a9d7 100644 --- a/lldb/source/Interpreter/OptionValueArch.cpp +++ b/lldb/source/Interpreter/OptionValueArch.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueArch.cpp ---------------------------------*- C++ -*-===// +//===-- OptionValueArch.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueArgs.cpp b/lldb/source/Interpreter/OptionValueArgs.cpp index d619dba5678a..9e7774a231c7 100644 --- a/lldb/source/Interpreter/OptionValueArgs.cpp +++ b/lldb/source/Interpreter/OptionValueArgs.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueArgs.cpp -------------------------------------*- C++ -*-===// +//===-- OptionValueArgs.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp index 30902c0f295a..9be11e32e2db 100644 --- a/lldb/source/Interpreter/OptionValueArray.cpp +++ b/lldb/source/Interpreter/OptionValueArray.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueArray.cpp ------------------------------------*- C++ -*-===// +//===-- OptionValueArray.cpp ----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueBoolean.cpp b/lldb/source/Interpreter/OptionValueBoolean.cpp index 6f893a94e863..24ae3f673bf9 100644 --- a/lldb/source/Interpreter/OptionValueBoolean.cpp +++ b/lldb/source/Interpreter/OptionValueBoolean.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueBoolean.cpp ----------------------------------*- C++ -*-===// +//===-- OptionValueBoolean.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueChar.cpp b/lldb/source/Interpreter/OptionValueChar.cpp index 23012e6e2ec3..af9a371f46d4 100644 --- a/lldb/source/Interpreter/OptionValueChar.cpp +++ b/lldb/source/Interpreter/OptionValueChar.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===// +//===-- OptionValueChar.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueDictionary.cpp b/lldb/source/Interpreter/OptionValueDictionary.cpp index a4022288fccb..caadccd04232 100644 --- a/lldb/source/Interpreter/OptionValueDictionary.cpp +++ b/lldb/source/Interpreter/OptionValueDictionary.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueDictionary.cpp -------------------------------*- C++ -*-===// +//===-- OptionValueDictionary.cpp -----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -45,7 +45,7 @@ void OptionValueDictionary::DumpValue(const ExecutionContext *exe_ctx, else strm.EOL(); - strm.Indent(pos->first.GetCString()); + strm.Indent(pos->first.GetStringRef()); const uint32_t extra_dump_options = m_raw_value_dump ? eDumpOptionRaw : 0; switch (dict_type) { diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index 26933aa78240..9a1e08d4fba0 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueEnumeration.cpp ------------------------------*- C++ -*-===// +//===-- OptionValueEnumeration.cpp ----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp index 20d3d4e68e33..15acb7e5e5b0 100644 --- a/lldb/source/Interpreter/OptionValueFileSpec.cpp +++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueFileSpec.cpp ---------------------------------*- C++ -*-===// +//===-- OptionValueFileSpec.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueFormat.cpp b/lldb/source/Interpreter/OptionValueFormat.cpp index ba5a44c270da..b676bed50e62 100644 --- a/lldb/source/Interpreter/OptionValueFormat.cpp +++ b/lldb/source/Interpreter/OptionValueFormat.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueFormat.cpp -----------------------------------*- C++ -*-===// +//===-- OptionValueFormat.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp index 8dc52650a331..6b36bd575186 100644 --- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp +++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueFormatEntity.cpp -----------------------------*- C++ -*-===// +//===-- OptionValueFormatEntity.cpp ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -95,7 +95,7 @@ Status OptionValueFormatEntity::SetValueFromString(llvm::StringRef value_str, error = FormatEntity::Parse(value_str, entry); if (error.Success()) { m_current_entry = std::move(entry); - m_current_format = value_str; + m_current_format = std::string(value_str); m_value_was_set = true; NotifyValueChanged(); } diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp index 1d7e18868b6f..5b310782a1ba 100644 --- a/lldb/source/Interpreter/OptionValueLanguage.cpp +++ b/lldb/source/Interpreter/OptionValueLanguage.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueLanguage.cpp ---------------------------------*- C++ -*-===// +//===-- OptionValueLanguage.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappings.cpp index 75fcf0247475..3b3f43d07293 100644 --- a/lldb/source/Interpreter/OptionValuePathMappings.cpp +++ b/lldb/source/Interpreter/OptionValuePathMappings.cpp @@ -1,4 +1,4 @@ -//===-- OptionValuePathMappings.cpp -----------------------------*- C++ -*-===// +//===-- OptionValuePathMappings.cpp ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -61,7 +61,7 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, count); } else { bool changed = false; - for (size_t i = 1; i < argc; i += 2, ++idx) { + for (size_t i = 1; i < argc; idx++, i += 2) { const char *orginal_path = args.GetArgumentAtIndex(i); const char *replace_path = args.GetArgumentAtIndex(i + 1); if (VerifyPathExists(replace_path)) { @@ -71,9 +71,11 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, m_path_mappings.Append(a, b, m_notify_changes); changed = true; } else { + std::string previousError = + error.Fail() ? std::string(error.AsCString()) + "\n" : ""; error.SetErrorStringWithFormat( - "the replacement path doesn't exist: \"%s\"", replace_path); - break; + "%sthe replacement path doesn't exist: \"%s\"", + previousError.c_str(), replace_path); } } if (changed) @@ -109,9 +111,11 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, m_value_was_set = true; changed = true; } else { + std::string previousError = + error.Fail() ? std::string(error.AsCString()) + "\n" : ""; error.SetErrorStringWithFormat( - "the replacement path doesn't exist: \"%s\"", replace_path); - break; + "%sthe replacement path doesn't exist: \"%s\"", + previousError.c_str(), replace_path); } } if (changed) @@ -135,7 +139,7 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, bool changed = false; if (op == eVarSetOperationInsertAfter) ++idx; - for (size_t i = 1; i < argc; i += 2, ++idx) { + for (size_t i = 1; i < argc; i += 2) { const char *orginal_path = args.GetArgumentAtIndex(i); const char *replace_path = args.GetArgumentAtIndex(i + 1); if (VerifyPathExists(replace_path)) { @@ -143,10 +147,13 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, ConstString b(replace_path); m_path_mappings.Insert(a, b, idx, m_notify_changes); changed = true; + idx++; } else { + std::string previousError = + error.Fail() ? std::string(error.AsCString()) + "\n" : ""; error.SetErrorStringWithFormat( - "the replacement path doesn't exist: \"%s\"", replace_path); - break; + "%sthe replacement path doesn't exist: \"%s\"", + previousError.c_str(), replace_path); } } if (changed) @@ -161,32 +168,23 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, case eVarSetOperationRemove: if (argc > 0) { std::vector<int> remove_indexes; - bool all_indexes_valid = true; - size_t i; - for (i = 0; all_indexes_valid && i < argc; ++i) { - const int idx = + for (size_t i = 0; i < argc; ++i) { + int idx = StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX); - if (idx == INT32_MAX) - all_indexes_valid = false; - else + if (idx < 0 || idx >= (int)m_path_mappings.GetSize()) { + error.SetErrorStringWithFormat( + "invalid array index '%s', aborting remove operation", + args.GetArgumentAtIndex(i)); + break; + } else remove_indexes.push_back(idx); } - if (all_indexes_valid) { - size_t num_remove_indexes = remove_indexes.size(); - if (num_remove_indexes) { - // Sort and then erase in reverse so indexes are always valid - llvm::sort(remove_indexes.begin(), remove_indexes.end()); - for (size_t j = num_remove_indexes - 1; j < num_remove_indexes; ++j) { - m_path_mappings.Remove(j, m_notify_changes); - } - } - NotifyValueChanged(); - } else { - error.SetErrorStringWithFormat( - "invalid array index '%s', aborting remove operation", - args.GetArgumentAtIndex(i)); - } + // Sort and then erase in reverse so indexes are always valid + llvm::sort(remove_indexes.begin(), remove_indexes.end()); + for (auto index : llvm::reverse(remove_indexes)) + m_path_mappings.Remove(index, m_notify_changes); + NotifyValueChanged(); } else { error.SetErrorString("remove operation takes one or more array index"); } diff --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp index 21750cf18615..24cda056977e 100644 --- a/lldb/source/Interpreter/OptionValueProperties.cpp +++ b/lldb/source/Interpreter/OptionValueProperties.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueProperties.cpp --------------------------------*- C++-*-===// +//===-- OptionValueProperties.cpp -----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp index cf806fb550f9..bec3942d9cb0 100644 --- a/lldb/source/Interpreter/OptionValueRegex.cpp +++ b/lldb/source/Interpreter/OptionValueRegex.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueRegex.cpp ------------------------------------*- C++ -*-===// +//===-- OptionValueRegex.cpp ----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueSInt64.cpp b/lldb/source/Interpreter/OptionValueSInt64.cpp index d26fc08a3132..ada20b2139a3 100644 --- a/lldb/source/Interpreter/OptionValueSInt64.cpp +++ b/lldb/source/Interpreter/OptionValueSInt64.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueSInt64.cpp -----------------------------------*- C++ -*-===// +//===-- OptionValueSInt64.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp index a519249ab472..22f5d08bf832 100644 --- a/lldb/source/Interpreter/OptionValueString.cpp +++ b/lldb/source/Interpreter/OptionValueString.cpp @@ -1,5 +1,4 @@ -//===-- OptionValueString.cpp ------------------------------------*- C++ -//-*-===// +//===-- OptionValueString.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -83,7 +82,7 @@ Status OptionValueString::SetValueFromString(llvm::StringRef value, Args::EncodeEscapeSequences(value_str.c_str(), str); new_value.append(str); } else - new_value.append(value); + new_value.append(std::string(value)); } if (m_validator) { error = m_validator(new_value.c_str(), m_validator_baton); @@ -128,7 +127,7 @@ Status OptionValueString::SetCurrentValue(llvm::StringRef value) { if (error.Fail()) return error; } - m_current_value.assign(value); + m_current_value.assign(std::string(value)); return Status(); } diff --git a/lldb/source/Interpreter/OptionValueUInt64.cpp b/lldb/source/Interpreter/OptionValueUInt64.cpp index 3be0772daa8c..98ef016e5f77 100644 --- a/lldb/source/Interpreter/OptionValueUInt64.cpp +++ b/lldb/source/Interpreter/OptionValueUInt64.cpp @@ -1,5 +1,4 @@ -//===-- OptionValueUInt64.cpp ------------------------------------*- C++ -//-*-===// +//===-- OptionValueUInt64.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/OptionValueUUID.cpp b/lldb/source/Interpreter/OptionValueUUID.cpp index 7a6bc65b25a4..2bd749773556 100644 --- a/lldb/source/Interpreter/OptionValueUUID.cpp +++ b/lldb/source/Interpreter/OptionValueUUID.cpp @@ -1,4 +1,4 @@ -//===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===// +//===-- OptionValueUUID.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -38,7 +38,7 @@ Status OptionValueUUID::SetValueFromString(llvm::StringRef value, case eVarSetOperationReplace: case eVarSetOperationAssign: { - if (m_uuid.SetFromStringRef(value) == 0) + if (!m_uuid.SetFromStringRef(value)) error.SetErrorStringWithFormat("invalid uuid string value '%s'", value.str().c_str()); else { diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 0bceea14269d..c14b6b6ce66a 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -1,4 +1,4 @@ -//===-- Options.cpp ---------------------------------------------*- C++ -*-===// +//===-- Options.cpp -------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -282,7 +282,7 @@ void Options::OutputFormattedUsageText(Stream &strm, if (static_cast<uint32_t>(actual_text.length() + strm.GetIndentLevel()) < output_max_columns) { // Output it as a single line. - strm.Indent(actual_text.c_str()); + strm.Indent(actual_text); strm.EOL(); } else { // We need to break it up into multiple lines. @@ -798,7 +798,8 @@ void Options::HandleOptionArgumentCompletion( interpreter.GetDebugger().GetSelectedTarget(); // Search filters require a target... if (target_sp) - filter_up.reset(new SearchFilterByModule(target_sp, module_spec)); + filter_up = + std::make_unique<SearchFilterByModule>(target_sp, module_spec); } break; } @@ -932,7 +933,7 @@ static size_t FindArgumentIndexForOption(const Args &args, const Option &long_option) { std::string short_opt = llvm::formatv("-{0}", char(long_option.val)).str(); std::string long_opt = - llvm::formatv("--{0}", long_option.definition->long_option); + std::string(llvm::formatv("--{0}", long_option.definition->long_option)); for (const auto &entry : llvm::enumerate(args)) { if (entry.value().ref().startswith(short_opt) || entry.value().ref().startswith(long_opt)) @@ -1061,8 +1062,8 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args, } if (!option_arg) option_arg = "<no-argument>"; - option_arg_vector->emplace_back(option_str.GetString(), has_arg, - option_arg); + option_arg_vector->emplace_back(std::string(option_str.GetString()), + has_arg, std::string(option_arg)); // Find option in the argument list; also see if it was supposed to take an // argument and if one was supplied. Remove option (and argument, if @@ -1075,7 +1076,7 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args, if (!input_line.empty()) { auto tmp_arg = args_copy[idx].ref(); - size_t pos = input_line.find(tmp_arg); + size_t pos = input_line.find(std::string(tmp_arg)); if (pos != std::string::npos) input_line.erase(pos, tmp_arg.size()); } @@ -1087,7 +1088,7 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args, (args_copy[idx].ref() == OptionParser::GetOptionArgument())) { if (input_line.size() > 0) { auto tmp_arg = args_copy[idx].ref(); - size_t pos = input_line.find(tmp_arg); + size_t pos = input_line.find(std::string(tmp_arg)); if (pos != std::string::npos) input_line.erase(pos, tmp_arg.size()); } diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index a81098373c25..923811249853 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/lldb/source/Interpreter/Property.cpp @@ -1,4 +1,4 @@ -//===-- Property.cpp --------------------------------------------*- C++ -*-===// +//===-- Property.cpp ------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index 00c460612ac1..86620449f2f4 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -1,4 +1,4 @@ -//===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===// +//===-- ScriptInterpreter.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,16 +7,21 @@ //===----------------------------------------------------------------------===// #include "lldb/Interpreter/ScriptInterpreter.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string> - +#include "lldb/Core/Debugger.h" +#include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/Pipe.h" #include "lldb/Host/PseudoTerminal.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StringList.h" +#if defined(_WIN32) +#include "lldb/Host/windows/ConnectionGenericFileWindows.h" +#endif +#include <memory> +#include <stdio.h> +#include <stdlib.h> +#include <string> using namespace lldb; using namespace lldb_private; @@ -102,6 +107,113 @@ Status ScriptInterpreter::SetBreakpointCommandCallbackFunction( std::unique_ptr<ScriptInterpreterLocker> ScriptInterpreter::AcquireInterpreterLock() { - return std::unique_ptr<ScriptInterpreterLocker>( - new ScriptInterpreterLocker()); + return std::make_unique<ScriptInterpreterLocker>(); +} + +static void ReadThreadBytesReceived(void *baton, const void *src, + size_t src_len) { + if (src && src_len) { + Stream *strm = (Stream *)baton; + strm->Write(src, src_len); + strm->Flush(); + } +} + +llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>> +ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger, + CommandReturnObject *result) { + if (enable_io) + return std::unique_ptr<ScriptInterpreterIORedirect>( + new ScriptInterpreterIORedirect(debugger, result)); + + auto nullin = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL), + File::eOpenOptionRead); + if (!nullin) + return nullin.takeError(); + + auto nullout = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL), + File::eOpenOptionWrite); + if (!nullout) + return nullin.takeError(); + + return std::unique_ptr<ScriptInterpreterIORedirect>( + new ScriptInterpreterIORedirect(std::move(*nullin), std::move(*nullout))); +} + +ScriptInterpreterIORedirect::ScriptInterpreterIORedirect( + std::unique_ptr<File> input, std::unique_ptr<File> output) + : m_input_file_sp(std::move(input)), + m_output_file_sp(std::make_shared<StreamFile>(std::move(output))), + m_error_file_sp(m_output_file_sp), + m_communication("lldb.ScriptInterpreterIORedirect.comm"), + m_disconnect(false) {} + +ScriptInterpreterIORedirect::ScriptInterpreterIORedirect( + Debugger &debugger, CommandReturnObject *result) + : m_communication("lldb.ScriptInterpreterIORedirect.comm"), + m_disconnect(false) { + + if (result) { + m_input_file_sp = debugger.GetInputFileSP(); + + Pipe pipe; + Status pipe_result = pipe.CreateNew(false); +#if defined(_WIN32) + lldb::file_t read_file = pipe.GetReadNativeHandle(); + pipe.ReleaseReadFileDescriptor(); + std::unique_ptr<ConnectionGenericFile> conn_up = + std::make_unique<ConnectionGenericFile>(read_file, true); +#else + std::unique_ptr<ConnectionFileDescriptor> conn_up = + std::make_unique<ConnectionFileDescriptor>( + pipe.ReleaseReadFileDescriptor(), true); +#endif + + if (conn_up->IsConnected()) { + m_communication.SetConnection(std::move(conn_up)); + m_communication.SetReadThreadBytesReceivedCallback( + ReadThreadBytesReceived, &result->GetOutputStream()); + m_communication.StartReadThread(); + m_disconnect = true; + + FILE *outfile_handle = fdopen(pipe.ReleaseWriteFileDescriptor(), "w"); + m_output_file_sp = std::make_shared<StreamFile>(outfile_handle, true); + m_error_file_sp = m_output_file_sp; + if (outfile_handle) + ::setbuf(outfile_handle, nullptr); + + result->SetImmediateOutputFile(debugger.GetOutputStream().GetFileSP()); + result->SetImmediateErrorFile(debugger.GetErrorStream().GetFileSP()); + } + } + + if (!m_input_file_sp || !m_output_file_sp || !m_error_file_sp) + debugger.AdoptTopIOHandlerFilesIfInvalid(m_input_file_sp, m_output_file_sp, + m_error_file_sp); +} + +void ScriptInterpreterIORedirect::Flush() { + if (m_output_file_sp) + m_output_file_sp->Flush(); + if (m_error_file_sp) + m_error_file_sp->Flush(); +} + +ScriptInterpreterIORedirect::~ScriptInterpreterIORedirect() { + if (!m_disconnect) + return; + + assert(m_output_file_sp); + assert(m_error_file_sp); + assert(m_output_file_sp == m_error_file_sp); + + // Close the write end of the pipe since we are done with our one line + // script. This should cause the read thread that output_comm is using to + // exit. + m_output_file_sp->GetFile().Close(); + // The close above should cause this thread to exit when it gets to the end + // of file, so let it get all its data. + m_communication.JoinReadThread(); + // Now we can close the read end of the pipe. + m_communication.Disconnect(); } diff --git a/lldb/source/Interpreter/embedded_interpreter.py b/lldb/source/Interpreter/embedded_interpreter.py index 8a1195d83c6f..9312dbfaca4e 100644 --- a/lldb/source/Interpreter/embedded_interpreter.py +++ b/lldb/source/Interpreter/embedded_interpreter.py @@ -73,7 +73,12 @@ def get_terminal_size(fd): def readfunc_stdio(prompt): sys.stdout.write(prompt) sys.stdout.flush() - return sys.stdin.readline().rstrip() + line = sys.stdin.readline() + # Readline always includes a trailing newline character unless the file + # ends with an incomplete line. An empty line indicates EOF. + if not line: + raise EOFError + return line.rstrip() def run_python_interpreter(local_dict): |