Skip to content

Commit

Permalink
[lldb/Commands] Alias script command to scripting execute
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
  • Loading branch information
medismailben committed Feb 2, 2024
1 parent 576b0c0 commit 368e578
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lldb/source/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
CommandObjectQuit.cpp
CommandObjectRegexCommand.cpp
CommandObjectRegister.cpp
CommandObjectScript.cpp
CommandObjectScripting.cpp
CommandObjectSession.cpp
CommandObjectSettings.cpp
CommandObjectSource.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//===-- CommandObjectScript.cpp -------------------------------------------===//
//===-- CommandObjectScripting.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "CommandObjectScript.h"
#include "CommandObjectScripting.h"
#include "lldb/Core/Debugger.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/Config.h"
Expand All @@ -21,10 +21,10 @@
using namespace lldb;
using namespace lldb_private;

#define LLDB_OPTIONS_script
#define LLDB_OPTIONS_scripting_execute
#include "CommandOptions.inc"

Status CommandObjectScript::CommandOptions::SetOptionValue(
Status CommandObjectScriptingExecute::CommandOptions::SetOptionValue(
uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) {
Status error;
Expand All @@ -46,27 +46,29 @@ Status CommandObjectScript::CommandOptions::SetOptionValue(
return error;
}

void CommandObjectScript::CommandOptions::OptionParsingStarting(
void CommandObjectScriptingExecute::CommandOptions::OptionParsingStarting(
ExecutionContext *execution_context) {
language = lldb::eScriptLanguageNone;
}

llvm::ArrayRef<OptionDefinition>
CommandObjectScript::CommandOptions::GetDefinitions() {
return llvm::ArrayRef(g_script_options);
CommandObjectScriptingExecute::CommandOptions::GetDefinitions() {
return llvm::ArrayRef(g_scripting_execute_options);
}

CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter)
CommandObjectScriptingExecute::CommandObjectScriptingExecute(
CommandInterpreter &interpreter)
: CommandObjectRaw(
interpreter, "script",
interpreter, "scripting execute",
"Invoke the script interpreter with provided code and display any "
"results. Start the interactive interpreter if no code is supplied.",
"script [--language <scripting-language> --] [<script-code>]") {}
"scripting execute [--language <scripting-language> --] "
"[<script-code>]") {}

CommandObjectScript::~CommandObjectScript() = default;
CommandObjectScriptingExecute::~CommandObjectScriptingExecute() = default;

void CommandObjectScript::DoExecute(llvm::StringRef command,
CommandReturnObject &result) {
void CommandObjectScriptingExecute::DoExecute(llvm::StringRef command,
CommandReturnObject &result) {
// Try parsing the language option but when the command contains a raw part
// separated by the -- delimiter.
OptionsWithRaw raw_args(command);
Expand Down Expand Up @@ -111,3 +113,19 @@ void CommandObjectScript::DoExecute(llvm::StringRef command,
else
result.SetStatus(eReturnStatusFailed);
}

#pragma mark CommandObjectMultiwordScripting

// CommandObjectMultiwordScripting

CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
CommandInterpreter &interpreter)
: CommandObjectMultiword(
interpreter, "scripting",
"Commands for operating on the scripting functionnalities.",
"scripting <subcommand> [<subcommand-options>]") {
LoadSubCommand("execute", CommandObjectSP(new CommandObjectScriptingExecute(
interpreter)));
}

CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- CommandObjectScript.h -----------------------------------*- C++ -*-===//
//===-- CommandObjectScripting.h --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,14 +9,21 @@
#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H

#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"

namespace lldb_private {

class CommandObjectScript : public CommandObjectRaw {
class CommandObjectMultiwordScripting : public CommandObjectMultiword {
public:
CommandObjectScript(CommandInterpreter &interpreter);
~CommandObjectScript() override;
CommandObjectMultiwordScripting(CommandInterpreter &interpreter);

~CommandObjectMultiwordScripting() override;
};

class CommandObjectScriptingExecute : public CommandObjectRaw {
public:
CommandObjectScriptingExecute(CommandInterpreter &interpreter);
~CommandObjectScriptingExecute() override;
Options *GetOptions() override { return &m_options; }

class CommandOptions : public Options {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ let Command = "container add" in {
Desc<"Overwrite an existing command at this node.">;
}

let Command = "script" in {
let Command = "scripting execute" in {
def script_language : Option<"language", "l">,
EnumArg<"ScriptLang">, Desc<"Specify the scripting "
" language. If none is specific the default scripting language is used.">;
Expand Down
9 changes: 7 additions & 2 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "Commands/CommandObjectQuit.h"
#include "Commands/CommandObjectRegexCommand.h"
#include "Commands/CommandObjectRegister.h"
#include "Commands/CommandObjectScript.h"
#include "Commands/CommandObjectScripting.h"
#include "Commands/CommandObjectSession.h"
#include "Commands/CommandObjectSettings.h"
#include "Commands/CommandObjectSource.h"
Expand Down Expand Up @@ -504,6 +504,11 @@ void CommandInterpreter::Initialize() {
AddAlias("re", cmd_obj_sp);
}

cmd_obj_sp = GetCommandSPExact("scripting execute");
if (cmd_obj_sp) {
AddAlias("script", cmd_obj_sp);
}

cmd_obj_sp = GetCommandSPExact("session history");
if (cmd_obj_sp) {
AddAlias("history", cmd_obj_sp);
Expand Down Expand Up @@ -555,7 +560,7 @@ void CommandInterpreter::LoadCommandDictionary() {
REGISTER_COMMAND_OBJECT("process", CommandObjectMultiwordProcess);
REGISTER_COMMAND_OBJECT("quit", CommandObjectQuit);
REGISTER_COMMAND_OBJECT("register", CommandObjectRegister);
REGISTER_COMMAND_OBJECT("script", CommandObjectScript);
REGISTER_COMMAND_OBJECT("scripting", CommandObjectMultiwordScripting);
REGISTER_COMMAND_OBJECT("settings", CommandObjectMultiwordSettings);
REGISTER_COMMAND_OBJECT("session", CommandObjectSession);
REGISTER_COMMAND_OBJECT("source", CommandObjectMultiwordSource);
Expand Down

0 comments on commit 368e578

Please sign in to comment.