LLDB mainline
SyntheticFrameProvider.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
12#include "lldb/Target/Thread.h"
14#include "lldb/Utility/Log.h"
15#include "lldb/Utility/Status.h"
16#include "lldb/Utility/Stream.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
23
25
27 if (!s)
28 return;
29
30 s->Format(" ID: {0:x}\n", GetID());
31 s->Printf(" Name: %s\n", GetName().str().c_str());
32
33 std::string description = GetDescription();
34 if (!description.empty())
35 s->Printf(" Description: %s\n", description.c_str());
36
37 // Show priority information.
38 std::optional<uint32_t> priority = GetPriority();
39 if (priority.has_value())
40 s->Printf(" Priority: %u\n", *priority);
41 else
42 s->PutCString(" Priority: Default (no priority specified)\n");
43
44 // Show thread filter information.
45 if (thread_specs.empty()) {
46 s->PutCString(" Thread Filter: (applies to all threads)\n");
47 } else {
48 s->Printf(" Thread Filter: %zu specification(s)\n", thread_specs.size());
49 for (size_t i = 0; i < thread_specs.size(); ++i) {
50 const ThreadSpec &spec = thread_specs[i];
51 s->Printf(" [%zu] ", i);
53 s->PutChar('\n');
54 }
55 }
56}
57
60 return 0;
61
62 return scripted_metadata_sp->GetID();
63}
64
66 // If we have an interface, call get_description() to fetch it.
68 return interface_sp->GetDescription(scripted_metadata_sp->GetClassName());
69 return {};
70}
71
72std::optional<uint32_t> ScriptedFrameProviderDescriptor::GetPriority() const {
73 // If we have an interface, call get_priority() to fetch it.
75 return interface_sp->GetPriority(scripted_metadata_sp->GetClassName());
76 return std::nullopt;
77}
78
79llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(
80 StackFrameListSP input_frames,
81 const ScriptedFrameProviderDescriptor &descriptor) {
82 if (!input_frames)
83 return llvm::createStringError(
84 "cannot create synthetic frame provider: invalid input frames");
85
86 // Iterate through all registered ScriptedFrameProvider plugins.
87 ScriptedFrameProviderCreateInstance create_callback = nullptr;
88 for (uint32_t idx = 0;
89 (create_callback =
91 idx)) != nullptr;
92 ++idx) {
93 auto provider_or_err = create_callback(input_frames, descriptor);
94 if (!provider_or_err) {
95 LLDB_LOG_ERROR(GetLog(LLDBLog::Target), provider_or_err.takeError(),
96 "Failed to create synthetic frame provider: {0}");
97 continue;
98 }
99
100 if (auto frame_provider_up = std::move(*provider_or_err))
101 return std::move(frame_provider_up);
102 }
103
104 return llvm::createStringError(
105 "cannot create synthetic frame provider: no suitable plugin found");
106}
107
108llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(
109 StackFrameListSP input_frames, llvm::StringRef plugin_name,
110 const std::vector<ThreadSpec> &thread_specs) {
111 if (!input_frames)
112 return llvm::createStringError(
113 "cannot create synthetic frame provider: invalid input frames");
114
115 // Look up the specific C++ plugin by name.
118 plugin_name);
119
120 if (!create_callback)
121 return llvm::createStringError(
122 "cannot create synthetic frame provider: C++ plugin '%s' not found",
123 plugin_name.str().c_str());
124
125 auto provider_or_err = create_callback(input_frames, thread_specs);
126 if (!provider_or_err)
127 return provider_or_err.takeError();
128
129 if (auto frame_provider_sp = std::move(*provider_or_err))
130 return std::move(frame_provider_sp);
131
132 return llvm::createStringError(
133 "cannot create synthetic frame provider: C++ plugin '%s' returned null",
134 plugin_name.str().c_str());
135}
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static SyntheticFrameProviderCreateInstance GetSyntheticFrameProviderCreateCallbackForPluginName(llvm::StringRef name)
static ScriptedFrameProviderCreateInstance GetScriptedFrameProviderCreateCallbackAtIndex(uint32_t idx)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Definition Stream.h:364
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
size_t PutChar(char ch)
Definition Stream.cpp:131
static llvm::Expected< lldb::SyntheticFrameProviderSP > CreateInstance(lldb::StackFrameListSP input_frames, const ScriptedFrameProviderDescriptor &descriptor)
Try to create a SyntheticFrameProvider instance for the given input frames and descriptor.
SyntheticFrameProvider(lldb::StackFrameListSP input_frames)
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
llvm::Expected< lldb::SyntheticFrameProviderSP >(* SyntheticFrameProviderCreateInstance)(lldb::StackFrameListSP input_frames, const std::vector< lldb_private::ThreadSpec > &thread_specs)
llvm::Expected< lldb::SyntheticFrameProviderSP >(* ScriptedFrameProviderCreateInstance)(lldb::StackFrameListSP input_frames, const lldb_private::ScriptedFrameProviderDescriptor &descriptor)
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
This struct contains the metadata needed to instantiate a frame provider and optional filters to cont...
std::vector< ThreadSpec > thread_specs
Optional list of thread specifications to which this provider applies.
uint32_t GetID() const
Get a unique identifier for this descriptor based on its contents.
lldb::ScriptedMetadataSP scripted_metadata_sp
Metadata for instantiating the provider (e.g. script class name and args).
void Dump(Stream *s) const
Dump a description of this descriptor to the given stream.
llvm::StringRef GetName() const
Get the name of this descriptor (the scripted class name).
lldb::ScriptedFrameProviderInterfaceSP interface_sp
Interface for calling static methods on the provider class.
std::string GetDescription() const
Get the description of this frame provider.
std::optional< uint32_t > GetPriority() const
Get the priority of this frame provider.