LLDB mainline
ScriptedThreadPythonInterface.cpp
Go to the documentation of this file.
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-python.h"
10
11#include "lldb/Host/Config.h"
13#include "lldb/Utility/Log.h"
15
16#include "../SWIGPythonBridge.h"
19#include <optional>
20
21using namespace lldb;
22using namespace lldb_private;
23using namespace lldb_private::python;
25
29
30llvm::Expected<StructuredData::GenericSP>
32 const ScriptedMetadata &scripted_metadata, ExecutionContext &exe_ctx,
33 StructuredData::Generic *script_obj) {
34 ExecutionContextRefSP exe_ctx_ref_sp =
35 std::make_shared<ExecutionContextRef>(exe_ctx);
37 scripted_metadata, script_obj, exe_ctx_ref_sp,
38 scripted_metadata.GetArgsSP());
39}
40
43 StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
44
45 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
46 error))
48
49 return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
50}
51
52std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
54 StructuredData::ObjectSP obj = Dispatch("get_name", error);
55
56 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
57 error))
58 return {};
59
60 return obj->GetStringValue().str();
61}
62
65 StructuredData::ObjectSP obj = Dispatch("get_state", error);
66
67 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
68 error))
69 return eStateInvalid;
70
71 return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
72}
73
74std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
76 StructuredData::ObjectSP obj = Dispatch("get_queue", error);
77
78 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
79 error))
80 return {};
81
82 return obj->GetStringValue().str();
83}
84
96
100 Dispatch<StructuredData::ArraySP>("get_stackframes", error);
101
102 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
103 error))
104 return {};
105
106 return arr;
107}
108
112 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
113
114 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
115 error))
116 return {};
117
118 return dict;
119}
120
123 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
124
125 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
126 error))
127 return {};
128
129 return obj->GetAsString()->GetValue().str();
130}
131
135 Dispatch<StructuredData::ArraySP>("get_extended_info", error);
136
137 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
138 error))
139 return {};
140
141 return arr;
142}
143
144std::optional<std::string>
147 StructuredData::ObjectSP obj = Dispatch("get_scripted_frame_plugin", error);
148
149 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
150 error))
151 return {};
152
153 return obj->GetStringValue().str();
154}
155
158 return m_interpreter.CreateScriptedFrameInterface();
159}
static llvm::raw_ostream & error(Stream &strm)
ScriptInterpreterPythonImpl::Locker Locker
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
StructuredData::DictionarySP GetArgsSP() const
ScriptInterpreterPythonImpl & m_interpreter
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
std::optional< std::string > GetScriptedFramePluginName() override
StructuredData::DictionarySP GetStopReason() override
StructuredData::DictionarySP GetRegisterInfo() override
std::optional< std::string > GetRegisterContext() override
ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, ExecutionContext &exe_ctx, StructuredData::Generic *script_obj=nullptr) override
lldb::ScriptedFrameInterfaceSP CreateScriptedFrameInterface() override
An error handling class.
Definition Status.h:118
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
#define LLDB_INVALID_THREAD_ID
A class that represents a running process on the host machine.
StateType
Process and Thread States.
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::ScriptedFrameInterface > ScriptedFrameInterfaceSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP