Skip to content

Commit

Permalink
[lldb/Plugins] Introduce Scripted Interface Factory
Browse files Browse the repository at this point in the history
This patch splits the previous `ScriptedProcessPythonInterface` into
multiple specific classes:

1. The `ScriptedInterface` abstract class that carries the interface
   instance object and its virtual pure abstract creation method.

2. The `ScriptedPythonInterface` that holds a generic `Dispatch` method that
   can be used by various interfaces to call python methods and also keeps a
   reference to the Python Script Interpreter instance.

3. The `ScriptedProcessInterface` that describes the base Scripted
   Process model with all the methods used in the underlying script.

All these components are used to refactor the `ScriptedProcessPythonInterface`
class, making it more modular.

This patch is also a requirement for the upcoming work on `ScriptedThread`.

Differential Revision: https://reviews.llvm.org/D107521

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
  • Loading branch information
medismailben committed Sep 3, 2021
1 parent b9e57e0 commit 3925204
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 240 deletions.
1 change: 0 additions & 1 deletion lldb/bindings/python/python-wrapper.swig
Expand Up @@ -288,7 +288,6 @@ LLDBSwigPythonCreateScriptedProcess
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
Py_RETURN_NONE;


PyErr_Cleaner py_err_cleaner(true);

auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
Expand Down
32 changes: 32 additions & 0 deletions lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -0,0 +1,32 @@
//===-- ScriptedInterface.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_INTERPRETER_SCRIPTEDINTERFACE_H
#define LLDB_INTERPRETER_SCRIPTEDINTERFACE_H

#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/lldb-private.h"

#include <string>

namespace lldb_private {
class ScriptedInterface {
public:
ScriptedInterface() = default;
virtual ~ScriptedInterface() = default;

virtual StructuredData::GenericSP
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp) = 0;

protected:
StructuredData::GenericSP m_object_instance_sp;
};
} // namespace lldb_private
#endif // LLDB_INTERPRETER_SCRIPTEDINTERFACE_H
17 changes: 6 additions & 11 deletions lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
Expand Up @@ -11,20 +11,18 @@

#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Interpreter/ScriptedInterface.h"

#include "lldb/lldb-private.h"

#include <string>

namespace lldb_private {
class ScriptedProcessInterface {
class ScriptedProcessInterface : virtual public ScriptedInterface {
public:
ScriptedProcessInterface() : m_object_instance_sp(nullptr) {}

virtual ~ScriptedProcessInterface() = default;

virtual StructuredData::GenericSP
CreatePluginObject(const llvm::StringRef class_name, lldb::TargetSP target_sp,
StructuredData::DictionarySP args_sp) {
StructuredData::GenericSP
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp) override {
return nullptr;
}

Expand Down Expand Up @@ -59,9 +57,6 @@ class ScriptedProcessInterface {
virtual lldb::pid_t GetProcessID() { return LLDB_INVALID_PROCESS_ID; }

virtual bool IsAlive() { return true; }

private:
StructuredData::ObjectSP m_object_instance_sp;
};
} // namespace lldb_private

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
Expand Up @@ -109,8 +109,10 @@ ScriptedProcess::ScriptedProcess(
return;
}

StructuredData::ObjectSP object_sp = GetInterface().CreatePluginObject(
m_scripted_process_info.GetClassName().c_str(), target_sp,
ExecutionContext exe_ctx(target_sp, /*get_process=*/false);

StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
m_scripted_process_info.GetClassName().c_str(), exe_ctx,
m_scripted_process_info.GetDictionarySP());

if (!object_sp || !object_sp->IsValid()) {
Expand Down
Expand Up @@ -11,6 +11,7 @@ add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN
PythonDataObjects.cpp
PythonReadline.cpp
ScriptInterpreterPython.cpp
ScriptedPythonInterface.cpp
ScriptedProcessPythonInterface.cpp
SWIGPythonBridge.cpp

Expand Down
Expand Up @@ -13,8 +13,6 @@

#if LLDB_ENABLE_PYTHON

#include "ScriptedProcessPythonInterface.h"

#include "lldb/Breakpoint/BreakpointOptions.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/StructuredDataImpl.h"
Expand Down

0 comments on commit 3925204

Please sign in to comment.