21#include "llvm/Support/Error.h"
31 "Provides synthetic frames via scripting",
39llvm::Expected<lldb::SyntheticFrameProviderSP>
44 return llvm::createStringError(
45 "failed to create scripted frame provider: invalid input frames");
47 Thread &thread = input_frames->GetThread();
48 ProcessSP process_sp = thread.GetProcess();
53 return llvm::createStringError(
54 "failed to create scripted frame provider: invalid scripted metadata");
60 process_sp->GetTarget().GetDebugger().GetScriptInterpreter();
62 return llvm::createStringError(
"cannot create scripted frame provider: No "
63 "script interpreter installed");
68 return llvm::createStringError(
69 "cannot create scripted frame provider: script interpreter couldn't "
70 "create Scripted Frame Provider Interface");
75 if (!interface_sp->AppliesToThread(scripted_metadata->GetClassName(),
76 thread.shared_from_this()))
79 auto obj_or_err = interface_sp->CreatePluginObject(
80 scripted_metadata->GetClassName(), input_frames,
81 scripted_metadata->GetArgsSP());
83 return obj_or_err.takeError();
86 if (!object_sp || !object_sp->IsValid())
87 return llvm::createStringError(
88 "cannot create scripted frame provider: failed to create valid scripted"
89 "frame provider object");
91 return std::make_shared<ScriptedFrameProvider>(input_frames, interface_sp,
118llvm::Expected<StackFrameSP>
121 return llvm::createStringError(
122 "cannot get stack frame: scripted frame provider not initialized");
124 auto create_frame_from_dict =
126 uint32_t index) -> llvm::Expected<StackFrameSP> {
129 return llvm::createStringError(
130 "missing 'pc' key from scripted frame dictionary");
136 const bool cfa_is_valid =
false;
137 const bool artificial =
false;
138 const bool behaves_like_zeroth_frame =
false;
143 return std::make_shared<StackFrame>(thread_sp, index, index, cfa,
146 behaves_like_zeroth_frame, &sc);
149 auto create_frame_from_script_object =
153 if (!object_sp || !object_sp->GetAsGeneric())
154 return llvm::createStringError(
"invalid script object");
158 object_sp->GetAsGeneric());
160 if (!frame_or_error) {
162 LLVM_PRETTY_FUNCTION,
toString(frame_or_error.takeError()),
error);
163 return error.ToError();
166 return *frame_or_error;
172 if (!obj_sp || !obj_sp->IsValid())
173 return llvm::createStringError(
"invalid script object returned for frame " +
178 obj_sp->GetAsUnsignedInteger()) {
179 uint32_t real_frame_index = int_obj->GetValue();
180 if (real_frame_index < m_input_frames->GetNumFrames()) {
184 (real_frame_index == idx)
186 : std::make_shared<BorrowedStackFrame>(real_frame_sp, idx);
190 auto frame_from_dict_or_err = create_frame_from_dict(dict, idx);
191 if (!frame_from_dict_or_err) {
192 return llvm::createStringError(llvm::Twine(
193 "couldn't create frame from dictionary at index " + llvm::Twine(idx) +
194 ": " +
toString(frame_from_dict_or_err.takeError())));
196 synth_frame_sp = *frame_from_dict_or_err;
197 }
else if (obj_sp->GetAsGeneric()) {
199 auto frame_from_script_obj_or_err = create_frame_from_script_object(obj_sp);
200 if (!frame_from_script_obj_or_err) {
201 return llvm::createStringError(
202 llvm::Twine(
"couldn't create frame from script object at index " +
203 llvm::Twine(idx) +
": " +
204 toString(frame_from_script_obj_or_err.takeError())));
206 synth_frame_sp = *frame_from_script_obj_or_err;
208 return llvm::createStringError(
209 llvm::Twine(
"invalid return type from get_frame_at_index at index " +
214 return llvm::createStringError(
215 llvm::Twine(
"failed to create frame at index " + llvm::Twine(idx)));
217 synth_frame_sp->SetFrameIndex(idx);
219 return synth_frame_sp;
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
A section + offset based address class.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
virtual lldb::ScriptedFrameProviderInterfaceSP CreateScriptedFrameProviderInterface()
lldb::ScriptedFrameProviderInterfaceSP m_interface_sp
static llvm::StringRef GetPluginNameStatic()
llvm::Expected< lldb::StackFrameSP > GetFrameAtIndex(uint32_t idx) override
Get a single stack frame at the specified index.
static llvm::Expected< lldb::SyntheticFrameProviderSP > CreateInstance(lldb::StackFrameListSP input_frames, const ScriptedFrameProviderDescriptor &descriptor)
~ScriptedFrameProvider() override
ScriptedFrameProvider(lldb::StackFrameListSP input_frames, lldb::ScriptedFrameProviderInterfaceSP interface_sp, const ScriptedFrameProviderDescriptor &descriptor)
const ScriptedFrameProviderDescriptor & m_descriptor
std::optional< uint32_t > GetPriority() const override
Get the priority of this frame provider.
std::string GetDescription() const override
static llvm::Expected< std::shared_ptr< ScriptedFrame > > Create(lldb::ThreadSP thread_sp, lldb::ScriptedThreadInterfaceSP scripted_thread_interface_sp, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_object=nullptr)
Create a ScriptedFrame from a object instanciated in the script interpreter.
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_category=LLDBLog::Process)
@ Synthetic
An synthetic stack frame (e.g.
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
std::shared_ptr< Object > ObjectSP
Integer< uint64_t > UnsignedInteger
Defines a symbol context baton that can be handed other debug core functions.
Thread & GetThread()
Get the thread associated with this provider.
lldb::StackFrameListSP m_input_frames
SyntheticFrameProvider(lldb::StackFrameListSP input_frames)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::ScriptedFrameProviderInterface > ScriptedFrameProviderInterfaceSP
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
This struct contains the metadata needed to instantiate a frame provider and optional filters to cont...
lldb::ScriptedMetadataSP scripted_metadata_sp
Metadata for instantiating the provider (e.g. script class name and args).
bool AppliesToThread(Thread &thread) const
Check if this descriptor applies to the given thread.
bool IsValid() const
Check if this descriptor has valid metadata for script-based providers.