forked from OSchip/llvm-project
Modernize the Args access pattern in a few more commands.
llvm-svn: 289164
This commit is contained in:
parent
86f0bdf832
commit
14f6b2c035
|
@ -193,7 +193,7 @@ public:
|
|||
|
||||
static const ArgumentTableEntry *GetArgumentTable();
|
||||
|
||||
static lldb::CommandArgumentType LookupArgumentName(const char *arg_name);
|
||||
static lldb::CommandArgumentType LookupArgumentName(llvm::StringRef arg_name);
|
||||
|
||||
static const ArgumentTableEntry *
|
||||
FindArgumentDataByType(lldb::CommandArgumentType arg_type);
|
||||
|
|
|
@ -108,11 +108,8 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
|
|||
// Get command object for the first command argument. Only search built-in
|
||||
// command dictionary.
|
||||
StringList matches;
|
||||
cmd_obj =
|
||||
m_interpreter.GetCommandObject(command.GetArgumentAtIndex(0), &matches);
|
||||
bool is_alias_command =
|
||||
m_interpreter.AliasExists(command.GetArgumentAtIndex(0));
|
||||
std::string alias_name = command.GetArgumentAtIndex(0);
|
||||
auto command_name = command[0].ref;
|
||||
cmd_obj = m_interpreter.GetCommandObject(command_name, &matches);
|
||||
|
||||
if (cmd_obj != nullptr) {
|
||||
StringList matches;
|
||||
|
@ -176,11 +173,11 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
|
|||
|
||||
sub_cmd_obj->GenerateHelpText(result);
|
||||
|
||||
if (is_alias_command) {
|
||||
if (m_interpreter.AliasExists(command_name)) {
|
||||
StreamString sstr;
|
||||
m_interpreter.GetAlias(alias_name)->GetAliasExpansion(sstr);
|
||||
m_interpreter.GetAlias(command_name)->GetAliasExpansion(sstr);
|
||||
result.GetOutputStream().Printf("\n'%s' is an abbreviation for %s\n",
|
||||
alias_name.c_str(), sstr.GetData());
|
||||
command[0].c_str(), sstr.GetData());
|
||||
}
|
||||
} else if (matches.GetSize() > 0) {
|
||||
Stream &output_strm = result.GetOutputStream();
|
||||
|
@ -194,16 +191,16 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
|
|||
// Maybe the user is asking for help about a command argument rather than
|
||||
// a command.
|
||||
const CommandArgumentType arg_type =
|
||||
CommandObject::LookupArgumentName(command.GetArgumentAtIndex(0));
|
||||
CommandObject::LookupArgumentName(command_name);
|
||||
if (arg_type != eArgTypeLastArg) {
|
||||
Stream &output_strm = result.GetOutputStream();
|
||||
CommandObject::GetArgumentHelp(output_strm, arg_type, m_interpreter);
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
} else {
|
||||
StreamString error_msg_stream;
|
||||
GenerateAdditionalHelpAvenuesMessage(&error_msg_stream,
|
||||
command.GetArgumentAtIndex(0),
|
||||
m_interpreter.GetCommandPrefix(), "");
|
||||
GenerateAdditionalHelpAvenuesMessage(&error_msg_stream, command_name,
|
||||
m_interpreter.GetCommandPrefix(),
|
||||
"");
|
||||
result.AppendError(error_msg_stream.GetString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
}
|
||||
|
@ -225,8 +222,7 @@ int CommandObjectHelp::HandleCompletion(Args &input, int &cursor_index,
|
|||
input, cursor_index, cursor_char_position, match_start_point,
|
||||
max_return_elements, word_complete, matches);
|
||||
} else {
|
||||
CommandObject *cmd_obj =
|
||||
m_interpreter.GetCommandObject(input.GetArgumentAtIndex(0));
|
||||
CommandObject *cmd_obj = m_interpreter.GetCommandObject(input[0].ref);
|
||||
|
||||
// The command that they are getting help on might be ambiguous, in which
|
||||
// case we should complete that,
|
||||
|
|
|
@ -88,28 +88,6 @@ public:
|
|||
|
||||
Options *GetOptions() override { return &m_options; }
|
||||
|
||||
// int
|
||||
// HandleArgumentCompletion (Args &input,
|
||||
// int &cursor_index,
|
||||
// int &cursor_char_position,
|
||||
// OptionElementVector &opt_element_vector,
|
||||
// int match_start_point,
|
||||
// int max_return_elements,
|
||||
// bool &word_complete,
|
||||
// StringList &matches)
|
||||
// {
|
||||
// std::string completion_str (input.GetArgumentAtIndex(cursor_index));
|
||||
// completion_str.erase (cursor_char_position);
|
||||
//
|
||||
// if (cursor_index == 1)
|
||||
// {
|
||||
// //
|
||||
// Log::AutoCompleteChannelName (completion_str.c_str(), matches);
|
||||
// }
|
||||
// return matches.GetSize();
|
||||
// }
|
||||
//
|
||||
|
||||
class CommandOptions : public Options {
|
||||
public:
|
||||
CommandOptions() : Options(), log_file(), log_options(0) {}
|
||||
|
@ -186,7 +164,7 @@ protected:
|
|||
}
|
||||
|
||||
// Store into a std::string since we're about to shift the channel off.
|
||||
std::string channel = args.GetArgumentAtIndex(0);
|
||||
const std::string channel = args[0].ref;
|
||||
args.Shift(); // Shift off the channel
|
||||
char log_file[PATH_MAX];
|
||||
if (m_options.log_file)
|
||||
|
@ -251,7 +229,7 @@ protected:
|
|||
|
||||
Log::Callbacks log_callbacks;
|
||||
|
||||
const std::string channel = args.GetArgumentAtIndex(0);
|
||||
const std::string channel = args[0].ref;
|
||||
args.Shift(); // Shift off the channel
|
||||
if (Log::GetLogChannelCallbacks(ConstString(channel), log_callbacks)) {
|
||||
log_callbacks.disable(args.GetConstArgumentVector(),
|
||||
|
@ -350,7 +328,7 @@ protected:
|
|||
result.SetStatus(eReturnStatusFailed);
|
||||
|
||||
if (args.GetArgumentCount() == 1) {
|
||||
llvm::StringRef sub_command = args.GetArgumentAtIndex(0);
|
||||
auto sub_command = args[0].ref;
|
||||
|
||||
if (sub_command.equals_lower("enable")) {
|
||||
Timer::SetDisplayDepth(UINT32_MAX);
|
||||
|
@ -367,8 +345,8 @@ protected:
|
|||
result.SetStatus(eReturnStatusSuccessFinishResult);
|
||||
}
|
||||
} else if (args.GetArgumentCount() == 2) {
|
||||
llvm::StringRef sub_command = args.GetArgumentAtIndex(0);
|
||||
llvm::StringRef param = args.GetArgumentAtIndex(1);
|
||||
auto sub_command = args[0].ref;
|
||||
auto param = args[1].ref;
|
||||
|
||||
if (sub_command.equals_lower("enable")) {
|
||||
uint32_t depth;
|
||||
|
|
|
@ -589,7 +589,7 @@ protected:
|
|||
}
|
||||
|
||||
if (argc > 0)
|
||||
addr = Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(0),
|
||||
addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
|
||||
if (addr == LLDB_INVALID_ADDRESS) {
|
||||
|
@ -600,9 +600,8 @@ protected:
|
|||
}
|
||||
|
||||
if (argc == 2) {
|
||||
lldb::addr_t end_addr =
|
||||
Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(1),
|
||||
LLDB_INVALID_ADDRESS, nullptr);
|
||||
lldb::addr_t end_addr = Args::StringToAddress(
|
||||
&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());
|
||||
|
@ -1036,16 +1035,14 @@ protected:
|
|||
}
|
||||
|
||||
Error error;
|
||||
lldb::addr_t low_addr =
|
||||
Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(0),
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
lldb::addr_t low_addr = Args::StringToAddress(&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 =
|
||||
Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(1),
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
lldb::addr_t high_addr = Args::StringToAddress(
|
||||
&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;
|
||||
|
@ -1347,9 +1344,8 @@ protected:
|
|||
size_t item_byte_size = byte_size_value.GetCurrentValue();
|
||||
|
||||
Error error;
|
||||
lldb::addr_t addr =
|
||||
Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(0),
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
lldb::addr_t addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
|
||||
if (addr == LLDB_INVALID_ADDRESS) {
|
||||
result.AppendError("invalid address expression\n");
|
||||
|
@ -1408,9 +1404,7 @@ protected:
|
|||
int64_t sval64;
|
||||
bool success = false;
|
||||
const size_t num_value_args = command.GetArgumentCount();
|
||||
for (size_t i = 0; i < num_value_args; ++i) {
|
||||
const char *value_str = command.GetArgumentAtIndex(i);
|
||||
|
||||
for (auto &entry : command) {
|
||||
switch (m_format_options.GetFormat()) {
|
||||
case kNumFormats:
|
||||
case eFormatFloat: // TODO: add support for floats soon
|
||||
|
@ -1449,10 +1443,9 @@ protected:
|
|||
case eFormatHexUppercase:
|
||||
case eFormatPointer:
|
||||
// Decode hex bytes
|
||||
uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 16, &success);
|
||||
if (!success) {
|
||||
if (entry.ref.getAsInteger(16, uval64)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid hex string value.\n", value_str);
|
||||
"'%s' is not a valid hex string value.\n", entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
|
||||
|
@ -1467,11 +1460,10 @@ protected:
|
|||
break;
|
||||
|
||||
case eFormatBoolean:
|
||||
uval64 = Args::StringToBoolean(
|
||||
llvm::StringRef::withNullAsEmpty(value_str), false, &success);
|
||||
uval64 = Args::StringToBoolean(entry.ref, false, &success);
|
||||
if (!success) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid boolean string value.\n", value_str);
|
||||
"'%s' is not a valid boolean string value.\n", entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
@ -1479,10 +1471,9 @@ protected:
|
|||
break;
|
||||
|
||||
case eFormatBinary:
|
||||
uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 2, &success);
|
||||
if (!success) {
|
||||
if (entry.ref.getAsInteger(2, uval64)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid binary string value.\n", value_str);
|
||||
"'%s' is not a valid binary string value.\n", entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
|
||||
|
@ -1498,30 +1489,30 @@ protected:
|
|||
|
||||
case eFormatCharArray:
|
||||
case eFormatChar:
|
||||
case eFormatCString:
|
||||
if (value_str[0]) {
|
||||
size_t len = strlen(value_str);
|
||||
// Include the NULL for C strings...
|
||||
if (m_format_options.GetFormat() == eFormatCString)
|
||||
++len;
|
||||
Error error;
|
||||
if (process->WriteMemory(addr, value_str, len, error) == len) {
|
||||
addr += len;
|
||||
} else {
|
||||
result.AppendErrorWithFormat("Memory write to 0x%" PRIx64
|
||||
" failed: %s.\n",
|
||||
addr, error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
case eFormatCString: {
|
||||
if (entry.ref.empty())
|
||||
break;
|
||||
|
||||
size_t len = entry.ref.size();
|
||||
// Include the NULL for C strings...
|
||||
if (m_format_options.GetFormat() == eFormatCString)
|
||||
++len;
|
||||
Error error;
|
||||
if (process->WriteMemory(addr, entry.c_str(), len, error) == len) {
|
||||
addr += len;
|
||||
} else {
|
||||
result.AppendErrorWithFormat("Memory write to 0x%" PRIx64
|
||||
" failed: %s.\n",
|
||||
addr, error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case eFormatDecimal:
|
||||
sval64 = StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
|
||||
if (!success) {
|
||||
if (entry.ref.getAsInteger(0, sval64)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid signed decimal value.\n", value_str);
|
||||
"'%s' is not a valid signed decimal value.\n", entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
} else if (!SIntValueIsValidForSize(sval64, item_byte_size)) {
|
||||
|
@ -1536,11 +1527,11 @@ protected:
|
|||
break;
|
||||
|
||||
case eFormatUnsigned:
|
||||
uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success);
|
||||
if (!success) {
|
||||
|
||||
if (!entry.ref.getAsInteger(0, uval64)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid unsigned decimal string value.\n",
|
||||
value_str);
|
||||
entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
|
||||
|
@ -1555,10 +1546,9 @@ protected:
|
|||
break;
|
||||
|
||||
case eFormatOctal:
|
||||
uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 8, &success);
|
||||
if (!success) {
|
||||
if (entry.ref.getAsInteger(8, uval64)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"'%s' is not a valid octal string value.\n", value_str);
|
||||
"'%s' is not a valid octal string value.\n", entry.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
|
||||
|
@ -1643,9 +1633,8 @@ protected:
|
|||
}
|
||||
|
||||
Error error;
|
||||
lldb::addr_t addr =
|
||||
Args::StringToAddress(&m_exe_ctx, command.GetArgumentAtIndex(0),
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
lldb::addr_t addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
|
||||
if (addr == LLDB_INVALID_ADDRESS) {
|
||||
result.AppendError("invalid address expression");
|
||||
|
@ -1711,13 +1700,13 @@ protected:
|
|||
m_cmd_name.c_str(), m_cmd_syntax.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
} else {
|
||||
const char *load_addr_cstr = command.GetArgumentAtIndex(0);
|
||||
auto load_addr_str = command[0].ref;
|
||||
if (command.GetArgumentCount() == 1) {
|
||||
load_addr = Args::StringToAddress(&m_exe_ctx, load_addr_cstr,
|
||||
load_addr = Args::StringToAddress(&m_exe_ctx, load_addr_str,
|
||||
LLDB_INVALID_ADDRESS, &error);
|
||||
if (error.Fail() || load_addr == LLDB_INVALID_ADDRESS) {
|
||||
result.AppendErrorWithFormat(
|
||||
"invalid address argument \"%s\": %s\n", load_addr_cstr,
|
||||
"invalid address argument \"%s\": %s\n", command[0].c_str(),
|
||||
error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
}
|
||||
|
|
|
@ -537,17 +537,15 @@ void CommandObject::GetFormattedCommandArguments(Stream &str,
|
|||
}
|
||||
}
|
||||
|
||||
CommandArgumentType CommandObject::LookupArgumentName(const char *arg_name) {
|
||||
CommandArgumentType
|
||||
CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
|
||||
CommandArgumentType return_type = eArgTypeLastArg;
|
||||
|
||||
std::string arg_name_str(arg_name);
|
||||
size_t len = arg_name_str.length();
|
||||
if (arg_name[0] == '<' && arg_name[len - 1] == '>')
|
||||
arg_name_str = arg_name_str.substr(1, len - 2);
|
||||
arg_name = arg_name.ltrim('<').rtrim('>');
|
||||
|
||||
const ArgumentTableEntry *table = GetArgumentTable();
|
||||
for (int i = 0; i < eArgTypeLastArg; ++i)
|
||||
if (arg_name_str.compare(table[i].arg_name) == 0)
|
||||
if (arg_name == table[i].arg_name)
|
||||
return_type = g_arguments_data[i].arg_type;
|
||||
|
||||
return return_type;
|
||||
|
|
Loading…
Reference in New Issue