Skip to content
Permalink
Browse files

[lldb][NFC] Remove ArgEntry::ref member

The StringRef should always be identical to the C string, so we
might as well just create the StringRef from the C-string. This
might be slightly slower until we implement the storage of ArgEntry
with a string instead of a std::unique_ptr<char[]>. Until then we
have to do the additional strlen on the C string to construct the
StringRef.

llvm-svn: 371842
  • Loading branch information
Teemperor committed Sep 13, 2019
1 parent 930ebc1 commit 0d9a201e2624998922f825ebbe01aae0cce4bbd5
Showing with 120 additions and 121 deletions.
  1. +1 −1 lldb/include/lldb/Utility/Args.h
  2. +5 −5 lldb/source/Breakpoint/BreakpointIDList.cpp
  3. +2 −2 lldb/source/Commands/CommandObjectApropos.cpp
  4. +1 −1 lldb/source/Commands/CommandObjectBreakpoint.cpp
  5. +11 −11 lldb/source/Commands/CommandObjectCommands.cpp
  6. +3 −3 lldb/source/Commands/CommandObjectFrame.cpp
  7. +3 −3 lldb/source/Commands/CommandObjectHelp.cpp
  8. +6 −6 lldb/source/Commands/CommandObjectLog.cpp
  9. +17 −17 lldb/source/Commands/CommandObjectMemory.cpp
  10. +3 −3 lldb/source/Commands/CommandObjectMultiword.cpp
  11. +2 −2 lldb/source/Commands/CommandObjectPlatform.cpp
  12. +1 −1 lldb/source/Commands/CommandObjectPlugin.cpp
  13. +3 −3 lldb/source/Commands/CommandObjectProcess.cpp
  14. +3 −3 lldb/source/Commands/CommandObjectRegister.cpp
  15. +2 −2 lldb/source/Commands/CommandObjectSettings.cpp
  16. +1 −1 lldb/source/Commands/CommandObjectSource.cpp
  17. +8 −8 lldb/source/Commands/CommandObjectTarget.cpp
  18. +1 −1 lldb/source/Commands/CommandObjectThread.cpp
  19. +17 −17 lldb/source/Commands/CommandObjectType.cpp
  20. +3 −3 lldb/source/Commands/CommandObjectWatchpoint.cpp
  21. +2 −2 lldb/source/Interpreter/CommandAlias.cpp
  22. +1 −1 lldb/source/Interpreter/CommandInterpreter.cpp
  23. +1 −1 lldb/source/Interpreter/CommandObject.cpp
  24. +3 −3 lldb/source/Interpreter/OptionValueDictionary.cpp
  25. +7 −7 lldb/source/Interpreter/Options.cpp
  26. +4 −4 lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  27. +6 −7 lldb/source/Utility/Args.cpp
  28. +3 −3 lldb/unittests/Utility/ArgsTest.cpp
