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