mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
[DebugInfo] Support parsing and dumping of DWARF64 macro units.
Differential Revision: https://reviews.llvm.org/D81844
This commit is contained in:
@@ -44,7 +44,7 @@ class DWARFDebugMacro {
|
||||
/// opcode_operands_table_flag:
|
||||
/// If the opcode_operands_table_flag is one, the opcode_operands_table
|
||||
/// field (see below) is present. If zero, that field is omitted.
|
||||
uint8_t Flags;
|
||||
uint8_t Flags = 0;
|
||||
|
||||
/// debug_line_offset
|
||||
/// An offset in the .debug_line section of the beginning of the line
|
||||
@@ -58,6 +58,12 @@ class DWARFDebugMacro {
|
||||
|
||||
/// Parse the debug_macro header.
|
||||
Error parseMacroHeader(DWARFDataExtractor Data, uint64_t *Offset);
|
||||
|
||||
/// Get the DWARF format according to the flags.
|
||||
dwarf::DwarfFormat getDwarfFormat() const;
|
||||
|
||||
/// Get the size of a reference according to the DWARF format.
|
||||
uint8_t getOffsetByteSize() const;
|
||||
};
|
||||
|
||||
/// A single macro entry within a macro list.
|
||||
|
||||
@@ -17,14 +17,23 @@
|
||||
using namespace llvm;
|
||||
using namespace dwarf;
|
||||
|
||||
DwarfFormat DWARFDebugMacro::MacroHeader::getDwarfFormat() const {
|
||||
return Flags & MACRO_OFFSET_SIZE ? DWARF64 : DWARF32;
|
||||
}
|
||||
|
||||
uint8_t DWARFDebugMacro::MacroHeader::getOffsetByteSize() const {
|
||||
return getDwarfOffsetByteSize(getDwarfFormat());
|
||||
}
|
||||
|
||||
void DWARFDebugMacro::MacroHeader::dumpMacroHeader(raw_ostream &OS) const {
|
||||
// FIXME: Add support for dumping opcode_operands_table
|
||||
OS << format("macro header: version = 0x%04" PRIx16 ", flags = 0x%02" PRIx8,
|
||||
Version, Flags);
|
||||
OS << format("macro header: version = 0x%04" PRIx16, Version)
|
||||
<< format(", flags = 0x%02" PRIx8, Flags)
|
||||
<< ", format = " << FormatString(getDwarfFormat());
|
||||
if (Flags & MACRO_DEBUG_LINE_OFFSET)
|
||||
OS << format(", debug_line_offset = 0x%04" PRIx64 "\n", DebugLineOffset);
|
||||
else
|
||||
OS << "\n";
|
||||
OS << format(", debug_line_offset = 0x%0*" PRIx64, 2 * getOffsetByteSize(),
|
||||
DebugLineOffset);
|
||||
OS << "\n";
|
||||
}
|
||||
|
||||
void DWARFDebugMacro::dump(raw_ostream &OS) const {
|
||||
@@ -72,7 +81,8 @@ void DWARFDebugMacro::dump(raw_ostream &OS) const {
|
||||
OS << " filenum: " << E.File;
|
||||
break;
|
||||
case DW_MACRO_import:
|
||||
OS << format(" - import offset: 0x%08" PRIx64, E.ImportOffset);
|
||||
OS << format(" - import offset: 0x%0*" PRIx64,
|
||||
2 * Macros.Header.getOffsetByteSize(), E.ImportOffset);
|
||||
break;
|
||||
case DW_MACRO_end_file:
|
||||
break;
|
||||
@@ -158,8 +168,8 @@ Error DWARFDebugMacro::parseImpl(
|
||||
// 2. Source line
|
||||
E.Line = Data.getULEB128(&Offset);
|
||||
// 3. Macro string
|
||||
// FIXME: Add support for DWARF64
|
||||
StrOffset = Data.getRelocatedValue(/*OffsetSize=*/4, &Offset);
|
||||
StrOffset =
|
||||
Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
|
||||
assert(StringExtractor && "String Extractor not found");
|
||||
E.MacroStr = StringExtractor->getCStr(&StrOffset);
|
||||
break;
|
||||
@@ -199,8 +209,8 @@ Error DWARFDebugMacro::parseImpl(
|
||||
case DW_MACRO_end_file:
|
||||
break;
|
||||
case DW_MACRO_import:
|
||||
// FIXME: Add support for DWARF64
|
||||
E.ImportOffset = Data.getRelocatedValue(/*OffsetSize=*/4, &Offset);
|
||||
E.ImportOffset =
|
||||
Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
|
||||
break;
|
||||
case DW_MACINFO_vendor_ext:
|
||||
// 2. Vendor extension constant
|
||||
@@ -217,9 +227,6 @@ Error DWARFDebugMacro::MacroHeader::parseMacroHeader(DWARFDataExtractor Data,
|
||||
uint64_t *Offset) {
|
||||
Version = Data.getU16(Offset);
|
||||
uint8_t FlagData = Data.getU8(Offset);
|
||||
// FIXME: Add support for DWARF64
|
||||
if (FlagData & MACRO_OFFSET_SIZE)
|
||||
return createStringError(errc::not_supported, "DWARF64 is not supported");
|
||||
|
||||
// FIXME: Add support for parsing opcode_operands_table
|
||||
if (FlagData & MACRO_OPCODE_OPERANDS_TABLE)
|
||||
@@ -227,6 +234,6 @@ Error DWARFDebugMacro::MacroHeader::parseMacroHeader(DWARFDataExtractor Data,
|
||||
"opcode_operands_table is not supported");
|
||||
Flags = FlagData;
|
||||
if (Flags & MACRO_DEBUG_LINE_OFFSET)
|
||||
DebugLineOffset = Data.getU32(Offset);
|
||||
DebugLineOffset = Data.getUnsigned(Offset, getOffsetByteSize());
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
## This checks that llvm-dwarfdump can parse and dump DWARF64 macro units.
|
||||
|
||||
# RUN: llvm-mc -triple x86_64 -filetype=obj %s -o - \
|
||||
# RUN: | llvm-dwarfdump -debug-macro - \
|
||||
# RUN: | FileCheck %s
|
||||
|
||||
# CHECK: .debug_macro contents:
|
||||
|
||||
# CHECK: 0x00000000:
|
||||
# CHECK-NEXT: macro header: version = 0x0005, flags = 0x03, format = DWARF64, debug_line_offset = 0x0000000000000000
|
||||
# CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_import - import offset: 0x00000000[[MACRO1OFF:[[:xdigit:]]{8}]]
|
||||
# CHECK-NEXT: DW_MACRO_end_file
|
||||
|
||||
# CHECK: 0x[[MACRO1OFF]]:
|
||||
# CHECK-NEXT: macro header: version = 0x0005, flags = 0x01, format = DWARF64
|
||||
# CHECK-NEXT: DW_MACRO_define_strp - lineno: 1 macro: FOO 1
|
||||
# CHECK-NEXT: DW_MACRO_undef_strp - lineno: 9 macro: BAR
|
||||
# CHECK-NEXT: DW_MACRO_undef_strp - lineno: 15 macro: BAZ
|
||||
|
||||
.section .debug_macro, "", @progbits
|
||||
.LMacro0:
|
||||
.short 5 # Version
|
||||
.byte 3 # Flags: offset_size_flag | debug_line_offset_flag
|
||||
.quad 0 # Debug Line Offset
|
||||
.byte 3 # DW_MACRO_start_file
|
||||
.uleb128 0 # Line
|
||||
.uleb128 0 # File
|
||||
.byte 7 # DW_MACRO_import
|
||||
.quad .LMacro1
|
||||
.byte 4 # DW_MACRO_end_file
|
||||
.byte 0 # End macro unit
|
||||
.LMacro1:
|
||||
.short 5 # Version
|
||||
.byte 1 # Flags: offset_size_flag
|
||||
.byte 5 # DW_MACRO_define_strp
|
||||
.uleb128 1 # Line
|
||||
.quad .LStr0 # "FOO 1"
|
||||
.byte 6 # DW_MACRO_undef_strp
|
||||
.uleb128 9 # Line
|
||||
.quad .LStr1 # "BAR"
|
||||
.byte 6 # DW_MACRO_undef_strp
|
||||
.uleb128 15 # Line
|
||||
.quad .LStr2 # "BAZ"
|
||||
.byte 0 # End macro unit
|
||||
|
||||
.section .debug_str, "MS", @progbits, 1
|
||||
.LStr0:
|
||||
.asciz "FOO 1"
|
||||
.LStr1:
|
||||
.asciz "BAR"
|
||||
.LStr2:
|
||||
.asciz "BAZ"
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
; CHECK-LABEL: .debug_macro.dwo contents:
|
||||
; CHECK-NEXT: 0x00000000:
|
||||
; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02
|
||||
; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32
|
||||
; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
; CHECK-NEXT: DW_MACRO_start_file - lineno: 1 filenum: 1
|
||||
; CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: FOO 5
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# CHECK:.debug_macro contents:
|
||||
# CHECK-NEXT:0x00000000:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_define_strp - lineno: 1 macro: DWARF_VERSION 5
|
||||
# CHECK-NEXT:DW_MACRO_end_file
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
# CHECK:.debug_macro contents:
|
||||
# CHECK-NEXT:0x00000000:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: DWARF_VERSION 5
|
||||
# CHECK-NEXT: DW_MACRO_define_strx - lineno: 2 macro: COMPILE_UNIT 1
|
||||
@@ -15,7 +15,7 @@
|
||||
# CHECK-NEXT:DW_MACRO_end_file
|
||||
|
||||
# CHECK:0x00000015:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 1 filenum: 3
|
||||
# CHECK-NEXT: DW_MACRO_define_strx - lineno: 2 macro: COMPILE_UNIT 2
|
||||
# CHECK-NEXT: DW_MACRO_undef_strx - lineno: 3 macro: COMPILE_UNIT
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# CHECK:.debug_macro.dwo contents:
|
||||
# CHECK-NEXT:0x00000000:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_define_strp - lineno: 1 macro: DWARF_VERSION 5
|
||||
# CHECK-NEXT: DW_MACRO_undef_strp - lineno: 4 macro: DWARF_VERSION
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# CHECK:.debug_macro.dwo contents:
|
||||
# CHECK-NEXT:0x00000000:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: DWARF_VERSION 5
|
||||
# CHECK-NEXT: DW_MACRO_undef_strx - lineno: 4 macro: DWARF_VERSION
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
; CHECK-LABEL: .debug_macro contents:
|
||||
; CHECK-NEXT: 0x00000000:
|
||||
; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
; CHECK-NEXT: DW_MACRO_start_file - lineno: 1 filenum: 1
|
||||
; CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: FOO 5
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# CHECK:.debug_macro contents:
|
||||
# CHECK-NEXT:0x00000000:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
|
||||
# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
|
||||
# CHECK-NEXT: DW_MACRO_start_file - lineno: 1 filenum: 6
|
||||
# CHECK-NEXT: DW_MACRO_define_strp - lineno: 1 macro: FOO 5
|
||||
@@ -16,7 +16,7 @@
|
||||
# CHECK-NEXT:DW_MACRO_end_file
|
||||
|
||||
# CHECK:0x[[OFFSET]]:
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x00
|
||||
# CHECK-NEXT:macro header: version = 0x0005, flags = 0x00, format = DWARF32
|
||||
# CHECK-NEXT:DW_MACRO_define_strp - lineno: 0 macro: WORLD 2
|
||||
|
||||
.section .debug_macro,"",@progbits
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
## This test checks llvm-dwarfdump emits correct error diagnostics for the
|
||||
## unsupported case where DWARF64 flag is present in the debug_macro section header.
|
||||
|
||||
# RUN: llvm-mc -triple x86_64-unknown-linux -filetype=obj %s -o -| \
|
||||
# RUN: not llvm-dwarfdump -debug-macro - /dev/null 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK:error: DWARF64 is not supported
|
||||
|
||||
.section .debug_macro,"",@progbits
|
||||
.Lcu_macro_begin0:
|
||||
.short 5 # Macro information version
|
||||
.byte 3 # Flags: 64 bit, debug_line_offset present
|
||||
.quad 0 # debug_line_offset
|
||||
Reference in New Issue
Block a user