[llvm] d3f49b8 - [ObjectYAML][DWARF] Let `dumpPubSection` return `DWARFYAML::PubSection`.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 23:34:54 PDT 2020


Author: Xing GUO
Date: 2020-06-02T14:38:26+08:00
New Revision: d3f49b8d378d0b7452f841d28db7b24e3fe9fcb6

URL: https://github.com/llvm/llvm-project/commit/d3f49b8d378d0b7452f841d28db7b24e3fe9fcb6
DIFF: https://github.com/llvm/llvm-project/commit/d3f49b8d378d0b7452f841d28db7b24e3fe9fcb6.diff

LOG: [ObjectYAML][DWARF] Let `dumpPubSection` return `DWARFYAML::PubSection`.

Summary: This patch addresses comments in [D80722](https://reviews.llvm.org/D80722#inline-742353)

Reviewers: grimar, jhenderson

Reviewed By: grimar, jhenderson

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80861

Added: 
    

Modified: 
    llvm/tools/obj2yaml/dwarf2yaml.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 0a1cac8c73c1..ec42f1caff7c 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -115,10 +115,12 @@ Error dumpDebugRanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
   return ErrorSuccess();
 }
 
-void dumpPubSection(DWARFContext &DCtx, DWARFYAML::PubSection &Y,
-                    DWARFSection Section) {
+static DWARFYAML::PubSection dumpPubSection(const DWARFContext &DCtx,
+                                            const DWARFSection &Section,
+                                            bool IsGNUStyle) {
   DWARFDataExtractor PubSectionData(DCtx.getDWARFObj(), Section,
                                     DCtx.isLittleEndian(), 0);
+  DWARFYAML::PubSection Y(IsGNUStyle);
   uint64_t Offset = 0;
   dumpInitialLength(PubSectionData, Offset, Y.Length);
   Y.Version = PubSectionData.getU16(&Offset);
@@ -127,41 +129,35 @@ void dumpPubSection(DWARFContext &DCtx, DWARFYAML::PubSection &Y,
   while (Offset < Y.Length.getLength()) {
     DWARFYAML::PubEntry NewEntry;
     NewEntry.DieOffset = PubSectionData.getU32(&Offset);
-    if (Y.IsGNUStyle)
+    if (IsGNUStyle)
       NewEntry.Descriptor = PubSectionData.getU8(&Offset);
     NewEntry.Name = PubSectionData.getCStr(&Offset);
     Y.Entries.push_back(NewEntry);
   }
+
+  return Y;
 }
 
 void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
   const DWARFObject &D = DCtx.getDWARFObj();
 
   const DWARFSection PubNames = D.getPubnamesSection();
-  if (!PubNames.Data.empty()) {
-    Y.PubNames.emplace(/*IsGNUStyle=*/false);
-    dumpPubSection(DCtx, *Y.PubNames, PubNames);
-  }
+  if (!PubNames.Data.empty())
+    Y.PubNames = dumpPubSection(DCtx, PubNames, /*IsGNUStyle=*/false);
 
   const DWARFSection PubTypes = D.getPubtypesSection();
-  if (!PubTypes.Data.empty()) {
-    Y.PubTypes.emplace(/*IsGNUStyle=*/false);
-    dumpPubSection(DCtx, *Y.PubTypes, PubTypes);
-  }
+  if (!PubTypes.Data.empty())
+    Y.PubTypes = dumpPubSection(DCtx, PubTypes, /*IsGNUStyle=*/false);
 
   const DWARFSection GNUPubNames = D.getGnuPubnamesSection();
-  if (!GNUPubNames.Data.empty()) {
+  if (!GNUPubNames.Data.empty())
     // TODO: Test dumping .debug_gnu_pubnames section.
-    Y.GNUPubNames.emplace(/*IsGNUStyle=*/true);
-    dumpPubSection(DCtx, *Y.GNUPubNames, GNUPubNames);
-  }
+    Y.GNUPubNames = dumpPubSection(DCtx, GNUPubNames, /*IsGNUStyle=*/true);
 
   const DWARFSection GNUPubTypes = D.getGnuPubtypesSection();
-  if (!GNUPubTypes.Data.empty()) {
+  if (!GNUPubTypes.Data.empty())
     // TODO: Test dumping .debug_gnu_pubtypes section.
-    Y.GNUPubTypes.emplace(/*IsGNUStyle=*/true);
-    dumpPubSection(DCtx, *Y.GNUPubTypes, GNUPubTypes);
-  }
+    Y.GNUPubTypes = dumpPubSection(DCtx, GNUPubTypes, /*IsGNUStyle=*/true);
 }
 
 void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {


        


More information about the llvm-commits mailing list