diff options
| author | Sylvestre Ledru <sylvestre@debian.org> | 2024-12-10 23:59:54 +0100 |
|---|---|---|
| committer | Sylvestre Ledru <sylvestre@debian.org> | 2024-12-11 00:00:44 +0100 |
| commit | a2fb70523ac310af6d8a4d9663dfe7c9cd370c53 (patch) | |
| tree | 78b2ea08853a809c0ab7e4e0021caf96ee5addd8 /lldb/source/Target/Target.cpp | |
| parent | cf27e8ea04c39a0f20d465563241bdf2872f2bd7 (diff) | |
Revert "[lldb] Add cast to fix compile error on 32-bit platforms"
This reverts commit f6012a209dca6b1866d00e6b4f96279469884320.
Revert "[lldb] Add cast to fix compile error on 32-but platforms"
This reverts commit d300337e93da4ed96b044557e4b0a30001967cf0.
Revert "[lldb] Improve log message to include missing strings"
This reverts commit 0be33484853557bc0fd9dfb94e0b6c15dda136ce.
Revert "[lldb] Add comment"
This reverts commit e2bb47443d2e5c022c7851dd6029e3869fc8835c.
Revert "[lldb] Implement a formatter bytecode interpreter in C++"
This reverts commit 9a9c1d4a6155a96ce9be494cec7e25731d36b33e.
Diffstat (limited to 'lldb/source/Target/Target.cpp')
| -rw-r--r-- | lldb/source/Target/Target.cpp | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 46216ba2d566..9ac85ad3ed5e 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -24,7 +24,9 @@ #include "lldb/Core/Section.h" #include "lldb/Core/SourceManager.h" #include "lldb/Core/StructuredDataImpl.h" -#include "lldb/DataFormatters/FormatterSection.h" +#include "lldb/Core/ValueObject.h" +#include "lldb/Core/ValueObjectConstResult.h" +#include "lldb/DataFormatters/DataVisualization.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Expression/REPL.h" @@ -64,6 +66,8 @@ #include "lldb/Utility/State.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/Timer.h" +#include "lldb/ValueObject/ValueObject.h" +#include "lldb/ValueObject/ValueObjectConstResult.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SetVector.h" @@ -1537,6 +1541,76 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp, feedback_stream.GetData()); } +// Load type summaries embedded in the binary. These are type summaries provided +// by the authors of the code. +static void LoadTypeSummariesForModule(ModuleSP module_sp) { + auto *sections = module_sp->GetSectionList(); + if (!sections) + return; + + auto summaries_sp = + sections->FindSectionByType(eSectionTypeLLDBTypeSummaries, true); + if (!summaries_sp) + return; + + Log *log = GetLog(LLDBLog::DataFormatters); + const char *module_name = module_sp->GetObjectName().GetCString(); + + TypeCategoryImplSP category; + DataVisualization::Categories::GetCategory(ConstString("default"), category); + + // The type summary record is serialized as follows. + // + // Each record contains, in order: + // * Version number of the record format + // * The remaining size of the record + // * The size of the type identifier + // * The type identifier, either a type name, or a regex + // * The size of the summary string + // * The summary string + // + // Integers are encoded using ULEB. + // + // Strings are encoded with first a length (ULEB), then the string contents, + // and lastly a null terminator. The length includes the null. + + DataExtractor extractor; + auto section_size = summaries_sp->GetSectionData(extractor); + lldb::offset_t offset = 0; + while (offset < section_size) { + uint64_t version = extractor.GetULEB128(&offset); + uint64_t record_size = extractor.GetULEB128(&offset); + if (version == 1) { + uint64_t type_size = extractor.GetULEB128(&offset); + llvm::StringRef type_name = extractor.GetCStr(&offset, type_size); + uint64_t summary_size = extractor.GetULEB128(&offset); + llvm::StringRef summary_string = extractor.GetCStr(&offset, summary_size); + if (!type_name.empty() && !summary_string.empty()) { + TypeSummaryImpl::Flags flags; + auto summary_sp = + std::make_shared<StringSummaryFormat>(flags, summary_string.data()); + FormatterMatchType match_type = eFormatterMatchExact; + if (summary_string.front() == '^' && summary_string.back() == '$') + match_type = eFormatterMatchRegex; + category->AddTypeSummary(type_name, match_type, summary_sp); + LLDB_LOGF(log, "Loaded embedded type summary for '%s' from %s.", + type_name.data(), module_name); + } else { + if (type_name.empty()) + LLDB_LOGF(log, "Missing string(s) in embedded type summary in %s.", + module_name); + } + } else { + // Skip unsupported record. + offset += record_size; + LLDB_LOGF( + log, + "Skipping unsupported embedded type summary of version %llu in %s.", + version, module_name); + } + } +} + void Target::ClearModules(bool delete_locations) { ModulesDidUnload(m_images, delete_locations); m_section_load_history.Clear(); @@ -1818,7 +1892,6 @@ void Target::ModulesDidLoad(ModuleList &module_list) { ModuleSP module_sp(module_list.GetModuleAtIndex(idx)); LoadScriptingResourceForModule(module_sp, this); LoadTypeSummariesForModule(module_sp); - LoadFormattersForModule(module_sp); } m_breakpoint_list.UpdateBreakpoints(module_list, true, false); m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false); |
