Skip to content

[lldb/Commands] Add scripting template list command with auto discovery #97273

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 1 commit into from
Jul 23, 2024

Conversation

medismailben
Copy link
Member

This patch introduces a new template multiword sub-command to the
scripting top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

Signed-off-by: Med Ismail Bennani [email protected]

@medismailben medismailben requested a review from bulbazord July 1, 2024 09:57
@llvmbot llvmbot added the lldb label Jul 1, 2024
@medismailben
Copy link
Member Author

Depends on #97263

@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2024

@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)

Changes

This patch introduces a new template multiword sub-command to the
scripting top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

Signed-off-by: Med Ismail Bennani <[email protected]>


Patch is 36.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/97273.diff

17 Files Affected:

  • (modified) lldb/include/lldb/Core/PluginManager.h (+25)
  • (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h (+7)
  • (modified) lldb/include/lldb/lldb-private-interfaces.h (+4)
  • (modified) lldb/source/Commands/CMakeLists.txt (+1-1)
  • (removed) lldb/source/Commands/CommandObjectScript.cpp (-113)
  • (removed) lldb/source/Commands/CommandObjectScript.h (-42)
  • (added) lldb/source/Commands/CommandObjectScripting.cpp (+290)
  • (added) lldb/source/Commands/CommandObjectScripting.h (+80)
  • (modified) lldb/source/Commands/Options.td (+8-2)
  • (modified) lldb/source/Core/PluginManager.cpp (+83)
  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+7-2)
  • (modified) lldb/source/Plugins/CMakeLists.txt (+3)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt (+5)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp (+23)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h (+12-1)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp (+18)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h (+12-1)
diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h
index f2296e2920238..df20109e791a5 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -487,6 +487,31 @@ class PluginManager {
 
   static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
 
+  // Scripted Interface
+  static bool
+  RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
+                 ScriptedInterfaceCreateInstance create_callback,
+                 lldb::ScriptLanguage language,
+                 std::vector<llvm::StringRef> command_interpreter_usages,
+                 std::vector<llvm::StringRef> api_usages);
+
+  static bool UnregisterPlugin(ScriptedInterfaceCreateInstance create_callback);
+
+  static ScriptedInterfaceCreateInstance
+  GetScriptedInterfaceCreateCallbackAtIndex(uint32_t idx);
+
+  static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);
+
+  static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);
+
+  static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t idx);
+
+  static std::vector<llvm::StringRef>
+  GetScriptedInterfaceCommandInterpreterUsagesAtIndex(uint32_t idx);
+
+  static std::vector<llvm::StringRef>
+  GetScriptedInterfaceAPIUsagesAtIndex(uint32_t idx);
+
   // REPL
   static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
                              REPLCreateInstance create_callback,
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 69504dbcda5dc..23658b90bb90a 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -68,6 +68,13 @@ class ScriptedInterface {
     return true;
   }
 
+  static bool
+  CreateInstance(lldb::ScriptLanguage language,
+                 std::vector<llvm::StringRef> command_interpreter_usages,
+                 std::vector<llvm::StringRef> api_usages) {
+    return false;
+  }
+
 protected:
   StructuredData::GenericSP m_object_instance_sp;
 };
diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
index cdd9b51d9329c..2404e28158690 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -124,6 +124,10 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
                                            lldb::LanguageType language,
                                            Debugger *debugger, Target *target,
                                            const char *repl_options);
+typedef bool (*ScriptedInterfaceCreateInstance)(
+    lldb::ScriptLanguage language,
+    std::vector<llvm::StringRef> command_interpreter_usages,
+    std::vector<llvm::StringRef> api_usages);
 typedef int (*ComparisonFunction)(const void *, const void *);
 typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
 /// Trace
