236 changes: 141 additions & 95 deletions lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lldb/include/lldb/Interpreter/OptionValueFileColonLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OptionValueFileColonLine :
FileSpec m_file_spec;
uint32_t m_line_number = LLDB_INVALID_LINE_NUMBER;
uint32_t m_column_number = LLDB_INVALID_COLUMN_NUMBER;
uint32_t m_completion_mask = CommandCompletions::eSourceFileCompletion;
uint32_t m_completion_mask = lldb::eSourceFileCompletion;
};

} // namespace lldb_private
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Interpreter/OptionValueFileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class OptionValueFileSpec : public Cloneable<OptionValueFileSpec, OptionValue> {
FileSpec m_default_value;
lldb::DataBufferSP m_data_sp;
llvm::sys::TimePoint<> m_data_mod_time;
uint32_t m_completion_mask = CommandCompletions::eDiskFileCompletion;
uint32_t m_completion_mask = lldb::eDiskFileCompletion;
bool m_resolve;
};

Expand Down
12 changes: 12 additions & 0 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,17 @@ class Target : public std::enable_shared_from_this<Target>,

bool IsDummyTarget() const { return m_is_dummy_target; }

const std::string &GetLabel() const { return m_label; }

/// Set a label for a target.
///
/// The label cannot be used by another target or be only integral.
///
/// \return
/// The label for this target or an error if the label didn't match the
/// requirements.
llvm::Error SetLabel(llvm::StringRef label);

/// Find a binary on the system and return its Module,
/// or return an existing Module that is already in the Target.
///
Expand Down Expand Up @@ -1520,6 +1531,7 @@ class Target : public std::enable_shared_from_this<Target>,
/// detect that code is running on the private state thread.
std::recursive_mutex m_private_mutex;
Arch m_arch;
std::string m_label;
ModuleList m_images; ///< The list of images for this process (shared
/// libraries and anything dynamically loaded).
SectionLoadHistory m_section_load_history;
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Target/TargetList.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class TargetList : public Broadcaster {
/// in \a target_sp which can then be properly released.
bool DeleteTarget(lldb::TargetSP &target_sp);

int GetNumTargets() const;
size_t GetNumTargets() const;

lldb::TargetSP GetTargetAtIndex(uint32_t index) const;

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Utility/OptionDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct OptionDefinition {
/// If not empty, an array of enum values.
OptionEnumValues enum_values;
/// The kind of completion for this option.
/// Contains values of the CommandCompletions::CommonCompletionTypes enum.
/// Contains values of the lldb::CompletionType enum.
uint32_t completion_type;
/// Type of argument this option takes.
lldb::CommandArgumentType argument_type;
Expand Down
34 changes: 34 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ enum CommandArgumentType {
eArgTypeConnectURL,
eArgTypeTargetID,
eArgTypeStopHookID,
eArgTypeCompletionType,
eArgTypeLastArg // Always keep this entry as the last entry in this
// enumeration!!
};
Expand Down Expand Up @@ -1245,6 +1246,39 @@ enum WatchpointValueKind {
eWatchPointValueKindExpression = 2,
};

enum CompletionType {
eNoCompletion = 0u,
eSourceFileCompletion = (1u << 0),
eDiskFileCompletion = (1u << 1),
eDiskDirectoryCompletion = (1u << 2),
eSymbolCompletion = (1u << 3),
eModuleCompletion = (1u << 4),
eSettingsNameCompletion = (1u << 5),
ePlatformPluginCompletion = (1u << 6),
eArchitectureCompletion = (1u << 7),
eVariablePathCompletion = (1u << 8),
eRegisterCompletion = (1u << 9),
eBreakpointCompletion = (1u << 10),
eProcessPluginCompletion = (1u << 11),
eDisassemblyFlavorCompletion = (1u << 12),
eTypeLanguageCompletion = (1u << 13),
eFrameIndexCompletion = (1u << 14),
eModuleUUIDCompletion = (1u << 15),
eStopHookIDCompletion = (1u << 16),
eThreadIndexCompletion = (1u << 17),
eWatchpointIDCompletion = (1u << 18),
eBreakpointNameCompletion = (1u << 19),
eProcessIDCompletion = (1u << 20),
eProcessNameCompletion = (1u << 21),
eRemoteDiskFileCompletion = (1u << 22),
eRemoteDiskDirectoryCompletion = (1u << 23),
eTypeCategoryNameCompletion = (1u << 24),
// This item serves two purposes. It is the last element in the enum, so
// you can add custom enums starting from here in your Option class. Also
// if you & in this bit the base code will not process the option.
eCustomCompletion = (1u << 25)
};

} // namespace lldb

#endif // LLDB_LLDB_ENUMERATIONS_H
20 changes: 20 additions & 0 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,26 @@ const char *SBTarget::GetABIName() {
return const_name.GetCString();
}

const char *SBTarget::GetLabel() const {
LLDB_INSTRUMENT_VA(this);

TargetSP target_sp(GetSP());
if (!target_sp)
return nullptr;

return ConstString(target_sp->GetLabel().data()).AsCString();
}

SBError SBTarget::SetLabel(const char *label) {
LLDB_INSTRUMENT_VA(this, label);

TargetSP target_sp(GetSP());
if (!target_sp)
return Status("Couldn't get internal target object.");

return Status(target_sp->SetLabel(label));
}

uint32_t SBTarget::GetDataByteSize() {
LLDB_INSTRUMENT_VA(this);

Expand Down
68 changes: 38 additions & 30 deletions lldb/source/Commands/CommandCompletions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,41 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
bool handled = false;

const CommonCompletionElement common_completions[] = {
{eSourceFileCompletion, CommandCompletions::SourceFiles},
{eDiskFileCompletion, CommandCompletions::DiskFiles},
{eDiskDirectoryCompletion, CommandCompletions::DiskDirectories},
{eSymbolCompletion, CommandCompletions::Symbols},
{eModuleCompletion, CommandCompletions::Modules},
{eModuleUUIDCompletion, CommandCompletions::ModuleUUIDs},
{eSettingsNameCompletion, CommandCompletions::SettingsNames},
{ePlatformPluginCompletion, CommandCompletions::PlatformPluginNames},
{eArchitectureCompletion, CommandCompletions::ArchitectureNames},
{eVariablePathCompletion, CommandCompletions::VariablePath},
{eRegisterCompletion, CommandCompletions::Registers},
{eBreakpointCompletion, CommandCompletions::Breakpoints},
{eProcessPluginCompletion, CommandCompletions::ProcessPluginNames},
{eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors},
{eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
{eFrameIndexCompletion, CommandCompletions::FrameIndexes},
{eStopHookIDCompletion, CommandCompletions::StopHookIDs},
{eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
{eWatchPointIDCompletion, CommandCompletions::WatchPointIDs},
{eBreakpointNameCompletion, CommandCompletions::BreakpointNames},
{eProcessIDCompletion, CommandCompletions::ProcessIDs},
{eProcessNameCompletion, CommandCompletions::ProcessNames},
{eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
{eRemoteDiskDirectoryCompletion,
{lldb::eSourceFileCompletion, CommandCompletions::SourceFiles},
{lldb::eDiskFileCompletion, CommandCompletions::DiskFiles},
{lldb::eDiskDirectoryCompletion, CommandCompletions::DiskDirectories},
{lldb::eSymbolCompletion, CommandCompletions::Symbols},
{lldb::eModuleCompletion, CommandCompletions::Modules},
{lldb::eModuleUUIDCompletion, CommandCompletions::ModuleUUIDs},
{lldb::eSettingsNameCompletion, CommandCompletions::SettingsNames},
{lldb::ePlatformPluginCompletion,
CommandCompletions::PlatformPluginNames},
{lldb::eArchitectureCompletion, CommandCompletions::ArchitectureNames},
{lldb::eVariablePathCompletion, CommandCompletions::VariablePath},
{lldb::eRegisterCompletion, CommandCompletions::Registers},
{lldb::eBreakpointCompletion, CommandCompletions::Breakpoints},
{lldb::eProcessPluginCompletion, CommandCompletions::ProcessPluginNames},
{lldb::eDisassemblyFlavorCompletion,
CommandCompletions::DisassemblyFlavors},
{lldb::eTypeLanguageCompletion, CommandCompletions::TypeLanguages},
{lldb::eFrameIndexCompletion, CommandCompletions::FrameIndexes},
{lldb::eStopHookIDCompletion, CommandCompletions::StopHookIDs},
{lldb::eThreadIndexCompletion, CommandCompletions::ThreadIndexes},
{lldb::eWatchpointIDCompletion, CommandCompletions::WatchPointIDs},
{lldb::eBreakpointNameCompletion, CommandCompletions::BreakpointNames},
{lldb::eProcessIDCompletion, CommandCompletions::ProcessIDs},
{lldb::eProcessNameCompletion, CommandCompletions::ProcessNames},
{lldb::eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
{lldb::eRemoteDiskDirectoryCompletion,
CommandCompletions::RemoteDiskDirectories},
{eTypeCategoryNameCompletion, CommandCompletions::TypeCategoryNames},
{eNoCompletion, nullptr} // This one has to be last in the list.
{lldb::eTypeCategoryNameCompletion,
CommandCompletions::TypeCategoryNames},
{lldb::CompletionType::eNoCompletion,
nullptr} // This one has to be last in the list.
};

for (int i = 0;; i++) {
if (common_completions[i].type == eNoCompletion)
if (common_completions[i].type == lldb::eNoCompletion)
break;
else if ((common_completions[i].type & completion_mask) ==
common_completions[i].type &&
Expand Down Expand Up @@ -377,6 +381,8 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
Storage.append(RemainderDir);
}
SearchDir = Storage;
} else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
SearchDir = CompletionBuffer;
} else {
SearchDir = path::parent_path(CompletionBuffer);
}
Expand All @@ -386,9 +392,11 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
PartialItem = path::filename(CompletionBuffer);

// path::filename() will return "." when the passed path ends with a
// directory separator. We have to filter those out, but only when the
// "." doesn't come from the completion request itself.
if (PartialItem == "." && path::is_separator(CompletionBuffer.back()))
// directory separator or the separator when passed the disk root directory.
// We have to filter those out, but only when the "." doesn't come from the
// completion request itself.
if ((PartialItem == "." || PartialItem == path::get_separator()) &&
path::is_separator(CompletionBuffer.back()))
PartialItem = llvm::StringRef();

if (SearchDir.empty()) {
Expand Down
40 changes: 16 additions & 24 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,8 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -902,9 +901,8 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -1017,9 +1015,8 @@ the second re-enables the first location.");
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -1394,9 +1391,8 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -1803,9 +1799,8 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down Expand Up @@ -1887,9 +1882,8 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down Expand Up @@ -2203,9 +2197,8 @@ class CommandObjectBreakpointRead : public CommandObjectParsed {

switch (GetDefinitions()[opt_defs_index].short_option) {
case 'f':
CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, CommandCompletions::eDiskFileCompletion, request,
nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, lldb::eDiskFileCompletion, request, nullptr);
break;

case 'N':
Expand Down Expand Up @@ -2343,9 +2336,8 @@ class CommandObjectBreakpointWrite : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eBreakpointCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eBreakpointCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down
75 changes: 56 additions & 19 deletions lldb/source/Commands/CommandObjectCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ class CommandObjectCommandsSource : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -1080,9 +1079,10 @@ class CommandObjectPythonFunction : public CommandObjectRaw {
public:
CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name,
std::string funct, std::string help,
ScriptedCommandSynchronicity synch)
ScriptedCommandSynchronicity synch,
CompletionType completion_type)
: CommandObjectRaw(interpreter, name), m_function_name(funct),
m_synchro(synch) {
m_synchro(synch), m_completion_type(completion_type) {
if (!help.empty())
SetHelp(help);
else {
Expand Down Expand Up @@ -1116,6 +1116,15 @@ class CommandObjectPythonFunction : public CommandObjectRaw {
return CommandObjectRaw::GetHelpLong();
}

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), m_completion_type, request, nullptr);
}

bool WantsCompletion() override { return true; }

protected:
bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
Expand Down Expand Up @@ -1146,17 +1155,19 @@ class CommandObjectPythonFunction : public CommandObjectRaw {
std::string m_function_name;
ScriptedCommandSynchronicity m_synchro;
bool m_fetched_help_long = false;
CompletionType m_completion_type = eNoCompletion;
};

class CommandObjectScriptingObject : public CommandObjectRaw {
public:
CommandObjectScriptingObject(CommandInterpreter &interpreter,
std::string name,
StructuredData::GenericSP cmd_obj_sp,
ScriptedCommandSynchronicity synch)
ScriptedCommandSynchronicity synch,
CompletionType completion_type)
: CommandObjectRaw(interpreter, name), m_cmd_obj_sp(cmd_obj_sp),
m_synchro(synch), m_fetched_help_short(false),
m_fetched_help_long(false) {
m_fetched_help_long(false), m_completion_type(completion_type) {
StreamString stream;
stream.Printf("For more information run 'help %s'", name.c_str());
SetHelp(stream.GetString());
Expand All @@ -1166,6 +1177,15 @@ class CommandObjectScriptingObject : public CommandObjectRaw {

~CommandObjectScriptingObject() override = default;

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), m_completion_type, request, nullptr);
}

bool WantsCompletion() override { return true; }

bool IsRemovable() const override { return true; }

ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; }
Expand Down Expand Up @@ -1232,6 +1252,7 @@ class CommandObjectScriptingObject : public CommandObjectRaw {
ScriptedCommandSynchronicity m_synchro;
bool m_fetched_help_short : 1;
bool m_fetched_help_long : 1;
CompletionType m_completion_type = eNoCompletion;
};

// CommandObjectCommandsScriptImport
Expand Down Expand Up @@ -1263,9 +1284,8 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -1439,6 +1459,18 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
"unrecognized value for synchronicity '%s'",
option_arg.str().c_str());
break;
case 'C': {
Status error;
OptionDefinition definition = GetDefinitions()[option_idx];
lldb::CompletionType completion_type =
static_cast<lldb::CompletionType>(OptionArgParser::ToOptionEnum(
option_arg, definition.enum_values, eNoCompletion, error));
if (!error.Success())
error.SetErrorStringWithFormat(
"unrecognized value for command completion type '%s'",
option_arg.str().c_str());
m_completion_type = completion_type;
} break;
default:
llvm_unreachable("Unimplemented option");
}
Expand All @@ -1450,6 +1482,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
m_class_name.clear();
m_funct_name.clear();
m_short_help.clear();
m_completion_type = eNoCompletion;
m_overwrite_lazy = eLazyBoolCalculate;
m_synchronicity = eScriptedCommandSynchronicitySynchronous;
}
Expand All @@ -1466,6 +1499,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
LazyBool m_overwrite_lazy = eLazyBoolCalculate;
ScriptedCommandSynchronicity m_synchronicity =
eScriptedCommandSynchronicitySynchronous;
CompletionType m_completion_type = eNoCompletion;
};

void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
Expand Down Expand Up @@ -1496,7 +1530,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,

CommandObjectSP command_obj_sp(new CommandObjectPythonFunction(
m_interpreter, m_cmd_name, funct_name_str, m_short_help,
m_synchronicity));
m_synchronicity, m_completion_type));
if (!m_container) {
Status error = m_interpreter.AddUserCommand(
m_cmd_name, command_obj_sp, m_overwrite);
Expand Down Expand Up @@ -1577,6 +1611,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,

m_short_help.assign(m_options.m_short_help);
m_synchronicity = m_options.m_synchronicity;
m_completion_type = m_options.m_completion_type;

// Handle the case where we prompt for the script code first:
if (m_options.m_class_name.empty() && m_options.m_funct_name.empty()) {
Expand All @@ -1589,7 +1624,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
if (m_options.m_class_name.empty()) {
new_cmd_sp.reset(new CommandObjectPythonFunction(
m_interpreter, m_cmd_name, m_options.m_funct_name,
m_options.m_short_help, m_synchronicity));
m_options.m_short_help, m_synchronicity, m_completion_type));
} else {
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
Expand All @@ -1606,7 +1641,8 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
}

new_cmd_sp.reset(new CommandObjectScriptingObject(
m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity));
m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity,
m_completion_type));
}

// Assume we're going to succeed...
Expand Down Expand Up @@ -1634,6 +1670,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
bool m_overwrite = false;
ScriptedCommandSynchronicity m_synchronicity =
eScriptedCommandSynchronicitySynchronous;
CompletionType m_completion_type = eNoCompletion;
};

// CommandObjectCommandsScriptList
Expand Down Expand Up @@ -1706,8 +1743,8 @@ class CommandObjectCommandsScriptDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
opt_element_vector);
lldb_private::CommandCompletions::CompleteModifiableCmdPathArgs(
m_interpreter, request, opt_element_vector);
}

protected:
Expand Down Expand Up @@ -1857,8 +1894,8 @@ class CommandObjectCommandsContainerAdd : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
opt_element_vector);
lldb_private::CommandCompletions::CompleteModifiableCmdPathArgs(
m_interpreter, request, opt_element_vector);
}

protected:
Expand Down Expand Up @@ -1997,8 +2034,8 @@ class CommandObjectCommandsContainerDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::CompleteModifiableCmdPathArgs(m_interpreter, request,
opt_element_vector);
lldb_private::CommandCompletions::CompleteModifiableCmdPathArgs(
m_interpreter, request, opt_element_vector);
}

protected:
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Commands/CommandObjectDWIMPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; }

void CommandObjectDWIMPrint::HandleArgumentCompletion(
CompletionRequest &request, OptionElementVector &opt_element_vector) {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eVariablePathCompletion, request, nullptr);
}

bool CommandObjectDWIMPrint::DoExecute(StringRef command,
Expand Down
11 changes: 5 additions & 6 deletions lldb/source/Commands/CommandObjectFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ class CommandObjectFrameSelect : public CommandObjectParsed {
if (request.GetCursorIndex() != 0)
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eFrameIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eFrameIndexCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -445,9 +444,9 @@ may even involve JITing and running code in the target program.)");
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
// Arguments are the standard source file completer.
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eVariablePathCompletion, request,
nullptr);
}

protected:
Expand Down
63 changes: 29 additions & 34 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class CommandObjectPlatformSelect : public CommandObjectParsed {
~CommandObjectPlatformSelect() override = default;

void HandleCompletion(CompletionRequest &request) override {
CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request,
nullptr);
lldb_private::CommandCompletions::PlatformPluginNames(
GetCommandInterpreter(), request, nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down Expand Up @@ -385,8 +385,7 @@ class CommandObjectPlatformSettings : public CommandObjectParsed {
"Set settings for the current target's platform.",
"platform settings", 0),
m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w',
CommandCompletions::eRemoteDiskDirectoryCompletion,
eArgTypePath,
lldb::eRemoteDiskDirectoryCompletion, eArgTypePath,
"The working directory for the platform.") {
m_options.Append(&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
}
Expand Down Expand Up @@ -484,9 +483,9 @@ class CommandObjectPlatformFOpen : public CommandObjectParsed {
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -831,13 +830,12 @@ class CommandObjectPlatformGetFile : public CommandObjectParsed {
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
else if (request.GetCursorIndex() == 1)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -907,9 +905,9 @@ class CommandObjectPlatformGetSize : public CommandObjectParsed {
if (request.GetCursorIndex() != 0)
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eRemoteDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -978,9 +976,9 @@ class CommandObjectPlatformGetPermissions : public CommandObjectParsed {
if (request.GetCursorIndex() != 0)
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eRemoteDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -1048,9 +1046,9 @@ class CommandObjectPlatformFileExists : public CommandObjectParsed {
if (request.GetCursorIndex() != 0)
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eRemoteDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -1107,13 +1105,12 @@ class CommandObjectPlatformPutFile : public CommandObjectParsed {
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
else if (request.GetCursorIndex() == 1)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request,
nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down Expand Up @@ -1523,9 +1520,8 @@ class CommandObjectPlatformProcessInfo : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eProcessIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eProcessIDCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -1834,9 +1830,8 @@ class CommandObjectPlatformInstall : public CommandObjectParsed {
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex())
return;
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Commands/CommandObjectPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ class CommandObjectPluginLoad : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

protected:
Expand Down
10 changes: 4 additions & 6 deletions lldb/source/Commands/CommandObjectProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_all_options; }
Expand Down Expand Up @@ -1026,9 +1025,8 @@ class CommandObjectProcessLoad : public CommandObjectParsed {
if (!m_exe_ctx.HasProcessScope())
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectRegexCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool CommandObjectRegexCommand::AddRegexCommand(llvm::StringRef re_cstr,

void CommandObjectRegexCommand::HandleCompletion(CompletionRequest &request) {
if (m_completion_type_mask) {
CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), m_completion_type_mask, request, nullptr);
}
}
10 changes: 4 additions & 6 deletions lldb/source/Commands/CommandObjectRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
if (!m_exe_ctx.HasProcessScope())
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eRegisterCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRegisterCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down Expand Up @@ -342,9 +341,8 @@ class CommandObjectRegisterWrite : public CommandObjectParsed {
if (!m_exe_ctx.HasProcessScope() || request.GetCursorIndex() != 0)
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eRegisterCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eRegisterCompletion, request, nullptr);
}

protected:
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Commands/CommandObjectSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ class CommandObjectSessionSave : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

protected:
Expand Down
54 changes: 27 additions & 27 deletions lldb/source/Commands/CommandObjectSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ insert-before or insert-after.");
}
if (request.GetCursorIndex() == setting_var_idx) {
// Attempting to complete setting variable name
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
return;
}
arg = request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex());
Expand Down Expand Up @@ -267,9 +267,9 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -511,9 +511,9 @@ class CommandObjectSettingsList : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -595,9 +595,9 @@ class CommandObjectSettingsRemove : public CommandObjectRaw {
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -703,9 +703,9 @@ class CommandObjectSettingsReplace : public CommandObjectRaw {
OptionElementVector &opt_element_vector) override {
// Attempting to complete variable name
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -795,9 +795,9 @@ class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
OptionElementVector &opt_element_vector) override {
// Attempting to complete variable name
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -891,9 +891,9 @@ class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
OptionElementVector &opt_element_vector) override {
// Attempting to complete variable name
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -976,9 +976,9 @@ class CommandObjectSettingsAppend : public CommandObjectRaw {
OptionElementVector &opt_element_vector) override {
// Attempting to complete variable name
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -1051,9 +1051,9 @@ class CommandObjectSettingsClear : public CommandObjectParsed {
OptionElementVector &opt_element_vector) override {
// Attempting to complete variable name
if (request.GetCursorIndex() < 2)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSettingsNameCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down
95 changes: 62 additions & 33 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target,
if (!exe_valid)
::strcpy(exe_path, "<none>");

strm.Printf("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx,
exe_path);
std::string formatted_label = "";
const std::string &label = target->GetLabel();
if (!label.empty()) {
formatted_label = " (" + label + ")";
}

strm.Printf("%starget #%u%s: %s", prefix_cstr ? prefix_cstr : "", target_idx,
formatted_label.data(), exe_path);

uint32_t properties = 0;
if (target_arch.IsValid()) {
Expand Down Expand Up @@ -209,6 +215,8 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
m_platform_options(true), // Include the --platform option.
m_core_file(LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename,
"Fullpath to a core file to use for this target."),
m_label(LLDB_OPT_SET_1, false, "label", 'l', 0, eArgTypeName,
"Optional name for this target.", nullptr),
m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
eArgTypeFilename,
"Fullpath to a stand alone debug "
Expand All @@ -234,6 +242,7 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
m_option_group.Append(&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
m_option_group.Append(&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_label, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_remote_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Expand All @@ -247,9 +256,8 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -303,6 +311,14 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
return false;
}

const llvm::StringRef label =
m_label.GetOptionValue().GetCurrentValueAsRef();
if (!label.empty()) {
if (auto E = target_sp->SetLabel(label))
result.SetError(std::move(E));
return false;
}

auto on_error = llvm::make_scope_exit(
[&target_list = debugger.GetTargetList(), &target_sp]() {
target_list.DeleteTarget(target_sp);
Expand Down Expand Up @@ -455,6 +471,7 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
OptionGroupArchitecture m_arch_option;
OptionGroupPlatform m_platform_options;
OptionGroupFile m_core_file;
OptionGroupString m_label;
OptionGroupFile m_symbol_file;
OptionGroupFile m_remote_file;
OptionGroupDependents m_add_dependents;
Expand Down Expand Up @@ -503,11 +520,11 @@ class CommandObjectTargetSelect : public CommandObjectParsed {
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() == 1) {
const char *target_idx_arg = args.GetArgumentAtIndex(0);
uint32_t target_idx;
if (llvm::to_integer(target_idx_arg, target_idx)) {
TargetList &target_list = GetDebugger().GetTargetList();
const uint32_t num_targets = target_list.GetNumTargets();
const char *target_identifier = args.GetArgumentAtIndex(0);
uint32_t target_idx = LLDB_INVALID_INDEX32;
TargetList &target_list = GetDebugger().GetTargetList();
const uint32_t num_targets = target_list.GetNumTargets();
if (llvm::to_integer(target_identifier, target_idx)) {
if (target_idx < num_targets) {
target_list.SetSelectedTarget(target_idx);
Stream &strm = result.GetOutputStream();
Expand All @@ -526,8 +543,26 @@ class CommandObjectTargetSelect : public CommandObjectParsed {
}
}
} else {
result.AppendErrorWithFormat("invalid index string value '%s'\n",
target_idx_arg);
for (size_t i = 0; i < num_targets; i++) {
if (TargetSP target_sp = target_list.GetTargetAtIndex(i)) {
const std::string &label = target_sp->GetLabel();
if (!label.empty() && label == target_identifier) {
target_idx = i;
break;
}
}
}

if (target_idx != LLDB_INVALID_INDEX32) {
target_list.SetSelectedTarget(target_idx);
Stream &strm = result.GetOutputStream();
bool show_stopped_process_status = false;
DumpTargetList(target_list, show_stopped_process_status, strm);
result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
result.AppendErrorWithFormat("invalid index string value '%s'\n",
target_identifier);
}
}
} else {
result.AppendError(
Expand Down Expand Up @@ -576,7 +611,7 @@ class CommandObjectTargetDelete : public CommandObjectParsed {
TargetSP target_sp;

if (m_all_option.GetOptionValue()) {
for (int i = 0; i < target_list.GetNumTargets(); ++i)
for (size_t i = 0; i < target_list.GetNumTargets(); ++i)
delete_target_list.push_back(target_list.GetTargetAtIndex(i));
} else if (argc > 0) {
const uint32_t num_targets = target_list.GetNumTargets();
Expand Down Expand Up @@ -1810,9 +1845,8 @@ class CommandObjectTargetModulesModuleAutoComplete
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eModuleCompletion, request,
nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eModuleCompletion, request, nullptr);
}
};

Expand Down Expand Up @@ -1848,9 +1882,8 @@ class CommandObjectTargetModulesSourceFileAutoComplete
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSourceFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eSourceFileCompletion, request, nullptr);
}
};

Expand Down Expand Up @@ -2495,9 +2528,8 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -4026,8 +4058,8 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
"target symbols add <cmd-options> [<symfile>]",
eCommandRequiresTarget),
m_file_option(
LLDB_OPT_SET_1, false, "shlib", 's',
CommandCompletions::eModuleCompletion, eArgTypeShlibName,
LLDB_OPT_SET_1, false, "shlib", 's', lldb::eModuleCompletion,
eArgTypeShlibName,
"Locate the debug symbols for the shared library specified by "
"name."),
m_current_frame_option(
Expand Down Expand Up @@ -4057,9 +4089,8 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down Expand Up @@ -4908,9 +4939,8 @@ class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eStopHookIDCompletion, request, nullptr);
}

protected:
Expand Down Expand Up @@ -4966,9 +4996,8 @@ class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex())
return;
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eStopHookIDCompletion, request, nullptr);
}

protected:
Expand Down
36 changes: 18 additions & 18 deletions lldb/source/Commands/CommandObjectThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
if (request.GetCursorIndex())
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_all_options; }
Expand Down Expand Up @@ -664,9 +664,9 @@ class CommandObjectThreadContinue : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

bool DoExecute(Args &command, CommandReturnObject &result) override {
Expand Down Expand Up @@ -1161,9 +1161,9 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
if (request.GetCursorIndex())
return;

CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -1295,9 +1295,9 @@ class CommandObjectThreadInfo : public CommandObjectIterateOverThreads {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -1345,9 +1345,9 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
Expand Down Expand Up @@ -1393,9 +1393,9 @@ class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eThreadIndexCompletion, request,
nullptr);
}

bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
Expand Down
10 changes: 4 additions & 6 deletions lldb/source/Commands/CommandObjectTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ class CommandObjectTraceSave : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

~CommandObjectTraceSave() override = default;
Expand Down Expand Up @@ -186,9 +185,8 @@ class CommandObjectTraceLoad : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
}

~CommandObjectTraceLoad() override = default;
Expand Down
30 changes: 15 additions & 15 deletions lldb/source/Commands/CommandObjectType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,9 +1767,9 @@ class CommandObjectTypeCategoryDefine : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eTypeCategoryNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -1869,9 +1869,9 @@ class CommandObjectTypeCategoryEnable : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eTypeCategoryNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -1937,9 +1937,9 @@ class CommandObjectTypeCategoryDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eTypeCategoryNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -2046,9 +2046,9 @@ class CommandObjectTypeCategoryDisable : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eTypeCategoryNameCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -2111,9 +2111,9 @@ class CommandObjectTypeCategoryList : public CommandObjectParsed {
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex())
return;
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eTypeCategoryNameCompletion, request,
nullptr);
}

protected:
Expand Down
36 changes: 18 additions & 18 deletions lldb/source/Commands/CommandObjectWatchpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ class CommandObjectWatchpointEnable : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -365,9 +365,9 @@ class CommandObjectWatchpointDisable : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request,
nullptr);
}

protected:
Expand Down Expand Up @@ -446,9 +446,9 @@ class CommandObjectWatchpointDelete : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -569,9 +569,9 @@ class CommandObjectWatchpointIgnore : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -694,9 +694,9 @@ class CommandObjectWatchpointModify : public CommandObjectParsed {
void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_options; }
Expand Down Expand Up @@ -846,9 +846,9 @@ corresponding to the byte size of the data type.");
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() != 0)
return;
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
request, nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), lldb::eVariablePathCompletion, request,
nullptr);
}

Options *GetOptions() override { return &m_option_group; }
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ let Command = "script add" in {
EnumArg<"ScriptedCommandSynchronicity">,
Desc<"Set the synchronicity of this command's executions with regard to "
"LLDB event system.">;
def completion_type : Option<"completion-type", "C">,
EnumArg<"CompletionType">,
Desc<"Specify which completion type the command should use - if none is specified, the command won't use auto-completion.">;
}

let Command = "container add" in {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ void IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler,
io_handler.GetDebugger().GetCommandInterpreter().HandleCompletion(request);
break;
case Completion::Expression:
CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
io_handler.GetDebugger().GetCommandInterpreter(),
CommandCompletions::eVariablePathCompletion, request, nullptr);
lldb::eVariablePathCompletion, request, nullptr);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/IOHandlerCursesGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3821,7 +3821,7 @@ class SearcherWindowDelegate : public WindowDelegate {

// This is a searcher delegate wrapper around CommandCompletions common
// callbacks. The callbacks are only given the match string. The completion_mask
// can be a combination of CommonCompletionTypes.
// can be a combination of lldb::CompletionType.
class CommonCompletionSearcherDelegate : public SearcherDelegate {
public:
typedef std::function<void(const std::string &)> CallbackType;
Expand All @@ -3840,7 +3840,7 @@ class CommonCompletionSearcherDelegate : public SearcherDelegate {
void UpdateMatches(const std::string &text) override {
CompletionResult result;
CompletionRequest request(text.c_str(), text.size(), result);
CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
m_debugger.GetCommandInterpreter(), m_completion_mask, request,
nullptr);
result.GetMatches(m_matches);
Expand All @@ -3852,7 +3852,7 @@ class CommonCompletionSearcherDelegate : public SearcherDelegate {

protected:
Debugger &m_debugger;
// A compound mask from CommonCompletionTypes.
// A compound mask from lldb::CompletionType.
uint32_t m_completion_mask;
// A callback to execute once the user selects a match. The match is passed to
// the callback as a string.
Expand Down
10 changes: 3 additions & 7 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,7 @@ void CommandInterpreter::LoadCommandDictionary() {
"current file\n"
" // containing text 'break "
"here'.\n",
CommandCompletions::eSymbolCompletion |
CommandCompletions::eSourceFileCompletion,
false));
lldb::eSymbolCompletion | lldb::eSourceFileCompletion, false));

if (break_regex_cmd_up) {
bool success = true;
Expand Down Expand Up @@ -669,9 +667,7 @@ void CommandInterpreter::LoadCommandDictionary() {
"current file\n"
" // containing text 'break "
"here'.\n",
CommandCompletions::eSymbolCompletion |
CommandCompletions::eSourceFileCompletion,
false));
lldb::eSymbolCompletion | lldb::eSourceFileCompletion, false));

if (tbreak_regex_cmd_up) {
bool success = true;
Expand Down Expand Up @@ -849,7 +845,7 @@ void CommandInterpreter::LoadCommandDictionary() {
"_regexp-list 0x<address> // List around specified address\n"
"_regexp-list -[<count>] // List previous <count> lines\n"
"_regexp-list // List subsequent lines",
CommandCompletions::eSourceFileCompletion, false));
lldb::eSourceFileCompletion, false));
if (list_regex_cmd_up) {
if (list_regex_cmd_up->AddRegexCommand("^([0-9]+)[[:space:]]*$",
"source list --line %1") &&
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Interpreter/OptionValueArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Status OptionValueArch::SetValueFromString(llvm::StringRef value,

void OptionValueArch::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, CommandCompletions::eArchitectureCompletion, request,
nullptr);
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, lldb::eArchitectureCompletion, request, nullptr);
}
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/OptionValueFileColonLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Status OptionValueFileColonLine::SetValueFromString(llvm::StringRef value,

void OptionValueFileColonLine::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, m_completion_mask, request, nullptr);
}
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/OptionValueFileSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Status OptionValueFileSpec::SetValueFromString(llvm::StringRef value,

void OptionValueFileSpec::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, m_completion_mask, request, nullptr);
}

Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Interpreter/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ void Options::HandleOptionArgumentCompletion(
}
}

if (completion_mask & CommandCompletions::eSourceFileCompletion ||
completion_mask & CommandCompletions::eSymbolCompletion) {
if (completion_mask & lldb::eSourceFileCompletion ||
completion_mask & lldb::eSymbolCompletion) {
for (size_t i = 0; i < opt_element_vector.size(); i++) {
int cur_defs_index = opt_element_vector[i].opt_defs_index;

Expand Down Expand Up @@ -748,7 +748,7 @@ void Options::HandleOptionArgumentCompletion(
}
}

CommandCompletions::InvokeCommonCompletionCallbacks(
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, completion_mask, request, filter_up.get());
}

Expand Down
22 changes: 22 additions & 0 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include <memory>
#include <mutex>
#include <optional>
#include <sstream>

using namespace lldb;
using namespace lldb_private;
Expand Down Expand Up @@ -2536,6 +2537,27 @@ void Target::SetDefaultArchitecture(const ArchSpec &arch) {
Target::GetGlobalProperties().SetDefaultArchitecture(arch);
}

llvm::Error Target::SetLabel(llvm::StringRef label) {
size_t n = LLDB_INVALID_INDEX32;
if (llvm::to_integer(label, n))
return llvm::make_error<llvm::StringError>(
"Cannot use integer as target label.", llvm::inconvertibleErrorCode());
TargetList &targets = GetDebugger().GetTargetList();
for (size_t i = 0; i < targets.GetNumTargets(); i++) {
TargetSP target_sp = targets.GetTargetAtIndex(i);
if (target_sp && target_sp->GetLabel() == label) {
return llvm::make_error<llvm::StringError>(
llvm::formatv(
"Cannot use label '{0}' since it's set in target #{1}.", label,
i),
llvm::inconvertibleErrorCode());
}
}

m_label = label.str();
return llvm::Error::success();
}

Target *Target::GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr,
const SymbolContext *sc_ptr) {
// The target can either exist in the "process" of ExecutionContext, or in
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/TargetList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ uint32_t TargetList::SignalIfRunning(lldb::pid_t pid, int signo) {
return num_signals_sent;
}

int TargetList::GetNumTargets() const {
size_t TargetList::GetNumTargets() const {
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
return m_target_list.size();
}
Expand Down
54 changes: 54 additions & 0 deletions lldb/test/API/functionalities/completion/TestCompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,60 @@ def test_target_modules_dump_line_table(self):
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
self.complete_from_to("target modules dump line-table main.cp", ["main.cpp"])

def test_custom_command_completion(self):
"""Tests completion in custom user provided commands."""
completion_types = [
"none",
"source-file",
"disk-file",
"disk-directory",
"symbol",
"module",
"settings-name",
"platform-plugin",
"architecture",
"variable-path",
"register",
"breakpoint",
"process-plugin",
"disassembly-flavor",
"type-language",
"frame-index",
"module-uuid",
"stophook-id",
"thread-index",
"watchpoint-id",
"breakpoint-name",
"process-id",
"process-name",
"remote-disk-file",
"remote-disk-directory",
"type-category-name",
"custom",
]
self.completions_contain("command script add -C ", completion_types)

source_path = os.path.join(self.getSourceDir(), "my_test_cmd.py")
self.runCmd("command script import '%s'" % (source_path))
self.runCmd(
"command script add -C disk-file -f my_test_cmd.my_test_cmd my_test_cmd"
)
self.complete_from_to("my_test_cmd main.cp", ["main.cpp"])
self.expect("my_test_cmd main.cpp", substrs=["main.cpp"])

def test_completion_target_create_from_root_dir(self):
"""Tests source file completion by completing ."""
root_dir = os.path.abspath(os.sep)
self.completions_contain(
"target create " + root_dir,
list(
filter(
lambda x: os.path.exists(x),
map(lambda x: root_dir + x + os.sep, os.listdir(root_dir)),
)
),
)

def test_target_modules_load_aout(self):
"""Tests modules completion by completing the target modules load argument."""
self.build()
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/functionalities/completion/my_test_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def my_test_cmd(debugger, command, exe_ctx, result, dict):
result.Print(command)
38 changes: 38 additions & 0 deletions lldb/test/Shell/Target/target-label.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# RUN: %lldb -b -o 'settings set interpreter.stop-command-source-on-error false' -s %s 2>&1 | FileCheck %s

target create -l "ls" /bin/ls
target list
# CHECK: * target #0 (ls): /bin/ls

script lldb.target.SetLabel("")
target list
# CHECK: * target #0: /bin/ls

target create -l "cat" /bin/cat
target list
# CHECK: target #0: /bin/ls
# CHECK-NEXT: * target #1 (cat): /bin/cat

target create -l "cat" /bin/cat
# CHECK: Cannot use label 'cat' since it's set in target #1.

target create -l 42 /bin/cat
# CHECK: error: Cannot use integer as target label.

target select 0
# CHECK: * target #0: /bin/ls
# CHECK-NEXT: target #1 (cat): /bin/cat

target select cat
# CHECK: target #0: /bin/ls
# CHECK-NEXT: * target #1 (cat): /bin/cat

script lldb.target.GetLabel()
# CHECK: 'cat'

script lldb.debugger.GetTargetAtIndex(0).SetLabel('Not cat')
# CHECK: success

target list
# CHECK: target #0 (Not cat): /bin/ls
# CHECK-NEXT: * target #1 (cat): /bin/cat
5 changes: 2 additions & 3 deletions lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ static void emitOption(const CommandOption &O, raw_ostream &OS) {
if (!O.Completions.empty()) {
std::vector<std::string> CompletionArgs;
for (llvm::StringRef Completion : O.Completions)
CompletionArgs.push_back("CommandCompletions::e" + Completion.str() +
"Completion");
CompletionArgs.push_back("e" + Completion.str() + "Completion");

OS << llvm::join(CompletionArgs.begin(), CompletionArgs.end(), " | ");
} else
OS << "CommandCompletions::eNoCompletion";
OS << "CompletionType::eNoCompletion";

// Add the argument type.
OS << ", eArgType";
Expand Down