This patch adds a `scripting extension generate <ExtensionType>...` command that introspects a Python extension base class and emits a skeleton subclass with `# TODO: Implement` stubs for its abstract methods (or, with `-a`, every method), then opens the result in an editor. Generated imports use `from <module> import <class>`, and the generated `__init__` forwards its arguments to `super().__init__(...)` since every base class relies on its constructor to set up attributes (`self.target`, `self.process`, ...) that inherited, non-overridden methods depend on. When the host can't open an external editor (e.g. non-macOS), the command reports that as a message rather than an error, since the file is already written. To catch regressions in the generator itself instead of just checking that a file was produced, this patch adds `TestScriptingExtensionGenerate.py`, which generates a template for every extension kind on the fly and drives it through a live lldb session (`process launch -C`, `breakpoint set -P`, `target stop-hook add -P`, etc.). Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> (cherry picked from commit c4962f5721a36e198234019b846d3788738f766a)
76 lines
3.0 KiB
C++
76 lines
3.0 KiB
C++
//===-- ScriptInterpreterPython.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
|
|
#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
|
|
|
|
#include "lldb/Breakpoint/BreakpointOptions.h"
|
|
#include "lldb/Core/IOHandler.h"
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
|
#include "lldb/lldb-private.h"
|
|
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace lldb_private {
|
|
/// Abstract interface for the Python script interpreter.
|
|
class ScriptInterpreterPython : public ScriptInterpreter,
|
|
public IOHandlerDelegateMultiline {
|
|
public:
|
|
class CommandDataPython : public BreakpointOptions::CommandData {
|
|
public:
|
|
CommandDataPython() : BreakpointOptions::CommandData() {
|
|
interpreter = lldb::eScriptLanguagePython;
|
|
}
|
|
CommandDataPython(StructuredData::ObjectSP extra_args_sp)
|
|
: BreakpointOptions::CommandData(),
|
|
m_extra_args(std::move(extra_args_sp)) {
|
|
interpreter = lldb::eScriptLanguagePython;
|
|
}
|
|
StructuredDataImpl m_extra_args;
|
|
};
|
|
|
|
ScriptInterpreterPython(Debugger &debugger)
|
|
: ScriptInterpreter(debugger, lldb::eScriptLanguagePython),
|
|
IOHandlerDelegateMultiline("DONE") {}
|
|
|
|
llvm::Expected<std::string>
|
|
ExtensionToImportPath(lldb::ScriptedExtension extension) override;
|
|
StructuredData::DictionarySP GetInterpreterInfo() override;
|
|
llvm::Expected<FileSpec>
|
|
GenerateExtensionTemplate(const std::string &name,
|
|
std::vector<ExtensionTemplateRequest> &extensions,
|
|
bool generate_non_abstract_methods,
|
|
std::string output_file) override;
|
|
|
|
static void Initialize();
|
|
static void Terminate();
|
|
static llvm::StringRef GetPluginNameStatic() { return "script-python"; }
|
|
static llvm::StringRef GetPluginDescriptionStatic();
|
|
static FileSpec GetPythonDir();
|
|
static void SharedLibraryDirectoryHelper(FileSpec &this_file);
|
|
|
|
protected:
|
|
llvm::Error
|
|
ParseExtensionSchema(Stream &s, llvm::StringRef output_script_prefix,
|
|
const llvm::SmallVector<llvm::StringRef> &extension_path,
|
|
bool generate_non_abstract_methods,
|
|
std::set<std::string> &typing_imports);
|
|
llvm::Expected<StructuredData::ObjectSP>
|
|
GetExtensionSchema(const llvm::SmallVector<llvm::StringRef> &extension_path);
|
|
|
|
static void ComputePythonDirForApple(llvm::SmallVectorImpl<char> &path);
|
|
static void ComputePythonDir(llvm::SmallVectorImpl<char> &path);
|
|
};
|
|
} // namespace lldb_private
|
|
|
|
#endif // LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
|