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/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
45
46 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
47 error))
49
50 return obj->GetUnsignedIntegerValue(LLDB_INVALID_FRAME_ID);
51}
52
56
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
58 error))
60
61 return obj->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
62}
63
64std::optional<SymbolContext> ScriptedFramePythonInterface::GetSymbolContext() {
66 auto sym_ctx = Dispatch<SymbolContext>("get_symbol_context", error);
67
68 if (error.Fail()) {
69 return ErrorWithMessage<SymbolContext>(LLVM_PRETTY_FUNCTION,
70 error.AsCString(), error);
71 }
72
73 return sym_ctx;
74}
75
78 StructuredData::ObjectSP obj = Dispatch("get_function_name", error);
79
80 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
81 error))
82 return {};
83
84 return obj->GetStringValue().str();
85}
86
87std::optional<std::string>
90 StructuredData::ObjectSP obj = Dispatch("get_display_function_name", error);
91
92 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
93 error))
94 return {};
95
96 return obj->GetStringValue().str();
97}
98
101 StructuredData::ObjectSP obj = Dispatch("is_inlined", error);
102
103 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
104 error))
105 return false;
106
107 return obj->GetBooleanValue();
108}
109
112 StructuredData::ObjectSP obj = Dispatch("is_artificial", error);
113
114 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
115 error))
116 return false;
117
118 return obj->GetBooleanValue();
119}
120
123 StructuredData::ObjectSP obj = Dispatch("is_hidden", error);
124
125 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
126 error))
127 return false;
128
129 return obj->GetBooleanValue();
130}
131
135 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
136
137 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
138 error))
139 return {};
140
141 return dict;
142}
143
146 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
147
148 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
149 error))
150 return {};
151
152 return obj->GetAsString()->GetValue().str();
153}
154
157 auto vals = Dispatch<lldb::ValueObjectListSP>("get_variables", error);
158
159 if (error.Fail()) {
160 return ErrorWithMessage<lldb::ValueObjectListSP>(LLVM_PRETTY_FUNCTION,
161 error.AsCString(), error);
162 }
163
164 return vals;
165}
166
169 llvm::StringRef expr, uint32_t options, Status &status) {
170 Status dispatch_error;
171 auto val = Dispatch<lldb::ValueObjectSP>("get_value_for_variable_expression",
172 dispatch_error, expr.data(), options,
173 status);
174
175 if (dispatch_error.Fail()) {
177 LLVM_PRETTY_FUNCTION, dispatch_error.AsCString(), dispatch_error);
178 }
179
180 return val;
181}
static llvm::raw_ostream & error(Stream &strm)
ScriptInterpreterPythonImpl::Locker Locker
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
std::optional< std::string > GetRegisterContext() 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)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:294
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:195
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.
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