[PATCH] D87024: [DebugInfo] Fix emitting DWARF64 .debug_macro[.dwo] sections (17/19).
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 06:23:08 PDT 2020
ikudrin created this revision.
ikudrin added reviewers: dblaikie, jhenderson, probinson, aprantl, SouraVX, dstenb.
ikudrin added projects: LLVM, debug-info.
Herald added subscribers: ormris, hiraditya.
ikudrin requested review of this revision.
The patch fixes emitting flags and the `debug_line_offset` field in the header, as well as the reference to the macro string for a pre-standard GNU `.debug_macro` extension.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87024
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/test/DebugInfo/X86/debug-macro-dwarf64.ll
Index: llvm/test/DebugInfo/X86/debug-macro-dwarf64.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-macro-dwarf64.ll
@@ -0,0 +1,34 @@
+; This checks that .debug_macro[.dwo] can be generated in the DWARF64 format.
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=4 -dwarf64 -use-gnu-debug-macro -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-macro %t | FileCheck %s --check-prefix=DWARF4
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=5 -dwarf64 -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-macro %t | FileCheck %s --check-prefix=DWARF5
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=5 -dwarf64 -split-dwarf-file=foo.dwo -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-macro %t | FileCheck %s --check-prefixes=DWARF5,DWO
+
+; DWARF4: .debug_macro contents:
+; DWARF4-NEXT: 0x00000000:
+; DWARF4-NEXT: macro header: version = 0x0004, flags = 0x03, format = DWARF64, debug_line_offset = 0x0000000000000000
+; DWARF4-NEXT: DW_MACRO_GNU_define_indirect - lineno: 2 macro: FOO 1
+; DWARF4-NEXT: DW_MACRO_GNU_undef_indirect - lineno: 5 macro: BAR
+
+; DWARF5: .debug_macro contents:
+; DWO: .debug_macro.dwo contents:
+; DWARF5-NEXT: 0x00000000:
+; DWARF5-NEXT: macro header: version = 0x0005, flags = 0x03, format = DWARF64, debug_line_offset = 0x0000000000000000
+; DWARF5-NEXT: DW_MACRO_define_strx - lineno: 2 macro: FOO 1
+; DWARF5-NEXT: DW_MACRO_undef_strx - lineno: 5 macro: BAR
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = !DIFile(filename: "foo.c", directory: "/tmp")
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Manual", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !3, macros: !4)
+!3 = !{}
+!4 = !{!5, !6}
+!5 = !DIMacro(type: DW_MACINFO_define, line: 2, name: "FOO", value: "1")
+!6 = !DIMacro(type: DW_MACINFO_undef, line: 5, name: "BAR")
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2962,21 +2962,22 @@
#define HANDLE_MACRO_FLAG(ID, NAME) MACRO_FLAG_##NAME = ID,
#include "llvm/BinaryFormat/Dwarf.def"
};
- uint8_t Flags = 0;
Asm->OutStreamer->AddComment("Macro information version");
Asm->emitInt16(DwarfVersion >= 5 ? DwarfVersion : 4);
- // We are setting Offset and line offset flags unconditionally here,
- // since we're only supporting DWARF32 and line offset should be mostly
- // present.
- // FIXME: Add support for DWARF64.
- Flags |= MACRO_FLAG_DEBUG_LINE_OFFSET;
- Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
- Asm->emitInt8(Flags);
+ // We emit the line offset flag unconditionally here, since line offset should
+ // be mostly present.
+ if (Asm->isDwarf64()) {
+ Asm->OutStreamer->AddComment("Flags: 64 bit, debug_line_offset present");
+ Asm->emitInt8(MACRO_FLAG_OFFSET_SIZE | MACRO_FLAG_DEBUG_LINE_OFFSET);
+ } else {
+ Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
+ Asm->emitInt8(MACRO_FLAG_DEBUG_LINE_OFFSET);
+ }
Asm->OutStreamer->AddComment("debug_line_offset");
if (DD.useSplitDwarf())
- Asm->OutStreamer->emitIntValue(0, /*Size=*/4);
+ Asm->emitDwarfLengthOrOffset(0);
else
- Asm->OutStreamer->emitSymbolValue(CU.getLineTableStartSym(), /*Size=*/4);
+ Asm->emitDwarfSymbolReference(CU.getLineTableStartSym());
}
void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {
@@ -3019,10 +3020,8 @@
Asm->OutStreamer->AddComment("Line Number");
Asm->emitULEB128(M.getLine());
Asm->OutStreamer->AddComment("Macro String");
- // FIXME: Add support for DWARF64.
- Asm->OutStreamer->emitSymbolValue(
- InfoHolder.getStringPool().getEntry(*Asm, Str).getSymbol(),
- /*Size=*/4);
+ Asm->emitDwarfSymbolReference(
+ InfoHolder.getStringPool().getEntry(*Asm, Str).getSymbol());
}
} else {
Asm->OutStreamer->AddComment(dwarf::MacinfoString(M.getMacinfoType()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87024.289429.patch
Type: text/x-patch
Size: 4194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200902/ae30780a/attachment.bin>
More information about the llvm-commits
mailing list