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
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 llvm::StringRef class_name, ExecutionContext &exe_ctx,
34 ExecutionContextRefSP exe_ctx_ref_sp =
35 std::make_shared<ExecutionContextRef>(exe_ctx);
36 ScriptedMetadata scripted_metadata(class_name, args_sp);
38 scripted_metadata, script_obj, exe_ctx_ref_sp, args_sp);
39}
40
44
45 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
46 error))
48
49 return obj->GetUnsignedIntegerValue(LLDB_INVALID_FRAME_ID);
50}
51
55
56 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
57 error))
59
60 return obj->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
61}
62
63std::optional<SymbolContext> ScriptedFramePythonInterface::GetSymbolContext() {
65 auto sym_ctx = Dispatch<SymbolContext>("get_symbol_context", error);
66
67 if (error.Fail()) {
68 return ErrorWithMessage<SymbolContext>(LLVM_PRETTY_FUNCTION,
69 error.AsCString(), error);
70 }
71
72 return sym_ctx;
73}
74
77 StructuredData::ObjectSP obj = Dispatch("get_function_name", error);
78
79 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
80 error))
81 return {};
82
83 return obj->GetStringValue().str();
84}
85
86std::optional<std::string>
89 StructuredData::ObjectSP obj = Dispatch("get_display_function_name", error);
90
91 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
92 error))
93 return {};
94
95 return obj->GetStringValue().str();
96}
97
100 StructuredData::ObjectSP obj = Dispatch("is_inlined", error);
101
102 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
103 error))
104 return false;
105
106 return obj->GetBooleanValue();
107}
108
111 StructuredData::ObjectSP obj = Dispatch("is_artificial", error);
112
113 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
114 error))
115 return false;
116
117 return obj->GetBooleanValue();
118}
119
122 StructuredData::ObjectSP obj = Dispatch("is_hidden", error);
123
124 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
125 error))
126 return false;
127
128 return obj->GetBooleanValue();
129}
130
134 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
135
136 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
137 error))
138 return {};
139
140 return dict;
141}
142
145 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
146
147 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
148 error))
149 return {};
150
151 return obj->GetAsString()->GetValue().str();
152}
153
156 auto vals = Dispatch<lldb::ValueObjectListSP>("get_variables", error);
157
158 if (error.Fail()) {
159 return ErrorWithMessage<lldb::ValueObjectListSP>(LLVM_PRETTY_FUNCTION,
160 error.AsCString(), error);
161 }
162
163 return vals;
164}
165
168 llvm::StringRef expr, uint32_t options, Status &status) {
169 Status dispatch_error;
170 auto val = Dispatch<lldb::ValueObjectSP>("get_value_for_variable_expression",
171 dispatch_error, expr.data(), options,
172 status);
173
174 if (dispatch_error.Fail()) {
176 LLVM_PRETTY_FUNCTION, dispatch_error.AsCString(), dispatch_error);
177 }
178
179 return val;
180}
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)
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.
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