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 | |
23 | using namespace lldb; |
24 | using namespace lldb_private; |
25 | using namespace lldb_private::python; |
26 | using Locker = ScriptInterpreterPythonImpl::Locker; |
27 | |
28 | OperatingSystemPythonInterface::OperatingSystemPythonInterface( |
29 | ScriptInterpreterPythonImpl &interpreter) |
30 | : OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {} |
31 | |
32 | llvm::Expected<StructuredData::GenericSP> |
33 | OperatingSystemPythonInterface::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 | |
40 | StructuredData::DictionarySP |
41 | OperatingSystemPythonInterface::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 | |
54 | StructuredData::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 | |
66 | StructuredData::DictionarySP OperatingSystemPythonInterface::GetRegisterInfo() { |
67 | return ScriptedThreadPythonInterface::GetRegisterInfo(); |
68 | } |
69 | |
70 | std::optional<std::string> |
71 | OperatingSystemPythonInterface::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 | |