LLDB mainline
ScriptedFramePythonInterface.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
12#include "lldb/Host/Config.h"
14#include "lldb/Utility/Log.h"
17
18#include "../SWIGPythonBridge.h"
21#include <optional>
22
23using namespace lldb;
24using namespace lldb_private;
25using namespace lldb_private::python;
27
31
32llvm::Expected<StructuredData::GenericSP>
34 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
36 ExecutionContextRefSP exe_ctx_ref_sp =
37 std::make_shared<ExecutionContextRef>(exe_ctx);
38 ScriptedMetadata scripted_metadata(class_name, args_sp);
40 scripted_metadata, script_obj, exe_ctx_ref_sp, args_sp);
41}
42
46
47 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
48 error))
50
51 return obj->GetUnsignedIntegerValue(LLDB_INVALID_FRAME_ID);
52}
53
57
58 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
59 error))
61
62 return obj->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
63}
64
65std::optional<SymbolContext> ScriptedFramePythonInterface::GetSymbolContext() {
67 auto sym_ctx = Dispatch<SymbolContext>("get_symbol_context", error);
68
69 if (error.Fail()) {
70 return ErrorWithMessage<SymbolContext>(LLVM_PRETTY_FUNCTION,
71 error.AsCString(), error);
72 }
73
74 return sym_ctx;
75}
76
79 StructuredData::ObjectSP obj = Dispatch("get_function_name", error);
80
81 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
82 error))
83 return {};
84
85 return obj->GetStringValue().str();
86}
87
88std::optional<std::string>
91 StructuredData::ObjectSP obj = Dispatch("get_display_function_name", error);
92
93 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
94 error))
95 return {};
96
97 return obj->GetStringValue().str();
98}
99
102 StructuredData::ObjectSP obj = Dispatch("is_inlined", error);
103
104 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
105 error))
106 return false;
107
108 return obj->GetBooleanValue();
109}
110
113 StructuredData::ObjectSP obj = Dispatch("is_artificial", error);
114
115 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
116 error))
117 return false;
118
119 return obj->GetBooleanValue();
120}
121
124 StructuredData::ObjectSP obj = Dispatch("is_hidden", error);
125
126 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
127 error))
128 return false;
129
130 return obj->GetBooleanValue();
131}
132
136 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
137
138 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
139 error))
140 return {};
141
142 return dict;
143}
144
147 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
148
149 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
150 error))
151 return {};
152
153 return obj->GetAsString()->GetValue().str();
154}
155
158 auto vals = Dispatch<lldb::ValueObjectListSP>("get_variables", error);
159
160 if (error.Fail()) {
161 return ErrorWithMessage<lldb::ValueObjectListSP>(LLVM_PRETTY_FUNCTION,
162 error.AsCString(), error);
163 }
164
165 return vals;
166}
167
168std::optional<lldb::ValueType>
170 lldb::ValueObjectSP value) {
173 "get_value_type_for_variable", error, std::move(value));
174
175 if (error.Fail()) {
177 LLVM_PRETTY_FUNCTION, error.AsCString(), error);
178 }
179
180 return val;
181}
182
185 llvm::StringRef expr, uint32_t options, Status &status) {
186 Status dispatch_error;
187 auto val = Dispatch<lldb::ValueObjectSP>("get_value_for_variable_expression",
188 dispatch_error, expr.data(), options,
189 status);
190
191 if (dispatch_error.Fail()) {
193 LLVM_PRETTY_FUNCTION, dispatch_error.AsCString(), dispatch_error);
194 }
195
196 return val;
197}
198
202 "Provide frame state for scripted threads and frame providers.",
204 {});
205}
206
static llvm::raw_ostream & error(Stream &strm)
ScriptInterpreterPythonImpl::Locker Locker
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
std::optional< std::string > GetRegisterContext() override
std::optional< lldb::ValueType > GetValueTypeForVariable(lldb::ValueObjectSP value) override
std::optional< std::string > GetDisplayFunctionName() override
std::optional< SymbolContext > GetSymbolContext() override
StructuredData::DictionarySP GetRegisterInfo() override
lldb::ValueObjectSP GetValueObjectForVariableExpression(llvm::StringRef expr, uint32_t options, Status &status) override
std::optional< std::string > GetFunctionName() override
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj=nullptr) override
ScriptedFramePythonInterface(ScriptInterpreterPythonImpl &interpreter)
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_category=LLDBLog::Process)
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
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)
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_FRAME_ID
A class that represents a running process on the host machine.
@ eScriptLanguagePython
@ eScriptedExtensionScriptedFrame
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP