Skip to content

Commit 2419ded

Browse files
committed
[lldb] Cleanup CommandObject registration (NFC)
- Remove the spurious argument to `CommandObjectScript`. - Use make_shared instead of bare `new`. - Move code duplication behind a macro. Differential revision: https://reviews.llvm.org/D84336
1 parent 0788ba0 commit 2419ded

File tree

3 files changed

+32
-52
lines changed

3 files changed

+32
-52
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -476,55 +476,40 @@ const char *CommandInterpreter::ProcessEmbeddedScriptCommands(const char *arg) {
476476
return arg;
477477
}
478478

479+
#define REGISTER_COMMAND_OBJECT(NAME, CLASS) \
480+
m_command_dict[NAME] = std::make_shared<CLASS>(*this);
481+
479482
void CommandInterpreter::LoadCommandDictionary() {
480483
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
481484
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
482485

483-
lldb::ScriptLanguage script_language = m_debugger.GetScriptLanguage();
484-
485-
m_command_dict["apropos"] = CommandObjectSP(new CommandObjectApropos(*this));
486-
m_command_dict["breakpoint"] =
487-
CommandObjectSP(new CommandObjectMultiwordBreakpoint(*this));
488-
m_command_dict["command"] =
489-
CommandObjectSP(new CommandObjectMultiwordCommands(*this));
490-
m_command_dict["disassemble"] =
491-
CommandObjectSP(new CommandObjectDisassemble(*this));
492-
m_command_dict["expression"] =
493-
CommandObjectSP(new CommandObjectExpression(*this));
494-
m_command_dict["frame"] =
495-
CommandObjectSP(new CommandObjectMultiwordFrame(*this));
496-
m_command_dict["gui"] = CommandObjectSP(new CommandObjectGUI(*this));
497-
m_command_dict["help"] = CommandObjectSP(new CommandObjectHelp(*this));
498-
m_command_dict["log"] = CommandObjectSP(new CommandObjectLog(*this));
499-
m_command_dict["memory"] = CommandObjectSP(new CommandObjectMemory(*this));
500-
m_command_dict["platform"] =
501-
CommandObjectSP(new CommandObjectPlatform(*this));
502-
m_command_dict["plugin"] = CommandObjectSP(new CommandObjectPlugin(*this));
503-
m_command_dict["process"] =
504-
CommandObjectSP(new CommandObjectMultiwordProcess(*this));
505-
m_command_dict["quit"] = CommandObjectSP(new CommandObjectQuit(*this));
506-
m_command_dict["register"] =
507-
CommandObjectSP(new CommandObjectRegister(*this));
508-
m_command_dict["reproducer"] =
509-
CommandObjectSP(new CommandObjectReproducer(*this));
510-
m_command_dict["script"] =
511-
CommandObjectSP(new CommandObjectScript(*this, script_language));
512-
m_command_dict["session"] = std::make_shared<CommandObjectSession>(*this);
513-
m_command_dict["settings"] =
514-
CommandObjectSP(new CommandObjectMultiwordSettings(*this));
515-
m_command_dict["source"] =
516-
CommandObjectSP(new CommandObjectMultiwordSource(*this));
517-
m_command_dict["statistics"] = CommandObjectSP(new CommandObjectStats(*this));
518-
m_command_dict["target"] =
519-
CommandObjectSP(new CommandObjectMultiwordTarget(*this));
520-
m_command_dict["thread"] =
521-
CommandObjectSP(new CommandObjectMultiwordThread(*this));
522-
m_command_dict["type"] = CommandObjectSP(new CommandObjectType(*this));
523-
m_command_dict["version"] = CommandObjectSP(new CommandObjectVersion(*this));
524-
m_command_dict["watchpoint"] =
525-
CommandObjectSP(new CommandObjectMultiwordWatchpoint(*this));
526-
m_command_dict["language"] =
527-
CommandObjectSP(new CommandObjectLanguage(*this));
486+
REGISTER_COMMAND_OBJECT("apropos", CommandObjectApropos);
487+
REGISTER_COMMAND_OBJECT("breakpoint", CommandObjectMultiwordBreakpoint);
488+
REGISTER_COMMAND_OBJECT("command", CommandObjectMultiwordCommands);
489+
REGISTER_COMMAND_OBJECT("disassemble", CommandObjectDisassemble);
490+
REGISTER_COMMAND_OBJECT("expression", CommandObjectExpression);
491+
REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame);
492+
REGISTER_COMMAND_OBJECT("gui", CommandObjectGUI);
493+
REGISTER_COMMAND_OBJECT("help", CommandObjectHelp);
494+
REGISTER_COMMAND_OBJECT("log", CommandObjectLog);
495+
REGISTER_COMMAND_OBJECT("memory", CommandObjectMemory);
496+
REGISTER_COMMAND_OBJECT("platform", CommandObjectPlatform);
497+
REGISTER_COMMAND_OBJECT("plugin", CommandObjectPlugin);
498+
REGISTER_COMMAND_OBJECT("process", CommandObjectMultiwordProcess);
499+
REGISTER_COMMAND_OBJECT("quit", CommandObjectQuit);
500+
REGISTER_COMMAND_OBJECT("register", CommandObjectRegister);
501+
REGISTER_COMMAND_OBJECT("reproducer", CommandObjectReproducer);
502+
REGISTER_COMMAND_OBJECT("script", CommandObjectScript);
503+
REGISTER_COMMAND_OBJECT("settings", CommandObjectMultiwordSettings);
504+
REGISTER_COMMAND_OBJECT("session", CommandObjectSession);
505+
REGISTER_COMMAND_OBJECT("source", CommandObjectMultiwordSource);
506+
REGISTER_COMMAND_OBJECT("statistics", CommandObjectStats);
507+
REGISTER_COMMAND_OBJECT("target", CommandObjectMultiwordTarget);
508+
REGISTER_COMMAND_OBJECT("thread", CommandObjectMultiwordThread);
509+
REGISTER_COMMAND_OBJECT("type", CommandObjectType);
510+
REGISTER_COMMAND_OBJECT("version", CommandObjectVersion);
511+
REGISTER_COMMAND_OBJECT("watchpoint", CommandObjectMultiwordWatchpoint);
512+
REGISTER_COMMAND_OBJECT("language", CommandObjectLanguage);
528513

529514
// clang-format off
530515
const char *break_regexes[][2] = {

lldb/source/Interpreter/CommandObjectScript.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using namespace lldb_private;
2020

2121
// CommandObjectScript
2222

23-
CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter,
24-
ScriptLanguage script_lang)
23+
CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter)
2524
: CommandObjectRaw(
2625
interpreter, "script",
2726
"Invoke the script interpreter with provided code and display any "

lldb/source/Interpreter/CommandObjectScript.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313

1414
namespace lldb_private {
1515

16-
// CommandObjectScript
17-
1816
class CommandObjectScript : public CommandObjectRaw {
1917
public:
20-
CommandObjectScript(CommandInterpreter &interpreter,
21-
lldb::ScriptLanguage script_lang);
22-
18+
CommandObjectScript(CommandInterpreter &interpreter);
2319
~CommandObjectScript() override;
2420

2521
protected:

0 commit comments

Comments
 (0)