16#include "llvm/Support/MemoryBuffer.h"
24 llvm::DataExtractor::Cursor &cursor) {
25 while (!section.eof(cursor)) {
26 if (section.getU8(cursor) == 0)
29 cursor.seek(cursor.tell() - 1);
38 std::function<
void(llvm::DataExtractor, llvm::StringRef)> fn) {
39 auto *sections =
module.GetSectionList();
43 auto section_sp = sections->FindSectionByType(section_type,
true);
66 auto section_size = section_sp->GetSectionData(lldb_extractor);
67 llvm::DataExtractor section = lldb_extractor.
GetAsLLVM();
68 bool le = section.isLittleEndian();
69 llvm::DataExtractor::Cursor cursor(0);
70 while (cursor && cursor.tell() < section_size) {
74 uint64_t version = section.getULEB128(cursor);
75 uint64_t record_size = section.getULEB128(cursor);
76 if (cursor && record_size > section_size - cursor.tell()) {
78 "Record size {0} exceeds the remaining size of the embedded "
79 "formatter section in {1}; ignoring the rest of the section.",
84 llvm::DataExtractor record(
85 section.getData().drop_front(cursor.tell()).take_front(record_size),
87 llvm::DataExtractor::Cursor cursor(0);
88 uint64_t type_size = record.getULEB128(cursor);
89 llvm::StringRef type_name = record.getBytes(cursor, type_size);
90 llvm::Error
error = cursor.takeError();
92 fn(llvm::DataExtractor(record.getData().drop_front(cursor.tell()), le),
101 "Skipping unsupported embedded type summary of version {0} in {1}.",
104 section.skip(cursor, record_size);
113 [&](llvm::DataExtractor extractor, llvm::StringRef type_name) {
123 llvm::DataExtractor::Cursor cursor(0);
124 uint64_t summary_size = extractor.getULEB128(cursor);
125 llvm::StringRef summary_string =
126 extractor.getBytes(cursor, summary_size);
132 if (type_name.empty() || summary_string.empty()) {
134 "Missing string(s) in embedded type summary in {0}, "
135 "type_name={1}, summary={2}",
136 module_sp->GetFileSpec(), type_name, summary_string);
140 auto summary_sp = std::make_shared<StringSummaryFormat>(
141 flags, summary_string.str().c_str());
143 if (type_name.front() ==
'^')
145 category->AddTypeSummary(type_name, match_type, summary_sp);
147 "Loaded embedded type summary for '{0}' from {1}.", type_name,
148 module_sp->GetFileSpec());
152static BytecodeSyntheticChildren::SyntheticBytecodeImplementation
154 llvm::MutableArrayRef<std::unique_ptr<llvm::MemoryBuffer>> methods) {
157 impl.
init = std::move(methods[Signatures::sig_init]);
158 impl.
update = std::move(methods[Signatures::sig_update]);
159 impl.
num_children = std::move(methods[Signatures::sig_get_num_children]);
161 std::move(methods[Signatures::sig_get_child_at_index]);
162 impl.
get_child_index = std::move(methods[Signatures::sig_get_child_index]);
169 [&](llvm::DataExtractor extractor, llvm::StringRef type_name) {
177 llvm::DataExtractor::Cursor cursor(0);
178 uint64_t flags = extractor.getULEB128(cursor);
180 std::unique_ptr<llvm::MemoryBuffer> summary_func_up;
183 bool has_synthetic_method =
false;
185 while (cursor && cursor.tell() < extractor.size()) {
186 auto signature =
static_cast<Signatures
>(extractor.getU8(cursor));
187 uint64_t size = extractor.getULEB128(cursor);
188 llvm::StringRef bytecode = extractor.getBytes(cursor, size);
191 auto buffer_up = llvm::MemoryBuffer::getMemBufferCopy(bytecode);
192 if (signature == Signatures::sig_summary)
193 summary_func_up = std::move(buffer_up);
194 else if (signature <= Signatures::sig_update) {
195 synthetic_methods[signature] = std::move(buffer_up);
196 has_synthetic_method =
true;
199 "Unsupported formatter signature {0} for '{1}' in {2}",
200 signature, type_name, module_sp->GetFileSpec());
209 if (type_name.front() ==
'^')
212 if (summary_func_up) {
213 auto summary_sp = std::make_shared<BytecodeSummaryFormat>(
215 category->AddTypeSummary(type_name, match_type, summary_sp);
217 "Loaded embedded type summary for '{0}' from {1}.",
218 type_name, module_sp->GetFileSpec());
219 }
else if (has_synthetic_method) {
222 auto synthetic_children_sp =
223 std::make_shared<BytecodeSyntheticChildren>(std::move(impl));
224 category->AddTypeSynthetic(type_name, match_type,
225 synthetic_children_sp);
227 "Loaded embedded type synthetic for '{0}' from {1}.",
228 type_name, module_sp->GetFileSpec());
231 "No summary or synthetic methods found for '{0}' in {1}, "
232 "not registering a formatter.",
233 type_name, module_sp->GetFileSpec());
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_LOG_VERBOSE(log,...)
A uniqued constant string class.
static bool GetCategory(ConstString category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
A class that describes an executable image and its associated object and symbol files.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
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.
static void ForEachFormatterInModule(Module &module, SectionType section_type, std::function< void(llvm::DataExtractor, llvm::StringRef)> fn)
static bool skipPadding(llvm::DataExtractor §ion, llvm::DataExtractor::Cursor &cursor)
static BytecodeSyntheticChildren::SyntheticBytecodeImplementation CreateSyntheticImpl(llvm::MutableArrayRef< std::unique_ptr< llvm::MemoryBuffer > > methods)
void LoadTypeSummariesForModule(lldb::ModuleSP module_sp)
Load type summaries embedded in the binary.
void LoadFormattersForModule(lldb::ModuleSP module_sp)
Load data formatters embedded in the binary.
FormatterMatchType
Type of match to be performed when looking for a formatter for a data type.
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
@ eSectionTypeLLDBFormatters
@ eSectionTypeLLDBTypeSummaries
std::shared_ptr< lldb_private::Module > ModuleSP
std::unique_ptr< llvm::MemoryBuffer > update
std::unique_ptr< llvm::MemoryBuffer > get_child_index
std::unique_ptr< llvm::MemoryBuffer > init
std::unique_ptr< llvm::MemoryBuffer > num_children
std::unique_ptr< llvm::MemoryBuffer > get_child_at_index