[PATCH] D83557: [DebugInfo] Simplify DwarfDebug::emitMacro

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 10 07:16:58 PDT 2020


dstenb created this revision.
dstenb added reviewers: SouraVX, dblaikie, ikudrin.
dstenb added a project: debug-info.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Broken out from a review comment on D82975 <https://reviews.llvm.org/D82975>. This is an NFC expect for
that the Macinfo macro string is now emitted using a single emitBytes()
invocation, so it can be done using a single string directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83557

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


Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2996,6 +2996,10 @@
   StringRef Name = M.getName();
   StringRef Value = M.getValue();
 
+  // There should be one space between the macro name and the macro value in
+  // define entries. In undef entries, only the macro name is emitted.
+  std::string Str = Value.empty() ? Name.str() : (Name + " " + Value).str();
+
   if (UseDebugMacroSection) {
     unsigned Type = M.getMacinfoType() == dwarf::DW_MACINFO_define
                         ? dwarf::DW_MACRO_define_strx
@@ -3005,29 +3009,15 @@
     Asm->OutStreamer->AddComment("Line Number");
     Asm->emitULEB128(M.getLine());
     Asm->OutStreamer->AddComment("Macro String");
-    if (!Value.empty())
-      Asm->emitULEB128(this->InfoHolder.getStringPool()
-                           .getIndexedEntry(*Asm, (Name + " " + Value).str())
-                           .getIndex());
-    else
-      // DW_MACRO_undef_strx doesn't have a value, so just emit the macro
-      // string.
-      Asm->emitULEB128(this->InfoHolder.getStringPool()
-                           .getIndexedEntry(*Asm, (Name).str())
-                           .getIndex());
+    Asm->emitULEB128(
+        InfoHolder.getStringPool().getIndexedEntry(*Asm, Str).getIndex());
   } else {
     Asm->OutStreamer->AddComment(dwarf::MacinfoString(M.getMacinfoType()));
     Asm->emitULEB128(M.getMacinfoType());
     Asm->OutStreamer->AddComment("Line Number");
     Asm->emitULEB128(M.getLine());
     Asm->OutStreamer->AddComment("Macro String");
-    Asm->OutStreamer->emitBytes(Name);
-    if (!Value.empty()) {
-      // There should be one space between macro name and macro value.
-      Asm->emitInt8(' ');
-      Asm->OutStreamer->AddComment("Macro Value=");
-      Asm->OutStreamer->emitBytes(Value);
-    }
+    Asm->OutStreamer->emitBytes(Str);
     Asm->emitInt8('\0');
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83557.277029.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200710/9a52830b/attachment-0001.bin>


More information about the llvm-commits mailing list