Skip to content

Commit 8af1b71

Browse files
committed
[lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method
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.
1 parent 6ee5e69 commit 8af1b71

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "lldb/Core/PluginManager.h"
1313
#include "lldb/Symbol/CompileUnit.h"
1414
#include "lldb/Symbol/ObjectFile.h"
15+
#include "lldb/Symbol/Symbol.h"
1516
#include "lldb/Symbol/SymbolFileOnDemand.h"
17+
#include "lldb/Symbol/Symtab.h"
1618
#include "lldb/Symbol/TypeMap.h"
1719
#include "lldb/Symbol/TypeSystem.h"
1820
#include "lldb/Symbol/VariableList.h"
@@ -259,3 +261,9 @@ void SymbolFileCommon::Dump(Stream &s) {
259261
if (Symtab *symtab = GetSymtab())
260262
symtab->Dump(&s, nullptr, eSortOrderNone);
261263
}
264+
265+
std::string SymbolFile::GetObjectName() const {
266+
if (const ObjectFile *object_file = GetObjectFile())
267+
return object_file->GetObjectName();
268+
return "";
269+
}

0 commit comments

Comments
 (0)