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/Host/Config.h"
11#include "lldb/Utility/Log.h"
13
14// LLDB Python header must be included first
15#include "../lldb-python.h"
16
17#include "../SWIGPythonBridge.h"
20#include <optional>
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::python;
26
30
31llvm::Expected<StructuredData::GenericSP>
33 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
35 ExecutionContextRefSP exe_ctx_ref_sp =
36 std::make_shared<ExecutionContextRef>(exe_ctx);
37 StructuredDataImpl sd_impl(args_sp);
38 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
39 exe_ctx_ref_sp, sd_impl);
40}
41
44 StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
45
46 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
47 error))
49
50 return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
51}
52
53std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
55 StructuredData::ObjectSP obj = Dispatch("get_name", error);
56
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
58 error))
59 return {};
60
61 return obj->GetStringValue().str();
62}
63
66 StructuredData::ObjectSP obj = Dispatch("get_state", error);
67
68 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
69 error))
70 return eStateInvalid;
71
72 return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
73}
74
75std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
77 StructuredData::ObjectSP obj = Dispatch("get_queue", error);
78
79 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
80 error))
81 return {};
82
83 return obj->GetStringValue().str();
84}
85
97
101 Dispatch<StructuredData::ArraySP>("get_stackframes", error);
102
103 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
104 error))
105 return {};
106
107 return arr;
108}
109
113 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
114
115 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
116 error))
117 return {};
118
119 return dict;
120}
121
124 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
125
126 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
127 error))
128 return {};
129
130 return obj->GetAsString()->GetValue().str();
131}
132
136 Dispatch<StructuredData::ArraySP>("get_extended_info", error);
137
138 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
139 error))
140 return {};
141
142 return arr;
143}
144
145std::optional<std::string>
148 StructuredData::ObjectSP obj = Dispatch("get_scripted_frame_plugin", error);
149
150 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
151 error))
152 return {};
153
154 return obj->GetStringValue().str();
155}
156
159 return m_interpreter.CreateScriptedFrameInterface();
160}
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)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
ScriptInterpreterPythonImpl & m_interpreter
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, 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)
lldb::ScriptedFrameInterfaceSP CreateScriptedFrameInterface() override
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj=nullptr) 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