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 thread filter information.
38 if (thread_specs.empty()) {
39 s->PutCString(" Thread Filter: (applies to all threads)\n");
40 } else {
41 s->Printf(" Thread Filter: %zu specification(s)\n", thread_specs.size());
42 for (size_t i = 0; i < thread_specs.size(); ++i) {
43 const ThreadSpec &spec = thread_specs[i];
44 s->Printf(" [%zu] ", i);
46 s->PutChar('\n');
47 }
48 }
49}
50
53 return 0;
54
55 return scripted_metadata_sp->GetID();
56}
57
59 // If we have an interface, call get_description() to fetch it.
61 return interface_sp->GetDescription(scripted_metadata_sp->GetClassName());
62 return {};
63}
64
65llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(
66 StackFrameListSP input_frames,
67 const ScriptedFrameProviderDescriptor &descriptor) {
68 if (!input_frames)
69 return llvm::createStringError(
70 "cannot create synthetic frame provider: invalid input frames");
71
72 // Iterate through all registered ScriptedFrameProvider plugins.
73 ScriptedFrameProviderCreateInstance create_callback = nullptr;
74 for (uint32_t idx = 0;
75 (create_callback =
77 idx)) != nullptr;
78 ++idx) {
79 auto provider_or_err = create_callback(input_frames, descriptor);
80 if (!provider_or_err) {
81 LLDB_LOG_ERROR(GetLog(LLDBLog::Target), provider_or_err.takeError(),
82 "Failed to create synthetic frame provider: {0}");
83 continue;
84 }
85
86 if (auto frame_provider_up = std::move(*provider_or_err))
87 return std::move(frame_provider_up);
88 }
89
90 return llvm::createStringError(
91 "cannot create synthetic frame provider: no suitable plugin found");
92}
93
94llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(
95 StackFrameListSP input_frames, llvm::StringRef plugin_name,
96 const std::vector<ThreadSpec> &thread_specs) {
97 if (!input_frames)
98 return llvm::createStringError(
99 "cannot create synthetic frame provider: invalid input frames");
100
101 // Look up the specific C++ plugin by name.
104 plugin_name);
105
106 if (!create_callback)
107 return llvm::createStringError(
108 "cannot create synthetic frame provider: C++ plugin '%s' not found",
109 plugin_name.str().c_str());
110
111 auto provider_or_err = create_callback(input_frames, thread_specs);
112 if (!provider_or_err)
113 return provider_or_err.takeError();
114
115 if (auto frame_provider_sp = std::move(*provider_or_err))
116 return std::move(frame_provider_sp);
117
118 return llvm::createStringError(
119 "cannot create synthetic frame provider: C++ plugin '%s' returned null",
120 plugin_name.str().c_str());
121}
#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.