diff options
| author | Zachary Turner <zturner@google.com> | 2016-11-16 21:15:24 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2016-11-16 21:15:24 +0000 |
| commit | c156427ded1dfa7686c90cc56ad16013a079a742 (patch) | |
| tree | f4912beeebd9e7a04e9c20a8e05d64e25bde192d /lldb/source/Interpreter | |
| parent | 725dc14bb21da8a01709a6b3370a658d071689dc (diff) | |
| download | bcm5719-llvm-c156427ded1dfa7686c90cc56ad16013a079a742.tar.gz bcm5719-llvm-c156427ded1dfa7686c90cc56ad16013a079a742.zip | |
Don't allow direct access to StreamString's internal buffer.
This is a large API change that removes the two functions from
StreamString that return a std::string& and a const std::string&,
and instead provide one function which returns a StringRef.
Direct access to the underlying buffer violates the concept of
a "stream" which is intended to provide forward only access,
and makes porting to llvm::raw_ostream more difficult in the
future.
Differential Revision: https://reviews.llvm.org/D26698
llvm-svn: 287152
Diffstat (limited to 'lldb/source/Interpreter')
| -rw-r--r-- | lldb/source/Interpreter/Args.cpp | 13 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandAlias.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 77 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 24 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandReturnObject.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Interpreter/OptionValueEnumeration.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Interpreter/OptionValueLanguage.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Interpreter/Options.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Interpreter/Property.cpp | 10 |
9 files changed, 73 insertions, 65 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index b989ee1f218..1e86deafb5f 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -803,7 +803,7 @@ int64_t Args::StringToOptionEnum(llvm::StringRef s, for (int i = 0; enum_values[i].string_value != nullptr; i++) { strm.Printf("%s\"%s\"", i > 0 ? ", " : "", enum_values[i].string_value); } - error.SetErrorString(strm.GetData()); + error.SetErrorString(strm.GetString()); return fail_value; } @@ -859,7 +859,7 @@ Error Args::StringToFormat(const char *s, lldb::Format &format, if (byte_size_ptr) error_strm.PutCString( "An optional byte size can precede the format character.\n"); - error.SetErrorString(error_strm.GetString().c_str()); + error.SetErrorString(error_strm.GetString()); } if (error.Fail()) @@ -1020,9 +1020,9 @@ std::string Args::ParseAliasOptions(Options &options, int val; while (1) { int long_options_index = -1; - val = - OptionParser::Parse(GetArgumentCount(), GetArgumentVector(), - sstr.GetData(), long_options, &long_options_index); + val = OptionParser::Parse(GetArgumentCount(), GetArgumentVector(), + sstr.GetString(), long_options, + &long_options_index); if (val == -1) break; @@ -1088,7 +1088,8 @@ std::string Args::ParseAliasOptions(Options &options, } if (!option_arg) option_arg = "<no-argument>"; - option_arg_vector->emplace_back(option_str.GetData(), has_arg, option_arg); + option_arg_vector->emplace_back(option_str.GetString(), has_arg, + 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 diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp index f31f60f66f7..a8f5343701d 100644 --- a/lldb/source/Interpreter/CommandAlias.cpp +++ b/lldb/source/Interpreter/CommandAlias.cpp @@ -92,7 +92,7 @@ CommandAlias::CommandAlias(CommandInterpreter &interpreter, translation_and_help.Printf( "(%s) %s", sstr.GetData(), GetUnderlyingCommand()->GetHelp().str().c_str()); - SetHelp(translation_and_help.GetData()); + SetHelp(translation_and_help.GetString()); } } } diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 8614bdae64e..2047d4a4433 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -352,8 +352,8 @@ void CommandInterpreter::Initialize() { StreamString defaultshell; defaultshell.Printf("--shell=%s --", HostInfo::GetDefaultShell().GetPath().c_str()); - AddAlias("r", cmd_obj_sp, defaultshell.GetData()); - AddAlias("run", cmd_obj_sp, defaultshell.GetData()); + AddAlias("r", cmd_obj_sp, defaultshell.GetString()); + AddAlias("run", cmd_obj_sp, defaultshell.GetString()); #endif #endif } @@ -1327,7 +1327,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.GetData(); + alias_result = result_str.GetString(); return alias_cmd_obj; } OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); @@ -1368,7 +1368,7 @@ CommandObject *CommandInterpreter::BuildAliasResult( } } - alias_result = result_str.GetData(); + alias_result = result_str.GetString(); return alias_cmd_obj; } @@ -1437,8 +1437,7 @@ Error 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.GetData(), - value_string_size); + command.insert(start_backtick, value_strm.GetString()); pos = start_backtick + value_string_size; continue; } else { @@ -2249,21 +2248,21 @@ void CommandInterpreter::HandleCommands(const StringList &commands, } if (!success || !tmp_result.Succeeded()) { - const char *error_msg = tmp_result.GetErrorData(); - if (error_msg == nullptr || error_msg[0] == '\0') + llvm::StringRef error_msg = tmp_result.GetErrorData(); + if (error_msg.empty()) error_msg = "<unknown error>.\n"; if (options.GetStopOnError()) { result.AppendErrorWithFormat( "Aborting reading of commands after command #%" PRIu64 ": '%s' failed with %s", - (uint64_t)idx, cmd, error_msg); + (uint64_t)idx, cmd, error_msg.str().c_str()); result.SetStatus(eReturnStatusFailed); m_debugger.SetAsyncExecution(old_async_execution); return; } else if (options.GetPrintResults()) { - result.AppendMessageWithFormat("Command #%" PRIu64 - " '%s' failed with %s", - (uint64_t)idx + 1, cmd, error_msg); + result.AppendMessageWithFormat( + "Command #%" PRIu64 " '%s' failed with %s", (uint64_t)idx + 1, cmd, + error_msg.str().c_str()); } } @@ -2546,7 +2545,15 @@ void CommandInterpreter::OutputFormattedHelpText(Stream &strm, StreamString prefix_stream; prefix_stream.Printf(" %-*s %*s ", (int)max_word_len, word_text.data(), (int)separator.size(), separator.data()); - OutputFormattedHelpText(strm, prefix_stream.GetData(), help_text); + OutputFormattedHelpText(strm, prefix_stream.GetString(), help_text); +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE +static size_t nextWordLength(llvm::StringRef S) { + size_t pos = S.find_first_of(' '); + if (pos == llvm::StringRef::npos) + return S.size(); + return pos; } void CommandInterpreter::OutputHelpText(Stream &strm, llvm::StringRef word_text, @@ -2563,22 +2570,24 @@ void CommandInterpreter::OutputHelpText(Stream &strm, llvm::StringRef word_text, const uint32_t max_columns = m_debugger.GetTerminalWidth(); - size_t len = text_strm.GetSize(); - const char *text = text_strm.GetData(); + llvm::StringRef text = text_strm.GetString(); uint32_t chars_left = max_columns; - for (uint32_t i = 0; i < len; i++) { - if ((text[i] == ' ' && ::strchr((text + i + 1), ' ') && - chars_left < static_cast<uint32_t>(::strchr((text + i + 1), ' ') - - (text + i))) || - text[i] == '\n') { - chars_left = max_columns - indent_size; + while (!text.empty()) { + if (text.front() == '\n' || + (text.front() == ' ' && nextWordLength(text.ltrim(' ')) < chars_left)) { strm.EOL(); strm.Indent(); + chars_left = max_columns - indent_size; + if (text.front() == '\n') + text = text.drop_front(); + else + text = text.ltrim(' '); } else { - strm.PutChar(text[i]); - chars_left--; + strm.PutChar(text.front()); + --chars_left; + text = text.drop_front(); } } @@ -2707,15 +2716,15 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler, GetProcessOutput(); if (!result.GetImmediateOutputStream()) { - const char *output = result.GetOutputData(); - if (output && output[0]) + llvm::StringRef output = result.GetOutputData(); + if (!output.empty()) io_handler.GetOutputStreamFile()->PutCString(output); } // Now emit the command error text from the command we just executed if (!result.GetImmediateErrorStream()) { - const char *error = result.GetErrorData(); - if (error && error[0]) + llvm::StringRef error = result.GetErrorData(); + if (!error.empty()) io_handler.GetErrorStreamFile()->PutCString(error); } } @@ -2993,7 +3002,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line, for (uint32_t i = 0; i < num_matches; ++i) { error_msg.Printf("\t%s\n", matches.GetStringAtIndex(i)); } - result.AppendRawError(error_msg.GetString().c_str()); + result.AppendRawError(error_msg.GetString()); } else { // We didn't have only one match, otherwise we wouldn't get here. assert(num_matches == 0); @@ -3029,18 +3038,16 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line, std::string gdb_format_option("--gdb-format="); gdb_format_option += (suffix.c_str() + 1); - bool inserted = false; - std::string &cmd = revised_command_line.GetString(); + std::string cmd = 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 // options gdb_format_option.append(1, ' '); cmd.insert(arg_terminator_idx, gdb_format_option); - inserted = true; - } - - if (!inserted) + revised_command_line.Clear(); + revised_command_line.PutCString(cmd); + } else revised_command_line.Printf(" %s", gdb_format_option.c_str()); if (wants_raw_input && @@ -3072,7 +3079,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line, revised_command_line.Printf(" %s", scratch_command.c_str()); if (cmd_obj != NULL) - command_line = revised_command_line.GetData(); + command_line = revised_command_line.GetString(); return cmd_obj; } diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index a7f590fd268..4c6ec8e4ba6 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -74,7 +74,7 @@ llvm::StringRef CommandObject::GetSyntax() { syntax_str.PutCString("-- "); GetFormattedCommandArguments(syntax_str); } - m_cmd_syntax = syntax_str.GetData(); + m_cmd_syntax = syntax_str.GetString(); return m_cmd_syntax; } @@ -392,14 +392,14 @@ void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type, if (entry->help_function) { llvm::StringRef help_text = entry->help_function(); if (!entry->help_function.self_formatting) { - interpreter.OutputFormattedHelpText(str, name_str.GetData(), "--", + interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--", help_text, name_str.GetSize()); } else { - interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text, + interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text, name_str.GetSize()); } } else - interpreter.OutputFormattedHelpText(str, name_str.GetData(), "--", + interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--", entry->help_text, name_str.GetSize()); } @@ -416,9 +416,7 @@ const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) { if (entry) return entry->arg_name; - StreamString str; - str << "Arg name for type (" << arg_type << ") not in arg table!"; - return str.GetData(); + return nullptr; } bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) { @@ -503,21 +501,23 @@ void CommandObject::GetFormattedCommandArguments(Stream &str, names.Printf(" | "); names.Printf("%s", GetArgumentName(arg_entry[j].arg_type)); } + + std::string name_str = names.GetString(); switch (arg_entry[0].arg_repetition) { case eArgRepeatPlain: - str.Printf("<%s>", names.GetData()); + str.Printf("<%s>", name_str.c_str()); break; case eArgRepeatPlus: - str.Printf("<%s> [<%s> [...]]", names.GetData(), names.GetData()); + str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str()); break; case eArgRepeatStar: - str.Printf("[<%s> [<%s> [...]]]", names.GetData(), names.GetData()); + str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str()); break; case eArgRepeatOptional: - str.Printf("[<%s>]", names.GetData()); + str.Printf("[<%s>]", name_str.c_str()); break; case eArgRepeatRange: - str.Printf("<%s_1> .. <%s_n>", names.GetData(), names.GetData()); + str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str()); break; // Explicitly test for all the rest of the cases, so if new types get // added we will notice the diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index 53f3bd2d8d6..72e66aa082e 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -69,7 +69,7 @@ void CommandReturnObject::AppendMessageWithFormat(const char *format, ...) { sstrm.PrintfVarArg(format, args); va_end(args); - GetOutputStream().Printf("%s", sstrm.GetData()); + GetOutputStream() << sstrm.GetString(); } void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) { @@ -81,7 +81,7 @@ void CommandReturnObject::AppendWarningWithFormat(const char *format, ...) { sstrm.PrintfVarArg(format, args); va_end(args); - GetErrorStream().Printf("warning: %s", sstrm.GetData()); + GetErrorStream() << "warning: " << sstrm.GetString(); } void CommandReturnObject::AppendMessage(llvm::StringRef in_string) { diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index fe151fa19ce..3ec2829c094 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -75,7 +75,7 @@ Error OptionValueEnumeration::SetValueFromString(llvm::StringRef value, m_enumerations.GetCStringAtIndex(i).str().c_str()); } } - error.SetErrorString(error_strm.GetData()); + error.SetErrorString(error_strm.GetString()); } break; } diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp index a59419f649e..2659762d2f2 100644 --- a/lldb/source/Interpreter/OptionValueLanguage.cpp +++ b/lldb/source/Interpreter/OptionValueLanguage.cpp @@ -61,7 +61,7 @@ Error OptionValueLanguage::SetValueFromString(llvm::StringRef value, error_strm.Printf("%s%s%s", " ", Language::GetNameForLanguageType(language), "\n"); } - error.SetErrorString(error_strm.GetData()); + error.SetErrorString(error_strm.GetString()); } } break; diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index c95876fe41a..d26e53f121c 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -529,7 +529,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, if (cmd->WantsRawCommandString() && !only_print_args) strm.Printf(" --"); - strm.Printf(" %s", args_str.GetData()); + strm << " " << args_str.GetString(); if (only_print_args) break; } @@ -541,7 +541,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, if (!only_print_args) strm.PutChar('\n'); strm.Indent(name); - strm.Printf(" %s", arguments_str.GetData()); + strm << " " << arguments_str.GetString(); } strm.Printf("\n\n"); diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index b6f6507083d..5bac5ea0002 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/lldb/source/Interpreter/Property.cpp @@ -277,17 +277,17 @@ void Property::DumpDescription(CommandInterpreter &interpreter, Stream &strm, strm.EOL(); if (m_value_sp->DumpQualifiedName(qualified_name)) - strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str()); + strm.Printf("'%s' variables:\n\n", qualified_name.GetData()); sub_properties->DumpAllDescriptions(interpreter, strm); } else { if (display_qualified_name) { StreamString qualified_name; DumpQualifiedName(qualified_name); - interpreter.OutputFormattedHelpText( - strm, qualified_name.GetString().c_str(), "--", desc, output_width); + interpreter.OutputFormattedHelpText(strm, qualified_name.GetString(), + "--", desc, output_width); } else { - interpreter.OutputFormattedHelpText(strm, m_name.GetCString(), "--", desc, - output_width); + interpreter.OutputFormattedHelpText(strm, m_name.GetStringRef(), "--", + desc, output_width); } } } |

