Author: Wanyi Date: 2024-02-19T00:33:23-05:00 New Revision: dd7386d85f11cf6ad911b9827c7018fb08c6c205
URL: https://github.com/llvm/llvm-project/commit/dd7386d85f11cf6ad911b9827c7018fb08c6c205 DIFF: https://github.com/llvm/llvm-project/commit/dd7386d85f11cf6ad911b9827c7018fb08c6c205.diff LOG: [Reland] Report only loaded debug info in statistics dump (#81706) (#82207) Updates: - The previous patch changed the default behavior to not load dwos in `DWARFUnit` ~~`SymbolFileDWARFDwo *GetDwoSymbolFile(bool load_all_debug_info = false);`~~ `SymbolFileDWARFDwo *GetDwoSymbolFile(bool load_all_debug_info = true);` - This broke some lldb-shell tests (see https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/16273/) - TestDebugInfoSize.py - with symbol on-demand, by default statistics dump only reports skeleton debug info size - `statistics dump -f` will load all dwos. debug info = skeleton debug info + all dwo debug info Currently running `statistics dump` will trigger lldb to load debug info that's not yet loaded (eg. dwo files). Resulted in a delay in the command return, which, can be interrupting. This patch also added a new option `--load-all-debug-info` asking statistics to dump all possible debug info, which will force loading all debug info available if not yet loaded. Added: lldb/test/API/functionalities/stats_api/main-main.dwo.yaml lldb/test/API/functionalities/stats_api/main.yaml Modified: lldb/bindings/interface/SBStatisticsOptionsDocstrings.i lldb/include/lldb/API/SBStatisticsOptions.h lldb/include/lldb/Symbol/SymbolFile.h lldb/include/lldb/Symbol/SymbolFileOnDemand.h lldb/include/lldb/Target/Statistics.h lldb/source/API/SBStatisticsOptions.cpp lldb/source/Commands/CommandObjectStats.cpp lldb/source/Commands/Options.td lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h lldb/source/Symbol/SymbolFile.cpp lldb/source/Symbol/SymbolFileOnDemand.cpp lldb/source/Target/Statistics.cpp lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py Removed: ################################################################################ diff --git a/lldb/bindings/interface/SBStatisticsOptionsDocstrings.i b/lldb/bindings/interface/SBStatisticsOptionsDocstrings.i index f72cf84319e19b..087f6ab8786630 100644 --- a/lldb/bindings/interface/SBStatisticsOptionsDocstrings.i +++ b/lldb/bindings/interface/SBStatisticsOptionsDocstrings.i @@ -6,3 +6,9 @@ ) lldb::SBStatisticsOptions::SetSummaryOnly; %feature("docstring", "Gets whether the statistics only dump a summary." ) lldb::SBStatisticsOptions::GetSummaryOnly; +%feature("docstring", " + Sets whether the statistics will force loading all possible debug info." +) lldb::SBStatisticsOptions::SetReportAllAvailableDebugInfo; +%feature("docstring", " + Gets whether the statistics will force loading all possible debug info." +) lldb::SBStatisticsOptions::GetReportAllAvailableDebugInfo; diff --git a/lldb/include/lldb/API/SBStatisticsOptions.h b/lldb/include/lldb/API/SBStatisticsOptions.h index 8019ed4315ca21..a0055135e36c2a 100644 --- a/lldb/include/lldb/API/SBStatisticsOptions.h +++ b/lldb/include/lldb/API/SBStatisticsOptions.h @@ -25,6 +25,14 @@ class LLDB_API SBStatisticsOptions { void SetSummaryOnly(bool b); bool GetSummaryOnly(); + /// If set to true, the debugger will load all debug info that is available + /// and report statistics on the total amount. If this is set to false, then + /// only report statistics on the currently loaded debug information. + /// This can avoid loading debug info from separate files just so it can + /// report the total size which can slow down statistics reporting. + void SetReportAllAvailableDebugInfo(bool b); + bool GetReportAllAvailableDebugInfo(); + protected: friend class SBTarget; const lldb_private::StatisticsOptions &ref() const; diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index f356f7b789fa38..d20766788192f7 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -381,7 +381,8 @@ class SymbolFile : public PluginInterface { /// Metrics gathering functions - /// Return the size in bytes of all debug information in the symbol file. + /// Return the size in bytes of all loaded debug information or total possible + /// debug info in the symbol file. /// /// If the debug information is contained in sections of an ObjectFile, then /// this call should add the size of all sections that contain debug @@ -391,7 +392,14 @@ class SymbolFile : public PluginInterface { /// entire file should be returned. The default implementation of this /// function will iterate over all sections in a module and add up their /// debug info only section byte sizes. - virtual uint64_t GetDebugInfoSize() = 0; + /// + /// \param load_all_debug_info + /// If true, force loading any symbol files if they are not yet loaded and + /// add to the total size. Default to false. + /// + /// \returns + /// Total currently loaded debug info size in bytes + virtual uint64_t GetDebugInfoSize(bool load_all_debug_info = false) = 0; /// Return the time taken to parse the debug information. /// @@ -534,7 +542,7 @@ class SymbolFileCommon : public SymbolFile { void Dump(Stream &s) override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; bool GetDebugInfoIndexWasLoadedFromCache() const override { return m_index_was_loaded_from_cache; diff --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h index 4e3009941aa7d6..8073d1816860e3 100644 --- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h +++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h @@ -178,7 +178,7 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile { void PreloadSymbols() override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override; lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override; diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index f838fa17f80c24..c4f17b503a1f99 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -132,6 +132,7 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; + bool load_all_debug_info = false; }; /// A class that represents statistics for a since lldb_private::Target. diff --git a/lldb/source/API/SBStatisticsOptions.cpp b/lldb/source/API/SBStatisticsOptions.cpp index 77a7e26a6bd4b5..7e826c4c93ebcd 100644 --- a/lldb/source/API/SBStatisticsOptions.cpp +++ b/lldb/source/API/SBStatisticsOptions.cpp @@ -44,6 +44,14 @@ void SBStatisticsOptions::SetSummaryOnly(bool b) { bool SBStatisticsOptions::GetSummaryOnly() { return m_opaque_up->summary_only; } +void SBStatisticsOptions::SetReportAllAvailableDebugInfo(bool b) { + m_opaque_up->load_all_debug_info = b; +} + +bool SBStatisticsOptions::GetReportAllAvailableDebugInfo() { + return m_opaque_up->load_all_debug_info; +} + const lldb_private::StatisticsOptions &SBStatisticsOptions::ref() const { return *m_opaque_up; } diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index b23b7024c82176..a92bb5d1165ee6 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -78,6 +78,9 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 's': m_stats_options.summary_only = true; break; + case 'f': + m_stats_options.load_all_debug_info = true; + break; default: llvm_unreachable("Unimplemented option"); } diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index dd732e35220287..ad4321d9a386cc 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1419,6 +1419,10 @@ let Command = "statistics dump" in { def statistics_dump_all: Option<"all-targets", "a">, Group<1>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, - Desc<"Dump only high-level summary statistics." + Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; + def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + Desc<"Dump the total possible debug info statistics. " + "Force loading all the debug information if not yet loaded, and collect " + "statistics with those.">; } diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp index b1f7397d6b0f00..3977dc3a6d67c5 100644 --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -918,7 +918,7 @@ void SymbolFileBreakpad::ParseUnwindData() { m_unwind_data->win.Sort(); } -uint64_t SymbolFileBreakpad::GetDebugInfoSize() { +uint64_t SymbolFileBreakpad::GetDebugInfoSize(bool load_all_debug_info) { // Breakpad files are all debug info. return m_objfile_sp->GetByteSize(); } diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h index 41e4e3b258014c..83215bf3c87e4a 100644 --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h @@ -141,7 +141,7 @@ class SymbolFileBreakpad : public SymbolFileCommon { llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; private: // A class representing a position in the breakpad file. Useful for diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 23e0b8a7f2c06b..e28036d34b34a6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -896,8 +896,9 @@ void DWARFUnit::ComputeAbsolutePath() { m_file_spec->MakeAbsolute(GetCompilationDirectory()); } -SymbolFileDWARFDwo *DWARFUnit::GetDwoSymbolFile() { - ExtractUnitDIEIfNeeded(); +SymbolFileDWARFDwo *DWARFUnit::GetDwoSymbolFile(bool load_all_debug_info) { + if (load_all_debug_info) + ExtractUnitDIEIfNeeded(); if (m_dwo) return &llvm::cast<SymbolFileDWARFDwo>(m_dwo->GetSymbolFileDWARF()); return nullptr; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h index 9f6d127056fa56..28981b51bfcb33 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -241,7 +241,7 @@ class DWARFUnit : public UserID { FileSpec GetFile(size_t file_idx); FileSpec::Style GetPathStyle(); - SymbolFileDWARFDwo *GetDwoSymbolFile(); + SymbolFileDWARFDwo *GetDwoSymbolFile(bool load_all_debug_info = true); die_iterator_range dies() { ExtractDIEsIfNeeded(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 781f5c5a436778..42211b9a21b0e3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2672,7 +2672,7 @@ static bool UpdateCompilerContextForSimpleTemplateNames(TypeQuery &match) { return any_context_updated; } -uint64_t SymbolFileDWARF::GetDebugInfoSize() { +uint64_t SymbolFileDWARF::GetDebugInfoSize(bool load_all_debug_info) { DWARFDebugInfo &info = DebugInfo(); uint32_t num_comp_units = info.GetNumUnits(); @@ -2687,7 +2687,7 @@ uint64_t SymbolFileDWARF::GetDebugInfoSize() { if (cu == nullptr) continue; - SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile(); + SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile(load_all_debug_info); if (dwo) debug_info_size += dwo->GetDebugInfoSize(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 01518b26ca669e..2f8f80f8765cb8 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -186,7 +186,7 @@ class SymbolFileDWARF : public SymbolFileCommon { GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector<ConstString> &mangled_names) override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp index ea23b75c3d708d..a0a7012dfaf0d7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -85,7 +85,7 @@ lldb::offset_t SymbolFileDWARFDwo::GetVendorDWARFOpcodeSize( return GetBaseSymbolFile().GetVendorDWARFOpcodeSize(data, data_offset, op); } -uint64_t SymbolFileDWARFDwo::GetDebugInfoSize() { +uint64_t SymbolFileDWARFDwo::GetDebugInfoSize(bool load_all_debug_info) { // Directly get debug info from current dwo object file's section list // instead of asking SymbolFileCommon::GetDebugInfo() which parses from // owning module which is wrong. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h index d5f48f2a8ed4e2..c2c420f711d345 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -47,7 +47,7 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF { const lldb::offset_t data_offset, const uint8_t op) const override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index 745685a1b31d05..7fded6a31a3af5 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -2156,7 +2156,7 @@ SymbolFileNativePDB::GetTypeSystemForLanguage(lldb::LanguageType language) { return type_system_or_err; } -uint64_t SymbolFileNativePDB::GetDebugInfoSize() { +uint64_t SymbolFileNativePDB::GetDebugInfoSize(bool load_all_debug_info) { // PDB files are a separate file that contains all debug info. return m_index->pdb().getFileSize(); } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h index 82577771f355c8..669c44aa131edc 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -77,7 +77,7 @@ class SymbolFileNativePDB : public SymbolFileCommon { void InitializeObject() override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; // Compile Unit function calls diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index e318e2beb6547b..16ed98d7840f78 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -227,7 +227,7 @@ SymbolFileCommon::GetTypeSystemForLanguage(lldb::LanguageType language) { return type_system_or_err; } -uint64_t SymbolFileCommon::GetDebugInfoSize() { +uint64_t SymbolFileCommon::GetDebugInfoSize(bool load_all_debug_info) { if (!m_objfile_sp) return 0; ModuleSP module_sp(m_objfile_sp->GetModule()); diff --git a/lldb/source/Symbol/SymbolFileOnDemand.cpp b/lldb/source/Symbol/SymbolFileOnDemand.cpp index bdb1951d51259d..c6d9f0071c392b 100644 --- a/lldb/source/Symbol/SymbolFileOnDemand.cpp +++ b/lldb/source/Symbol/SymbolFileOnDemand.cpp @@ -535,11 +535,11 @@ void SymbolFileOnDemand::PreloadSymbols() { return m_sym_file_impl->PreloadSymbols(); } -uint64_t SymbolFileOnDemand::GetDebugInfoSize() { +uint64_t SymbolFileOnDemand::GetDebugInfoSize(bool load_all_debug_info) { // Always return the real debug info size. LLDB_LOG(GetLog(), "[{0}] {1} is not skipped", GetSymbolFileName(), __FUNCTION__); - return m_sym_file_impl->GetDebugInfoSize(); + return m_sym_file_impl->GetDebugInfoSize(load_all_debug_info); } StatsDuration::Duration SymbolFileOnDemand::GetDebugInfoParseTime() { diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index ec0a4c84692dea..7f866ae0ef3242 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -224,6 +224,7 @@ llvm::json::Value DebuggerStats::ReportStatistics( const lldb_private::StatisticsOptions &options) { const bool summary_only = options.summary_only; + const bool load_all_debug_info = options.load_all_debug_info; json::Array json_targets; json::Array json_modules; @@ -280,7 +281,8 @@ llvm::json::Value DebuggerStats::ReportStatistics( ++debug_index_saved; module_stat.debug_index_time = sym_file->GetDebugInfoIndexTime().count(); module_stat.debug_parse_time = sym_file->GetDebugInfoParseTime().count(); - module_stat.debug_info_size = sym_file->GetDebugInfoSize(); + module_stat.debug_info_size = + sym_file->GetDebugInfoSize(load_all_debug_info); module_stat.symtab_stripped = module->GetObjectFile()->IsStripped(); if (module_stat.symtab_stripped) ++num_stripped_modules; diff --git a/lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py b/lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py index a70212fb426268..ef56fa654065b8 100644 --- a/lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py +++ b/lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py @@ -120,6 +120,7 @@ def test_dwos_loaded_symbols_on_demand(self): target = self.dbg.CreateTarget(exe) self.assertTrue(target, lldbtest.VALID_TARGET) + # By default dwo files will not be loaded stats = target.GetStatistics() stream = lldb.SBStream() res = stats.GetAsJSON(stream) @@ -129,6 +130,15 @@ def test_dwos_loaded_symbols_on_demand(self): debug_stats, 'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()', ) + self.assertEqual(debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE) + + # Force loading all the dwo files + stats_options = lldb.SBStatisticsOptions() + stats_options.SetReportAllAvailableDebugInfo(True) + stats = target.GetStatistics(stats_options) + stream = lldb.SBStream() + stats.GetAsJSON(stream) + debug_stats = json.loads(stream.GetData()) self.assertEqual( debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE + MAIN_DWO_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE, diff --git a/lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py b/lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py index 457a2022fe4b8f..eee91bfadead97 100644 --- a/lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py +++ b/lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py @@ -117,3 +117,42 @@ def test_command_stats_api(self): self.assertNotIn("bt", command_stats) # Verify bt's regex command is not duplicatedly captured. self.assertNotIn("_regexp-bt", command_stats) + + @add_test_categories(["dwo"]) + def test_command_stats_force(self): + """ + Test reporting all pssible debug info stats by force loading all debug + info. For example, dwo files + """ + src_dir = self.getSourceDir() + dwo_yaml_path = os.path.join(src_dir, "main-main.dwo.yaml") + exe_yaml_path = os.path.join(src_dir, "main.yaml") + dwo_path = self.getBuildArtifact("main-main.dwo") + exe_path = self.getBuildArtifact("main") + self.yaml2obj(dwo_yaml_path, dwo_path) + self.yaml2obj(exe_yaml_path, exe_path) + + # Turn on symbols on-demand loading + self.runCmd("settings set symbols.load-on-demand true") + + # We need the current working directory to be set to the build directory + os.chdir(self.getBuildDir()) + # Create a target with the object file we just created from YAML + target = self.dbg.CreateTarget(exe_path) + self.assertTrue(target, VALID_TARGET) + + # Get statistics + stats_options = lldb.SBStatisticsOptions() + stats = target.GetStatistics(stats_options) + stream = lldb.SBStream() + stats.GetAsJSON(stream) + debug_stats = json.loads(stream.GetData()) + self.assertEqual(debug_stats["totalDebugInfoByteSize"], 193) + + # Get statistics with force loading + stats_options.SetReportAllAvailableDebugInfo(True) + stats_force = target.GetStatistics(stats_options) + stream_force = lldb.SBStream() + stats_force.GetAsJSON(stream_force) + debug_stats_force = json.loads(stream_force.GetData()) + self.assertEqual(debug_stats_force["totalDebugInfoByteSize"], 445) diff --git a/lldb/test/API/functionalities/stats_api/main-main.dwo.yaml b/lldb/test/API/functionalities/stats_api/main-main.dwo.yaml new file mode 100644 index 00000000000000..d24dde3ce96d97 --- /dev/null +++ b/lldb/test/API/functionalities/stats_api/main-main.dwo.yaml @@ -0,0 +1,37 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + SectionHeaderStringTable: .strtab +Sections: + - Name: .debug_str.dwo + Type: SHT_PROGBITS + Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x1 + EntSize: 0x1 + Content: 5F5A33666F6F7600666F6F006D61696E00696E7400636C616E672076657273696F6E2031372E302E36202843656E744F532031372E302E362D342E656C3929006D61696E2E637070006D61696E2D6D61696E2E64776F00 + - Name: .debug_str_offsets.dwo + Type: SHT_PROGBITS + Flags: [ SHF_EXCLUDE ] + AddressAlign: 0x1 + Content: 00000000080000000C00000011000000150000004000000049000000 + - Name: .debug_info.dwo + Type: SHT_PROGBITS + Flags: [ SHF_EXCLUDE ] + AddressAlign: 0x1 + Content: 3500000004000000000008010421000506939F5FCB7816797B02000600000001560001010103011C0000000156020105340000000403050400 + - Name: .debug_abbrev.dwo + Type: SHT_PROGBITS + Flags: [ SHF_EXCLUDE ] + AddressAlign: 0x1 + Content: 01110125823E130503823EB042823EB142070000022E0011813E120640186E823E03823E3A0B3B0B3F190000032E0011813E1206401803823E3A0B3B0B49133F19000004240003823E3E0B0B0B000000 + - Type: SectionHeaderTable + Sections: + - Name: .strtab + - Name: .debug_str.dwo + - Name: .debug_str_offsets.dwo + - Name: .debug_info.dwo + - Name: .debug_abbrev.dwo +... diff --git a/lldb/test/API/functionalities/stats_api/main.yaml b/lldb/test/API/functionalities/stats_api/main.yaml new file mode 100644 index 00000000000000..39d9ffeb663c7d --- /dev/null +++ b/lldb/test/API/functionalities/stats_api/main.yaml @@ -0,0 +1,543 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x401020 +ProgramHeaders: + - Type: PT_PHDR + Flags: [ PF_R ] + VAddr: 0x400040 + Align: 0x8 + - Type: PT_INTERP + Flags: [ PF_R ] + FirstSec: .interp + LastSec: .interp + VAddr: 0x400318 + - Type: PT_LOAD + Flags: [ PF_R ] + FirstSec: .interp + LastSec: .rela.dyn + VAddr: 0x400000 + Align: 0x1000 + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + FirstSec: .init + LastSec: .fini + VAddr: 0x401000 + Align: 0x1000 + - Type: PT_LOAD + Flags: [ PF_R ] + FirstSec: .rodata + LastSec: .eh_frame + VAddr: 0x402000 + Align: 0x1000 + - Type: PT_LOAD + Flags: [ PF_W, PF_R ] + FirstSec: .init_array + LastSec: .bss + VAddr: 0x403DF8 + Align: 0x1000 + - Type: PT_DYNAMIC + Flags: [ PF_W, PF_R ] + FirstSec: .dynamic + LastSec: .dynamic + VAddr: 0x403E08 + Align: 0x8 + - Type: PT_NOTE + Flags: [ PF_R ] + FirstSec: .note.gnu.property + LastSec: .note.gnu.property + VAddr: 0x400338 + Align: 0x8 + - Type: PT_NOTE + Flags: [ PF_R ] + FirstSec: .note.gnu.build-id + LastSec: .note.ABI-tag + VAddr: 0x400358 + Align: 0x4 + - Type: PT_GNU_PROPERTY + Flags: [ PF_R ] + FirstSec: .note.gnu.property + LastSec: .note.gnu.property + VAddr: 0x400338 + Align: 0x8 + - Type: PT_GNU_EH_FRAME + Flags: [ PF_R ] + FirstSec: .eh_frame_hdr + LastSec: .eh_frame_hdr + VAddr: 0x402010 + Align: 0x4 + - Type: PT_GNU_STACK + Flags: [ PF_W, PF_R ] + Align: 0x10 + - Type: PT_GNU_RELRO + Flags: [ PF_R ] + FirstSec: .init_array + LastSec: .got.plt + VAddr: 0x403DF8 +Sections: + - Name: .interp + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x400318 + AddressAlign: 0x1 + Content: 2F6C696236342F6C642D6C696E75782D7838362D36342E736F2E3200 + - Name: .note.gnu.property + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x400338 + AddressAlign: 0x8 + Notes: + - Name: GNU + Desc: 028000C0040000000300000000000000 + Type: NT_GNU_PROPERTY_TYPE_0 + - Name: .note.gnu.build-id + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x400358 + AddressAlign: 0x4 + Notes: + - Name: GNU + Desc: 85D91301922FA88F7A5C60D2002CC1421377E935 + Type: NT_PRPSINFO + - Name: .note.ABI-tag + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x40037C + AddressAlign: 0x4 + Notes: + - Name: GNU + Desc: '00000000030000000200000000000000' + Type: NT_VERSION + - Name: .gnu.hash + Type: SHT_GNU_HASH + Flags: [ SHF_ALLOC ] + Address: 0x4003A0 + Link: .dynsym + AddressAlign: 0x8 + Header: + SymNdx: 0x1 + Shift2: 0x0 + BloomFilter: [ 0x0 ] + HashBuckets: [ 0x0 ] + HashValues: [ ] + - Name: .dynsym + Type: SHT_DYNSYM + Flags: [ SHF_ALLOC ] + Address: 0x4003C0 + Link: .dynstr + AddressAlign: 0x8 + - Name: .dynstr + Type: SHT_STRTAB + Flags: [ SHF_ALLOC ] + Address: 0x400438 + AddressAlign: 0x1 + - Name: .gnu.version + Type: SHT_GNU_versym + Flags: [ SHF_ALLOC ] + Address: 0x4004CC + Link: .dynsym + AddressAlign: 0x2 + Entries: [ 0, 2, 1, 1, 1 ] + - Name: .gnu.version_r + Type: SHT_GNU_verneed + Flags: [ SHF_ALLOC ] + Address: 0x4004D8 + Link: .dynstr + AddressAlign: 0x8 + Dependencies: + - Version: 1 + File: libc.so.6 + Entries: + - Name: GLIBC_2.34 + Hash: 110530996 + Flags: 0 + Other: 2 + - Name: .rela.dyn + Type: SHT_RELA + Flags: [ SHF_ALLOC ] + Address: 0x4004F8 + Link: .dynsym + AddressAlign: 0x8 + Relocations: + - Offset: 0x403FC8 + Symbol: __libc_start_main + Type: R_X86_64_GLOB_DAT + - Offset: 0x403FD0 + Symbol: _ITM_deregisterTMCloneTable + Type: R_X86_64_GLOB_DAT + - Offset: 0x403FD8 + Symbol: __gmon_start__ + Type: R_X86_64_GLOB_DAT + - Offset: 0x403FE0 + Symbol: _ITM_registerTMCloneTable + Type: R_X86_64_GLOB_DAT + - Name: .init + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x401000 + AddressAlign: 0x4 + Offset: 0x1000 + Content: F30F1EFA4883EC08488B05C92F00004885C07402FFD04883C408C3 + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x401020 + AddressAlign: 0x10 + Content: F30F1EFA31ED4989D15E4889E24883E4F050544531C031C948C7C720114000FF15832F0000F4662E0F1F840000000000F30F1EFAC3662E0F1F84000000000090488D3DA12F0000488D059A2F00004839F87415488B05562F00004885C07409FFE00F1F8000000000C30F1F8000000000488D3D712F0000488D356A2F00004829FE4889F048C1EE3F48C1F8034801C648D1FE7414488B05252F00004885C07408FFE0660F1F440000C30F1F8000000000F30F1EFA803D292F0000007513554889E5E87AFFFFFFC605172F0000015DC390C366662E0F1F8400000000000F1F4000F30F1EFAEB8A662E0F1F840000000000554889E55DC3662E0F1F840000000000554889E54883EC10C745FC00000000E8DCFFFFFF31C04883C4105DC3 + - Name: .fini + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x40113C + AddressAlign: 0x4 + Content: F30F1EFA4883EC084883C408C3 + - Name: .rodata + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x402000 + AddressAlign: 0x8 + Offset: 0x2000 + Content: '01000200000000000000000000000000' + - Name: .eh_frame_hdr + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x402010 + AddressAlign: 0x4 + Content: 011B033B2C0000000400000010F0FFFF4800000040F0FFFF5C00000000F1FFFF7000000010F1FFFF90000000 + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x402040 + AddressAlign: 0x8 + Content: 1400000000000000017A5200017810011B0C070890010000100000001C000000C0EFFFFF26000000004407101000000030000000DCEFFFFF05000000000000001C0000004400000088F0FFFF0600000000410E108602430D06410C07080000001C0000006400000078F0FFFF1C00000000410E108602430D06570C070800000000000000 + - Name: .init_array + Type: SHT_INIT_ARRAY + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x403DF8 + AddressAlign: 0x8 + EntSize: 0x8 + Offset: 0x2DF8 + Content: '0011400000000000' + - Name: .fini_array + Type: SHT_FINI_ARRAY + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x403E00 + AddressAlign: 0x8 + EntSize: 0x8 + Content: D010400000000000 + - Name: .dynamic + Type: SHT_DYNAMIC + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x403E08 + Link: .dynstr + AddressAlign: 0x8 + Entries: + - Tag: DT_NEEDED + Value: 0x58 + - Tag: DT_NEEDED + Value: 0x67 + - Tag: DT_NEEDED + Value: 0x71 + - Tag: DT_NEEDED + Value: 0x7F + - Tag: DT_INIT + Value: 0x401000 + - Tag: DT_FINI + Value: 0x40113C + - Tag: DT_INIT_ARRAY + Value: 0x403DF8 + - Tag: DT_INIT_ARRAYSZ + Value: 0x8 + - Tag: DT_FINI_ARRAY + Value: 0x403E00 + - Tag: DT_FINI_ARRAYSZ + Value: 0x8 + - Tag: DT_GNU_HASH + Value: 0x4003A0 + - Tag: DT_STRTAB + Value: 0x400438 + - Tag: DT_SYMTAB + Value: 0x4003C0 + - Tag: DT_STRSZ + Value: 0x94 + - Tag: DT_SYMENT + Value: 0x18 + - Tag: DT_DEBUG + Value: 0x0 + - Tag: DT_RELA + Value: 0x4004F8 + - Tag: DT_RELASZ + Value: 0x60 + - Tag: DT_RELAENT + Value: 0x18 + - Tag: DT_VERNEED + Value: 0x4004D8 + - Tag: DT_VERNEEDNUM + Value: 0x1 + - Tag: DT_VERSYM + Value: 0x4004CC + - Tag: DT_NULL + Value: 0x0 + - Tag: DT_NULL + Value: 0x0 + - Tag: DT_NULL + Value: 0x0 + - Tag: DT_NULL + Value: 0x0 + - Tag: DT_NULL + Value: 0x0 + - Tag: DT_NULL + Value: 0x0 + - Name: .got + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x403FC8 + AddressAlign: 0x8 + EntSize: 0x8 + Content: '0000000000000000000000000000000000000000000000000000000000000000' + - Name: .got.plt + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x403FE8 + AddressAlign: 0x8 + EntSize: 0x8 + Content: '083E40000000000000000000000000000000000000000000' + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x404000 + AddressAlign: 0x1 + Content: '00000000' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x404004 + AddressAlign: 0x1 + Size: 0x4 + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x1 + EntSize: 0x1 + Content: 4743433A2028474E55292031312E342E312032303233303630352028526564204861742031312E342E312D3229004743433A2028474E55292031332E322E312032303233313230352028526564204861742031332E322E312D362900636C616E672076657273696F6E2031372E302E36202843656E744F532031372E302E362D342E656C392900 + - Name: .gnu.build.attributes + Type: SHT_NOTE + Address: 0x406008 + AddressAlign: 0x4 + Notes: + - Name: "GA$\x013a1" + Desc: '20104000000000004610400000000000' + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: '55104000000000005510400000000000' + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: '00104000000000001610400000000000' + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: 3C114000000000004411400000000000 + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: '60104000000000000611400000000000' + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: 3C114000000000003C11400000000000 + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: 3C114000000000003C11400000000000 + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: 16104000000000001B10400000000000 + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: "GA$\x013a1" + Desc: '44114000000000004911400000000000' + Type: NT_GNU_BUILD_ATTRIBUTE_OPEN + - Name: .debug_info + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 2C000000040000000000080100000000000000000E000000939F5FCB7816797B10114000000000002C00000000000000 + - Name: .debug_abbrev + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 01110010171B0EB44219B0420EB1420711011206B34217000000 + - Name: .debug_line + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 47000000040020000000010101FB0E0D000101010100000001000001006D61696E2E637070000000000000090210114000000000000105050A0B4B0500BD05050AE559060B2E0206000101 + - Name: .debug_addr + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: '10114000000000002011400000000000' + - Name: .debug_gnu_pubnames + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 21000000020000000000300000001900000030666F6F0025000000306D61696E0000000000 + - Name: .debug_gnu_pubtypes + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: '17000000020000000000300000003400000090696E740000000000' +Symbols: + - Name: crt1.o + Type: STT_FILE + Index: SHN_ABS + - Name: __abi_tag + Type: STT_OBJECT + Section: .note.ABI-tag + Value: 0x40037C + Size: 0x20 + - Name: crtstuff.c + Type: STT_FILE + Index: SHN_ABS + - Name: deregister_tm_clones + Type: STT_FUNC + Section: .text + Value: 0x401060 + - Name: register_tm_clones + Type: STT_FUNC + Section: .text + Value: 0x401090 + - Name: __do_global_dtors_aux + Type: STT_FUNC + Section: .text + Value: 0x4010D0 + - Name: completed.0 + Type: STT_OBJECT + Section: .bss + Value: 0x404004 + Size: 0x1 + - Name: __do_global_dtors_aux_fini_array_entry + Type: STT_OBJECT + Section: .fini_array + Value: 0x403E00 + - Name: frame_dummy + Type: STT_FUNC + Section: .text + Value: 0x401100 + - Name: __frame_dummy_init_array_entry + Type: STT_OBJECT + Section: .init_array + Value: 0x403DF8 + - Name: main.cpp + Type: STT_FILE + Index: SHN_ABS + - Name: 'crtstuff.c (1)' + Type: STT_FILE + Index: SHN_ABS + - Name: __FRAME_END__ + Type: STT_OBJECT + Section: .eh_frame + Value: 0x4020C0 + - Type: STT_FILE + Index: SHN_ABS + - Name: __GNU_EH_FRAME_HDR + Section: .eh_frame_hdr + Value: 0x402010 + - Name: _DYNAMIC + Type: STT_OBJECT + Section: .dynamic + Value: 0x403E08 + - Name: _GLOBAL_OFFSET_TABLE_ + Type: STT_OBJECT + Section: .got.plt + Value: 0x403FE8 + - Name: _edata + Section: .data + Binding: STB_GLOBAL + Value: 0x404004 + - Name: data_start + Section: .data + Binding: STB_WEAK + Value: 0x404000 + - Name: _IO_stdin_used + Type: STT_OBJECT + Section: .rodata + Binding: STB_GLOBAL + Value: 0x402000 + Size: 0x4 + - Name: main + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Value: 0x401120 + Size: 0x1C + - Name: __dso_handle + Type: STT_OBJECT + Section: .rodata + Binding: STB_GLOBAL + Value: 0x402008 + Other: [ STV_HIDDEN ] + - Name: _fini + Type: STT_FUNC + Section: .fini + Binding: STB_GLOBAL + Value: 0x40113C + Other: [ STV_HIDDEN ] + - Name: '__libc_start_main@GLIBC_2.34' + Type: STT_FUNC + Binding: STB_GLOBAL + - Name: _dl_relocate_static_pie + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Value: 0x401050 + Size: 0x5 + Other: [ STV_HIDDEN ] + - Name: _start + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Value: 0x401020 + Size: 0x26 + - Name: _init + Type: STT_FUNC + Section: .init + Binding: STB_GLOBAL + Value: 0x401000 + Other: [ STV_HIDDEN ] + - Name: __TMC_END__ + Type: STT_OBJECT + Section: .data + Binding: STB_GLOBAL + Value: 0x404008 + Other: [ STV_HIDDEN ] + - Name: __data_start + Section: .data + Binding: STB_GLOBAL + Value: 0x404000 + - Name: _end + Section: .bss + Binding: STB_GLOBAL + Value: 0x404008 + - Name: __bss_start + Section: .bss + Binding: STB_GLOBAL + Value: 0x404004 + - Name: _Z3foov + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Value: 0x401110 + Size: 0x6 + - Name: _ITM_deregisterTMCloneTable + Binding: STB_WEAK + - Name: __gmon_start__ + Binding: STB_WEAK + - Name: _ITM_registerTMCloneTable + Binding: STB_WEAK +DynamicSymbols: + - Name: __libc_start_main + Type: STT_FUNC + Binding: STB_GLOBAL + - Name: _ITM_deregisterTMCloneTable + Binding: STB_WEAK + - Name: __gmon_start__ + Binding: STB_WEAK + - Name: _ITM_registerTMCloneTable + Binding: STB_WEAK +DWARF: + debug_str: + - '/tmp/test_dwo' + - main-main.dwo +... _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits