diff options
author | Zachary Turner <zturner@google.com> | 2016-09-19 17:54:06 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-09-19 17:54:06 +0000 |
commit | ecbb0bb1690cd59da0224d7b906f968356b1265c (patch) | |
tree | 90951f44a7abb40b355e849a2e64cb09ec3ac900 /lldb/source/Interpreter | |
parent | 495b211a6c775e6fbc00a1e3a91786f6a880b82e (diff) | |
download | bcm5719-llvm-ecbb0bb1690cd59da0224d7b906f968356b1265c.tar.gz bcm5719-llvm-ecbb0bb1690cd59da0224d7b906f968356b1265c.zip |
Fix more functions in Args to use StringRef.
This patch also marks the const char* versions as =delete to prevent
their use. This has the potential to cause build breakages on some
platforms which I can't compile. I have tested on Windows, Linux,
and OSX. Best practices for fixing broken callsites are outlined in
Args.h in a comment above the deleted function declarations.
Eventually we can remove these =delete declarations, but for now they
are important to make sure that all implicit conversions from
const char * are manually audited to make sure that they do not invoke a
conversion from nullptr.
llvm-svn: 281919
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/Args.cpp | 47 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 23 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 8 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueBoolean.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueDictionary.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/Property.cpp | 2 |
7 files changed, 41 insertions, 53 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index b6a60263e8f..0dd093fe27a 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -362,23 +362,23 @@ const char *Args::Unshift(const char *arg_cstr, char quote_char) { void Args::AppendArguments(const Args &rhs) { const size_t rhs_argc = rhs.GetArgumentCount(); for (size_t i = 0; i < rhs_argc; ++i) - AppendArgument(rhs.GetArgumentAtIndex(i), + AppendArgument(llvm::StringRef(rhs.GetArgumentAtIndex(i)), rhs.GetArgumentQuoteCharAtIndex(i)); } void Args::AppendArguments(const char **argv) { if (argv) { for (uint32_t i = 0; argv[i]; ++i) - AppendArgument(argv[i]); + AppendArgument(llvm::StringRef::withNullAsEmpty(argv[i])); } } -const char *Args::AppendArgument(const char *arg_cstr, char quote_char) { - return InsertArgumentAtIndex(GetArgumentCount(), arg_cstr, quote_char); +llvm::StringRef Args::AppendArgument(llvm::StringRef arg_str, char quote_char) { + return InsertArgumentAtIndex(GetArgumentCount(), arg_str, quote_char); } -const char *Args::InsertArgumentAtIndex(size_t idx, const char *arg_cstr, - char quote_char) { +llvm::StringRef Args::InsertArgumentAtIndex(size_t idx, llvm::StringRef arg_str, + char quote_char) { // Since we are using a std::list to hold onto the copied C string and // we don't have direct access to the elements, we have to iterate to // find the value. @@ -387,7 +387,7 @@ const char *Args::InsertArgumentAtIndex(size_t idx, const char *arg_cstr, for (pos = m_args.begin(); i > 0 && pos != end; ++pos) --i; - pos = m_args.insert(pos, arg_cstr); + pos = m_args.insert(pos, arg_str); if (idx >= m_args_quote_char.size()) { m_args_quote_char.resize(idx + 1); @@ -399,8 +399,9 @@ const char *Args::InsertArgumentAtIndex(size_t idx, const char *arg_cstr, return GetArgumentAtIndex(idx); } -const char *Args::ReplaceArgumentAtIndex(size_t idx, const char *arg_cstr, - char quote_char) { +llvm::StringRef Args::ReplaceArgumentAtIndex(size_t idx, + llvm::StringRef arg_str, + char quote_char) { // Since we are using a std::list to hold onto the copied C string and // we don't have direct access to the elements, we have to iterate to // find the value. @@ -410,7 +411,7 @@ const char *Args::ReplaceArgumentAtIndex(size_t idx, const char *arg_cstr, --i; if (pos != end) { - pos->assign(arg_cstr); + pos->assign(arg_str); assert(idx < m_argv.size() - 1); m_argv[idx] = pos->c_str(); if (idx >= m_args_quote_char.size()) @@ -732,11 +733,6 @@ const char *Args::StripSpaces(std::string &s, bool leading, bool trailing, return s.c_str(); } -bool Args::StringToBoolean(const char *s, bool fail_value, - bool *success_ptr) { - return StringToBoolean(llvm::StringRef(s ? s : ""), fail_value, success_ptr); -} - bool Args::StringToBoolean(llvm::StringRef ref, bool fail_value, bool *success_ptr) { if (success_ptr) @@ -915,13 +911,6 @@ Error Args::StringToFormat(const char *s, lldb::Format &format, return error; } -lldb::Encoding Args::StringToEncoding(const char *s, - lldb::Encoding fail_value) { - if (!s) - return fail_value; - return StringToEncoding(llvm::StringRef(s), fail_value); -} - lldb::Encoding Args::StringToEncoding(llvm::StringRef s, lldb::Encoding fail_value) { return llvm::StringSwitch<lldb::Encoding>(s) @@ -932,12 +921,6 @@ lldb::Encoding Args::StringToEncoding(llvm::StringRef s, .Default(fail_value); } -uint32_t Args::StringToGenericRegister(const char *s) { - if (!s) - return LLDB_INVALID_REGNUM; - return StringToGenericRegister(llvm::StringRef(s)); -} - uint32_t Args::StringToGenericRegister(llvm::StringRef s) { if (s.empty()) return LLDB_INVALID_REGNUM; @@ -1015,13 +998,13 @@ void Args::AddOrReplaceEnvironmentVariable(const char *env_var_name, // Check if the name matches the given env_var_name. if (strncmp(env_var_name, arg_value, equal_p - arg_value) == 0) { - ReplaceArgumentAtIndex(i, stream.GetString().c_str()); + ReplaceArgumentAtIndex(i, stream.GetString()); return; } } // We didn't find it. Append it instead. - AppendArgument(stream.GetString().c_str()); + AppendArgument(stream.GetString()); } bool Args::ContainsEnvironmentVariable(const char *env_var_name, @@ -1239,7 +1222,7 @@ void Args::ParseAliasOptions(Options &options, CommandReturnObject &result, if (pos != std::string::npos) raw_input_string.erase(pos, strlen(tmp_arg)); } - ReplaceArgumentAtIndex(idx, ""); + ReplaceArgumentAtIndex(idx, llvm::StringRef()); if ((long_options[long_options_index].definition->option_has_arg != OptionParser::eNoArgument) && (OptionParser::GetOptionArgument() != nullptr) && @@ -1252,7 +1235,7 @@ void Args::ParseAliasOptions(Options &options, CommandReturnObject &result, if (pos != std::string::npos) raw_input_string.erase(pos, strlen(tmp_arg)); } - ReplaceArgumentAtIndex(idx + 1, ""); + ReplaceArgumentAtIndex(idx + 1, llvm::StringRef()); } } } diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 1bc5103793b..32bcca83522 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1760,7 +1760,7 @@ int CommandInterpreter::HandleCompletionMatches( look_for_subcommand = true; num_command_matches = 0; matches.DeleteStringAtIndex(0); - parsed_line.AppendArgument(""); + parsed_line.AppendArgument(llvm::StringRef()); cursor_index++; cursor_char_position = 0; } @@ -1842,7 +1842,8 @@ int CommandInterpreter::HandleCompletion( partial_parsed_line.GetArgumentAtIndex(cursor_index); if (cursor_char_position == 0 || current_elem[cursor_char_position - 1] != ' ') { - parsed_line.InsertArgumentAtIndex(cursor_index + 1, "", '\0'); + parsed_line.InsertArgumentAtIndex(cursor_index + 1, llvm::StringRef(), + '\0'); cursor_index++; cursor_char_position = 0; } @@ -1987,21 +1988,23 @@ void CommandInterpreter::BuildAliasCommandArgs(CommandObject *alias_cmd_obj, // this above, make // sure we don't // insert it twice - new_args.AppendArgument(value.c_str()); + new_args + .AppendArgument( + value); } else { if (value_type != OptionParser::eOptionalArgument) - new_args.AppendArgument(option.c_str()); + new_args.AppendArgument(option); if (value.compare("<no-argument>") != 0) { int index = GetOptionArgumentPosition(value.c_str()); if (index == 0) { // value was NOT a positional argument; must be a real value if (value_type != OptionParser::eOptionalArgument) - new_args.AppendArgument(value.c_str()); + new_args.AppendArgument(value); else { char buffer[255]; ::snprintf(buffer, sizeof(buffer), "%s%s", option.c_str(), value.c_str()); - new_args.AppendArgument(buffer); + new_args.AppendArgument(llvm::StringRef(buffer)); } } else if (static_cast<size_t>(index) >= @@ -2023,12 +2026,13 @@ void CommandInterpreter::BuildAliasCommandArgs(CommandObject *alias_cmd_obj, } if (value_type != OptionParser::eOptionalArgument) - new_args.AppendArgument(cmd_args.GetArgumentAtIndex(index)); + new_args.AppendArgument(llvm::StringRef::withNullAsEmpty( + cmd_args.GetArgumentAtIndex(index))); else { char buffer[255]; ::snprintf(buffer, sizeof(buffer), "%s%s", option.c_str(), cmd_args.GetArgumentAtIndex(index)); - new_args.AppendArgument(buffer); + new_args.AppendArgument(llvm::StringRef(buffer)); } used[index] = true; } @@ -2038,7 +2042,8 @@ void CommandInterpreter::BuildAliasCommandArgs(CommandObject *alias_cmd_obj, for (size_t j = 0; j < cmd_args.GetArgumentCount(); ++j) { if (!used[j] && !wants_raw_input) - new_args.AppendArgument(cmd_args.GetArgumentAtIndex(j)); + new_args.AppendArgument( + llvm::StringRef(cmd_args.GetArgumentAtIndex(j))); } cmd_args.Clear(); diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index d42d3c7f111..702939a1110 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -300,10 +300,9 @@ int CommandObject::HandleCompletion(Args &input, int &cursor_index, cursor_index++; // I stick an element on the end of the input, because if the last element - // is - // option that requires an argument, getopt_long_only will freak out. + // is option that requires an argument, getopt_long_only will freak out. - input.AppendArgument("<FAKE-VALUE>"); + input.AppendArgument(llvm::StringRef("<FAKE-VALUE>")); input.ParseArgsForCompletion(*cur_options, opt_element_vector, cursor_index); @@ -1001,7 +1000,8 @@ bool CommandObjectParsed::Execute(const char *args_string, const char *tmp_str = cmd_args.GetArgumentAtIndex(i); if (tmp_str[0] == '`') // back-quote cmd_args.ReplaceArgumentAtIndex( - i, m_interpreter.ProcessEmbeddedScriptCommands(tmp_str)); + i, llvm::StringRef::withNullAsEmpty( + m_interpreter.ProcessEmbeddedScriptCommands(tmp_str))); } if (CheckRequirements(result)) { diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp index 5ce7fb8ed72..e5943925e86 100644 --- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp +++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp @@ -85,6 +85,8 @@ Error OptionGroupValueObjectDisplay::SetOptionValue( const int short_option = g_option_table[option_idx].short_option; bool success = false; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); + switch (short_option) { case 'd': { int32_t result; @@ -141,13 +143,13 @@ Error OptionGroupValueObjectDisplay::SetOptionValue( break; case 'S': - use_synth = Args::StringToBoolean(option_arg, true, &success); + use_synth = Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); break; case 'V': - run_validator = Args::StringToBoolean(option_arg, true, &success); + run_validator = Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); break; diff --git a/lldb/source/Interpreter/OptionValueBoolean.cpp b/lldb/source/Interpreter/OptionValueBoolean.cpp index dbbd46ea093..bd988fa5750 100644 --- a/lldb/source/Interpreter/OptionValueBoolean.cpp +++ b/lldb/source/Interpreter/OptionValueBoolean.cpp @@ -1,5 +1,4 @@ -//===-- OptionValueBoolean.cpp ------------------------------------*- C++ -//-*-===// +//===-- OptionValueBoolean.cpp ----------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -48,8 +47,7 @@ Error OptionValueBoolean::SetValueFromString(llvm::StringRef value_str, case eVarSetOperationReplace: case eVarSetOperationAssign: { bool success = false; - bool value = - Args::StringToBoolean(value_str.str().c_str(), false, &success); + bool value = Args::StringToBoolean(value_str, false, &success); if (success) { m_value_was_set = true; m_current_value = value; diff --git a/lldb/source/Interpreter/OptionValueDictionary.cpp b/lldb/source/Interpreter/OptionValueDictionary.cpp index cf8715eebb1..da68a686045 100644 --- a/lldb/source/Interpreter/OptionValueDictionary.cpp +++ b/lldb/source/Interpreter/OptionValueDictionary.cpp @@ -85,7 +85,7 @@ size_t OptionValueDictionary::GetArgs(Args &args) const { StreamString strm; strm.Printf("%s=", pos->first.GetCString()); pos->second->DumpValue(nullptr, strm, eDumpOptionValue | eDumpOptionRaw); - args.AppendArgument(strm.GetString().c_str()); + args.AppendArgument(strm.GetString()); } return args.GetArgumentCount(); } diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index ba859a5398c..a15b985e8bb 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/lldb/source/Interpreter/Property.cpp @@ -54,7 +54,7 @@ Property::Property(const PropertyDefinition &definition) // default value. if (definition.default_cstr_value) m_value_sp.reset(new OptionValueBoolean(Args::StringToBoolean( - definition.default_cstr_value, false, nullptr))); + llvm::StringRef(definition.default_cstr_value), false, nullptr))); else m_value_sp.reset( new OptionValueBoolean(definition.default_uint_value != 0)); |