Skip to content

Start to clean up the process of defining command arguments. #83097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lldb/include/lldb/Interpreter/CommandObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
static const ArgumentTableEntry *
FindArgumentDataByType(lldb::CommandArgumentType arg_type);

// Sets the argument list for this command to one homogenous argument type,
// with the repeat specified.
void AddSimpleArgumentList(
lldb::CommandArgumentType arg_type,
ArgumentRepetitionType repetition_type = eArgRepeatPlain);

// Helper function to set BP IDs or ID ranges as the command argument data
// for this command.
// This used to just populate an entry you could add to, but that was never
// used. If we ever need that we can take optional extra args here.
// Use this to define a simple argument list:
enum IDType { eBreakpointArgs = 0, eWatchpointArgs = 1 };
void AddIDsArgumentData(IDType type);

int GetNumArgumentEntries();

CommandArgumentEntry *GetArgumentEntryAtIndex(int idx);
Expand Down Expand Up @@ -391,12 +405,6 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
lldb_private::CommandOverrideCallbackWithResult m_command_override_callback;
void *m_command_override_baton;
bool m_is_user_command = false;

// Helper function to populate IDs or ID ranges as the command argument data
// to the specified command argument entry.
static void AddIDsArgumentData(CommandArgumentEntry &arg,
lldb::CommandArgumentType ID,
lldb::CommandArgumentType IDRange);
};

class CommandObjectParsed : public CommandObject {
Expand Down
14 changes: 1 addition & 13 deletions lldb/source/Commands/CommandObjectApropos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@ CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "apropos",
"List debugger commands related to a word or subject.", nullptr) {
CommandArgumentEntry arg;
CommandArgumentData search_word_arg;

// Define the first (and only) variant of this arg.
search_word_arg.arg_type = eArgTypeSearchWord;
search_word_arg.arg_repetition = eArgRepeatPlain;

// There is only one variant this argument could be; put it into the argument
// entry.
arg.push_back(search_word_arg);

// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back(arg);
AddSimpleArgumentList(eArgTypeSearchWord);
}

CommandObjectApropos::~CommandObjectApropos() = default;
Expand Down
72 changes: 9 additions & 63 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,7 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
"With the exception of -e, -d and -i, passing an "
"empty argument clears the modification.",
nullptr) {
CommandArgumentEntry arg;
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
eArgTypeBreakpointIDRange);
// Add the entry for the first argument for this command to the object's
// arguments vector.
m_arguments.push_back(arg);
CommandObject::AddIDsArgumentData(eBreakpointArgs);

m_options.Append(&m_bp_opts,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
Expand Down Expand Up @@ -887,12 +882,7 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
"Enable the specified disabled breakpoint(s). If "
"no breakpoints are specified, enable all of them.",
nullptr) {
CommandArgumentEntry arg;
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
eArgTypeBreakpointIDRange);
// Add the entry for the first argument for this command to the object's
// arguments vector.
m_arguments.push_back(arg);
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}

~CommandObjectBreakpointEnable() override = default;
Expand Down Expand Up @@ -999,12 +989,7 @@ execution will NOT stop at location 1.1. To achieve that, type:
"The first command disables all locations for breakpoint 1, \
the second re-enables the first location.");

CommandArgumentEntry arg;
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
eArgTypeBreakpointIDRange);
// Add the entry for the first argument for this command to the object's
// arguments vector.
m_arguments.push_back(arg);
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}

~CommandObjectBreakpointDisable() override = default;
Expand Down Expand Up @@ -1095,15 +1080,7 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
CommandArgumentData bp_id_arg;

// Define the first (and only) variant of this arg.
bp_id_arg.arg_type = eArgTypeBreakpointID;
bp_id_arg.arg_repetition = eArgRepeatOptional;

// There is only one variant this argument could be; put it into the
// argument entry.
arg.push_back(bp_id_arg);

// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back(arg);
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
}

~CommandObjectBreakpointList() override = default;
Expand Down Expand Up @@ -1369,12 +1346,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
"Delete the specified breakpoint(s). If no "
"breakpoints are specified, delete them all.",
nullptr) {
CommandArgumentEntry arg;
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
eArgTypeBreakpointIDRange);
// Add the entry for the first argument for this command to the object's
// arguments vector.
m_arguments.push_back(arg);
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}

~CommandObjectBreakpointDelete() override = default;
Expand Down Expand Up @@ -1676,14 +1648,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
"on the name.",
"breakpoint name configure <command-options> "
"<breakpoint-name-list>") {
// Create the first variant for the first (and only) argument for this
// command.
CommandArgumentEntry arg1;
CommandArgumentData id_arg;
id_arg.arg_type = eArgTypeBreakpointName;
id_arg.arg_repetition = eArgRepeatOptional;
arg1.push_back(id_arg);
m_arguments.push_back(arg1);
AddSimpleArgumentList(eArgTypeBreakpointName, eArgRepeatOptional);

m_option_group.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_access_options, LLDB_OPT_SET_ALL,
Expand Down Expand Up @@ -1769,14 +1734,7 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
: CommandObjectParsed(
interpreter, "add", "Add a name to the breakpoints provided.",
"breakpoint name add <command-options> <breakpoint-id-list>") {
// Create the first variant for the first (and only) argument for this
// command.
CommandArgumentEntry arg1;
CommandArgumentData id_arg;
id_arg.arg_type = eArgTypeBreakpointID;
id_arg.arg_repetition = eArgRepeatOptional;
arg1.push_back(id_arg);
m_arguments.push_back(arg1);
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);

m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
Expand Down Expand Up @@ -1850,14 +1808,7 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
interpreter, "delete",
"Delete a name from the breakpoints provided.",
"breakpoint name delete <command-options> <breakpoint-id-list>") {
// Create the first variant for the first (and only) argument for this
// command.
CommandArgumentEntry arg1;
CommandArgumentData id_arg;
id_arg.arg_type = eArgTypeBreakpointID;
id_arg.arg_repetition = eArgRepeatOptional;
arg1.push_back(id_arg);
m_arguments.push_back(arg1);
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);

m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
Expand Down Expand Up @@ -2305,12 +2256,7 @@ class CommandObjectBreakpointWrite : public CommandObjectParsed {
"be read in with \"breakpoint read\". "
"If given no arguments, writes all breakpoints.",
nullptr) {
CommandArgumentEntry arg;
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
eArgTypeBreakpointIDRange);
// Add the entry for the first argument for this command to the object's
// arguments vector.
m_arguments.push_back(arg);
CommandObject::AddIDsArgumentData(eBreakpointArgs);
}

~CommandObjectBreakpointWrite() override = default;
Expand Down
42 changes: 3 additions & 39 deletions lldb/source/Commands/CommandObjectBreakpointCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,7 @@ are no syntax errors may indicate that a function was declared but never called.
LLDB_OPT_SET_2);
m_all_options.Finalize();

CommandArgumentEntry arg;
CommandArgumentData bp_id_arg;

// Define the first (and only) variant of this arg.
bp_id_arg.arg_type = eArgTypeBreakpointID;
bp_id_arg.arg_repetition = eArgRepeatOptional;

// There is only one variant this argument could be; put it into the
// argument entry.
arg.push_back(bp_id_arg);

// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back(arg);
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
}

~CommandObjectBreakpointCommandAdd() override = default;
Expand Down Expand Up @@ -449,19 +437,7 @@ class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
: CommandObjectParsed(interpreter, "delete",
"Delete the set of commands from a breakpoint.",
nullptr) {
CommandArgumentEntry arg;
CommandArgumentData bp_id_arg;

// Define the first (and only) variant of this arg.
bp_id_arg.arg_type = eArgTypeBreakpointID;
bp_id_arg.arg_repetition = eArgRepeatPlain;

// There is only one variant this argument could be; put it into the
// argument entry.
arg.push_back(bp_id_arg);

// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back(arg);
AddSimpleArgumentList(eArgTypeBreakpointID);
}

~CommandObjectBreakpointCommandDelete() override = default;
Expand Down Expand Up @@ -565,19 +541,7 @@ class CommandObjectBreakpointCommandList : public CommandObjectParsed {
"List the script or set of commands to be "
"executed when the breakpoint is hit.",
nullptr, eCommandRequiresTarget) {
CommandArgumentEntry arg;
CommandArgumentData bp_id_arg;

// Define the first (and only) variant of this arg.
bp_id_arg.arg_type = eArgTypeBreakpointID;
bp_id_arg.arg_repetition = eArgRepeatPlain;

// There is only one variant this argument could be; put it into the
// argument entry.
arg.push_back(bp_id_arg);

// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back(arg);
AddSimpleArgumentList(eArgTypeBreakpointID);
}

~CommandObjectBreakpointCommandList() override = default;
Expand Down
Loading