Skip to content

Commit 2d704f4

Browse files
authored
Start to clean up the process of defining command arguments. (llvm#83097)
Partly, there's just a lot of unnecessary boiler plate. It's also possible to define combinations of arguments that make no sense (e.g. eArgRepeatPlus followed by eArgRepeatPlain...) but these are never checked since we just push_back directly into the argument definitions. This commit is step 1 of this cleanup - do the obvious stuff. In it, all the simple homogenous argument lists and the breakpoint/watchpoint ID/Range types, are set with common functions. This is an NFC change, it just centralizes boiler plate. There's no checking yet because you can't get a single argument wrong. The end goal is that all argument definition goes through functions and m_arguments is hidden so that you can't define inconsistent argument sets.
1 parent abc693f commit 2d704f4

28 files changed

+162
-987
lines changed

lldb/include/lldb/Interpreter/CommandObject.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
207207
static const ArgumentTableEntry *
208208
FindArgumentDataByType(lldb::CommandArgumentType arg_type);
209209

210+
// Sets the argument list for this command to one homogenous argument type,
211+
// with the repeat specified.
212+
void AddSimpleArgumentList(
213+
lldb::CommandArgumentType arg_type,
214+
ArgumentRepetitionType repetition_type = eArgRepeatPlain);
215+
216+
// Helper function to set BP IDs or ID ranges as the command argument data
217+
// for this command.
218+
// This used to just populate an entry you could add to, but that was never
219+
// used. If we ever need that we can take optional extra args here.
220+
// Use this to define a simple argument list:
221+
enum IDType { eBreakpointArgs = 0, eWatchpointArgs = 1 };
222+
void AddIDsArgumentData(IDType type);
223+
210224
int GetNumArgumentEntries();
211225

212226
CommandArgumentEntry *GetArgumentEntryAtIndex(int idx);
@@ -391,12 +405,6 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
391405
lldb_private::CommandOverrideCallbackWithResult m_command_override_callback;
392406
void *m_command_override_baton;
393407
bool m_is_user_command = false;
394-
395-
// Helper function to populate IDs or ID ranges as the command argument data
396-
// to the specified command argument entry.
397-
static void AddIDsArgumentData(CommandArgumentEntry &arg,
398-
lldb::CommandArgumentType ID,
399-
lldb::CommandArgumentType IDRange);
400408
};
401409

402410
class CommandObjectParsed : public CommandObject {

lldb/source/Commands/CommandObjectApropos.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,7 @@ CommandObjectApropos::CommandObjectApropos(CommandInterpreter &interpreter)
2121
: CommandObjectParsed(
2222
interpreter, "apropos",
2323
"List debugger commands related to a word or subject.", nullptr) {
24-
CommandArgumentEntry arg;
25-
CommandArgumentData search_word_arg;
26-
27-
// Define the first (and only) variant of this arg.
28-
search_word_arg.arg_type = eArgTypeSearchWord;
29-
search_word_arg.arg_repetition = eArgRepeatPlain;
30-
31-
// There is only one variant this argument could be; put it into the argument
32-
// entry.
33-
arg.push_back(search_word_arg);
34-
35-
// Push the data for the first argument into the m_arguments vector.
36-
m_arguments.push_back(arg);
24+
AddSimpleArgumentList(eArgTypeSearchWord);
3725
}
3826

3927
CommandObjectApropos::~CommandObjectApropos() = default;

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,7 @@ class CommandObjectBreakpointModify : public CommandObjectParsed {
813813
"With the exception of -e, -d and -i, passing an "
814814
"empty argument clears the modification.",
815815
nullptr) {
816-
CommandArgumentEntry arg;
817-
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
818-
eArgTypeBreakpointIDRange);
819-
// Add the entry for the first argument for this command to the object's
820-
// arguments vector.
821-
m_arguments.push_back(arg);
816+
CommandObject::AddIDsArgumentData(eBreakpointArgs);
822817

823818
m_options.Append(&m_bp_opts,
824819
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
@@ -890,12 +885,7 @@ class CommandObjectBreakpointEnable : public CommandObjectParsed {
890885
"Enable the specified disabled breakpoint(s). If "
891886
"no breakpoints are specified, enable all of them.",
892887
nullptr) {
893-
CommandArgumentEntry arg;
894-
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
895-
eArgTypeBreakpointIDRange);
896-
// Add the entry for the first argument for this command to the object's
897-
// arguments vector.
898-
m_arguments.push_back(arg);
888+
CommandObject::AddIDsArgumentData(eBreakpointArgs);
899889
}
900890

901891
~CommandObjectBreakpointEnable() override = default;
@@ -1002,12 +992,7 @@ execution will NOT stop at location 1.1. To achieve that, type:
1002992
"The first command disables all locations for breakpoint 1, \
1003993
the second re-enables the first location.");
1004994

1005-
CommandArgumentEntry arg;
1006-
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1007-
eArgTypeBreakpointIDRange);
1008-
// Add the entry for the first argument for this command to the object's
1009-
// arguments vector.
1010-
m_arguments.push_back(arg);
995+
CommandObject::AddIDsArgumentData(eBreakpointArgs);
1011996
}
1012997

1013998
~CommandObjectBreakpointDisable() override = default;
@@ -1098,15 +1083,7 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
10981083
CommandArgumentData bp_id_arg;
10991084

11001085
// Define the first (and only) variant of this arg.
1101-
bp_id_arg.arg_type = eArgTypeBreakpointID;
1102-
bp_id_arg.arg_repetition = eArgRepeatOptional;
1103-
1104-
// There is only one variant this argument could be; put it into the
1105-
// argument entry.
1106-
arg.push_back(bp_id_arg);
1107-
1108-
// Push the data for the first argument into the m_arguments vector.
1109-
m_arguments.push_back(arg);
1086+
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
11101087
}
11111088

11121089
~CommandObjectBreakpointList() override = default;
@@ -1372,12 +1349,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
13721349
"Delete the specified breakpoint(s). If no "
13731350
"breakpoints are specified, delete them all.",
13741351
nullptr) {
1375-
CommandArgumentEntry arg;
1376-
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1377-
eArgTypeBreakpointIDRange);
1378-
// Add the entry for the first argument for this command to the object's
1379-
// arguments vector.
1380-
m_arguments.push_back(arg);
1352+
CommandObject::AddIDsArgumentData(eBreakpointArgs);
13811353
}
13821354

13831355
~CommandObjectBreakpointDelete() override = default;
@@ -1677,14 +1649,7 @@ class CommandObjectBreakpointNameConfigure : public CommandObjectParsed {
16771649
"on the name.",
16781650
"breakpoint name configure <command-options> "
16791651
"<breakpoint-name-list>") {
1680-
// Create the first variant for the first (and only) argument for this
1681-
// command.
1682-
CommandArgumentEntry arg1;
1683-
CommandArgumentData id_arg;
1684-
id_arg.arg_type = eArgTypeBreakpointName;
1685-
id_arg.arg_repetition = eArgRepeatOptional;
1686-
arg1.push_back(id_arg);
1687-
m_arguments.push_back(arg1);
1652+
AddSimpleArgumentList(eArgTypeBreakpointName, eArgRepeatOptional);
16881653

16891654
m_option_group.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
16901655
m_option_group.Append(&m_access_options, LLDB_OPT_SET_ALL,
@@ -1770,14 +1735,7 @@ class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
17701735
: CommandObjectParsed(
17711736
interpreter, "add", "Add a name to the breakpoints provided.",
17721737
"breakpoint name add <command-options> <breakpoint-id-list>") {
1773-
// Create the first variant for the first (and only) argument for this
1774-
// command.
1775-
CommandArgumentEntry arg1;
1776-
CommandArgumentData id_arg;
1777-
id_arg.arg_type = eArgTypeBreakpointID;
1778-
id_arg.arg_repetition = eArgRepeatOptional;
1779-
arg1.push_back(id_arg);
1780-
m_arguments.push_back(arg1);
1738+
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
17811739

17821740
m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
17831741
m_option_group.Finalize();
@@ -1851,14 +1809,7 @@ class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
18511809
interpreter, "delete",
18521810
"Delete a name from the breakpoints provided.",
18531811
"breakpoint name delete <command-options> <breakpoint-id-list>") {
1854-
// Create the first variant for the first (and only) argument for this
1855-
// command.
1856-
CommandArgumentEntry arg1;
1857-
CommandArgumentData id_arg;
1858-
id_arg.arg_type = eArgTypeBreakpointID;
1859-
id_arg.arg_repetition = eArgRepeatOptional;
1860-
arg1.push_back(id_arg);
1861-
m_arguments.push_back(arg1);
1812+
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
18621813

18631814
m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
18641815
m_option_group.Finalize();
@@ -2308,12 +2259,7 @@ class CommandObjectBreakpointWrite : public CommandObjectParsed {
23082259
"be read in with \"breakpoint read\". "
23092260
"If given no arguments, writes all breakpoints.",
23102261
nullptr) {
2311-
CommandArgumentEntry arg;
2312-
CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
2313-
eArgTypeBreakpointIDRange);
2314-
// Add the entry for the first argument for this command to the object's
2315-
// arguments vector.
2316-
m_arguments.push_back(arg);
2262+
CommandObject::AddIDsArgumentData(eBreakpointArgs);
23172263
}
23182264

23192265
~CommandObjectBreakpointWrite() override = default;

lldb/source/Commands/CommandObjectBreakpointCommand.cpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,7 @@ are no syntax errors may indicate that a function was declared but never called.
185185
LLDB_OPT_SET_2);
186186
m_all_options.Finalize();
187187

188-
CommandArgumentEntry arg;
189-
CommandArgumentData bp_id_arg;
190-
191-
// Define the first (and only) variant of this arg.
192-
bp_id_arg.arg_type = eArgTypeBreakpointID;
193-
bp_id_arg.arg_repetition = eArgRepeatOptional;
194-
195-
// There is only one variant this argument could be; put it into the
196-
// argument entry.
197-
arg.push_back(bp_id_arg);
198-
199-
// Push the data for the first argument into the m_arguments vector.
200-
m_arguments.push_back(arg);
188+
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
201189
}
202190

203191
~CommandObjectBreakpointCommandAdd() override = default;
@@ -449,19 +437,7 @@ class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
449437
: CommandObjectParsed(interpreter, "delete",
450438
"Delete the set of commands from a breakpoint.",
451439
nullptr) {
452-
CommandArgumentEntry arg;
453-
CommandArgumentData bp_id_arg;
454-
455-
// Define the first (and only) variant of this arg.
456-
bp_id_arg.arg_type = eArgTypeBreakpointID;
457-
bp_id_arg.arg_repetition = eArgRepeatPlain;
458-
459-
// There is only one variant this argument could be; put it into the
460-
// argument entry.
461-
arg.push_back(bp_id_arg);
462-
463-
// Push the data for the first argument into the m_arguments vector.
464-
m_arguments.push_back(arg);
440+
AddSimpleArgumentList(eArgTypeBreakpointID);
465441
}
466442

467443
~CommandObjectBreakpointCommandDelete() override = default;
@@ -565,19 +541,7 @@ class CommandObjectBreakpointCommandList : public CommandObjectParsed {
565541
"List the script or set of commands to be "
566542
"executed when the breakpoint is hit.",
567543
nullptr, eCommandRequiresTarget) {
568-
CommandArgumentEntry arg;
569-
CommandArgumentData bp_id_arg;
570-
571-
// Define the first (and only) variant of this arg.
572-
bp_id_arg.arg_type = eArgTypeBreakpointID;
573-
bp_id_arg.arg_repetition = eArgRepeatPlain;
574-
575-
// There is only one variant this argument could be; put it into the
576-
// argument entry.
577-
arg.push_back(bp_id_arg);
578-
579-
// Push the data for the first argument into the m_arguments vector.
580-
m_arguments.push_back(arg);
544+
AddSimpleArgumentList(eArgTypeBreakpointID);
581545
}
582546

583547
~CommandObjectBreakpointCommandList() override = default;

0 commit comments

Comments
 (0)