@@ -43,7 +43,7 @@ class Args {
ArgEntry() = default;
ArgEntry(llvm::StringRef str, char quote);

llvm::StringRef ref;
llvm::StringRef ref() const { return c_str(); }
const char *c_str() const { return ptr.get(); }

/// Returns true if this argument was quoted in any way.
@@ -122,7 +122,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target,
for (size_t i = 0; i < old_args.size(); ++i) {
bool is_range = false;

current_arg = old_args[i].ref;
current_arg = old_args[i].ref();
if (!allow_locations && current_arg.contains('.')) {
result.AppendErrorWithFormat(
"Breakpoint locations not allowed, saw location: %s.",
@@ -146,16 +146,16 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target,
} else
names_found.insert(current_arg);
} else if ((i + 2 < old_args.size()) &&
BreakpointID::IsRangeIdentifier(old_args[i + 1].ref) &&
BreakpointID::IsRangeIdentifier(old_args[i + 1].ref()) &&
BreakpointID::IsValidIDExpression(current_arg) &&
BreakpointID::IsValidIDExpression(old_args[i + 2].ref)) {
BreakpointID::IsValidIDExpression(old_args[i + 2].ref())) {
range_from = current_arg;
range_to = old_args[i + 2].ref;
range_to = old_args[i + 2].ref();
is_range = true;
i = i + 2;
} else {
// See if user has specified id.*
llvm::StringRef tmp_str = old_args[i].ref;
llvm::StringRef tmp_str = old_args[i].ref();
size_t pos = tmp_str.find('.');
if (pos != llvm::StringRef::npos) {
llvm::StringRef bp_id_str = tmp_str.substr(0, pos);
@@ -44,7 +44,7 @@ bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
const size_t argc = args.GetArgumentCount();

if (argc == 1) {
auto search_word = args[0].ref;
auto search_word = args[0].ref();
if (!search_word.empty()) {
// The bulk of the work must be done inside the Command Interpreter,
// since the command dictionary is private.
@@ -79,7 +79,7 @@ bool CommandObjectApropos::DoExecute(Args &args, CommandReturnObject &result) {
const bool dump_qualified_name = true;
result.AppendMessageWithFormatv(
"\nThe following settings variables may relate to '{0}': \n\n",
args[0].ref);
args[0].ref());
for (size_t i = 0; i < num_properties; ++i)
properties[i]->DumpDescription(
m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
@@ -1707,7 +1707,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
// Make a pass through first to see that all the names are legal.
for (auto &entry : command.entries()) {
Status error;
if (!BreakpointID::StringIsBreakpointName(entry.ref, error))
if (!BreakpointID::StringIsBreakpointName(entry.ref(), error))
{
result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s",
entry.c_str(), error.AsCString());
@@ -283,7 +283,7 @@ class CommandObjectCommandsSource : public CommandObjectParsed {
return false;
}

FileSpec cmd_file(command[0].ref);
FileSpec cmd_file(command[0].ref());
FileSystem::Instance().Resolve(cmd_file);
ExecutionContext *exe_ctx = nullptr; // Just use the default context.

@@ -546,7 +546,7 @@ rather than using a positional placeholder:"

// Get the alias command.

auto alias_command = args[0].ref;
auto alias_command = args[0].ref();
if (alias_command.startswith("-")) {
result.AppendError("aliases starting with a dash are not supported");
if (alias_command == "--help" || alias_command == "--long-help") {
@@ -653,8 +653,8 @@ rather than using a positional placeholder:"
}

// Save these in std::strings since we're going to shift them off.
const std::string alias_command(args[0].ref);
const std::string actual_command(args[1].ref);
const std::string alias_command(args[0].ref());
const std::string actual_command(args[1].ref());

args.Shift(); // Shift the alias command word off the argument vector.
args.Shift(); // Shift the old command word off the argument vector.
@@ -686,7 +686,7 @@ rather than using a positional placeholder:"
OptionArgVectorSP(new OptionArgVector);

while (cmd_obj->IsMultiwordObject() && !args.empty()) {
auto sub_command = args[0].ref;
auto sub_command = args[0].ref();
assert(!sub_command.empty());
subcommand_obj_sp = cmd_obj->GetSubcommandSP(sub_command);
if (!subcommand_obj_sp) {
@@ -780,7 +780,7 @@ class CommandObjectCommandsUnalias : public CommandObjectParsed {
return false;
}

auto command_name = args[0].ref;
auto command_name = args[0].ref();
cmd_obj = m_interpreter.GetCommandObject(command_name);
if (!cmd_obj) {
result.AppendErrorWithFormat(
@@ -862,7 +862,7 @@ class CommandObjectCommandsDelete : public CommandObjectParsed {
return false;
}

auto command_name = args[0].ref;
auto command_name = args[0].ref();
if (!m_interpreter.CommandExists(command_name)) {
StreamString error_msg_stream;
const bool generate_upropos = true;
@@ -988,7 +988,7 @@ a number follows 'f':"
}

Status error;
auto name = command[0].ref;
auto name = command[0].ref();
m_regex_cmd_up = std::make_unique<CommandObjectRegexCommand>(
m_interpreter, name, m_options.GetHelp(), m_options.GetSyntax(), 10, 0,
true);
@@ -1013,7 +1013,7 @@ a number follows 'f':"
} else {
for (auto &entry : command.entries().drop_front()) {
bool check_only = false;
error = AppendRegexSubstitution(entry.ref, check_only);
error = AppendRegexSubstitution(entry.ref(), check_only);
if (error.Fail())
break;
}
@@ -1656,7 +1656,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
}

// Store the options in case we get multi-line input
m_cmd_name = command[0].ref;
m_cmd_name = command[0].ref();
m_short_help.assign(m_options.m_short_help);
m_synchronicity = m_options.m_synchronicity;

@@ -1798,7 +1798,7 @@ class CommandObjectCommandsScriptDelete : public CommandObjectParsed {
return false;
}

auto cmd_name = command[0].ref;
auto cmd_name = command[0].ref();

if (cmd_name.empty() || !m_interpreter.HasUserCommands() ||
!m_interpreter.UserCommandExists(cmd_name)) {
@@ -358,7 +358,7 @@ class CommandObjectFrameSelect : public CommandObjectParsed {
}

if (command.GetArgumentCount() == 1) {
if (command[0].ref.getAsInteger(0, frame_idx)) {
if (command[0].ref().getAsInteger(0, frame_idx)) {
result.AppendErrorWithFormat("invalid frame index argument '%s'.",
command[0].c_str());
result.SetStatus(eReturnStatusFailed);
@@ -527,7 +527,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
for (auto &entry : command) {
if (m_option_variable.use_regex) {
const size_t regex_start_index = regex_var_list.GetSize();
llvm::StringRef name_str = entry.ref;
llvm::StringRef name_str = entry.ref();
RegularExpression regex(name_str);
if (regex.IsValid()) {
size_t num_matches = 0;
@@ -586,7 +586,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
StackFrame::eExpressionPathOptionsInspectAnonymousUnions;
lldb::VariableSP var_sp;
valobj_sp = frame->GetValueForVariableExpressionPath(
entry.ref, m_varobj_options.use_dynamic, expr_path_options,
entry.ref(), m_varobj_options.use_dynamic, expr_path_options,
var_sp, error);
if (valobj_sp) {
std::string scope_string;
@@ -96,7 +96,7 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
// Get command object for the first command argument. Only search built-in
// command dictionary.
StringList matches;
auto command_name = command[0].ref;
auto command_name = command[0].ref();
cmd_obj = m_interpreter.GetCommandObject(command_name, &matches);

if (cmd_obj != nullptr) {
@@ -107,7 +107,7 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
// object that corresponds to the help command entered.
std::string sub_command;
for (auto &entry : command.entries().drop_front()) {
sub_command = entry.ref;
sub_command = entry.ref();
matches.Clear();
if (sub_cmd_obj->IsAlias())
sub_cmd_obj =
@@ -208,7 +208,7 @@ void CommandObjectHelp::HandleCompletion(CompletionRequest &request) {
return;
}
CommandObject *cmd_obj =
m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref);
m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref());

// The command that they are getting help on might be ambiguous, in which
// case we should complete that, otherwise complete with the command the
@@ -145,7 +145,7 @@ class CommandObjectLogEnable : public CommandObjectParsed {
}

// Store into a std::string since we're about to shift the channel off.
const std::string channel = args[0].ref;
const std::string channel = args[0].ref();
args.Shift(); // Shift off the channel
char log_file[PATH_MAX];
if (m_options.log_file)
@@ -212,7 +212,7 @@ class CommandObjectLogDisable : public CommandObjectParsed {
return false;
}

const std::string channel = args[0].ref;
const std::string channel = args[0].ref();
args.Shift(); // Shift off the channel
if (channel == "all") {
Log::DisableAllLogChannels();
@@ -265,7 +265,7 @@ class CommandObjectLogList : public CommandObjectParsed {
bool success = true;
for (const auto &entry : args.entries())
success =
success && Log::ListChannelCategories(entry.ref, output_stream);
success && Log::ListChannelCategories(entry.ref(), output_stream);
if (success)
result.SetStatus(eReturnStatusSuccessFinishResult);
}
@@ -291,7 +291,7 @@ class CommandObjectLogTimer : public CommandObjectParsed {
result.SetStatus(eReturnStatusFailed);

if (args.GetArgumentCount() == 1) {
auto sub_command = args[0].ref;
auto sub_command = args[0].ref();

if (sub_command.equals_lower("enable")) {
Timer::SetDisplayDepth(UINT32_MAX);
@@ -308,8 +308,8 @@ class CommandObjectLogTimer : public CommandObjectParsed {
result.SetStatus(eReturnStatusSuccessFinishResult);
}
} else if (args.GetArgumentCount() == 2) {
auto sub_command = args[0].ref;
auto param = args[1].ref;
auto sub_command = args[0].ref();
auto param = args[1].ref();

if (sub_command.equals_lower("enable")) {
uint32_t depth;
@@ -593,7 +593,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
}

if (argc > 0)
addr = OptionArgParser::ToAddress(&m_exe_ctx, command[0].ref,
addr = OptionArgParser::ToAddress(&m_exe_ctx, command[0].ref(),
LLDB_INVALID_ADDRESS, &error);

if (addr == LLDB_INVALID_ADDRESS) {
@@ -605,7 +605,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {

if (argc == 2) {
lldb::addr_t end_addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[1].ref, LLDB_INVALID_ADDRESS, nullptr);
&m_exe_ctx, command[1].ref(), LLDB_INVALID_ADDRESS, nullptr);
if (end_addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid end address expression.");
result.AppendError(error.AsCString());
@@ -1034,13 +1034,13 @@ class CommandObjectMemoryFind : public CommandObjectParsed {

Status error;
lldb::addr_t low_addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);
if (low_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
result.AppendError("invalid low address");
return false;
}
lldb::addr_t high_addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[1].ref, LLDB_INVALID_ADDRESS, &error);
&m_exe_ctx, command[1].ref(), LLDB_INVALID_ADDRESS, &error);
if (high_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
result.AppendError("invalid high address");
return false;
@@ -1339,7 +1339,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {

Status error;
lldb::addr_t addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);

if (addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid address expression\n");
@@ -1442,10 +1442,10 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
// Be careful, getAsInteger with a radix of 16 rejects "0xab" so we
// have to special case that:
bool success = false;
if (entry.ref.startswith("0x"))
success = !entry.ref.getAsInteger(0, uval64);
if (entry.ref().startswith("0x"))
success = !entry.ref().getAsInteger(0, uval64);
if (!success)
success = !entry.ref.getAsInteger(16, uval64);
success = !entry.ref().getAsInteger(16, uval64);
if (!success) {
result.AppendErrorWithFormat(
"'%s' is not a valid hex string value.\n", entry.c_str());
@@ -1463,7 +1463,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
break;
}
case eFormatBoolean:
uval64 = OptionArgParser::ToBoolean(entry.ref, false, &success);
uval64 = OptionArgParser::ToBoolean(entry.ref(), false, &success);
if (!success) {
result.AppendErrorWithFormat(
"'%s' is not a valid boolean string value.\n", entry.c_str());
@@ -1474,7 +1474,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
break;

case eFormatBinary:
if (entry.ref.getAsInteger(2, uval64)) {
if (entry.ref().getAsInteger(2, uval64)) {
result.AppendErrorWithFormat(
"'%s' is not a valid binary string value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
@@ -1493,10 +1493,10 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
case eFormatCharArray:
case eFormatChar:
case eFormatCString: {
if (entry.ref.empty())
if (entry.ref().empty())
break;

size_t len = entry.ref.size();
size_t len = entry.ref().size();
// Include the NULL for C strings...
if (m_format_options.GetFormat() == eFormatCString)
++len;
@@ -1513,7 +1513,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
break;
}
case eFormatDecimal:
if (entry.ref.getAsInteger(0, sval64)) {
if (entry.ref().getAsInteger(0, sval64)) {
result.AppendErrorWithFormat(
"'%s' is not a valid signed decimal value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
@@ -1531,7 +1531,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {

case eFormatUnsigned:

if (!entry.ref.getAsInteger(0, uval64)) {
if (!entry.ref().getAsInteger(0, uval64)) {
result.AppendErrorWithFormat(
"'%s' is not a valid unsigned decimal string value.\n",
entry.c_str());
@@ -1549,7 +1549,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
break;

case eFormatOctal:
if (entry.ref.getAsInteger(8, uval64)) {
if (entry.ref().getAsInteger(8, uval64)) {
result.AppendErrorWithFormat(
"'%s' is not a valid octal string value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
@@ -1635,7 +1635,7 @@ class CommandObjectMemoryHistory : public CommandObjectParsed {

Status error;
lldb::addr_t addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error);

if (addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid address expression");
@@ -1700,7 +1700,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
result.SetStatus(eReturnStatusFailed);
} else {
if (command.GetArgumentCount() == 1) {
auto load_addr_str = command[0].ref;
auto load_addr_str = command[0].ref();
load_addr = OptionArgParser::ToAddress(&m_exe_ctx, load_addr_str,
LLDB_INVALID_ADDRESS, &error);
if (error.Fail() || load_addr == LLDB_INVALID_ADDRESS) {

0 comments on commit 0d9a201

Please sign in to comment.
You can’t perform that action at this time.