Skip to content

Commit 30d7985

Browse files
committed
[lldb] Add OperatingSystem to scripting template list
This patch is a follow-up to bccff3b which adds the `OperatingSystem` extension to the `scripting template list` command as well as its description. Signed-off-by: Med Ismail Bennani <[email protected]> (cherry picked from commit 995f643)
1 parent 459c28f commit 30d7985

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if (LLDB_ENABLE_LIBEDIT)
2020
endif()
2121

2222
add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
23-
OperatingSystemPythonInterface.cpp
2423
ScriptedPythonInterface.cpp
2524
ScriptedProcessPythonInterface.cpp
2625
ScriptedThreadPythonInterface.cpp
@@ -36,5 +35,8 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
3635
LINK_COMPONENTS
3736
Support
3837
)
38+
39+
add_subdirectory(OperatingSystemPythonInterface)
3940
add_subdirectory(ScriptedPlatformPythonInterface)
4041
add_subdirectory(ScriptedThreadPlanPythonInterface)
42+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_lldb_library(lldbPluginScriptInterpreterPythonOperatingSystemPythonInterface PLUGIN
2+
3+
OperatingSystemPythonInterface.cpp
4+
5+
LINK_LIBS
6+
lldbCore
7+
lldbHost
8+
lldbInterpreter
9+
lldbTarget
10+
lldbPluginScriptInterpreterPython
11+
${Python3_LIBRARIES}
12+
${LLDB_LIBEDIT_LIBS}
13+
14+
LINK_COMPONENTS
15+
Support
16+
)

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp renamed to lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "lldb/Core/PluginManager.h"
910
#include "lldb/Host/Config.h"
1011
#include "lldb/Target/ExecutionContext.h"
1112
#include "lldb/Utility/Log.h"
1213
#include "lldb/lldb-enumerations.h"
1314

1415
#if LLDB_ENABLE_PYTHON
1516

17+
// clang-format off
1618
// LLDB Python header must be included first
17-
#include "../lldb-python.h"
19+
#include "../../lldb-python.h"
20+
//clang-format on
1821

19-
#include "../SWIGPythonBridge.h"
20-
#include "../ScriptInterpreterPythonImpl.h"
22+
#include "../../SWIGPythonBridge.h"
23+
#include "../../ScriptInterpreterPythonImpl.h"
2124
#include "OperatingSystemPythonInterface.h"
2225

2326
using namespace lldb;
2427
using namespace lldb_private;
2528
using namespace lldb_private::python;
2629
using Locker = ScriptInterpreterPythonImpl::Locker;
2730

31+
LLDB_PLUGIN_DEFINE_ADV(OperatingSystemPythonInterface, ScriptInterpreterPythonOperatingSystemPythonInterface)
32+
2833
OperatingSystemPythonInterface::OperatingSystemPythonInterface(
2934
ScriptInterpreterPythonImpl &interpreter)
3035
: OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
@@ -79,4 +84,18 @@ OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
7984
return obj->GetAsString()->GetValue().str();
8085
}
8186

87+
void OperatingSystemPythonInterface::Initialize() {
88+
const std::vector<llvm::StringRef> ci_usages = {
89+
"settings set target.process.python-os-plugin-path <script-path>",
90+
"settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
91+
const std::vector<llvm::StringRef> api_usages = {};
92+
PluginManager::RegisterPlugin(
93+
GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
94+
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
95+
}
96+
97+
void OperatingSystemPythonInterface::Terminate() {
98+
PluginManager::UnregisterPlugin(CreateInstance);
99+
}
100+
82101
#endif

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h renamed to lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
1111

1212
#include "lldb/Host/Config.h"
13+
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"
1314

1415
#if LLDB_ENABLE_PYTHON
1516

16-
#include "ScriptedThreadPythonInterface.h"
17-
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"
17+
#include "../ScriptedThreadPythonInterface.h"
18+
1819
#include <optional>
1920

2021
namespace lldb_private {
2122
class OperatingSystemPythonInterface
2223
: virtual public OperatingSystemInterface,
23-
virtual public ScriptedThreadPythonInterface {
24+
virtual public ScriptedThreadPythonInterface,
25+
public PluginInterface {
2426
public:
2527
OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter);
2628

@@ -41,6 +43,16 @@ class OperatingSystemPythonInterface
4143
StructuredData::DictionarySP GetRegisterInfo() override;
4244

4345
std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) override;
46+
47+
static void Initialize();
48+
49+
static void Terminate();
50+
51+
static llvm::StringRef GetPluginNameStatic() {
52+
return "OperatingSystemPythonInterface";
53+
}
54+
55+
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
4456
};
4557
} // namespace lldb_private
4658

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
// LLDB Python header must be included first
1515
#include "lldb-python.h"
1616

17-
#include "Interfaces/OperatingSystemPythonInterface.h"
17+
#include "Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h"
1818
#include "Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.h"
1919
#include "Interfaces/ScriptedProcessPythonInterface.h"
2020
#include "Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.h"
21-
#include "Interfaces/ScriptedThreadPythonInterface.h"
2221
#include "PythonDataObjects.h"
2322
#include "PythonReadline.h"
2423
#include "SWIGPythonBridge.h"

0 commit comments

Comments
 (0)