diff --git a/lldb/source/Commands/CMakeLists.txt b/lldb/source/Commands/CMakeLists.txt
index 6a36c5376d5c5..76397227d535d 100644
--- a/lldb/source/Commands/CMakeLists.txt
+++ b/lldb/source/Commands/CMakeLists.txt
@@ -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
diff --git a/lldb/source/Commands/CommandObjectScript.cpp b/lldb/source/Commands/CommandObjectScript.cpp
deleted file mode 100644
index 25f25b8e65947..0000000000000
--- a/lldb/source/Commands/CommandObjectScript.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-//===-- CommandObjectScript.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 "lldb/Core/Debugger.h"
-#include "lldb/DataFormatters/DataVisualization.h"
-#include "lldb/Host/Config.h"
-#include "lldb/Host/OptionParser.h"
-#include "lldb/Interpreter/CommandInterpreter.h"
-#include "lldb/Interpreter/CommandOptionArgumentTable.h"
-#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/OptionArgParser.h"
-#include "lldb/Interpreter/ScriptInterpreter.h"
-#include "lldb/Utility/Args.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-#define LLDB_OPTIONS_script
-#include "CommandOptions.inc"
-
-Status CommandObjectScript::CommandOptions::SetOptionValue(
-    uint32_t option_idx, llvm::StringRef option_arg,
-    ExecutionContext *execution_context) {
-  Status error;
-  const int short_option = m_getopt_table[option_idx].val;
-
-  switch (short_option) {
-  case 'l':
-    language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
-        option_arg, GetDefinitions()[option_idx].enum_values,
-        eScriptLanguageNone, error);
-    if (!error.Success())
-      error.SetErrorStringWithFormat("unrecognized value for language '%s'",
-                                     option_arg.str().c_str());
-    break;
-  default:
-    llvm_unreachable("Unimplemented option");
-  }
-
-  return error;
-}
-
-void CommandObjectScript::CommandOptions::OptionParsingStarting(
-    ExecutionContext *execution_context) {
-  language = lldb::eScriptLanguageNone;
-}
-
-llvm::ArrayRef<OptionDefinition>
-CommandObjectScript::CommandOptions::GetDefinitions() {
-  return llvm::ArrayRef(g_script_options);
-}
-
-CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter)
-    : CommandObjectRaw(
-          interpreter, "script",
-          "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>]") {}
-
-CommandObjectScript::~CommandObjectScript() = default;
-
-void CommandObjectScript::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);
-  if (raw_args.HasArgs()) {
-    if (!ParseOptions(raw_args.GetArgs(), result))
-      return;
-    command = raw_args.GetRawPart();
-  }
-
-  lldb::ScriptLanguage language =
-      (m_options.language == lldb::eScriptLanguageNone)
-          ? m_interpreter.GetDebugger().GetScriptLanguage()
-          : m_options.language;
-
-  if (language == lldb::eScriptLanguageNone) {
-    result.AppendError(
-        "the script-lang setting is set to none - scripting not available");
-    return;
-  }
-
-  ScriptInterpreter *script_interpreter =
-      GetDebugger().GetScriptInterpreter(true, language);
-
-  if (script_interpreter == nullptr) {
-    result.AppendError("no script interpreter");
-    return;
-  }
-
-  // Script might change Python code we use for formatting. Make sure we keep
-  // up to date with it.
-  DataVisualization::ForceUpdate();
-
-  if (command.empty()) {
-    script_interpreter->ExecuteInterpreterLoop();
-    result.SetStatus(eReturnStatusSuccessFinishNoResult);
-    return;
-  }
-
-  // We can do better when reporting the status of one-liner script execution.
-  if (script_interpreter->ExecuteOneLine(command, &result))
-    result.SetStatus(eReturnStatusSuccessFinishNoResult);
-  else
-    result.SetStatus(eReturnStatusFailed);
-}
diff --git a/lldb/source/Commands/CommandObjectScript.h b/lldb/source/Commands/CommandObjectScript.h
deleted file mode 100644
index 3a8c4a890404a..0000000000000
--- a/lldb/source/Commands/CommandObjectScript.h
+++ /dev/null
@@ -1,42 +0,0 @@
-//===-- CommandObjectScript.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.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
-#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
-
-#include "lldb/Interpreter/CommandObject.h"
-
-namespace lldb_private {
-
-class CommandObjectScript : public CommandObjectRaw {
-public:
-  CommandObjectScript(CommandInterpreter &interpreter);
-  ~CommandObjectScript() override;
-  Options *GetOptions() override { return &m_options; }
-
-  class CommandOptions : public Options {
-  public:
-    CommandOptions() = default;
-    ~CommandOptions() override = default;
-    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
-                          ExecutionContext *execution_context) override;
-    void OptionParsingStarting(ExecutionContext *execution_context) override;
-    llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
-    lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
-  };
-
-protected:
-  void DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
-
-private:
-  CommandOptions m_options;
-};
-
-} // namespace lldb_private
-
-#endif // LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
diff --git a/lldb/source/Commands/CommandObjectScripting.cpp b/lldb/source/Commands/CommandObjectScripting.cpp
new file mode 100644
index 0000000000000..f03c93ed1ef9d
--- /dev/null
+++ b/lldb/source/Commands/CommandObjectScripting.cpp
@@ -0,0 +1,290 @@
+//===-- 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 "CommandObjectScripting.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/DataFormatters/DataVisualization.h"
+#include "lldb/Host/Config.h"
+#include "lldb/Host/OptionParser.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandOptionArgumentTable.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Args.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+#pragma mark CommandObjectScriptingExecute
+
+#define LLDB_OPTIONS_scripting_execute
+#include "CommandOptions.inc"
+
+Status CommandObjectScriptingExecute::CommandOptions::SetOptionValue(
+    uint32_t option_idx, llvm::StringRef option_arg,
+    ExecutionContext *execution_context) {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+    language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+        option_arg, GetDefinitions()[option_idx].enum_values,
+        eScriptLanguageNone, error);
+    if (!error.Success())
+      error.SetErrorStringWithFormat("unrecognized value for language '%s'",
+                                     option_arg.str().c_str());
+    break;
+  default:
+    llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void CommandObjectScriptingExecute::CommandOptions::OptionParsingStarting(
+    ExecutionContext *execution_context) {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef<OptionDefinition>
+CommandObjectScriptingExecute::CommandOptions::GetDefinitions() {
+  return llvm::ArrayRef(g_scripting_execute_options);
+}
+
+CommandObjectScriptingExecute::CommandObjectScriptingExecute(
+    CommandInterpreter &interpreter)
+    : CommandObjectRaw(
+          interpreter, "scripting execute",
+          "Invoke the script interpreter with provided code and display any "
+          "results.  Start the interactive interpreter if no code is supplied.",
+          "scripting execute [--language <scripting-language> --] "
+          "[<script-code>]") {}
+
+CommandObjectScriptingExecute::~CommandObjectScriptingExecute() = default;
+
+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);
+  if (raw_args.HasArgs()) {
+    if (!ParseOptions(raw_args.GetArgs(), result))
+      return;
+    command = raw_args.GetRawPart();
+  }
+
+  lldb::ScriptLanguage language =
+      (m_options.language == lldb::eScriptLanguageNone)
+          ? m_interpreter.GetDebugger().GetScriptLanguage()
+          : m_options.language;
+
+  if (language == lldb::eScriptLanguageNone) {
+    result.AppendError(
+        "the script-lang setting is set to none - scripting not available");
+    return;
+  }
+
+  ScriptInterpreter *script_interpreter =
+      GetDebugger().GetScriptInterpreter(true, language);
+
+  if (script_interpreter == nullptr) {
+    result.AppendError("no script interpreter");
+    return;
+  }
+
+  // Script might change Python code we use for formatting. Make sure we keep
+  // up to date with it.
+  DataVisualization::ForceUpdate();
+
+  if (command.empty()) {
+    script_interpreter->ExecuteInterpreterLoop();
+    result.SetStatus(eReturnStatusSuccessFinishNoResult);
+    return;
+  }
+
+  // We can do better when reporting the status of one-liner script execution.
+  if (script_interpreter->ExecuteOneLine(command, &result))
+    result.SetStatus(eReturnStatusSuccessFinishNoResult);
+  else
+    result.SetStatus(eReturnStatusFailed);
+}
+
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+Status CommandObjectScriptingTemplateList::CommandOptions::SetOptionValue(
+    uint32_t option_idx, llvm::StringRef option_arg,
+    ExecutionContext *execution_context) {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+    language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+        option_arg, GetDefinitions()[option_idx].enum_values,
+        eScriptLanguageNone, error);
+    if (!error.Success())
+      error.SetErrorStringWithFormat("unrecognized value for language '%s'",
+                                     option_arg.str().c_str());
+    break;
+  default:
+    llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void CommandObjectScriptingTemplateList::CommandOptions::OptionParsingStarting(
+    ExecutionContext *execution_context) {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef<OptionDefinition>
+CommandObjectScriptingTemplateList::CommandOptions::GetDefinitions() {
+  return llvm::ArrayRef(g_scripting_execute_options);
+}
+
+CommandObjectScriptingTemplateList::CommandObjectScriptingTemplateList(
+    CommandInterpreter &interpreter)
+    : CommandObjectParsed(
+          interpreter, "scripting template list",
+          "List all the available scripting affordances templates. ",
+          "scripting template list [--language <scripting-language> --]") {}
+
+CommandObjectScriptingTemplateList::~CommandObjectScriptingTemplateList() =
+    default;
+
+void CommandObjectScriptingTemplateList::DoExecute(
+    Args &command, CommandReturnObject &result) {
+  lldb::ScriptLanguage language =
+      (m_options.language == lldb::eScriptLanguageNone)
+          ? m_interpreter.GetDebugger().GetScriptLanguage()
+          : m_options.language;
+
+  if (language == lldb::eScriptLanguageNone) {
+    result.AppendError(
+        "the script-lang setting is set to none - scripting not available");
+    return;
+  }
+
+  ScriptInterpreter *script_interpreter =
+      GetDebugger().GetScriptInterpreter(true, language);
+
+  if (script_interpreter == nullptr) {
+    result.AppendError("no script interpreter");
+    return;
+  }
+
+  Stream &s = result.GetOutputStream();
+  s.Printf("Available scripted affordances:\n");
+
+  auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
+                          bool check_validy = false) {
+    if (!check_validy || !value.empty()) {
+      s.IndentMore();
+      s.Indent();
+      s << key << ": " << value << '\n';
+      s.IndentLess();
+    }
+  };
+  auto print_usages = [&s](llvm::StringRef usage_kind,
+                           std::vector<llvm::StringRef> &usages) {
+    s.IndentMore();
+    s.Indent();
+    s << usage_kind << " Usages:";
+    if (usages.empty())
+      s << " No usages.\n";
+    else if (usages.size() == 1)
+      s << " " << usages.front() << '\n';
+    else {
+      s << '\n';
+      for (llvm::StringRef usage : usages) {
+        s.IndentMore();
+        s.Indent();
+        s << usage << '\n';
+        s.IndentLess();
+      }
+    }
+    s.IndentLess();
+  };
+
+  size_t i = 0;
+  for (llvm::StringRef plugin_name =
+           PluginManager::GetScriptedInterfaceNameAtIndex(i);
+       !plugin_name.empty();) {
+
+    llvm::StringRef desc =
+        PluginManager::GetScriptedInterfaceDescriptionAtIndex(i);
+    lldb::ScriptLanguage lang =
+        PluginManager::GetScriptedInterfaceLanguageAtIndex(i);
+    std::vector<llvm::StringRef> ci_usages =
+        PluginManager::GetScriptedInterfaceCommandInterpreterUsagesAtIndex(i);
+    std::vector<llvm::StringRef> api_usages =
+        PluginManager::GetScriptedInterfaceAPIUsagesAtIndex(i);
+
+    print_field("Name", plugin_name);
+    switch (lang) {
+    case eScriptLanguagePython:
+      print_field("Language", "Python");
+      break;
+    case eScriptLanguageLua:
+      print_field("Language", "Lua");
+      break;
+    default:
+      break;
+    }
+    print_field("Description", desc);
+    print_usages("Command Interpreter", ci_usages);
+    print_usages("API", api_usages);
+
+    plugin_name = PluginManager::GetScriptedInterfaceNameAtIndex(++i);
+    if (!plugin_name.empty())
+      s.EOL();
+  }
+}
+
+#pragma mark CommandObjectMultiwordScriptingTemplate
+
+// CommandObjectMultiwordScriptingTemplate
+
+CommandObjectMultiwordScriptingTemplate::
+    CommandObjectMultiwordScriptingTemplate(CommandInterpreter &interpreter)
+    : CommandObjectMultiword(
+          interpreter, "scripting template",
+          "Commands for operating on the scripting templates.",
+          "scripting template [<subcommand-options>]") {
+  LoadSubCommand("list", CommandObjectSP(new CommandObjectScriptingTemplateList(
+                             interpreter)));
+}
+
+CommandObjectMultiwordScriptingTemplate::
+    ~CommandObjectMultiwordScriptingTemplate() = default;
+
+#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)));
+  LoadSubCommand("template",
+                 CommandObjectSP(
+                     new CommandObjectMultiwordScriptingTemplate(interpreter)));
+}
+
+CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default;
diff --git a/lldb/source/Commands/CommandObjectScripting.h b/lldb/source/Commands/CommandObjectScripting.h
new file mode 100644
index 0000000000000..a9af6ee62e298
--- /dev/null
+++ b/lldb/source/Commands/CommandObjectScripting.h
@@ -0,0 +1,80 @@
+//===-- 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H
+#define LLDB_SOURCE_INTE...
[truncated]

@medismailben medismailben force-pushed the scripting-template-list branch 2 times, most recently from 55e53e4 to 828d8e8 Compare July 2, 2024 05:24
@medismailben medismailben requested a review from jimingham July 2, 2024 23:52
@medismailben
Copy link
Member Author

FWIW, this is the output it's producing for now:

(lldb) scripting template list 
Available scripted affordances:
  Name: ScriptedProcessPythonInterface
  Language: Python
  Description: Mock process state
  Command Interpreter Usages:
    process attach -C <script-name> [-k key -v value ...]
    process launch -C <script-name> [-k key -v value ...]
  API Usages:
    SBAttachInfo.SetScriptedProcessClassName
    SBAttachInfo.SetScriptedProcessDictionary
    SBTarget.Attach
    SBLaunchInfo.SetScriptedProcessClassName
    SBLaunchInfo.SetScriptedProcessDictionary
    SBTarget.Launch

  Name: ScriptedThreadPlanPythonInterface
  Language: Python
  Description: Alter thread stepping logic and stop reason
  Command Interpreter Usages: thread step-scripted -C <script-name> [-k key -v value ...]
  API Usages: SBThread.StepUsingScriptedThreadPlan

@medismailben medismailben force-pushed the scripting-template-list branch 2 times, most recently from c475dcf to 54e2299 Compare July 3, 2024 04:42
Copy link

