1//===-- ScriptedThreadPythonInterface.cpp ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Host/Config.h"
10#include "lldb/Target/ExecutionContext.h"
11#include "lldb/Utility/Log.h"
12#include "lldb/lldb-enumerations.h"
13
14#if LLDB_ENABLE_PYTHON
15
16// LLDB Python header must be included first
17#include "../lldb-python.h"
18
19#include "../SWIGPythonBridge.h"
20#include "../ScriptInterpreterPythonImpl.h"
21#include "OperatingSystemPythonInterface.h"
22
23using namespace lldb;
24using namespace lldb_private;
25using namespace lldb_private::python;
26using Locker = ScriptInterpreterPythonImpl::Locker;
27
28OperatingSystemPythonInterface::OperatingSystemPythonInterface(
29 ScriptInterpreterPythonImpl &interpreter)
30 : OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
31
32llvm::Expected<StructuredData::GenericSP>
33OperatingSystemPythonInterface::CreatePluginObject(
34 llvm::StringRef class_name, ExecutionContext &exe_ctx,
35 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
36 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj: nullptr,
37 args: exe_ctx.GetProcessSP());
38}
39
40StructuredData::DictionarySP
41OperatingSystemPythonInterface::CreateThread(lldb::tid_t tid,
42 lldb::addr_t context) {
43 Status error;
44 StructuredData::DictionarySP dict = Dispatch<StructuredData::DictionarySP>(
45 method_name: "create_thread", error, args&: tid, args&: context);
46
47 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj: dict,
48 error))
49 return {};
50
51 return dict;
52}
53
54StructuredData::ArraySP OperatingSystemPythonInterface::GetThreadInfo() {
55 Status error;
56 StructuredData::ArraySP arr =
57 Dispatch<StructuredData::ArraySP>(method_name: "get_thread_info", error);
58
59 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj: arr,
60 error))
61 return {};
62
63 return arr;
64}
65
66StructuredData::DictionarySP OperatingSystemPythonInterface::GetRegisterInfo() {
67 return ScriptedThreadPythonInterface::GetRegisterInfo();
68}
69
70std::optional<std::string>
71OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
72 Status error;
73 StructuredData::ObjectSP obj = Dispatch(method_name: "get_register_data", error, args&: tid);
74
75 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
76 error))
77 return {};
78
79 return obj->GetAsString()->GetValue().str();
80}
81
82#endif
83

source code of lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp