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 uint8_t addr_size = section.getAddressSize();
70 llvm::DataExtractor::Cursor cursor(0);
71 while (cursor && cursor.tell() < section_size) {
75 uint64_t version = section.getULEB128(cursor);
76 uint64_t record_size = section.getULEB128(cursor);
78 llvm::DataExtractor record(
79 section.getData().drop_front(cursor.tell()).take_front(record_size),
81 llvm::DataExtractor::Cursor cursor(0);
82 uint64_t type_size = record.getULEB128(cursor);
83 llvm::StringRef type_name = record.getBytes(cursor, type_size);
84 llvm::Error
error = cursor.takeError();
86 fn(llvm::DataExtractor(record.getData().drop_front(cursor.tell()), le,
96 "Skipping unsupported embedded type summary of version {0} in {1}.",
99 section.skip(cursor, record_size);
108 [&](llvm::DataExtractor extractor, llvm::StringRef type_name) {
118 llvm::DataExtractor::Cursor cursor(0);
119 uint64_t summary_size = extractor.getULEB128(cursor);
120 llvm::StringRef summary_string =
121 extractor.getBytes(cursor, summary_size);
127 if (type_name.empty() || summary_string.empty()) {
129 "Missing string(s) in embedded type summary in {0}, "
130 "type_name={1}, summary={2}",
131 module_sp->GetFileSpec(), type_name, summary_string);
135 auto summary_sp = std::make_shared<StringSummaryFormat>(
136 flags, summary_string.str().c_str());
138 if (type_name.front() ==
'^')
140 category->AddTypeSummary(type_name, match_type, summary_sp);
142 "Loaded embedded type summary for '{0}' from {1}.", type_name,
143 module_sp->GetFileSpec());
147static BytecodeSyntheticChildren::SyntheticBytecodeImplementation
149 llvm::MutableArrayRef<std::unique_ptr<llvm::MemoryBuffer>> methods) {
152 impl.
init = std::move(methods[Signatures::sig_init]);
153 impl.
update = std::move(methods[Signatures::sig_update]);
154 impl.
num_children = std::move(methods[Signatures::sig_get_num_children]);
156 std::move(methods[Signatures::sig_get_child_at_index]);
157 impl.
get_child_index = std::move(methods[Signatures::sig_get_child_index]);
164 [&](llvm::DataExtractor extractor, llvm::StringRef type_name) {
172 llvm::DataExtractor::Cursor cursor(0);
173 uint64_t flags = extractor.getULEB128(cursor);
175 std::unique_ptr<llvm::MemoryBuffer> summary_func_up;
179 while (cursor && cursor.tell() < extractor.size()) {
180 auto signature =
static_cast<Signatures
>(extractor.getU8(cursor));
181 uint64_t size = extractor.getULEB128(cursor);
182 llvm::StringRef bytecode = extractor.getBytes(cursor, size);
188 auto buffer_up = llvm::MemoryBuffer::getMemBufferCopy(bytecode);
189 if (signature == Signatures::sig_summary)
190 summary_func_up = std::move(buffer_up);
191 else if (signature <= Signatures::sig_update)
192 synthetic_methods[signature] = std::move(buffer_up);
195 "Unsupported formatter signature {0} for '{1}' in {2}",
196 signature, type_name, module_sp->GetFileSpec());
200 if (type_name.front() ==
'^')
203 if (summary_func_up) {
204 auto summary_sp = std::make_shared<BytecodeSummaryFormat>(
206 category->AddTypeSummary(type_name, match_type, summary_sp);
208 "Loaded embedded type summary for '{0}' from {1}.",
209 type_name, module_sp->GetFileSpec());
213 auto synthetic_children_sp =
214 std::make_shared<BytecodeSyntheticChildren>(std::move(impl));
215 category->AddTypeSynthetic(type_name, match_type,
216 synthetic_children_sp);
218 "Loaded embedded type synthetic for '{0}' from {1}.",
219 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,...)
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