github-actions bot commented Jul 3, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@medismailben medismailben force-pushed the scripting-template-list branch 2 times, most recently from d812b80 to a3aea65 Compare July 20, 2024 09:08
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems alright to me, left a few minor suggestions inline.

@medismailben medismailben force-pushed the scripting-template-list branch 2 times, most recently from faa1aec to d40b66d Compare July 22, 2024 21:13
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, you'll probably want sign off from Jonas too though since he had a ton of comments.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo comment.

…very

This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

Signed-off-by: Med Ismail Bennani <[email protected]>
@medismailben medismailben force-pushed the scripting-template-list branch from d40b66d to 52bdaac Compare July 23, 2024 17:15
@medismailben medismailben merged commit 43ca631 into llvm:main Jul 23, 2024
4 of 5 checks passed
medismailben added a commit that referenced this pull request Jul 25, 2024
…very

This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

This was previously reviewed in #97273.

Signed-off-by: Med Ismail Bennani <[email protected]>
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…very (#97273)

Summary:
This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

Signed-off-by: Med Ismail Bennani <[email protected]>

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251298
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…to discovery" (#100273)

Summary:
Reverts #97273 since it broke the windows bot:

https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251026
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…very

Summary:
This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

This was previously reviewed in #97273.

Signed-off-by: Med Ismail Bennani <[email protected]>

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250700
@mysterymath
Copy link
Contributor

mysterymath commented Jul 25, 2024

The reland broke the Fuchsia Windows build with a similar error to the LLVM Windows bots, but I wasn't able to cleanly revert this commit without detailed knowledge of the contents. Could you revert this (preferentially) or fix forward?

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8741458989697976961/overview

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8741458989697976961/+/u/clang/build/stdout

@medismailben
Copy link
Member Author

The reland broke the Fuchsia Windows build with a similar error to the LLVM Windows bots, but I wasn't able to cleanly revert this commit without detailed knowledge of the contents. Could you revert this (preferentially) or fix forward?

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8741458989697976961/overview

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8741458989697976961/+/u/clang/build/stdout

Looking at this. Thanks

medismailben added a commit that referenced this pull request Jul 27, 2024
…very

This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

This was previously reviewed in #97273.

Signed-off-by: Med Ismail Bennani <[email protected]>
@zeroomega
Copy link
Contributor

Hi @medismailben
We are seeing redefinition of pid_t error again on windows builder: https://lab.llvm.org/buildbot/#/builders/141/builds/1254
after multiple revert and reland like e72cdae. Could you revert the change please? Could you also not testing code in production please? It is a bad practice.

@DavidSpickett
Copy link
Collaborator

DavidSpickett commented Aug 1, 2024

I thought I saw that fixed once already, but perhaps that was just a full revert.

We (Linaro) can test a patch for you if it's fiddly to verify, we just need to know the general idea of it.

Edit: I was thinking of bbc457a, but I could swear there was something about the include order on Windows that was already addressed once.

@DavidSpickett
Copy link
Collaborator

Actually I'm looking at old results, the latest build makes it to tests https://lab.llvm.org/buildbot/#/builders/141/builds/1285 (which fail for reasons unrelated to this patch).

@medismailben
Copy link
Member Author

Hey @DavidSpickett! Thanks for the help! I don't have a system to try this on and it only fails on windows :/

Actually I'm looking at old results, the latest build makes it to tests https://lab.llvm.org/buildbot/#/builders/141/builds/1285 (which fail for reasons unrelated to this patch).

My patch has already been reverted in 9effefb and the failure you're talking about was introduced in #100710. I believe @Michael137 is trying to fix it.

If you have a recent build of lldb on windows (with python enabled), could you run the scripting template list command and paste the output here.

I've split this patch in smaller chunks (bccff3b, ecf125e, 995f643) and they've all landed without any build failure on windows except for 2402b32. I've noticed however that the cmake configure phase would produce some warnings on the bot regarding the files related to my changes, about the fact that they'd exceed CMAKE_OBJECT_PATH_MAX limit (250 on windows apparently).

You can see it happening here : https://lab.llvm.org/buildbot/#/builders/141/builds/1222

CMake Warning in C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt:
  The object file directory
    C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeFiles/lldbPluginScriptInterpreterPythonScriptedProcessPythonInterface.dir/./
  has 227 characters.  The maximum full path to an object file is 250
  characters (see CMAKE_OBJECT_PATH_MAX).  Object file
    ScriptedProcessPythonInterface.cpp.obj
  cannot be safely placed under this directory.  The build may not work
  correctly.

Also, if you could re-apply e72cdae and attach your build log here, that would be very helpful, and hopefully help us narrow down the ambiguous typedef issue.

If I'm not able to make it work on windows, I'll unfortunately have to compile it out of lldb for that platform, since I don't have access to a machine to investigate the issue further.

Thank you in advance!

@DavidSpickett
Copy link
Collaborator

If you have a recent build of lldb on windows (with python enabled), could you run the scripting template list command and paste the output here.

As of 229a165:

C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build>.\bin\lldb.exe
(lldb) scripting template list
Available scripted extension templates:
  Name: OperatingSystemPythonInterface
  Language: Python
  Description: Mock thread state
  API Usages: None
  Command Interpreter Usages:
    settings set target.process.python-os-plugin-path <script-path>
    settings set process.experimental.os-plugin-reports-all-threads [0/1]

  Name: ScriptedPlatformPythonInterface
  Language: Python
  Description: Mock platform and interact with its processes.
  API Usages: None
  Command Interpreter Usages: None

  Name: ScriptedThreadPlanPythonInterface
  Language: Python
  Description: Alter thread stepping logic and stop reason
  API Usages: SBThread.StepUsingScriptedThreadPlan
  Command Interpreter Usages: thread step-scripted -C <script-name> [-k key -v value ...]

@DavidSpickett
Copy link
Collaborator

What did you intend with /H? If anything it would be https://learn.microsoft.com/en-us/cpp/build/reference/h-restrict-length-of-external-names?view=msvc-170 but clang-cl doesn't support this one.

(yes, the bot uses clang-cl, we really should change the name)

@DavidSpickett
Copy link
Collaborator

I got it to build - #101672.

adrian-prantl pushed a commit to swiftlang/llvm-project that referenced this pull request Oct 11, 2024
…very

This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

This was previously reviewed in llvm#97273.

Signed-off-by: Med Ismail Bennani <[email protected]>
(cherry picked from commit bccff3b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants