[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2023-01-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb1256f2345f6: [lldb/Interpreter] Introduce 
ScriptedPlatform{,Python}Interface (authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

Files:
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
@@ -0,0 +1,44 @@
+//===-- ScriptedPlatformPythonInterface.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedPythonInterface.h"
+#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+
+namespace lldb_private {
+class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
+public ScriptedPythonInterface {
+public:
+  ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name,
+ ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+  StructuredData::DictionarySP ListProcesses() override;
+
+  StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
+
+  Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) override;
+
+  Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) override;
+
+  Status KillProcess(lldb::pid_t pid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
@@ -0,0 +1,108 @@
+//===-- ScriptedPlatformPythonInterface.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 "lldb/Host/Config.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "lldb-python.h"
+
+#include "SWIGPythonBridge.h"
+#include "ScriptInterpreterPythonImpl.h"
+#include "ScriptedPlatformPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
+ScriptInterpreterPythonImpl &interpreter)
+: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
+
+StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::StringRef class_name, ExecutionContext &exe_ctx,
+StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+  if (class_name.empty())
+return {};
+
+  StructuredDataImpl args_impl(args_sp);
+  std::string error_string;
+
+  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+  lldb::ExecutionContextRefSP exe_ctx_ref_sp =
+  std::make_shared(exe_ctx);
+
+  PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
+  class_name.str().c_str(), m_interpreter.GetDictionaryName(),
+  exe_ctx_ref_sp, args_impl, error_string);
+
+  m_object_instance_sp =
+  StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
+
+ 

[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2023-01-11 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 488488.
mib added a comment.

Add `AttachToProcess` method to interface


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

Files:
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
@@ -0,0 +1,44 @@
+//===-- ScriptedPlatformPythonInterface.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedPythonInterface.h"
+#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+
+namespace lldb_private {
+class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
+public ScriptedPythonInterface {
+public:
+  ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name,
+ ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+  StructuredData::DictionarySP ListProcesses() override;
+
+  StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
+
+  Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) override;
+
+  Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) override;
+
+  Status KillProcess(lldb::pid_t pid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
@@ -0,0 +1,108 @@
+//===-- ScriptedPlatformPythonInterface.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 "lldb/Host/Config.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "lldb-python.h"
+
+#include "SWIGPythonBridge.h"
+#include "ScriptInterpreterPythonImpl.h"
+#include "ScriptedPlatformPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
+ScriptInterpreterPythonImpl &interpreter)
+: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
+
+StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::StringRef class_name, ExecutionContext &exe_ctx,
+StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+  if (class_name.empty())
+return {};
+
+  StructuredDataImpl args_impl(args_sp);
+  std::string error_string;
+
+  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+  lldb::ExecutionContextRefSP exe_ctx_ref_sp =
+  std::make_shared(exe_ctx);
+
+  PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
+  class_name.str().c_str(), m_interpreter.GetDictionaryName(),
+  exe_ctx_ref_sp, args_impl, error_string);
+
+  m_object_instance_sp =
+  StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
+
+  return m_object_instance_sp;
+}
+
+StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
+  Stat

[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2023-01-10 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 488006.
mib marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

Files:
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
@@ -0,0 +1,42 @@
+//===-- ScriptedPlatformPythonInterface.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedPythonInterface.h"
+#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+
+namespace lldb_private {
+class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
+public ScriptedPythonInterface {
+public:
+  ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name,
+ ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+  StructuredData::DictionarySP ListProcesses() override;
+
+  StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
+
+  Status LaunchProcess() override;
+
+  Status KillProcess(lldb::pid_t pid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
@@ -0,0 +1,100 @@
+//===-- ScriptedPlatformPythonInterface.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 "lldb/Host/Config.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "lldb-python.h"
+
+#include "SWIGPythonBridge.h"
+#include "ScriptInterpreterPythonImpl.h"
+#include "ScriptedPlatformPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
+ScriptInterpreterPythonImpl &interpreter)
+: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
+
+StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::StringRef class_name, ExecutionContext &exe_ctx,
+StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+  if (class_name.empty())
+return {};
+
+  StructuredDataImpl args_impl(args_sp);
+  std::string error_string;
+
+  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+  lldb::ExecutionContextRefSP exe_ctx_ref_sp =
+  std::make_shared(exe_ctx);
+
+  PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
+  class_name.str().c_str(), m_interpreter.GetDictionaryName(),
+  exe_ctx_ref_sp, args_impl, error_string);
+
+  m_object_instance_sp =
+  StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
+
+  return m_object_instance_sp;
+}
+
+StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
+  Status error;
+  StructuredData::DictionarySP dict_sp =
+  Dispatch("list_processes", error);
+
+  if (!dict_sp || !dict_sp->IsValid() || err

[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2022-12-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp:97
+
+#endif

nit: This `#endif` should have a ` // LLDB_ENABLE_PYTHON` at the end of it to 
be consistent style-wise.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2022-12-10 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 481848.
mib marked 4 inline comments as done.
mib added a comment.

Address @bulbazord comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

Files:
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
@@ -0,0 +1,42 @@
+//===-- ScriptedPlatformPythonInterface.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedPythonInterface.h"
+#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+
+namespace lldb_private {
+class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
+public ScriptedPythonInterface {
+public:
+  ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name,
+ ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+  StructuredData::DictionarySP ListProcesses() override;
+
+  StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
+
+  Status LaunchProcess() override;
+
+  Status KillProcess(lldb::pid_t pid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
@@ -0,0 +1,97 @@
+//===-- ScriptedPlatformPythonInterface.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 "lldb/Host/Config.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "lldb-python.h"
+
+#include "SWIGPythonBridge.h"
+#include "ScriptInterpreterPythonImpl.h"
+#include "ScriptedPlatformPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
+ScriptInterpreterPythonImpl &interpreter)
+: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
+
+StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::StringRef class_name, ExecutionContext &exe_ctx,
+StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+  if (class_name.empty())
+return {};
+
+  StructuredDataImpl args_impl(args_sp);
+  std::string error_string;
+
+  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+  PythonObject ret_val = LLDBSwigPythonCreateScriptedPlatform(
+  class_name.str().c_str(), m_interpreter.GetDictionaryName(), args_impl,
+  error_string);
+
+  m_object_instance_sp =
+  StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
+
+  return m_object_instance_sp;
+}
+
+StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
+  Status error;
+  StructuredData::DictionarySP dict_sp =
+  Dispatch("list_processes", error);
+
+  if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
+return ScriptedInterface::Erro

[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2022-12-06 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h:14
+#include "lldb/Interpreter/ScriptedInterface.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+

What is `MemoryRegionInfo.h` for?



Comment at: lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h:36-42
+  virtual Status LaunchProcess() {
+return Status("ScriptedPlatform cannot launch process");
+  }
+
+  virtual Status KillProcess(lldb::pid_t pid) {
+return Status("ScriptedPlatform cannot kill process");
+  }

The status messages should probably refer to `ScriptedPlatformInterface` 
instead of `ScriptedPlatform` to be clearer.



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp:1-2
+//===-- ScriptedPlatformPythonInterface.cpp
+//===//
+//

This header is also broken.



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h:1-2
+//===-- ScriptedPlatformPythonInterface.h *- C++
+//-*-===//
+//

The header is a little broken here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139251/new/

https://reviews.llvm.org/D139251

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface

2022-12-02 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: JDevlieghere, bulbazord.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch introduces both the ScriptedPlatformInterface and the
ScriptedPlatformPythonInterface. As the name suggests, these calls will
be used to call into the Scripted Platform python implementation from
the C++ Scripted Platform plugin instance.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139251

Files:
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
@@ -0,0 +1,43 @@
+//===-- ScriptedPlatformPythonInterface.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_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedPythonInterface.h"
+#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+
+namespace lldb_private {
+class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
+public ScriptedPythonInterface {
+public:
+  ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name,
+ ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+  StructuredData::DictionarySP ListProcesses() override;
+
+  StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
+
+  Status LaunchProcess() override;
+
+  Status KillProcess(lldb::pid_t pid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
@@ -0,0 +1,98 @@
+//===-- ScriptedPlatformPythonInterface.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 "lldb/Host/Config.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "lldb-python.h"
+
+#include "SWIGPythonBridge.h"
+#include "ScriptInterpreterPythonImpl.h"
+#include "ScriptedPlatformPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
+ScriptInterpreterPythonImpl &interpreter)
+: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
+
+StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::StringRef class_name, ExecutionContext &exe_ctx,
+StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+  if (class_name.empty())
+return {};
+
+  StructuredDataImpl args_impl(args_sp);
+  std::string error_string;
+
+  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+  PythonObject ret_val = LLDBSwigPythonCreateScriptedPlatform(
+  class_name.str().c_str(), m_interpreter.GetDictionaryName(), args_impl,
+  error_string);
+
+  m_object_instance_sp =
+  StructuredData::GenericSP(new StructuredPytho