Skip to content

Commit 5271dea

Browse files
authored
[lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method (llvm#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 llvm#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.
1 parent 6f34d03 commit 5271dea

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
748748

749749
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
750750
uint64_t Offset);
751+
std::string GetObjectName() const;
751752

752753
protected:
753754
// Member variables.

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ class SymbolFile : public PluginInterface {
491491
return args;
492492
}
493493

494+
std::string GetObjectName() const;
495+
494496
protected:
495497
void AssertModuleLock();
496498

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,7 @@ void SymbolFileDWARFDebugMap::ForEachSymbolFile(
727727
Progress::kDefaultHighFrequencyReportTime);
728728
for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
729729
if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
730-
progress.Increment(oso_idx, oso_dwarf->GetObjectFile()
731-
? oso_dwarf->GetObjectFile()
732-
->GetFileSpec()
733-
.GetFilename()
734-
.GetString()
735-
: "");
730+
progress.Increment(oso_idx, oso_dwarf->GetObjectName());
736731
if (closure(*oso_dwarf) == IterationAction::Stop)
737732
return;
738733
}

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,15 @@ uint32_t ObjectFile::GetCacheHash() {
775775
return *m_cache_hash;
776776
}
777777

778+
std::string ObjectFile::GetObjectName() const {
779+
if (ModuleSP module_sp = GetModule())
780+
if (ConstString object_name = module_sp->GetObjectName())
781+
return llvm::formatv("{0}({1})", GetFileSpec().GetFilename().GetString(),
782+
object_name.GetString())
783+
.str();
784+
return GetFileSpec().GetFilename().GetString();
785+
}
786+
778787
namespace llvm {
779788
namespace json {
780789

lldb/source/Symbol/SymbolFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,9 @@ void SymbolFileCommon::Dump(Stream &s) {
259259
if (Symtab *symtab = GetSymtab())
260260
symtab->Dump(&s, nullptr, eSortOrderNone);
261261
}
262+
263+
std::string SymbolFile::GetObjectName() const {
264+
if (const ObjectFile *object_file = GetObjectFile())
265+
return object_file->GetObjectName();
266+
return "";
267+
}

0 commit comments

Comments
 (0)