Skip to content

Commit 1f3d049

Browse files
committed
[lldb/Commands] Alias script command to scripting execute
This patch introduces a new top-level `scripting` command with an `execute` sub-command, that basically replaces the `script` raw command. To avoid breaking the `script` command usages, this patch also adds an `script` alias to the `scripting execute` sub-command. The reason behind this change is to have a top-level command that will cover scripting related subcommands. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent a9c12e4 commit 1f3d049

File tree

6 files changed

+57
-23
lines changed

6 files changed

+57
-23
lines changed

lldb/source/Commands/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
2626
CommandObjectQuit.cpp
2727
CommandObjectRegexCommand.cpp
2828
CommandObjectRegister.cpp
29-
CommandObjectScript.cpp
29+
CommandObjectScripting.cpp
3030
CommandObjectSession.cpp
3131
CommandObjectSettings.cpp
3232
CommandObjectSource.cpp

lldb/source/Commands/CommandObjectScript.cpp renamed to lldb/source/Commands/CommandObjectScripting.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===-- CommandObjectScript.cpp -------------------------------------------===//
1+
//===-- CommandObjectScripting.cpp ----------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "CommandObjectScript.h"
9+
#include "CommandObjectScripting.h"
1010
#include "lldb/Core/Debugger.h"
1111
#include "lldb/DataFormatters/DataVisualization.h"
1212
#include "lldb/Host/Config.h"
@@ -21,10 +21,10 @@
2121
using namespace lldb;
2222
using namespace lldb_private;
2323

24-
#define LLDB_OPTIONS_script
24+
#define LLDB_OPTIONS_scripting_execute
2525
#include "CommandOptions.inc"
2626

