Skip to content

[lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method #133370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025

Conversation

JDevlieghere
Copy link
Member

@JDevlieghere JDevlieghere commented Mar 28, 2025

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.

@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

In #133211, Greg pointed out that the old code would print the static archive (the .a file) rather than the actual object file inside of it.


Full diff: https://github.com/llvm/llvm-project/pull/133370.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (+10-6)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index e346d588a449f..fff2464c38c12 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -718,6 +718,15 @@ bool SymbolFileDWARFDebugMap::ParseDebugMacros(CompileUnit &comp_unit) {
   return false;
 }
 
+static std::string GetObjectName(SymbolFileDWARF &oso_dwarf) {
+  if (ObjectFile *object_file = oso_dwarf.GetObjectFile()) {
+    if (ModuleSP module_sp = object_file->GetModule()) {
+      return module_sp->GetObjectName().GetString();
+    }
+  }
+  return "";
+}
+
 void SymbolFileDWARFDebugMap::ForEachSymbolFile(
     std::string description,
     std::function<IterationAction(SymbolFileDWARF &)> closure) {
@@ -727,12 +736,7 @@ void SymbolFileDWARFDebugMap::ForEachSymbolFile(
                     /*minimum_report_time=*/std::chrono::milliseconds(20));
   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, GetObjectName(*oso_dwarf));
       if (closure(*oso_dwarf) == IterationAction::Stop)
         return;
     }

@jimingham
Copy link
Collaborator

One common mistake with .o files is to strip the .a file before linking. Then you end up with no debug info even though the original .o file definitely HAS debug info. In that case showing the .o file rather than the usual form libfoo.a(bar.o) would be confusing.
But I can't think of a way that we would know about the original .o file if the .a file got stripped too early. So I think this concern is moot.

@JDevlieghere
Copy link
Member Author

Any concerns with this @clayborg? This pretty much does exactly what you suggested in #133211.

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.
@JDevlieghere JDevlieghere changed the title [lldb] Show the path to the .o instead of the containing .a in progress events [lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method Apr 4, 2025
Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JDevlieghere JDevlieghere merged commit 5271dea into llvm:main Apr 4, 2025
10 checks passed
@JDevlieghere JDevlieghere deleted the GetObjectName branch April 4, 2025 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants