diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 20:23:46 +0100 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 23:25:25 +0100 |
commit | adcd02683856c30ba6f349279509acecd90063df (patch) | |
tree | 7b5927ef2ecab1618842183fac5ebe848f5832dd /lldb/source/Interpreter/CommandInterpreter.cpp | |
parent | 5eaf44f99f0a0a3bdfa892892b8aaca841c8dbe0 (diff) | |
download | llvm-adcd02683856c30ba6f349279509acecd90063df.zip llvm-adcd02683856c30ba6f349279509acecd90063df.tar.gz llvm-adcd02683856c30ba6f349279509acecd90063df.tar.bz2 |
Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.
This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.
This doesn't actually modify StringRef yet, I'll do that in a follow-up.
Diffstat (limited to 'lldb/source/Interpreter/CommandInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index aedd71b..c2c70dc 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -571,7 +571,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; } } @@ -631,7 +632,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; } } @@ -651,7 +652,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; } } @@ -667,7 +668,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; } } @@ -681,7 +683,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; } } @@ -694,7 +697,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; } } @@ -709,7 +712,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; } } @@ -728,7 +731,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; } } @@ -746,7 +749,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; } } @@ -771,7 +774,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; } } @@ -807,7 +810,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; } } @@ -825,7 +829,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; } } @@ -848,7 +853,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; } } } @@ -873,7 +879,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); @@ -1002,18 +1008,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; @@ -1099,14 +1105,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; @@ -1132,11 +1139,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 * @@ -1151,7 +1158,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(); } @@ -1159,7 +1167,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; @@ -1168,7 +1176,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 @@ -1179,7 +1187,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; @@ -1263,7 +1272,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. @@ -1404,7 +1414,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); @@ -1412,7 +1422,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(); @@ -1453,7 +1463,7 @@ CommandObject *CommandInterpreter::BuildAliasResult( } } - alias_result = result_str.GetString(); + alias_result = std::string(result_str.GetString()); return alias_cmd_obj; } @@ -1537,7 +1547,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 { @@ -1662,8 +1672,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()); @@ -1872,7 +1882,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(); @@ -3083,7 +3093,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 @@ -3124,7 +3134,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; } |