Skip to content

[llvm-gsymutil] Print one-time DWO file missing warning under --quiet flag #79882

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
Feb 1, 2024

Conversation

kusmour
Copy link
Contributor

@kusmour kusmour commented Jan 29, 2024

FileCheck test added

./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test

Manual test steps:

  • Create binary with split-dwarf:
clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
  • Remane the dwo file to a different name so llvm-gsymutil can't find it
mv main_split-main.dwo main_split-main__.dwo
  • Now run llvm-gsymutil conversion, it should print out warning with and without the --quiet flag
$ ./bin/llvm-gsymutil --convert=./main_split
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
Loaded 0 functions from DWARF.
Loaded 12 functions from symbol table.
Pruned 0 functions, ended with 12 total
$ ./bin/llvm-gsymutil --convert=./main_split --quiet
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
Pruned 0 functions, ended with 12 total

@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2024

@llvm/pr-subscribers-debuginfo

Author: kusmour (kusmour)

Changes

FileCheck test added

./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test

Manual test steps:

  • Create binary with split-dwarf:
clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
  • Remane the dwo file to a different name so llvm-gsymutil can't find it
mv main_split-main.dwo main_split-main__.dwo
  • Now run llvm-gsymutil conversion, it should print out warning with and without the --quiet flag
$ ./bin/llvm-gsymutil --convert=./main_split
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
Loaded 0 functions from DWARF.
Loaded 12 functions from symbol table.
Pruned 0 functions, ended with 12 total
$ ./bin/llvm-gsymutil --convert=./main_split --quiet
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
Pruned 0 functions, ended with 12 total

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

6 Files Affected:

  • (modified) llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp (+17-7)
  • (added) llvm/test/tools/llvm-gsymutil/X86/Inputs/main.cpp (+13)
  • (added) llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split ()
  • (added) llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split-main__.dwo ()
  • (added) llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split.gsym ()
  • (added) llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test (+32)
diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index 0b225376349ece..6268c7845a142a 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -537,17 +537,27 @@ void DwarfTransformer::handleDie(raw_ostream *OS, CUInfo &CUI, DWARFDie Die) {
 
 Error DwarfTransformer::convert(uint32_t NumThreads, raw_ostream *OS) {
   size_t NumBefore = Gsym.getNumFunctionInfos();
+  std::once_flag flag;
   auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
     DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
     if (DwarfUnit.getDWOId()) {
       DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
-      if (OS && !DWOCU->isDWOUnit()) {
-        std::string DWOName = dwarf::toString(
-            DwarfUnit.getUnitDIE().find(
-                {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
-            "");
-        *OS << "warning: Unable to retrieve DWO .debug_info section for "
-            << DWOName << "\n";
+      if (!DWOCU->isDWOUnit()) {
+        if (OS) {
+          std::string DWOName = dwarf::toString(
+              DwarfUnit.getUnitDIE().find(
+                  {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
+              "");
+          *OS << "warning: Unable to retrieve DWO .debug_info section for "
+              << DWOName << "\n";
+        } else {
+          std::call_once(flag, []() {
+            outs()
+                << "warning: Unable to retrieve DWO .debug_info section for "
+                   "some "
+                   "object files. (Remove the --quiet flag for full output)\n";
+          });
+        }
       } else {
         ReturnDie = DWOCU->getUnitDIE(false);
       }
diff --git a/llvm/test/tools/llvm-gsymutil/X86/Inputs/main.cpp b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main.cpp
new file mode 100644
index 00000000000000..4c72cdf16a232a
--- /dev/null
+++ b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main.cpp
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <unistd.h>
+
+void foo() {
+    std::cout << "This is foo" << std::endl;
+}
+
+int main() {
+    std::cout << "hello world" << std::endl;
+    foo();
+    std::cout << "after foo" << std::endl;
+    return 0;
+}
diff --git a/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split
new file mode 100755
index 00000000000000..a448f1bdf93b2b
Binary files /dev/null and b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split differ
diff --git a/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split-main__.dwo b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split-main__.dwo
new file mode 100644
index 00000000000000..4bb34ae7bd6bdf
Binary files /dev/null and b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split-main__.dwo differ
diff --git a/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split.gsym b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split.gsym
new file mode 100644
index 00000000000000..c9e074bb3568d8
Binary files /dev/null and b/llvm/test/tools/llvm-gsymutil/X86/Inputs/main_split.gsym differ
diff --git a/llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test b/llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test
new file mode 100644
index 00000000000000..0a57c8dfe8791d
--- /dev/null
+++ b/llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test
@@ -0,0 +1,32 @@
+$ cat > main.cpp
+#include <iostream>
+#include <unistd.h>
+
+void foo() {
+    std::cout << "This is foo" << std::endl;
+}
+
+int main() {
+    std::cout << "hello world" << std::endl;
+    foo();
+    std::cout << "after foo" << std::endl;
+    return 0;
+}
+
+$ clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
+$ mv main_split-main.dwo main_split-main__.dwo
+
+// RUN: llvm-gsymutil --convert=%p/Inputs/main_split | FileCheck %s --check-prefix=WARNING
+// RUN: llvm-gsymutil --convert=%p/Inputs/main_split --quiet 2>&1 | FileCheck %s --check-prefix=WARNING-QUIET
+
+// WARNING: Input file:  {{.*\/main_split}}
+// WARNING: Output file (x86_64): {{.*\.gsym}}
+// WARNING: warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
+// WARNING: Loaded 0 functions from DWARF.
+// WARNING: Loaded 12 functions from symbol table.
+// WARNING: Pruned 0 functions, ended with 12 total
+
+// WARNING-QUIET: Input file: {{.*\/main_split}}
+// WARNING-QUIET: Output file (x86_64): {{.*\.gsym}}
+// WARNING-QUIET: warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
+// WARNING-QUIET: Pruned 0 functions, ended with 12 total

@kusmour kusmour force-pushed the llvm-gsymutil-wanrning branch 2 times, most recently from e572b36 to e1ee27b Compare January 30, 2024 03:58
Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

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

Very close, just one inline comment

@dwblaikie
Copy link
Collaborator

FWIW, these days we tend to avoid checking in binaries for testing these tools - instead checking in assembly and generating dwarf objects from that in the test with llvm-mc, or similar pipelines, where possible.

"");
*OS << "warning: Unable to retrieve DWO .debug_info section for "
<< DWOName << "\n";
if (!DWOCU->isDWOUnit()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is --verbose option. Maybe have the same path for default verbosity and no OS, and print all the files for higher verbosity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the --verbose is only used for lookups. We will need to expose that option (the same way as --quiet) to Transformer level. If we want to go this path I will do it in a separate patch. Let's focus on the changing the --quiet behavior here :D

@ayermolo
Copy link
Contributor

+1 on assembly. bolt/test/X86 has bunch of examples.

… flag

FileCheck test added
```
./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/dwo-warning.test
```

Manual test steps:

- Create binary with split-dwarf:
```
clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
```

- Remane the dwo file to a different name so llvm-gsymutil can't find it
```
mv main_split-main.dwo main_split-main__.dwo
```

- Now run llvm-gsymutil conversion, it should print out warning with and without the `--quiet` flag
```
$ ./bin/llvm-gsymutil --convert=./main_split
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
Loaded 0 functions from DWARF.
Loaded 12 functions from symbol table.
Pruned 0 functions, ended with 12 total
```

```
$ ./bin/llvm-gsymutil --convert=./main_split --quiet
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
Pruned 0 functions, ended with 12 total
```
@kusmour kusmour force-pushed the llvm-gsymutil-wanrning branch from e1ee27b to d03fc83 Compare January 31, 2024 23:56
Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

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

LGTM

@kusmour kusmour merged commit 5a8f290 into llvm:main Feb 1, 2024
carlosgalvezp pushed a commit to carlosgalvezp/llvm-project that referenced this pull request Feb 1, 2024
… flag (llvm#79882)

FileCheck test added
```
./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/elf-dwo.yaml
```

Manual test steps:

- Create binary with split-dwarf:
```
clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
```

- Remove or remane the dwo file to a different name so llvm-gsymutil can't find it
```
mv main_split-main.dwo main_split-main__.dwo
```

- Now run llvm-gsymutil conversion, it should print out warning with and
without the `--quiet` flag
```
$ ./bin/llvm-gsymutil --convert=./main_split
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
Loaded 0 functions from DWARF.
Loaded 12 functions from symbol table.
Pruned 0 functions, ended with 12 total
```

```
$ ./bin/llvm-gsymutil --convert=./main_split --quiet
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
Pruned 0 functions, ended with 12 total
```
@kusmour kusmour deleted the llvm-gsymutil-wanrning branch February 2, 2024 20:11
agozillon pushed a commit to agozillon/llvm-project that referenced this pull request Feb 5, 2024
… flag (llvm#79882)

FileCheck test added
```
./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/elf-dwo.yaml
```

Manual test steps:

- Create binary with split-dwarf:
```
clang++ -g -gdwarf-4 -gsplit-dwarf main.cpp -o main_split
```

- Remove or remane the dwo file to a different name so llvm-gsymutil can't find it
```
mv main_split-main.dwo main_split-main__.dwo
```

- Now run llvm-gsymutil conversion, it should print out warning with and
without the `--quiet` flag
```
$ ./bin/llvm-gsymutil --convert=./main_split
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for main_split-main.dwo
Loaded 0 functions from DWARF.
Loaded 12 functions from symbol table.
Pruned 0 functions, ended with 12 total
```

```
$ ./bin/llvm-gsymutil --convert=./main_split --quiet
Input file: ./main_split
Output file (x86_64): ./main_split.gsym
warning: Unable to retrieve DWO .debug_info section for some object files. (Remove the --quiet flag for full output)
Pruned 0 functions, ended with 12 total
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants