[lld] [llvm] [llvm-readobj][COFF] Consistent PDBGUID Formatting (PR #94256)

Miguel A. Arroyo via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 4 09:14:29 PDT 2024


https://github.com/mayanez updated https://github.com/llvm/llvm-project/pull/94256

>From 3ffca5f701e9c4153da5997db96736c0e1557f04 Mon Sep 17 00:00:00 2001
From: Miguel Arroyo <miguel.arroyo at rockstargames.com>
Date: Fri, 31 May 2024 09:32:42 -0700
Subject: [PATCH 1/3] [llvm-readobj][COFF] Consistent PDBGUID Formatting

---
 lld/test/COFF/rsds.test                                | 6 +++---
 llvm/test/tools/llvm-readobj/COFF/debug-directory.test | 2 +-
 llvm/tools/llvm-readobj/COFFDumper.cpp                 | 6 +++++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/lld/test/COFF/rsds.test b/lld/test/COFF/rsds.test
index 3b611c091e2ef..babf8cba5df19 100644
--- a/lld/test/COFF/rsds.test
+++ b/lld/test/COFF/rsds.test
@@ -60,7 +60,7 @@
 # CHECK:     PointerToRawData: 0x{{[^0]}}
 # CHECK:     PDBInfo {
 # CHECK:       PDBSignature: 0x53445352
-# CHECK:       PDBGUID: [[GUID:\(([A-Za-z0-9]{2} ?){16}\)]]
+# CHECK:       PDBGUID: [[GUID:\{[A-Za-z0-9\-]{36}\}]]
 # CHECK:       PDBAge: 1
 # CHECK:       PDBFileName: {{.*}}.pdb
 # CHECK:     }
@@ -99,7 +99,7 @@
 # TWOPDBS:     PointerToRawData: 0x{{[^0]}}
 # TWOPDBS:     PDBInfo {
 # TWOPDBS:       PDBSignature: 0x53445352
-# TWOPDBS:       PDBGUID: [[GUID:\(([A-Za-z0-9]{2} ?){16}\)]]
+# TWOPDBS:       PDBGUID: [[GUID:\{[A-Za-z0-9\-]{36}\}]]
 # TWOPDBS:       PDBAge: 1
 # TWOPDBS:       PDBFileName: {{.*}}.pdb
 # TWOPDBS:     }
@@ -182,7 +182,7 @@
 # BUILDID:     PointerToRawData: 0x{{[^0]}}
 # BUILDID:     PDBInfo {
 # BUILDID:       PDBSignature: 0x53445352
-# BUILDID:       PDBGUID: [[GUID:\(([A-Za-z0-9]{2} ?){16}\)]]
+# BUILDID:       PDBGUID: [[GUID:\{[A-Za-z0-9\-]{36}\}]]
 # BUILDID:       PDBAge: 1
 # BUILDID:       PDBFileName:
 # BUILDID:     }
diff --git a/llvm/test/tools/llvm-readobj/COFF/debug-directory.test b/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
index f67eb70d82095..88295679a290a 100644
--- a/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
+++ b/llvm/test/tools/llvm-readobj/COFF/debug-directory.test
@@ -12,7 +12,7 @@ CHECK:     AddressOfRawData: 0x5B068
 CHECK:     PointerToRawData: 0x5A268
 CHECK:     PDBInfo {
 CHECK:       PDBSignature: 0x53445352
-CHECK:       PDBGUID: (96 83 40 42 81 07 9D 40 90 1B 4A 3C 0D 4F 56 32)
+CHECK:       PDBGUID: {42408396-0781-409D-901B-4A3C0D4F5632}
 CHECK:       PDBAge: 3
 CHECK:       PDBFileName: D:\src\llvm\build\has_pdb.pdb
 CHECK:     }
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 32b1d6a2089ca..b2939f7826393 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -27,6 +27,7 @@
 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
+#include "llvm/DebugInfo/CodeView/Formatters.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/CodeView/Line.h"
 #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
@@ -793,7 +794,10 @@ void COFFDumper::printCOFFDebugDirectory() {
       DictScope PDBScope(W, "PDBInfo");
       W.printHex("PDBSignature", DebugInfo->Signature.CVSignature);
       if (DebugInfo->Signature.CVSignature == OMF::Signature::PDB70) {
-        W.printBinary("PDBGUID", ArrayRef(DebugInfo->PDB70.Signature));
+        SmallString<38> FormattedGUIDStr;
+        raw_svector_ostream OS(FormattedGUIDStr);
+        fmt_guid(DebugInfo->PDB70.Signature).format(OS, "" /*Style=unused*/);
+        W.printString("PDBGUID", FormattedGUIDStr);
         W.printNumber("PDBAge", DebugInfo->PDB70.Age);
         W.printString("PDBFileName", PDBFileName);
       }

>From 8f0e24f4e814a07918f12a6440bbe9c95b8dce1f Mon Sep 17 00:00:00 2001
From: Miguel Arroyo <miguel.arroyo at rockstargames.com>
Date: Mon, 3 Jun 2024 16:28:05 -0700
Subject: [PATCH 2/3] [llvm-readobj][COFF] GuidAdapter raw_ostream Support

---
 llvm/include/llvm/DebugInfo/CodeView/Formatters.h | 2 ++
 llvm/lib/DebugInfo/CodeView/Formatters.cpp        | 6 ++++++
 llvm/tools/llvm-readobj/COFFDumper.cpp            | 6 ++----
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
index 10683c289224a..188151878ab63 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/Formatters.h
@@ -46,6 +46,8 @@ inline detail::GuidAdapter fmt_guid(ArrayRef<uint8_t> Item) {
   return detail::GuidAdapter(Item);
 }
 
+raw_ostream &operator<<(raw_ostream &OS, detail::GuidAdapter Guid);
+
 } // end namespace codeview
 
 template <> struct format_provider<codeview::TypeIndex> {
diff --git a/llvm/lib/DebugInfo/CodeView/Formatters.cpp b/llvm/lib/DebugInfo/CodeView/Formatters.cpp
index 8c21764600b60..45cb6bec1588e 100644
--- a/llvm/lib/DebugInfo/CodeView/Formatters.cpp
+++ b/llvm/lib/DebugInfo/CodeView/Formatters.cpp
@@ -59,3 +59,9 @@ raw_ostream &llvm::codeview::operator<<(raw_ostream &OS, const GUID &Guid) {
   A.format(OS, "");
   return OS;
 }
+
+raw_ostream &llvm::codeview::operator<<(raw_ostream &OS,
+                                        detail::GuidAdapter Guid) {
+  Guid.format(OS, "");
+  return OS;
+}
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index b2939f7826393..48a4a276e6dba 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -794,10 +794,8 @@ void COFFDumper::printCOFFDebugDirectory() {
       DictScope PDBScope(W, "PDBInfo");
       W.printHex("PDBSignature", DebugInfo->Signature.CVSignature);
       if (DebugInfo->Signature.CVSignature == OMF::Signature::PDB70) {
-        SmallString<38> FormattedGUIDStr;
-        raw_svector_ostream OS(FormattedGUIDStr);
-        fmt_guid(DebugInfo->PDB70.Signature).format(OS, "" /*Style=unused*/);
-        W.printString("PDBGUID", FormattedGUIDStr);
+        W.startLine() << "PDBGUID: " << fmt_guid(DebugInfo->PDB70.Signature)
+                      << "\n";
         W.printNumber("PDBAge", DebugInfo->PDB70.Age);
         W.printString("PDBFileName", PDBFileName);
       }

>From cfffb1a4f597dafc69aee3d5e63fb88d779ae60c Mon Sep 17 00:00:00 2001
From: Miguel Arroyo <miguel.arroyo at rockstargames.com>
Date: Tue, 4 Jun 2024 09:13:05 -0700
Subject: [PATCH 3/3] [llvm-readobj][COFF] PDBGUID using printString()

---
 llvm/tools/llvm-readobj/COFFDumper.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 48a4a276e6dba..b104774d37a93 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -794,8 +794,9 @@ void COFFDumper::printCOFFDebugDirectory() {
       DictScope PDBScope(W, "PDBInfo");
       W.printHex("PDBSignature", DebugInfo->Signature.CVSignature);
       if (DebugInfo->Signature.CVSignature == OMF::Signature::PDB70) {
-        W.startLine() << "PDBGUID: " << fmt_guid(DebugInfo->PDB70.Signature)
-                      << "\n";
+        W.printString(
+            "PDBGUID",
+            formatv("{0}", fmt_guid(DebugInfo->PDB70.Signature)).str());
         W.printNumber("PDBAge", DebugInfo->PDB70.Age);
         W.printString("PDBFileName", PDBFileName);
       }



More information about the llvm-commits mailing list