[Lldb-commits] [lldb] r281919 - Fix more functions in Args to use StringRef.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 19 10:54:07 PDT 2016
Author: zturner
Date: Mon Sep 19 12:54:06 2016
New Revision: 281919
URL: http://llvm.org/viewvc/llvm-project?rev=281919&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/Interpreter/Args.h
lldb/trunk/source/API/SBPlatform.cpp
lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectLog.cpp
lldb/trunk/source/Commands/CommandObjectMemory.cpp
lldb/trunk/source/Commands/CommandObjectMultiword.cpp
lldb/trunk/source/Commands/CommandObjectPlatform.cpp
lldb/trunk/source/Commands/CommandObjectProcess.cpp
lldb/trunk/source/Commands/CommandObjectThread.cpp
lldb/trunk/source/Commands/CommandObjectType.cpp
lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
lldb/trunk/source/Host/linux/Host.cpp
lldb/trunk/source/Host/windows/Host.cpp
lldb/trunk/source/Interpreter/Args.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Interpreter/CommandObject.cpp
lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
lldb/trunk/source/Interpreter/OptionValueDictionary.cpp
lldb/trunk/source/Interpreter/Property.cpp
lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
lldb/trunk/source/Target/Process.cpp
lldb/trunk/source/Target/ProcessInfo.cpp
lldb/trunk/source/Target/ProcessLaunchInfo.cpp
lldb/trunk/unittests/Interpreter/TestArgs.cpp
Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Mon Sep 19 12:54:06 2016
@@ -179,13 +179,53 @@ public:
/// @return
/// The NULL terminated C string of the copy of \a arg_cstr.
//------------------------------------------------------------------
- // TODO: Convert this function to use a StringRef.
- const char *AppendArgument(const char *arg_cstr, char quote_char = '\0');
+ llvm::StringRef AppendArgument(llvm::StringRef arg_str,
+ char quote_char = '\0');
void AppendArguments(const Args &rhs);
void AppendArguments(const char **argv);
+ // Delete const char* versions of StringRef functions. Normally this would
+ // not
+ // be necessary, as const char * is implicitly convertible to StringRef.
+ // However,
+ // since the use of const char* is so pervasive, and since StringRef will
+ // assert
+ // if you try to construct one from nullptr, this allows the compiler to catch
+ // instances of the function being invoked with a const char *, allowing us to
+ // replace them with explicit conversions at each call-site. Once StringRef
+ // use becomes more pervasive, there will be fewer implicit conversions
+ // because
+ // we will be using StringRefs across the whole pipeline, so we won't have to
+ // have
+ // this "glue" that converts between the two, and at that point it becomes
+ // easy
+ // to just make sure you don't pass nullptr into the function.
+ // Call-site fixing methodology:
+ // 1. If you know the string cannot be null (e.g. it's a const char[], or
+ // it's
+ // been checked for null), use llvm::StringRef(ptr).
+ // 2. If you don't know if it can be null (e.g. it's returned from a
+ // function
+ // whose semantics are unclear), use
+ // llvm::StringRef::withNullAsEmpty(ptr).
+ // 3. If it's .c_str() of a std::string, just pass the std::string directly.
+ // 4. If it's .str().c_str() of a StringRef, just pass the StringRef
+ // directly.
+ void ReplaceArgumentAtIndex(size_t, const char *, char = '\0') = delete;
+ void AppendArgument(const char *arg_str, char quote_char = '\0') = delete;
+ void InsertArgumentAtIndex(size_t, const char *, char = '\0') = delete;
+ static bool StringToBoolean(const char *, bool, bool *) = delete;
+ static lldb::ScriptLanguage
+ StringToScriptLanguage(const char *, lldb::ScriptLanguage, bool *) = delete;
+ static lldb::Encoding
+ StringToEncoding(const char *,
+ lldb::Encoding = lldb::eEncodingInvalid) = delete;
+ static uint32_t StringToGenericRegister(const char *) = delete;
+ static bool StringToVersion(const char *, uint32_t &, uint32_t &,
+ uint32_t &) = delete;
+
//------------------------------------------------------------------
/// Insert the argument value at index \a idx to \a arg_cstr.
///
@@ -201,8 +241,8 @@ public:
/// @return
/// The NULL terminated C string of the copy of \a arg_cstr.
//------------------------------------------------------------------
- const char *InsertArgumentAtIndex(size_t idx, const char *arg_cstr,
- char quote_char = '\0');
+ llvm::StringRef InsertArgumentAtIndex(size_t idx, llvm::StringRef arg_str,
+ char quote_char = '\0');
//------------------------------------------------------------------
/// Replaces the argument value at index \a idx to \a arg_cstr
@@ -221,8 +261,8 @@ public:
/// The NULL terminated C string of the copy of \a arg_cstr if
/// \a idx was a valid index, NULL otherwise.
//------------------------------------------------------------------
- const char *ReplaceArgumentAtIndex(size_t idx, const char *arg_cstr,
- char quote_char = '\0');
+ llvm::StringRef ReplaceArgumentAtIndex(size_t idx, llvm::StringRef arg_str,
+ char quote_char = '\0');
//------------------------------------------------------------------
/// Deletes the argument value at index
@@ -359,9 +399,6 @@ public:
const char *s, lldb::addr_t fail_value,
Error *error);
- static bool StringToBoolean(const char *s, bool fail_value,
- bool *success_ptr);
-
static bool StringToBoolean(llvm::StringRef s, bool fail_value,
bool *success_ptr);
@@ -383,15 +420,9 @@ public:
// the format character
static lldb::Encoding
- StringToEncoding(const char *s,
- lldb::Encoding fail_value = lldb::eEncodingInvalid);
-
- static lldb::Encoding
StringToEncoding(llvm::StringRef s,
lldb::Encoding fail_value = lldb::eEncodingInvalid);
- static uint32_t StringToGenericRegister(const char *s);
-
static uint32_t StringToGenericRegister(llvm::StringRef s);
static bool StringToVersion(llvm::StringRef string, uint32_t &major,
Modified: lldb/trunk/source/API/SBPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBPlatform.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/API/SBPlatform.cpp (original)
+++ lldb/trunk/source/API/SBPlatform.cpp Mon Sep 19 12:54:06 2016
@@ -251,7 +251,8 @@ SBError SBPlatform::ConnectRemote(SBPlat
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");
Modified: lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointIDList.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointIDList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointIDList.cpp Mon Sep 19 12:54:06 2016
@@ -215,7 +215,7 @@ void BreakpointIDList::FindAndReplaceIDR
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::FindAndReplaceIDR
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::FindAndReplaceIDR
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::FindAndReplaceIDR
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());
}
}
}
Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Mon Sep 19 12:54:06 2016
@@ -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;
Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Mon Sep 19 12:54:06 2016
@@ -268,6 +268,7 @@ are no syntax errors may indicate that a
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
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);
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Mon Sep 19 12:54:06 2016
@@ -78,6 +78,7 @@ Error CommandObjectExpression::CommandOp
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::CommandOp
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::CommandOp
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::CommandOp
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::CommandOp
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::CommandOp
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
Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectLog.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectLog.cpp Mon Sep 19 12:54:06 2016
@@ -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);
Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Mon Sep 19 12:54:06 2016
@@ -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);
Modified: lldb/trunk/source/Commands/CommandObjectMultiword.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMultiword.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMultiword.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMultiword.cpp Mon Sep 19 12:54:06 2016
@@ -210,7 +210,7 @@ int CommandObjectMultiword::HandleComple
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);
Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Mon Sep 19 12:54:06 2016
@@ -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();
}
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Mon Sep 19 12:54:06 2016
@@ -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;
Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Mon Sep 19 12:54:06 2016
@@ -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 {
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Mon Sep 19 12:54:06 2016
@@ -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::Comma
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);
Modified: lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp Mon Sep 19 12:54:06 2016
@@ -318,7 +318,8 @@ are no syntax errors may indicate that a
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);
Modified: lldb/trunk/source/Host/linux/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/Host.cpp (original)
+++ lldb/trunk/source/Host/linux/Host.cpp Mon Sep 19 12:54:06 2016
@@ -323,7 +323,7 @@ static bool GetProcessAndStatInfo(lldb::
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::
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;
}
}
Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Mon Sep 19 12:54:06 2016
@@ -273,7 +273,7 @@ Error Host::ShellExpandArguments(Process
if (!str_sp)
continue;
- launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str());
+ launch_info.GetArguments().AppendArgument(str_sp->GetValue());
}
}
Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Mon Sep 19 12:54:06 2016
@@ -362,23 +362,23 @@ const char *Args::Unshift(const char *ar
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(
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(
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
--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::strin
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
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(ll
.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::AddOrReplaceEnvironmentVariab
// 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 &op
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 &op
if (pos != std::string::npos)
raw_input_string.erase(pos, strlen(tmp_arg));
}
- ReplaceArgumentAtIndex(idx + 1, "");
+ ReplaceArgumentAtIndex(idx + 1, llvm::StringRef());
}
}
}
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Sep 19 12:54:06 2016
@@ -1760,7 +1760,7 @@ int CommandInterpreter::HandleCompletion
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::BuildAliasComma
// 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::BuildAliasComma
}
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::BuildAliasComma
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();
Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Mon Sep 19 12:54:06 2016
@@ -300,10 +300,9 @@ int CommandObject::HandleCompletion(Args
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
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)) {
Modified: lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp Mon Sep 19 12:54:06 2016
@@ -85,6 +85,8 @@ Error OptionGroupValueObjectDisplay::Set
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::Set
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;
Modified: lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueBoolean.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueBoolean.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueBoolean.cpp Mon Sep 19 12:54:06 2016
@@ -1,5 +1,4 @@
-//===-- OptionValueBoolean.cpp ------------------------------------*- C++
-//-*-===//
+//===-- OptionValueBoolean.cpp ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -48,8 +47,7 @@ Error OptionValueBoolean::SetValueFromSt
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;
Modified: lldb/trunk/source/Interpreter/OptionValueDictionary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueDictionary.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueDictionary.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueDictionary.cpp Mon Sep 19 12:54:06 2016
@@ -85,7 +85,7 @@ size_t OptionValueDictionary::GetArgs(Ar
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();
}
Modified: lldb/trunk/source/Interpreter/Property.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Property.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Property.cpp (original)
+++ lldb/trunk/source/Interpreter/Property.cpp Mon Sep 19 12:54:06 2016
@@ -54,7 +54,7 @@ Property::Property(const PropertyDefinit
// 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));
Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp Mon Sep 19 12:54:06 2016
@@ -137,7 +137,7 @@ Error PlatformAndroidRemoteGDBServer::Co
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)
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Sep 19 12:54:06 2016
@@ -1886,7 +1886,7 @@ PlatformDarwin::LaunchProcess(lldb_priva
// 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.
Modified: lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp Mon Sep 19 12:54:06 2016
@@ -305,8 +305,7 @@ DynamicRegisterInfo::SetRegisterInfo(con
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(con
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],
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Mon Sep 19 12:54:06 2016
@@ -1067,31 +1067,31 @@ Error GDBRemoteCommunication::StartDebug
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::StartDebug
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::StartDebug
// 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::StartDebug
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::StartDebug
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::StartDebug
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::StartDebug
} 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::StartDebug
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.
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Mon Sep 19 12:54:06 2016
@@ -946,7 +946,8 @@ GDBRemoteCommunicationServerCommon::Hand
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::Hand
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::Hand
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());
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Mon Sep 19 12:54:06 2016
@@ -4158,8 +4158,7 @@ bool ParseRegisters(XMLNode feature_node
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
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") {
Modified: lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp (original)
+++ lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp Mon Sep 19 12:54:06 2016
@@ -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':
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Sep 19 12:54:06 2016
@@ -416,6 +416,7 @@ Error ProcessLaunchCommandOptions::SetOp
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::SetOp
{
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::SetOp
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::SetOp
break;
case 'v':
- launch_info.GetEnvironmentEntries().AppendArgument(option_arg);
+ launch_info.GetEnvironmentEntries().AppendArgument(
+ llvm::StringRef::withNullAsEmpty(option_arg));
break;
default:
Modified: lldb/trunk/source/Target/ProcessInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ProcessInfo.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Target/ProcessInfo.cpp (original)
+++ lldb/trunk/source/Target/ProcessInfo.cpp Mon Sep 19 12:54:06 2016
@@ -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(cons
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 {
Modified: lldb/trunk/source/Target/ProcessLaunchInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ProcessLaunchInfo.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/source/Target/ProcessLaunchInfo.cpp (original)
+++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp Mon Sep 19 12:54:06 2016
@@ -344,13 +344,13 @@ bool ProcessLaunchInfo::ConvertArguments
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::ConvertArguments
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;
Modified: lldb/trunk/unittests/Interpreter/TestArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestArgs.cpp?rev=281919&r1=281918&r2=281919&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestArgs.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestArgs.cpp Mon Sep 19 12:54:06 2016
@@ -57,7 +57,7 @@ TEST(ArgsTest, TestAppendArg) {
Args args;
args.SetCommandString("first_arg");
EXPECT_EQ(1u, args.GetArgumentCount());
- args.AppendArgument("second_arg");
+ args.AppendArgument(llvm::StringRef("second_arg"));
EXPECT_EQ(2u, args.GetArgumentCount());
EXPECT_STREQ(args.GetArgumentAtIndex(0), "first_arg");
EXPECT_STREQ(args.GetArgumentAtIndex(1), "second_arg");
More information about the lldb-commits
mailing list