aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Interpreter
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/lldb/source/Interpreter
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
downloadsrc-349cc55c9796c4596a5b9904cd3281af295f878f.tar.gz
src-349cc55c9796c4596a5b9904cd3281af295f878f.zip
Merge llvm-project main llvmorg-14-init-10186-gff7f2cfa959b
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp to llvmorg-14-init-10186-gff7f2cfa959b. PR: 261742 MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/lldb/source/Interpreter')
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp253
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp2
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValueArray.cpp24
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValueFileSpecList.cpp24
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValuePathMappings.cpp45
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValueProperties.cpp3
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValueSInt64.cpp8
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp10
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/Property.cpp37
-rw-r--r--contrib/llvm-project/lldb/source/Interpreter/ScriptInterpreter.cpp16
10 files changed, 296 insertions, 126 deletions
diff --git a/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp b/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp
index 00e9ccb762c3..301bf949feef 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -744,8 +744,10 @@ void CommandInterpreter::LoadCommandDictionary() {
std::unique_ptr<CommandObjectRegexCommand> connect_gdb_remote_cmd_up(
new CommandObjectRegexCommand(
*this, "gdb-remote",
- "Connect to a process via remote GDB server. "
- "If no host is specifed, localhost is assumed.",
+ "Connect to a process via remote GDB server.\n"
+ "If no host is specifed, localhost is assumed.\n"
+ "gdb-remote is an abbreviation for 'process connect --plugin "
+ "gdb-remote connect://<hostname>:<port>'\n",
"gdb-remote [<hostname>:]<portnum>", 2, 0, false));
if (connect_gdb_remote_cmd_up) {
if (connect_gdb_remote_cmd_up->AddRegexCommand(
@@ -762,9 +764,10 @@ void CommandInterpreter::LoadCommandDictionary() {
std::unique_ptr<CommandObjectRegexCommand> connect_kdp_remote_cmd_up(
new CommandObjectRegexCommand(
*this, "kdp-remote",
- "Connect to a process via remote KDP server. "
- "If no UDP port is specified, port 41139 is "
- "assumed.",
+ "Connect to a process via remote KDP server.\n"
+ "If no UDP port is specified, port 41139 is assumed.\n"
+ "kdp-remote is an abbreviation for 'process connect --plugin "
+ "kdp-remote udp://<hostname>:<port>'\n",
"kdp-remote <hostname>[:<portnum>]", 2, 0, false));
if (connect_kdp_remote_cmd_up) {
if (connect_kdp_remote_cmd_up->AddRegexCommand(
@@ -897,6 +900,63 @@ int CommandInterpreter::GetCommandNamesMatchingPartialString(
return matches.GetSize();
}
+CommandObjectMultiword *CommandInterpreter::VerifyUserMultiwordCmdPath(
+ Args &path, bool leaf_is_command, Status &result) {
+ result.Clear();
+
+ auto get_multi_or_report_error =
+ [&result](CommandObjectSP cmd_sp,
+ const char *name) -> CommandObjectMultiword * {
+ if (!cmd_sp) {
+ result.SetErrorStringWithFormat("Path component: '%s' not found", name);
+ return nullptr;
+ }
+ if (!cmd_sp->IsUserCommand()) {
+ result.SetErrorStringWithFormat("Path component: '%s' is not a user "
+ "command",
+ name);
+ return nullptr;
+ }
+ CommandObjectMultiword *cmd_as_multi = cmd_sp->GetAsMultiwordCommand();
+ if (!cmd_as_multi) {
+ result.SetErrorStringWithFormat("Path component: '%s' is not a container "
+ "command",
+ name);
+ return nullptr;
+ }
+ return cmd_as_multi;
+ };
+
+ size_t num_args = path.GetArgumentCount();
+ if (num_args == 0) {
+ result.SetErrorString("empty command path");
+ return nullptr;
+ }
+
+ if (num_args == 1 && leaf_is_command) {
+ // We just got a leaf command to be added to the root. That's not an error,
+ // just return null for the container.
+ return nullptr;
+ }
+
+ // Start by getting the root command from the interpreter.
+ const char *cur_name = path.GetArgumentAtIndex(0);
+ CommandObjectSP cur_cmd_sp = GetCommandSPExact(cur_name);
+ CommandObjectMultiword *cur_as_multi =
+ get_multi_or_report_error(cur_cmd_sp, cur_name);
+ if (cur_as_multi == nullptr)
+ return nullptr;
+
+ size_t num_path_elements = num_args - (leaf_is_command ? 1 : 0);
+ for (size_t cursor = 1; cursor < num_path_elements && cur_as_multi != nullptr;
+ cursor++) {
+ cur_name = path.GetArgumentAtIndex(cursor);
+ cur_cmd_sp = cur_as_multi->GetSubcommandSPExact(cur_name);
+ cur_as_multi = get_multi_or_report_error(cur_cmd_sp, cur_name);
+ }
+ return cur_as_multi;
+}
+
CommandObjectSP
CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
bool exact, StringList *matches,
@@ -923,10 +983,17 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
command_sp = pos->second;
}
+ if (HasUserMultiwordCommands()) {
+ auto pos = m_user_mw_dict.find(cmd);
+ if (pos != m_user_mw_dict.end())
+ command_sp = pos->second;
+ }
+
if (!exact && !command_sp) {
// We will only get into here if we didn't find any exact matches.
- CommandObjectSP user_match_sp, alias_match_sp, real_match_sp;
+ CommandObjectSP user_match_sp, user_mw_match_sp, alias_match_sp,
+ real_match_sp;
StringList local_matches;
if (matches == nullptr)
@@ -935,6 +1002,7 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
unsigned int num_cmd_matches = 0;
unsigned int num_alias_matches = 0;
unsigned int num_user_matches = 0;
+ unsigned int num_user_mw_matches = 0;
// Look through the command dictionaries one by one, and if we get only one
// match from any of them in toto, then return that, otherwise return an
@@ -978,14 +1046,32 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
user_match_sp = pos->second;
}
+ if (HasUserMultiwordCommands()) {
+ num_user_mw_matches = AddNamesMatchingPartialString(
+ m_user_mw_dict, cmd_str, *matches, descriptions);
+ }
+
+ if (num_user_mw_matches == 1) {
+ cmd.assign(matches->GetStringAtIndex(num_cmd_matches + num_alias_matches +
+ num_user_matches));
+
+ auto pos = m_user_mw_dict.find(cmd);
+ if (pos != m_user_mw_dict.end())
+ user_mw_match_sp = pos->second;
+ }
+
// If we got exactly one match, return that, otherwise return the match
// list.
- if (num_user_matches + num_cmd_matches + num_alias_matches == 1) {
+ if (num_user_matches + num_user_mw_matches + num_cmd_matches +
+ num_alias_matches ==
+ 1) {
if (num_cmd_matches)
return real_match_sp;
else if (num_alias_matches)
return alias_match_sp;
+ else if (num_user_mw_matches)
+ return user_mw_match_sp;
else
return user_match_sp;
}
@@ -1008,6 +1094,8 @@ bool CommandInterpreter::AddCommand(llvm::StringRef name,
if (name.empty())
return false;
+ cmd_sp->SetIsUserCommand(false);
+
std::string name_sstr(name);
auto name_iter = m_command_dict.find(name_sstr);
if (name_iter != m_command_dict.end()) {
@@ -1020,33 +1108,49 @@ bool CommandInterpreter::AddCommand(llvm::StringRef name,
return true;
}
-bool CommandInterpreter::AddUserCommand(llvm::StringRef name,
- const lldb::CommandObjectSP &cmd_sp,
- bool can_replace) {
+Status CommandInterpreter::AddUserCommand(llvm::StringRef name,
+ const lldb::CommandObjectSP &cmd_sp,
+ bool can_replace) {
+ Status result;
if (cmd_sp.get())
lldbassert((this == &cmd_sp->GetCommandInterpreter()) &&
"tried to add a CommandObject from a different interpreter");
-
- if (!name.empty()) {
- // do not allow replacement of internal commands
- if (CommandExists(name)) {
- if (!can_replace)
- return false;
- if (!m_command_dict[std::string(name)]->IsRemovable())
- return false;
+ if (name.empty()) {
+ result.SetErrorString("can't use the empty string for a command name");
+ return result;
+ }
+ // do not allow replacement of internal commands
+ if (CommandExists(name)) {
+ result.SetErrorString("can't replace builtin command");
+ return result;
+ }
+
+ if (UserCommandExists(name)) {
+ if (!can_replace) {
+ result.SetErrorString("user command exists and force replace not set");
+ return result;
+ }
+ if (cmd_sp->IsMultiwordObject()) {
+ if (!m_user_mw_dict[std::string(name)]->IsRemovable()) {
+ result.SetErrorString(
+ "can't replace explicitly non-removable multi-word command");
+ return result;
+ }
+ } else {
+ if (!m_user_dict[std::string(name)]->IsRemovable()) {
+ result.SetErrorString("can't replace explicitly non-removable command");
+ return result;
+ }
}
+ }
- if (UserCommandExists(name)) {
- if (!can_replace)
- return false;
- if (!m_user_dict[std::string(name)]->IsRemovable())
- return false;
- }
+ cmd_sp->SetIsUserCommand(true);
+ if (cmd_sp->IsMultiwordObject())
+ m_user_mw_dict[std::string(name)] = cmd_sp;
+ else
m_user_dict[std::string(name)] = cmd_sp;
- return true;
- }
- return false;
+ return result;
}
CommandObjectSP
@@ -1127,6 +1231,42 @@ CommandInterpreter::GetCommandObject(llvm::StringRef cmd_str,
return GetCommandSP(cmd_str, true, false, matches, descriptions).get();
}
+CommandObject *CommandInterpreter::GetUserCommandObject(
+ llvm::StringRef cmd, StringList *matches, StringList *descriptions) const {
+ std::string cmd_str(cmd);
+ auto find_exact = [&](const CommandObject::CommandMap &map) {
+ auto found_elem = map.find(std::string(cmd));
+ if (found_elem == map.end())
+ return (CommandObject *)nullptr;
+ CommandObject *exact_cmd = found_elem->second.get();
+ if (exact_cmd) {
+ if (matches)
+ matches->AppendString(exact_cmd->GetCommandName());
+ if (descriptions)
+ descriptions->AppendString(exact_cmd->GetHelp());
+ return exact_cmd;
+ }
+ return (CommandObject *)nullptr;
+ };
+
+ CommandObject *exact_cmd = find_exact(GetUserCommands());
+ if (exact_cmd)
+ return exact_cmd;
+
+ exact_cmd = find_exact(GetUserMultiwordCommands());
+ if (exact_cmd)
+ return exact_cmd;
+
+ // We didn't have an exact command, so now look for partial matches.
+ StringList tmp_list;
+ StringList *matches_ptr = matches ? matches : &tmp_list;
+ AddNamesMatchingPartialString(GetUserCommands(), cmd_str, *matches_ptr);
+ AddNamesMatchingPartialString(GetUserMultiwordCommands(),
+ cmd_str, *matches_ptr);
+
+ return {};
+}
+
bool CommandInterpreter::CommandExists(llvm::StringRef cmd) const {
return m_command_dict.find(std::string(cmd)) != m_command_dict.end();
}
@@ -1169,6 +1309,10 @@ bool CommandInterpreter::UserCommandExists(llvm::StringRef cmd) const {
return m_user_dict.find(std::string(cmd)) != m_user_dict.end();
}
+bool CommandInterpreter::UserMultiwordCommandExists(llvm::StringRef cmd) const {
+ return m_user_mw_dict.find(std::string(cmd)) != m_user_mw_dict.end();
+}
+
CommandAlias *
CommandInterpreter::AddAlias(llvm::StringRef alias_name,
lldb::CommandObjectSP &command_obj_sp,
@@ -1209,9 +1353,10 @@ bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd) {
}
return false;
}
-bool CommandInterpreter::RemoveUser(llvm::StringRef alias_name) {
+
+bool CommandInterpreter::RemoveUser(llvm::StringRef user_name) {
CommandObject::CommandMap::iterator pos =
- m_user_dict.find(std::string(alias_name));
+ m_user_dict.find(std::string(user_name));
if (pos != m_user_dict.end()) {
m_user_dict.erase(pos);
return true;
@@ -1219,6 +1364,16 @@ bool CommandInterpreter::RemoveUser(llvm::StringRef alias_name) {
return false;
}
+bool CommandInterpreter::RemoveUserMultiword(llvm::StringRef multi_name) {
+ CommandObject::CommandMap::iterator pos =
+ m_user_mw_dict.find(std::string(multi_name));
+ if (pos != m_user_mw_dict.end()) {
+ m_user_mw_dict.erase(pos);
+ return true;
+ }
+ return false;
+}
+
void CommandInterpreter::GetHelp(CommandReturnObject &result,
uint32_t cmd_types) {
llvm::StringRef help_prologue(GetDebugger().GetIOHandlerHelpPrologue());
@@ -1274,6 +1429,18 @@ void CommandInterpreter::GetHelp(CommandReturnObject &result,
result.AppendMessage("");
}
+ if (!m_user_mw_dict.empty() &&
+ ((cmd_types & eCommandTypesUserMW) == eCommandTypesUserMW)) {
+ result.AppendMessage("Current user-defined container commands:");
+ result.AppendMessage("");
+ max_len = FindLongestCommandWord(m_user_mw_dict);
+ for (pos = m_user_dict.begin(); pos != m_user_mw_dict.end(); ++pos) {
+ OutputFormattedHelpText(result.GetOutputStream(), pos->first, "--",
+ pos->second->GetHelp(), max_len);
+ }
+ result.AppendMessage("");
+ }
+
result.AppendMessageWithFormat(
"For more information on any command, type '%shelp <command-name>'.\n",
GetCommandPrefix());
@@ -1931,6 +2098,10 @@ bool CommandInterpreter::HasAliases() const { return (!m_alias_dict.empty()); }
bool CommandInterpreter::HasUserCommands() const { return (!m_user_dict.empty()); }
+bool CommandInterpreter::HasUserMultiwordCommands() const {
+ return (!m_user_mw_dict.empty());
+}
+
bool CommandInterpreter::HasAliasOptions() const { return HasAliases(); }
void CommandInterpreter::BuildAliasCommandArgs(CommandObject *alias_cmd_obj,
@@ -2113,13 +2284,6 @@ static void GetCwdInitFile(llvm::SmallVectorImpl<char> &init_file) {
FileSystem::Instance().Resolve(init_file);
}
-static LoadCWDlldbinitFile ShouldLoadCwdInitFile() {
- lldb::TargetPropertiesSP properties = Target::GetGlobalProperties();
- if (!properties)
- return eLoadCWDlldbinitFalse;
- return properties->GetLoadCWDlldbinitFile();
-}
-
void CommandInterpreter::SourceInitFile(FileSpec file,
CommandReturnObject &result) {
assert(!m_skip_lldbinit_files);
@@ -2155,7 +2319,8 @@ void CommandInterpreter::SourceInitFileCwd(CommandReturnObject &result) {
return;
}
- LoadCWDlldbinitFile should_load = ShouldLoadCwdInitFile();
+ LoadCWDlldbinitFile should_load =
+ Target::GetGlobalProperties().GetLoadCWDlldbinitFile();
switch (should_load) {
case eLoadCWDlldbinitFalse:
@@ -2433,7 +2598,7 @@ void CommandInterpreter::HandleCommandsFromFile(FileSpec &cmd_file,
std::string cmd_file_path = cmd_file.GetPath();
auto input_file_up =
- FileSystem::Instance().Open(cmd_file, File::eOpenOptionRead);
+ FileSystem::Instance().Open(cmd_file, File::eOpenOptionReadOnly);
if (!input_file_up) {
std::string error = llvm::toString(input_file_up.takeError());
result.AppendErrorWithFormatv(
@@ -2587,6 +2752,9 @@ void CommandInterpreter::OutputFormattedHelpText(Stream &strm,
strm.IndentMore(prefix.size());
bool prefixed_yet = false;
+ // Even if we have no help text we still want to emit the command name.
+ if (help_text.empty())
+ help_text = "No help text";
while (!help_text.empty()) {
// Prefix the first line, indent subsequent lines to line up
if (!prefixed_yet) {
@@ -2706,7 +2874,8 @@ void CommandInterpreter::FindCommandsForApropos(llvm::StringRef search_word,
StringList &commands_help,
bool search_builtin_commands,
bool search_user_commands,
- bool search_alias_commands) {
+ bool search_alias_commands,
+ bool search_user_mw_commands) {
CommandObject::CommandMap::const_iterator pos;
if (search_builtin_commands)
@@ -2717,6 +2886,10 @@ void CommandInterpreter::FindCommandsForApropos(llvm::StringRef search_word,
FindCommandsForApropos(search_word, commands_found, commands_help,
m_user_dict);
+ if (search_user_mw_commands)
+ FindCommandsForApropos(search_word, commands_found, commands_help,
+ m_user_mw_dict);
+
if (search_alias_commands)
FindCommandsForApropos(search_word, commands_found, commands_help,
m_alias_dict);
@@ -2954,7 +3127,7 @@ bool CommandInterpreter::SaveTranscript(
return false;
};
- File::OpenOptions flags = File::eOpenOptionWrite |
+ File::OpenOptions flags = File::eOpenOptionWriteOnly |
File::eOpenOptionCanCreate |
File::eOpenOptionTruncate;
diff --git a/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp b/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp
index a7dcd5682701..64b23d04abea 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp
@@ -1120,7 +1120,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
{ eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." },
{ eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." },
{ eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes. To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." },
- { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." },
+ { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command element." },
{ eArgTypeColumnNum, "column", CommandCompletions::eNoCompletion, { nullptr, false }, "Column number in a source file." },
{ eArgTypeModuleUUID, "module-uuid", CommandCompletions::eModuleUUIDCompletion, { nullptr, false }, "A module UUID value." },
{ eArgTypeSaveCoreStyle, "corefile-style", CommandCompletions::eNoCompletion, { nullptr, false }, "The type of corefile that lldb will try to create, dependant on this target's capabilities." }
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValueArray.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValueArray.cpp
index b1545bdebf10..4468fe57702e 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValueArray.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValueArray.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueArray.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -167,13 +166,12 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) {
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid insert array index %u, index must be 0 through %u", idx,
- count);
+ "invalid insert array index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
if (op == eVarSetOperationInsertAfter)
++idx;
@@ -207,9 +205,8 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) {
bool all_indexes_valid = true;
size_t i;
for (i = 0; i < argc; ++i) {
- const size_t idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx >= size) {
+ size_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx >= size) {
all_indexes_valid = false;
break;
} else
@@ -249,13 +246,12 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) {
case eVarSetOperationReplace:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid replace array index %u, index must be 0 through %u", idx,
- count);
+ "invalid replace array index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
for (size_t i = 1; i < argc; ++i, ++idx) {
lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask(
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 2160fd61d428..6566eee09d73 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueFileSpecList.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -57,13 +56,12 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
case eVarSetOperationReplace:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = m_current_value.GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid file list index %u, index must be 0 through %u", idx,
- count);
+ "invalid file list index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
for (size_t i = 1; i < argc; ++i, ++idx) {
FileSpec file(args.GetArgumentAtIndex(i));
@@ -101,13 +99,12 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = m_current_value.GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid insert file list index %u, index must be 0 through %u",
- idx, count);
+ "invalid insert file list index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
if (op == eVarSetOperationInsertAfter)
++idx;
@@ -129,9 +126,8 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
bool all_indexes_valid = true;
size_t i;
for (i = 0; all_indexes_valid && i < argc; ++i) {
- const int idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx == INT32_MAX)
+ int idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx))
all_indexes_valid = false;
else
remove_indexes.push_back(idx);
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValuePathMappings.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValuePathMappings.cpp
index 4dceb5632716..543b0e1b8ea8 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValuePathMappings.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValuePathMappings.cpp
@@ -9,21 +9,19 @@
#include "lldb/Interpreter/OptionValuePathMappings.h"
#include "lldb/Host/FileSystem.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
-namespace {
+
static bool VerifyPathExists(const char *path) {
if (path && path[0])
return FileSystem::Instance().Exists(path);
else
return false;
}
-}
void OptionValuePathMappings::DumpValue(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask) {
@@ -52,23 +50,22 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
// Must be at least one index + 1 pair of paths, and the pair count must be
// even
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = m_path_mappings.GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid file list index %u, index must be 0 through %u", idx,
- count);
+ "invalid file list index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
bool changed = false;
for (size_t i = 1; i < argc; idx++, i += 2) {
const char *orginal_path = args.GetArgumentAtIndex(i);
const char *replace_path = args.GetArgumentAtIndex(i + 1);
if (VerifyPathExists(replace_path)) {
- ConstString a(orginal_path);
- ConstString b(replace_path);
- if (!m_path_mappings.Replace(a, b, idx, m_notify_changes))
- m_path_mappings.Append(a, b, m_notify_changes);
+ if (!m_path_mappings.Replace(orginal_path, replace_path, idx,
+ m_notify_changes))
+ m_path_mappings.Append(orginal_path, replace_path,
+ m_notify_changes);
changed = true;
} else {
std::string previousError =
@@ -105,9 +102,7 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
const char *orginal_path = args.GetArgumentAtIndex(i);
const char *replace_path = args.GetArgumentAtIndex(i + 1);
if (VerifyPathExists(replace_path)) {
- ConstString a(orginal_path);
- ConstString b(replace_path);
- m_path_mappings.Append(a, b, m_notify_changes);
+ m_path_mappings.Append(orginal_path, replace_path, m_notify_changes);
m_value_was_set = true;
changed = true;
} else {
@@ -128,13 +123,12 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
// Must be at least one index + 1 pair of paths, and the pair count must be
// even
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
const uint32_t count = m_path_mappings.GetSize();
- if (idx > count) {
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid file list index %u, index must be 0 through %u", idx,
- count);
+ "invalid file list index %s, index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
bool changed = false;
if (op == eVarSetOperationInsertAfter)
@@ -143,9 +137,8 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
const char *orginal_path = args.GetArgumentAtIndex(i);
const char *replace_path = args.GetArgumentAtIndex(i + 1);
if (VerifyPathExists(replace_path)) {
- ConstString a(orginal_path);
- ConstString b(replace_path);
- m_path_mappings.Insert(a, b, idx, m_notify_changes);
+ m_path_mappings.Insert(orginal_path, replace_path, idx,
+ m_notify_changes);
changed = true;
idx++;
} else {
@@ -169,9 +162,9 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value,
if (argc > 0) {
std::vector<int> remove_indexes;
for (size_t i = 0; i < argc; ++i) {
- int idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx < 0 || idx >= (int)m_path_mappings.GetSize()) {
+ int idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx < 0 ||
+ idx >= (int)m_path_mappings.GetSize()) {
error.SetErrorStringWithFormat(
"invalid array index '%s', aborting remove operation",
args.GetArgumentAtIndex(i));
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValueProperties.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValueProperties.cpp
index ae073798ca12..1a8f2f0ab180 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValueProperties.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValueProperties.cpp
@@ -48,7 +48,8 @@ void OptionValueProperties::AppendProperty(ConstString name,
ConstString desc,
bool is_global,
const OptionValueSP &value_sp) {
- Property property(name, desc, is_global, value_sp);
+ Property property(name.GetStringRef(), desc.GetStringRef(), is_global,
+ value_sp);
m_name_to_index.Append(name, m_properties.size());
m_properties.push_back(property);
value_sp->SetParent(shared_from_this());
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValueSInt64.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValueSInt64.cpp
index b875ba8e3536..c1db5056cd94 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValueSInt64.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValueSInt64.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueSInt64.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -41,10 +40,9 @@ Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
- bool success = false;
- std::string value_str = value_ref.trim().str();
- int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success);
- if (success) {
+ llvm::StringRef value_trimmed = value_ref.trim();
+ int64_t value;
+ if (llvm::to_integer(value_trimmed, value)) {
if (value >= m_min_value && value <= m_max_value) {
m_value_was_set = true;
m_current_value = value;
diff --git a/contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp b/contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp
index a2751a4d02eb..1999c63d11af 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueUInt64.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -45,16 +44,15 @@ Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
- bool success = false;
- std::string value_str = value_ref.trim().str();
- uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
- if (success) {
+ llvm::StringRef value_trimmed = value_ref.trim();
+ uint64_t value;
+ if (llvm::to_integer(value_trimmed, value)) {
m_value_was_set = true;
m_current_value = value;
NotifyValueChanged();
} else {
error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
- value_str.c_str());
+ value_ref.str().c_str());
}
} break;
diff --git a/contrib/llvm-project/lldb/source/Interpreter/Property.cpp b/contrib/llvm-project/lldb/source/Interpreter/Property.cpp
index 55400a2bc42d..fe3a8a31394b 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/Property.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/Property.cpp
@@ -9,7 +9,6 @@
#include "lldb/Interpreter/Property.h"
#include "lldb/Core/UserSettingsController.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValues.h"
@@ -176,28 +175,32 @@ Property::Property(const PropertyDefinition &definition)
std::make_shared<OptionValueRegex>(definition.default_cstr_value);
break;
- case OptionValue::eTypeSInt64:
+ case OptionValue::eTypeSInt64: {
// "definition.default_uint_value" is the default integer value if
// "definition.default_cstr_value" is NULL, otherwise interpret
// "definition.default_cstr_value" as a string value that represents the
// default value.
+ int64_t value = 0;
+ // FIXME: improve error handling for llvm::to_integer()
+ if (definition.default_cstr_value)
+ llvm::to_integer(definition.default_cstr_value, value);
m_value_sp = std::make_shared<OptionValueSInt64>(
- definition.default_cstr_value
- ? StringConvert::ToSInt64(definition.default_cstr_value)
- : definition.default_uint_value);
+ definition.default_cstr_value ? value : definition.default_uint_value);
break;
-
- case OptionValue::eTypeUInt64:
+ }
+ case OptionValue::eTypeUInt64: {
+ uint64_t value = 0;
+ // FIXME: improve error handling for llvm::to_integer()
+ if (definition.default_cstr_value)
+ llvm::to_integer(definition.default_cstr_value, value);
// "definition.default_uint_value" is the default unsigned integer value if
// "definition.default_cstr_value" is NULL, otherwise interpret
// "definition.default_cstr_value" as a string value that represents the
// default value.
m_value_sp = std::make_shared<OptionValueUInt64>(
- definition.default_cstr_value
- ? StringConvert::ToUInt64(definition.default_cstr_value)
- : definition.default_uint_value);
+ definition.default_cstr_value ? value : definition.default_uint_value);
break;
-
+ }
case OptionValue::eTypeUUID:
// "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
// "definition.default_cstr_value" can contain a default UUID value
@@ -224,13 +227,13 @@ Property::Property(const PropertyDefinition &definition)
}
}
-Property::Property(ConstString name, ConstString desc,
- bool is_global, const lldb::OptionValueSP &value_sp)
+Property::Property(llvm::StringRef name, llvm::StringRef desc, bool is_global,
+ const lldb::OptionValueSP &value_sp)
: m_name(name), m_description(desc), m_value_sp(value_sp),
m_is_global(is_global) {}
bool Property::DumpQualifiedName(Stream &strm) const {
- if (m_name) {
+ if (!m_name.empty()) {
if (m_value_sp->DumpQualifiedName(strm))
strm.PutChar('.');
strm << m_name;
@@ -248,7 +251,7 @@ void Property::Dump(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_cmd && !transparent)
strm << "settings set -f ";
if (dump_desc || !transparent) {
- if ((dump_mask & OptionValue::eDumpOptionName) && m_name) {
+ if ((dump_mask & OptionValue::eDumpOptionName) && !m_name.empty()) {
DumpQualifiedName(strm);
if (dump_mask & ~OptionValue::eDumpOptionName)
strm.PutChar(' ');
@@ -292,8 +295,8 @@ void Property::DumpDescription(CommandInterpreter &interpreter, Stream &strm,
interpreter.OutputFormattedHelpText(strm, qualified_name.GetString(),
"--", desc, output_width);
} else {
- interpreter.OutputFormattedHelpText(strm, m_name.GetStringRef(), "--",
- desc, output_width);
+ interpreter.OutputFormattedHelpText(strm, m_name, "--", desc,
+ output_width);
}
}
}
diff --git a/contrib/llvm-project/lldb/source/Interpreter/ScriptInterpreter.cpp b/contrib/llvm-project/lldb/source/Interpreter/ScriptInterpreter.cpp
index f26474836a68..fbdcbb8da868 100644
--- a/contrib/llvm-project/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/contrib/llvm-project/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -46,6 +46,10 @@ void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
"This script interpreter does not support watchpoint callbacks.");
}
+StructuredData::DictionarySP ScriptInterpreter::GetInterpreterInfo() {
+ return nullptr;
+}
+
bool ScriptInterpreter::LoadScriptingModule(const char *filename,
const LoadScriptOptions &options,
lldb_private::Status &error,
@@ -83,6 +87,14 @@ ScriptInterpreter::GetStatusFromSBError(const lldb::SBError &error) const {
return Status();
}
+llvm::Optional<MemoryRegionInfo>
+ScriptInterpreter::GetOpaqueTypeFromSBMemoryRegionInfo(
+ const lldb::SBMemoryRegionInfo &mem_region) const {
+ if (!mem_region.m_opaque_up)
+ return llvm::None;
+ return *mem_region.m_opaque_up.get();
+}
+
lldb::ScriptLanguage
ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
if (language.equals_insensitive(LanguageToString(eScriptLanguageNone)))
@@ -141,12 +153,12 @@ ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger,
new ScriptInterpreterIORedirect(debugger, result));
auto nullin = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL),
- File::eOpenOptionRead);
+ File::eOpenOptionReadOnly);
if (!nullin)
return nullin.takeError();
auto nullout = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL),
- File::eOpenOptionWrite);
+ File::eOpenOptionWriteOnly);
if (!nullout)
return nullin.takeError();