27-
Status CommandObjectScript::CommandOptions::SetOptionValue(
27+
Status CommandObjectScriptingExecute::CommandOptions::SetOptionValue(
2828
uint32_t option_idx, llvm::StringRef option_arg,
2929
ExecutionContext *execution_context) {
3030
Status error;
@@ -46,27 +46,29 @@ Status CommandObjectScript::CommandOptions::SetOptionValue(
4646
return error;
4747
}
4848

49-
void CommandObjectScript::CommandOptions::OptionParsingStarting(
49+
void CommandObjectScriptingExecute::CommandOptions::OptionParsingStarting(
5050
ExecutionContext *execution_context) {
5151
language = lldb::eScriptLanguageNone;
5252
}
5353

5454
llvm::ArrayRef<OptionDefinition>
55-
CommandObjectScript::CommandOptions::GetDefinitions() {
56-
return llvm::ArrayRef(g_script_options);
55+
CommandObjectScriptingExecute::CommandOptions::GetDefinitions() {
56+
return llvm::ArrayRef(g_scripting_execute_options);
5757
}
5858

59-
CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter)
59+
CommandObjectScriptingExecute::CommandObjectScriptingExecute(
60+
CommandInterpreter &interpreter)
6061
: CommandObjectRaw(
61-
interpreter, "script",
62+
interpreter, "scripting execute",
6263
"Invoke the script interpreter with provided code and display any "
6364
"results. Start the interactive interpreter if no code is supplied.",
64-
"script [--language <scripting-language> --] [<script-code>]") {}
65+
"scripting execute [--language <scripting-language> --] "
66+
"[<script-code>]") {}
6567

66-
CommandObjectScript::~CommandObjectScript() = default;
68+
CommandObjectScriptingExecute::~CommandObjectScriptingExecute() = default;
6769

68-
void CommandObjectScript::DoExecute(llvm::StringRef command,
69-
CommandReturnObject &result) {
70+
void CommandObjectScriptingExecute::DoExecute(llvm::StringRef command,
71+
CommandReturnObject &result) {
7072
// Try parsing the language option but when the command contains a raw part
7173
// separated by the -- delimiter.
7274
OptionsWithRaw raw_args(command);
@@ -111,3 +113,19 @@ void CommandObjectScript::DoExecute(llvm::StringRef command,
111113
else
112114
result.SetStatus(eReturnStatusFailed);
113115
}
116+
117+
#pragma mark CommandObjectMultiwordScripting
118+
119+
// CommandObjectMultiwordScripting
120+
121+
CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
122+
CommandInterpreter &interpreter)
123+
: CommandObjectMultiword(
124+
interpreter, "scripting",
125+
"Commands for operating on the scripting functionnalities.",
126+
"scripting <subcommand> [<subcommand-options>]") {
127+
LoadSubCommand("execute", CommandObjectSP(new CommandObjectScriptingExecute(
128+
interpreter)));
129+
}
130+
131+
CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default;

lldb/source/Commands/CommandObjectScript.h renamed to lldb/source/Commands/CommandObjectScripting.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- CommandObjectScript.h -----------------------------------*- C++ -*-===//
1+
//===-- CommandObjectScripting.h --------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,14 +9,21 @@
99
#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
1010
#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
1111

12-
#include "lldb/Interpreter/CommandObject.h"
12+
#include "lldb/Interpreter/CommandObjectMultiword.h"
1313

1414
namespace lldb_private {
1515

16-
class CommandObjectScript : public CommandObjectRaw {
16+
class CommandObjectMultiwordScripting : public CommandObjectMultiword {
1717
public:
18-
CommandObjectScript(CommandInterpreter &interpreter);
19-
~CommandObjectScript() override;
18+
CommandObjectMultiwordScripting(CommandInterpreter &interpreter);
19+
20+
~CommandObjectMultiwordScripting() override;
21+
};
22+
23+
class CommandObjectScriptingExecute : public CommandObjectRaw {
24+
public:
25+
CommandObjectScriptingExecute(CommandInterpreter &interpreter);
26+
~CommandObjectScriptingExecute() override;
2027
Options *GetOptions() override { return &m_options; }
2128

2229
class CommandOptions : public Options {

lldb/source/Commands/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ let Command = "container add" in {
835835
Desc<"Overwrite an existing command at this node.">;
836836
}
837837

838-
let Command = "script" in {
838+
let Command = "scripting execute" in {
839839
def script_language : Option<"language", "l">,
840840
EnumArg<"ScriptLang">, Desc<"Specify the scripting "
841841
" language. If none is specific the default scripting language is used.">;

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "Commands/CommandObjectQuit.h"
3434
#include "Commands/CommandObjectRegexCommand.h"
3535
#include "Commands/CommandObjectRegister.h"
36-
#include "Commands/CommandObjectScript.h"
36+
#include "Commands/CommandObjectScripting.h"
3737
#include "Commands/CommandObjectSession.h"
3838
#include "Commands/CommandObjectSettings.h"
3939
#include "Commands/CommandObjectSource.h"
@@ -518,6 +518,15 @@ void CommandInterpreter::Initialize() {
518518
AddAlias("re", cmd_obj_sp);
519519
}
520520

521+
cmd_obj_sp = GetCommandSPExact("scripting execute");
522+
if (cmd_obj_sp) {
523+
AddAlias("sc", cmd_obj_sp);
524+
AddAlias("scr", cmd_obj_sp);
525+
AddAlias("scri", cmd_obj_sp);
526+
AddAlias("scrip", cmd_obj_sp);
527+
AddAlias("script", cmd_obj_sp);
528+
}
529+
521530
cmd_obj_sp = GetCommandSPExact("session history");
522531
if (cmd_obj_sp) {
523532
AddAlias("history", cmd_obj_sp);
@@ -569,7 +578,7 @@ void CommandInterpreter::LoadCommandDictionary() {
569578
REGISTER_COMMAND_OBJECT("process", CommandObjectMultiwordProcess);
570579
REGISTER_COMMAND_OBJECT("quit", CommandObjectQuit);
571580
REGISTER_COMMAND_OBJECT("register", CommandObjectRegister);
572-
REGISTER_COMMAND_OBJECT("script", CommandObjectScript);
581+
REGISTER_COMMAND_OBJECT("scripting", CommandObjectMultiwordScripting);
573582
REGISTER_COMMAND_OBJECT("settings", CommandObjectMultiwordSettings);
574583
REGISTER_COMMAND_OBJECT("session", CommandObjectSession);
575584
REGISTER_COMMAND_OBJECT("source", CommandObjectMultiwordSource);

lldb/test/API/functionalities/abbreviation/TestAbbreviations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_command_abbreviations_and_aliases(self):
8080
# Check a command that wants the raw input.
8181
command_interpreter.ResolveCommand(r"""sc print("\n\n\tHello!\n")""", result)
8282
self.assertTrue(result.Succeeded())
83-
self.assertEqual(r"""script print("\n\n\tHello!\n")""", result.GetOutput())
83+
self.assertEqual(r"""scripting execute print("\n\n\tHello!\n")""", result.GetOutput())
8484

8585
# Prompt changing stuff should be tested, but this doesn't seem like the
8686
# right test to do it in. It has nothing to do with aliases or abbreviations.

0 commit comments

Comments
 (0)