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 | |
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')
32 files changed, 147 insertions, 135 deletions
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp index 10b7219eb35..6085cef3206 100644 --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -251,7 +251,8 @@ SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) { PlatformSP platform_sp(GetSP()); if (platform_sp && connect_options.GetURL()) { Args args; - args.AppendArgument(connect_options.GetURL()); + args.AppendArgument( + llvm::StringRef::withNullAsEmpty(connect_options.GetURL())); sb_error.ref() = platform_sp->ConnectRemote(args); } else { sb_error.SetErrorString("invalid platform"); diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp index 0c5ff82082b..d7bf191b2e7 100644 --- a/lldb/source/Breakpoint/BreakpointIDList.cpp +++ b/lldb/source/Breakpoint/BreakpointIDList.cpp @@ -215,7 +215,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target, StreamString canonical_id_str; BreakpointID::GetCanonicalReference(&canonical_id_str, bp_id, bp_loc->GetID()); - new_args.AppendArgument(canonical_id_str.GetData()); + new_args.AppendArgument(canonical_id_str.GetString()); } } } @@ -309,7 +309,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target, StreamString canonical_id_str; BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, bp_loc->GetID()); - new_args.AppendArgument(canonical_id_str.GetData()); + new_args.AppendArgument(canonical_id_str.GetString()); } } } else if ((cur_bp_id == end_bp_id) && @@ -321,19 +321,19 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target, StreamString canonical_id_str; BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, bp_loc->GetID()); - new_args.AppendArgument(canonical_id_str.GetData()); + new_args.AppendArgument(canonical_id_str.GetString()); } } } else { StreamString canonical_id_str; BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, LLDB_INVALID_BREAK_ID); - new_args.AppendArgument(canonical_id_str.GetData()); + new_args.AppendArgument(canonical_id_str.GetString()); } } } else // else is_range was false { - new_args.AppendArgument(current_arg); + new_args.AppendArgument(llvm::StringRef::withNullAsEmpty(current_arg)); } } @@ -345,7 +345,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target, StreamString canonical_id_str; BreakpointID::GetCanonicalReference( &canonical_id_str, bkpt_sp->GetID(), LLDB_INVALID_BREAK_ID); - new_args.AppendArgument(canonical_id_str.GetData()); + new_args.AppendArgument(canonical_id_str.GetString()); } } } diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index 682e26bbbb4..bab8ecbf0ab 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -172,7 +172,7 @@ public: case 'h': { bool success; - m_catch_bp = Args::StringToBoolean(option_arg, true, &success); + m_catch_bp = Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat( "Invalid boolean value for on-catch option: '%s'", option_arg); @@ -192,7 +192,7 @@ public: case 'K': { bool success; bool value; - value = Args::StringToBoolean(option_arg, true, &success); + value = Args::StringToBoolean(option_strref, true, &success); if (value) m_skip_prologue = eLazyBoolYes; else @@ -223,7 +223,7 @@ public: case 'm': { bool success; bool value; - value = Args::StringToBoolean(option_arg, true, &success); + value = Args::StringToBoolean(option_strref, true, &success); if (value) m_move_to_nearest_code = eLazyBoolYes; else @@ -265,8 +265,8 @@ public: break; case 'O': - m_exception_extra_args.AppendArgument("-O"); - m_exception_extra_args.AppendArgument(option_arg); + m_exception_extra_args.AppendArgument(llvm::StringRef("-O")); + m_exception_extra_args.AppendArgument(option_strref); break; case 'p': @@ -304,7 +304,7 @@ public: case 'w': { bool success; - m_throw_bp = Args::StringToBoolean(option_arg, true, &success); + m_throw_bp = Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat( "Invalid boolean value for on-throw option: '%s'", option_arg); @@ -861,7 +861,8 @@ public: break; case 'o': { bool value, success; - value = Args::StringToBoolean(option_arg, false, &success); + value = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_arg), false, &success); if (success) { m_one_shot_passed = true; m_one_shot = value; diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index bf758b93ae5..ed10a2454cc 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -268,6 +268,7 @@ are no syntax errors may indicate that a function was declared but never called. ExecutionContext *execution_context) override { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 'o': @@ -290,7 +291,7 @@ are no syntax errors may indicate that a function was declared but never called. case 'e': { bool success = false; - m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); + m_stop_on_error = Args::StringToBoolean(option_strref, false, &success); if (!success) error.SetErrorStringWithFormat( "invalid value for stop-on-error: \"%s\"", option_arg); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index be4f54616c5..cc1fdf44b12 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -78,6 +78,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( ExecutionContext *execution_context) { Error error; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); const int short_option = g_option_table[option_idx].short_option; switch (short_option) { @@ -91,7 +92,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( case 'a': { bool success; bool result; - result = Args::StringToBoolean(option_arg, true, &success); + result = Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat( "invalid all-threads value setting: \"%s\"", option_arg); @@ -101,7 +102,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( case 'i': { bool success; - bool tmp_value = Args::StringToBoolean(option_arg, true, &success); + bool tmp_value = Args::StringToBoolean(option_strref, true, &success); if (success) ignore_breakpoints = tmp_value; else @@ -112,7 +113,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( case 'j': { bool success; - bool tmp_value = Args::StringToBoolean(option_arg, true, &success); + bool tmp_value = Args::StringToBoolean(option_strref, true, &success); if (success) allow_jit = tmp_value; else @@ -134,7 +135,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( case 'u': { bool success; - bool tmp_value = Args::StringToBoolean(option_arg, true, &success); + bool tmp_value = Args::StringToBoolean(option_strref, true, &success); if (success) unwind_on_error = tmp_value; else @@ -168,7 +169,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( case 'X': { bool success; - bool tmp_value = Args::StringToBoolean(option_arg, true, &success); + bool tmp_value = Args::StringToBoolean(option_strref, true, &success); if (success) auto_apply_fixits = tmp_value ? eLazyBoolYes : eLazyBoolNo; else diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index e4c5a8656ed..85134442213 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -387,8 +387,9 @@ protected: } if (strcasecmp(sub_command, "increment") == 0) { bool success; - bool increment = - Args::StringToBoolean(args.GetArgumentAtIndex(1), false, &success); + bool increment = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(args.GetArgumentAtIndex(1)), false, + &success); if (success) { Timer::SetQuiet(!increment); result.SetStatus(eReturnStatusSuccessFinishNoResult); diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 54dfdd1ecef..9a2180c5ed4 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -1478,7 +1478,8 @@ protected: break; case eFormatBoolean: - uval64 = Args::StringToBoolean(value_str, false, &success); + uval64 = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(value_str), false, &success); if (!success) { result.AppendErrorWithFormat( "'%s' is not a valid boolean string value.\n", value_str); diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index dd60af0fc79..80d64193e64 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -210,7 +210,7 @@ int CommandObjectMultiword::HandleCompletion(Args &input, int &cursor_index, matches.DeleteStringAtIndex(0); input.Shift(); cursor_char_position = 0; - input.AppendArgument(""); + input.AppendArgument(llvm::StringRef()); return cmd_obj->HandleCompletion( input, cursor_index, cursor_char_position, match_start_point, max_return_elements, word_complete, matches); diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 1a981ce49ea..295f4c7133c 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -29,6 +29,8 @@ #include "lldb/Target/Process.h" #include "lldb/Utility/Utils.h" +#include "llvm/ADT/SmallString.h" + using namespace lldb; using namespace lldb_private; @@ -1057,9 +1059,9 @@ protected: Module *exe_module = target->GetExecutableModulePointer(); if (exe_module) { m_options.launch_info.GetExecutableFile() = exe_module->GetFileSpec(); - char exe_path[PATH_MAX]; - if (m_options.launch_info.GetExecutableFile().GetPath(exe_path, - sizeof(exe_path))) + llvm::SmallString<PATH_MAX> exe_path; + m_options.launch_info.GetExecutableFile().GetPath(exe_path); + if (!exe_path.empty()) m_options.launch_info.GetArguments().AppendArgument(exe_path); m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture(); } diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 77305fcef1a..26e7602493d 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -212,7 +212,7 @@ protected: if (target_settings_argv0) { m_options.launch_info.GetArguments().AppendArgument( - target_settings_argv0); + llvm::StringRef(target_settings_argv0)); m_options.launch_info.SetExecutableFile( exe_module_sp->GetPlatformFileSpec(), false); } else { @@ -760,12 +760,13 @@ public: ExecutionContext *execution_context) override { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 's': bool tmp_result; bool success; - tmp_result = Args::StringToBoolean(option_arg, false, &success); + tmp_result = Args::StringToBoolean(option_strref, false, &success); if (!success) error.SetErrorStringWithFormat("invalid boolean option: \"%s\"", option_arg); @@ -1458,7 +1459,7 @@ public: bool VerifyCommandOptionValue(const std::string &option, int &real_value) { bool okay = true; bool success = false; - bool tmp_value = Args::StringToBoolean(option.c_str(), false, &success); + bool tmp_value = Args::StringToBoolean(option, false, &success); if (success && tmp_value) real_value = 1; diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index f2f7cdc212a..6cefa6ee003 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -157,6 +157,7 @@ public: ExecutionContext *execution_context) override { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 'c': { @@ -181,7 +182,7 @@ public: case 'e': { bool success; m_extended_backtrace = - Args::StringToBoolean(option_arg, false, &success); + Args::StringToBoolean(option_strref, false, &success); if (!success) error.SetErrorStringWithFormat( "invalid boolean value for option '%c'", short_option); @@ -315,11 +316,13 @@ public: ExecutionContext *execution_context) override { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 'a': { bool success; - bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success); + bool avoid_no_debug = + Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat( "invalid boolean value for option '%c'", short_option); @@ -331,7 +334,8 @@ public: case 'A': { bool success; - bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success); + bool avoid_no_debug = + Args::StringToBoolean(option_strref, true, &success); if (!success) error.SetErrorStringWithFormat( "invalid boolean value for option '%c'", short_option); @@ -1441,11 +1445,12 @@ public: ExecutionContext *execution_context) override { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 'x': { bool success; - bool tmp_value = Args::StringToBoolean(option_arg, false, &success); + bool tmp_value = Args::StringToBoolean(option_strref, false, &success); if (success) m_from_expression = tmp_value; else { diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 60ff00a0330..358e9c67138 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -298,7 +298,8 @@ private: switch (short_option) { case 'C': - m_cascade = Args::StringToBoolean(option_arg, true, &success); + m_cascade = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_arg), true, &success); if (!success) error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg); @@ -530,7 +531,8 @@ private: switch (short_option) { case 'C': - m_cascade = Args::StringToBoolean(option_value, true, &success); + m_cascade = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_value), true, &success); if (!success) error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value); @@ -1246,7 +1248,8 @@ Error CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue( switch (short_option) { case 'C': - m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success)); + m_flags.SetCascades(Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_arg), true, &success)); if (!success) error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg); @@ -2557,7 +2560,8 @@ private: switch (short_option) { case 'C': - m_cascade = Args::StringToBoolean(option_arg, true, &success); + m_cascade = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_arg), true, &success); if (!success) error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg); diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index b576ce8b2f8..c67bae015d4 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -318,7 +318,8 @@ are no syntax errors may indicate that a function was declared but never called. case 'e': { bool success = false; - m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); + m_stop_on_error = Args::StringToBoolean( + llvm::StringRef::withNullAsEmpty(option_arg), false, &success); if (!success) error.SetErrorStringWithFormat( "invalid value for stop-on-error: \"%s\"", option_arg); diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp index ca2084d62e5..8acf4a94e5b 100644 --- a/lldb/source/Host/linux/Host.cpp +++ b/lldb/source/Host/linux/Host.cpp @@ -323,7 +323,7 @@ static bool GetProcessAndStatInfo(lldb::pid_t pid, char *next_var = (char *)buf_sp->GetBytes(); char *end_buf = next_var + buf_sp->GetByteSize(); while (next_var < end_buf && 0 != *next_var) { - info_env.AppendArgument(next_var); + info_env.AppendArgument(llvm::StringRef(next_var)); next_var += strlen(next_var) + 1; } @@ -340,7 +340,7 @@ static bool GetProcessAndStatInfo(lldb::pid_t pid, char *next_arg = cmd + strlen(cmd) + 1; end_buf = cmd + buf_sp->GetByteSize(); while (next_arg < end_buf && 0 != *next_arg) { - info_args.AppendArgument(next_arg); + info_args.AppendArgument(llvm::StringRef(next_arg)); next_arg += strlen(next_arg) + 1; } } diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index 9fbea89cb9e..e4a6ebe07f1 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -273,7 +273,7 @@ Error Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) { if (!str_sp) continue; - launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str()); + launch_info.GetArguments().AppendArgument(str_sp->GetValue()); } } 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)); diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp index 239ac578321..9650fb4028c 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp @@ -137,7 +137,7 @@ Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) { if (error.Fail()) return error; - args.ReplaceArgumentAtIndex(0, connect_url.c_str()); + args.ReplaceArgumentAtIndex(0, connect_url); Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); if (log) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index d554ba8b768..f9ff4983598 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1886,7 +1886,7 @@ PlatformDarwin::LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) { // we get os_log and NSLog messages mirrored to the target process // stderr. if (!env_vars.ContainsEnvironmentVariable("OS_ACTIVITY_DT_MODE")) - env_vars.AppendArgument("OS_ACTIVITY_DT_MODE=enable"); + env_vars.AppendArgument(llvm::StringRef("OS_ACTIVITY_DT_MODE=enable")); } // Let our parent class do the real launching. diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp index dfb60e1ddc9..e609cb96456 100644 --- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp +++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp @@ -305,8 +305,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, std::string encoding_str; if (reg_info_dict->GetValueForKeyAsString("encoding", encoding_str)) - reg_info.encoding = - Args::StringToEncoding(encoding_str.c_str(), eEncodingUint); + reg_info.encoding = Args::StringToEncoding(encoding_str, eEncodingUint); else reg_info_dict->GetValueForKeyAsInteger("encoding", reg_info.encoding, eEncodingUint); @@ -337,7 +336,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, std::string generic_str; if (reg_info_dict->GetValueForKeyAsString("generic", generic_str)) reg_info.kinds[lldb::eRegisterKindGeneric] = - Args::StringToGenericRegister(generic_str.c_str()); + Args::StringToGenericRegister(generic_str); else reg_info_dict->GetValueForKeyAsInteger( "generic", reg_info.kinds[lldb::eRegisterKindGeneric], diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index ef3e75bbf09..14c64f2e514 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -1067,31 +1067,31 @@ Error GDBRemoteCommunication::StartDebugserverProcess( char arg_cstr[PATH_MAX]; // Start args with "debugserver /file/path -r --" - debugserver_args.AppendArgument(debugserver_path); + debugserver_args.AppendArgument(llvm::StringRef(debugserver_path)); #if !defined(__APPLE__) // First argument to lldb-server must be mode in which to run. - debugserver_args.AppendArgument("gdbserver"); + debugserver_args.AppendArgument(llvm::StringRef("gdbserver")); #endif // If a url is supplied then use it if (url) - debugserver_args.AppendArgument(url); + debugserver_args.AppendArgument(llvm::StringRef(url)); if (pass_comm_fd >= 0) { StreamString fd_arg; fd_arg.Printf("--fd=%i", pass_comm_fd); - debugserver_args.AppendArgument(fd_arg.GetData()); + debugserver_args.AppendArgument(fd_arg.GetString()); // Send "pass_comm_fd" down to the inferior so it can use it to // communicate back with this process launch_info.AppendDuplicateFileAction(pass_comm_fd, pass_comm_fd); } // use native registers, not the GDB registers - debugserver_args.AppendArgument("--native-regs"); + debugserver_args.AppendArgument(llvm::StringRef("--native-regs")); if (launch_info.GetLaunchInSeparateProcessGroup()) { - debugserver_args.AppendArgument("--setsid"); + debugserver_args.AppendArgument(llvm::StringRef("--setsid")); } llvm::SmallString<PATH_MAX> named_pipe_path; @@ -1137,8 +1137,8 @@ Error GDBRemoteCommunication::StartDebugserverProcess( return error; } int write_fd = socket_pipe.GetWriteFileDescriptor(); - debugserver_args.AppendArgument("--pipe"); - debugserver_args.AppendArgument(llvm::to_string(write_fd).c_str()); + debugserver_args.AppendArgument(llvm::StringRef("--pipe")); + debugserver_args.AppendArgument(llvm::to_string(write_fd)); launch_info.AppendCloseFileAction(socket_pipe.GetReadFileDescriptor()); #endif } else { @@ -1164,8 +1164,8 @@ Error GDBRemoteCommunication::StartDebugserverProcess( // Send the host and port down that debugserver and specify an option // so that it connects back to the port we are listening to in this // process - debugserver_args.AppendArgument("--reverse-connect"); - debugserver_args.AppendArgument(port_cstr); + debugserver_args.AppendArgument(llvm::StringRef("--reverse-connect")); + debugserver_args.AppendArgument(llvm::StringRef(port_cstr)); if (port) *port = port_; } else { @@ -1182,7 +1182,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( if (env_debugserver_log_file) { ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-file=%s", env_debugserver_log_file); - debugserver_args.AppendArgument(arg_cstr); + debugserver_args.AppendArgument(llvm::StringRef(arg_cstr)); } #if defined(__APPLE__) @@ -1199,7 +1199,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( if (env_debugserver_log_channels) { ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-channels=%s", env_debugserver_log_channels); - debugserver_args.AppendArgument(arg_cstr); + debugserver_args.AppendArgument(llvm::StringRef(arg_cstr)); } #endif @@ -1215,7 +1215,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( has_env_var = extra_arg != nullptr; if (has_env_var) { - debugserver_args.AppendArgument(extra_arg); + debugserver_args.AppendArgument(llvm::StringRef(extra_arg)); if (log) log->Printf("GDBRemoteCommunication::%s adding env var %s contents " "to stub command line (%s)", @@ -1224,7 +1224,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( } while (has_env_var); if (inferior_args && inferior_args->GetArgumentCount() > 0) { - debugserver_args.AppendArgument("--"); + debugserver_args.AppendArgument(llvm::StringRef("--")); debugserver_args.AppendArguments(*inferior_args); } @@ -1232,7 +1232,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( StringList env; if (Host::GetEnvironment(env)) { for (size_t i = 0; i < env.GetSize(); ++i) - launch_info.GetEnvironmentEntries().AppendArgument(env[i].c_str()); + launch_info.GetEnvironmentEntries().AppendArgument(env[i]); } // Close STDIN, STDOUT and STDERR. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index 0d7ca3c53e4..9dfb47d1a76 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -946,7 +946,8 @@ GDBRemoteCommunicationServerCommon::Handle_QEnvironment( packet.SetFilePos(::strlen("QEnvironment:")); const uint32_t bytes_left = packet.GetBytesLeft(); if (bytes_left > 0) { - m_process_launch_info.GetEnvironmentEntries().AppendArgument(packet.Peek()); + m_process_launch_info.GetEnvironmentEntries().AppendArgument( + llvm::StringRef::withNullAsEmpty(packet.Peek())); return SendOKResponse(); } return SendErrorResponse(12); @@ -960,7 +961,7 @@ GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded( if (bytes_left > 0) { std::string str; packet.GetHexByteString(str); - m_process_launch_info.GetEnvironmentEntries().AppendArgument(str.c_str()); + m_process_launch_info.GetEnvironmentEntries().AppendArgument(str); return SendOKResponse(); } return SendErrorResponse(12); @@ -1032,8 +1033,7 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) { if (arg_idx == 0) m_process_launch_info.GetExecutableFile().SetFile(arg.c_str(), false); - m_process_launch_info.GetArguments().AppendArgument( - arg.c_str()); + m_process_launch_info.GetArguments().AppendArgument(arg); if (log) log->Printf("LLGSPacketHandler::%s added arg %d: \"%s\"", __FUNCTION__, actual_arg_index, arg.c_str()); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 504aa4f29e2..4230601d993 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -4158,8 +4158,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info, alt_name.SetString(value); } else if (name == "encoding") { encoding_set = true; - reg_info.encoding = - Args::StringToEncoding(value.data(), eEncodingUint); + reg_info.encoding = Args::StringToEncoding(value, eEncodingUint); } else if (name == "format") { format_set = true; Format format = eFormatInvalid; @@ -4198,7 +4197,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info, StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); } else if (name == "generic") { reg_info.kinds[eRegisterKindGeneric] = - Args::StringToGenericRegister(value.data()); + Args::StringToGenericRegister(value); } else if (name == "value_regnums") { SplitCommaSeparatedRegisterNumberString(value, value_regs, 0); } else if (name == "invalidate_regnums") { diff --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp index a7fffdbeeba..6d940e84b4f 100644 --- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -429,6 +429,7 @@ public: Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 'a': m_include_any_process = true; @@ -442,7 +443,7 @@ public: break; case 'b': - m_broadcast_events = Args::StringToBoolean(option_arg, true, nullptr); + m_broadcast_events = Args::StringToBoolean(option_strref, true, nullptr); break; case 'c': @@ -458,7 +459,7 @@ public: break; case 'e': - m_echo_to_stderr = Args::StringToBoolean(option_arg, false, nullptr); + m_echo_to_stderr = Args::StringToBoolean(option_strref, false, nullptr); break; case 'f': @@ -469,12 +470,12 @@ public: break; case 'l': - m_live_stream = Args::StringToBoolean(option_arg, false, nullptr); + m_live_stream = Args::StringToBoolean(option_strref, false, nullptr); break; case 'n': m_filter_fall_through_accepts = - Args::StringToBoolean(option_arg, true, nullptr); + Args::StringToBoolean(option_strref, true, nullptr); break; case 'r': diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index f370676e73a..7837881fb82 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -416,6 +416,7 @@ Error ProcessLaunchCommandOptions::SetOptionValue( ExecutionContext *execution_context) { Error error; const int short_option = m_getopt_table[option_idx].val; + auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); switch (short_option) { case 's': // Stop at program entry point @@ -484,7 +485,7 @@ Error ProcessLaunchCommandOptions::SetOptionValue( { bool success; const bool disable_aslr_arg = - Args::StringToBoolean(option_arg, true, &success); + Args::StringToBoolean(option_strref, true, &success); if (success) disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo; else @@ -497,7 +498,8 @@ Error ProcessLaunchCommandOptions::SetOptionValue( case 'X': // shell expand args. { bool success; - const bool expand_args = Args::StringToBoolean(option_arg, true, &success); + const bool expand_args = + Args::StringToBoolean(option_strref, true, &success); if (success) launch_info.SetShellExpandArguments(expand_args); else @@ -515,7 +517,8 @@ Error ProcessLaunchCommandOptions::SetOptionValue( break; case 'v': - launch_info.GetEnvironmentEntries().AppendArgument(option_arg); + launch_info.GetEnvironmentEntries().AppendArgument( + llvm::StringRef::withNullAsEmpty(option_arg)); break; default: diff --git a/lldb/source/Target/ProcessInfo.cpp b/lldb/source/Target/ProcessInfo.cpp index be537c1b313..4b02332f4d9 100644 --- a/lldb/source/Target/ProcessInfo.cpp +++ b/lldb/source/Target/ProcessInfo.cpp @@ -18,6 +18,8 @@ #include "lldb/Core/Stream.h" #include "lldb/Host/PosixApi.h" +#include "llvm/ADT/SmallString.h" + using namespace lldb; using namespace lldb_private; @@ -66,8 +68,9 @@ void ProcessInfo::SetExecutableFile(const FileSpec &exe_file, if (exe_file) { m_executable = exe_file; if (add_exe_file_as_first_arg) { - char filename[PATH_MAX]; - if (exe_file.GetPath(filename, sizeof(filename))) + llvm::SmallString<PATH_MAX> filename; + exe_file.GetPath(filename); + if (!filename.empty()) m_arguments.InsertArgumentAtIndex(0, filename); } } else { diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp index 2f9e95ecc7b..e29c9bcc11b 100644 --- a/lldb/source/Target/ProcessLaunchInfo.cpp +++ b/lldb/source/Target/ProcessLaunchInfo.cpp @@ -344,13 +344,13 @@ bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell( return false; Args shell_arguments; std::string safe_arg; - shell_arguments.AppendArgument(shell_executable.c_str()); + shell_arguments.AppendArgument(shell_executable); const llvm::Triple &triple = GetArchitecture().GetTriple(); if (triple.getOS() == llvm::Triple::Win32 && !triple.isWindowsCygwinEnvironment()) - shell_arguments.AppendArgument("/C"); + shell_arguments.AppendArgument(llvm::StringRef("/C")); else - shell_arguments.AppendArgument("-c"); + shell_arguments.AppendArgument(llvm::StringRef("-c")); StreamString shell_command; if (will_debug) { @@ -428,7 +428,7 @@ bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell( shell_command.Printf(" %s", arg); } } - shell_arguments.AppendArgument(shell_command.GetString().c_str()); + shell_arguments.AppendArgument(shell_command.GetString()); m_executable = m_shell; m_arguments = shell_arguments; return true; |