Author: Jonas Devlieghere Date: 2025-04-04T16:33:40-07:00 New Revision: 5271dead61dca30f4a6db0f0df8da00f8987449e
URL: https://github.com/llvm/llvm-project/commit/5271dead61dca30f4a6db0f0df8da00f8987449e DIFF: https://github.com/llvm/llvm-project/commit/5271dead61dca30f4a6db0f0df8da00f8987449e.diff LOG: [lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method (#133370) Add ObjectFile::GetObjectName and SymbolFile::GetObjectName to retrieve the name of the object file, including the `.a` for static libraries. We currently do something similar in CommandObjectTarget, but the code for dumping this is a lot more involved than what's being offered by the new method. We have options to print he full path, the base name, and the directoy of the path and trim it to a specific width. This is motivated by #133211, where Greg pointed out that the old code would print the static archive (the .a file) rather than the actual object file inside of it. Added: Modified: lldb/include/lldb/Symbol/ObjectFile.h lldb/include/lldb/Symbol/SymbolFile.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/source/Symbol/ObjectFile.cpp lldb/source/Symbol/SymbolFile.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index 874926da2ceb7..cfcca04a76de8 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -748,6 +748,7 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>, static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset); + std::string GetObjectName() const; protected: // Member variables. diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index dd056035d546e..f35d3ee9f22ae 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -491,6 +491,8 @@ class SymbolFile : public PluginInterface { return args; } + std::string GetObjectName() const; + protected: void AssertModuleLock(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index ce351274b4576..961c212e2e6dc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -727,12 +727,7 @@ void SymbolFileDWARFDebugMap::ForEachSymbolFile( Progress::kDefaultHighFrequencyReportTime); for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) { if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) { - progress.Increment(oso_idx, oso_dwarf->GetObjectFile() - ? oso_dwarf->GetObjectFile() - ->GetFileSpec() - .GetFilename() - .GetString() - : ""); + progress.Increment(oso_idx, oso_dwarf->GetObjectName()); if (closure(*oso_dwarf) == IterationAction::Stop) return; } diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 264acad050e35..2f2c59d6af620 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -775,6 +775,15 @@ uint32_t ObjectFile::GetCacheHash() { return *m_cache_hash; } +std::string ObjectFile::GetObjectName() const { + if (ModuleSP module_sp = GetModule()) + if (ConstString object_name = module_sp->GetObjectName()) + return llvm::formatv("{0}({1})", GetFileSpec().GetFilename().GetString(), + object_name.GetString()) + .str(); + return GetFileSpec().GetFilename().GetString(); +} + namespace llvm { namespace json { diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index 16ed98d7840f7..94e32b55572dd 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -259,3 +259,9 @@ void SymbolFileCommon::Dump(Stream &s) { if (Symtab *symtab = GetSymtab()) symtab->Dump(&s, nullptr, eSortOrderNone); } + +std::string SymbolFile::GetObjectName() const { + if (const ObjectFile *object_file = GetObjectFile()) + return object_file->GetObjectName(); + return ""; +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits