[PATCH] D82971: [DebugInfo] Refactor .debug_macro checks. NFCI

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 09:10:21 PDT 2020


dstenb created this revision.
dstenb added reviewers: SouraVX, dblaikie, ikudrin.
dstenb added a project: debug-info.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.
dstenb added a child revision: D82974: [DebugInfo] Allow GNU macro extension to be read.

Move the Dwarf version checks that determines if the .debug_macro
section should be emitted, into a DwarfDebug member. This is a
preparatory refactoring for allowing the GNU .debug_macro extension,
which is a precursor to the DWARF 5 format, to be emitted by LLVM for
earlier DWARF versions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82971

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -372,6 +372,9 @@
   /// Generate DWARF v4 type units.
   bool GenerateTypeUnits;
 
+  /// Emit a .debug_macro section instead of .debug_macinfo.
+  bool UseDebugMacroSection;
+
   /// DWARF5 Experimental Options
   /// @{
   AccelTableKind TheAccelTableKind;
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -429,6 +429,8 @@
                           (tuneForGDB() || tuneForLLDB())) ||
                          EmitDwarfDebugEntryValues;
 
+  UseDebugMacroSection = DwarfVersion >= 5;
+
   Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
 }
 
@@ -1348,7 +1350,7 @@
     // If compile Unit has macros, emit "DW_AT_macro_info/DW_AT_macros"
     // attribute.
     if (CUNode->getMacros()) {
-      if (getDwarfVersion() >= 5) {
+      if (UseDebugMacroSection) {
         if (useSplitDwarf())
           TheCU.addSectionDelta(
               TheCU.getUnitDie(), dwarf::DW_AT_macros, U.getMacroLabelBegin(),
@@ -2993,9 +2995,8 @@
 void DwarfDebug::emitMacro(DIMacro &M) {
   StringRef Name = M.getName();
   StringRef Value = M.getValue();
-  bool UseMacro = getDwarfVersion() >= 5;
 
-  if (UseMacro) {
+  if (UseDebugMacroSection) {
     unsigned Type = M.getMacinfoType() == dwarf::DW_MACINFO_define
                         ? dwarf::DW_MACRO_define_strx
                         : dwarf::DW_MACRO_undef_strx;
@@ -3050,8 +3051,7 @@
   // DWARFv5 macro and DWARFv4 macinfo share some common encodings,
   // so for readibility/uniformity, We are explicitly emitting those.
   assert(F.getMacinfoType() == dwarf::DW_MACINFO_start_file);
-  bool UseMacro = getDwarfVersion() >= 5;
-  if (UseMacro)
+  if (UseDebugMacroSection)
     emitMacroFileImpl(F, U, dwarf::DW_MACRO_start_file,
                       dwarf::DW_MACRO_end_file, dwarf::MacroString);
   else
@@ -3070,7 +3070,7 @@
       continue;
     Asm->OutStreamer->SwitchSection(Section);
     Asm->OutStreamer->emitLabel(U.getMacroLabelBegin());
-    if (getDwarfVersion() >= 5)
+    if (UseDebugMacroSection)
       emitMacroHeader(Asm, *this, U);
     handleMacroNodes(Macros, U);
     Asm->OutStreamer->AddComment("End Of Macro List Mark");
@@ -3081,14 +3081,14 @@
 /// Emit macros into a debug macinfo/macro section.
 void DwarfDebug::emitDebugMacinfo() {
   auto &ObjLower = Asm->getObjFileLowering();
-  emitDebugMacinfoImpl(getDwarfVersion() >= 5
+  emitDebugMacinfoImpl(UseDebugMacroSection
                            ? ObjLower.getDwarfMacroSection()
                            : ObjLower.getDwarfMacinfoSection());
 }
 
 void DwarfDebug::emitDebugMacinfoDWO() {
   auto &ObjLower = Asm->getObjFileLowering();
-  emitDebugMacinfoImpl(getDwarfVersion() >= 5
+  emitDebugMacinfoImpl(UseDebugMacroSection
                            ? ObjLower.getDwarfMacroDWOSection()
                            : ObjLower.getDwarfMacinfoDWOSection());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82971.274829.patch
Type: text/x-patch
Size: 3199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200701/2bcab81c/attachment.bin>


More information about the llvm-commits mailing list