[llvm] r201427 - Support DWARF discriminators in object streamer.

Diego Novillo dnovillo at google.com
Fri Feb 14 11:27:54 PST 2014


Author: dnovillo
Date: Fri Feb 14 13:27:53 2014
New Revision: 201427

URL: http://llvm.org/viewvc/llvm-project?rev=201427&view=rev
Log:
Support DWARF discriminators in object streamer.

Summary:
This adds support for emitting DWARF path discriminator values in
the object streamer. It also changes the DWARF dumper to show
discriminator values in the line table output.

Reviewers: echristo

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D2794

Added:
    llvm/trunk/test/MC/ELF/discriminator.s
Modified:
    llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp
    llvm/trunk/lib/DebugInfo/DWARFDebugLine.h
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/test/DebugInfo/X86/ending-run.ll
    llvm/trunk/test/DebugInfo/X86/line-info.ll
    llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s
    llvm/trunk/test/MC/MachO/gen-dwarf.s

Modified: llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp Fri Feb 14 13:27:53 2014
@@ -62,6 +62,7 @@ void DWARFDebugLine::Row::reset(bool def
   Column = 0;
   File = 1;
   Isa = 0;
+  Discriminator = 0;
   IsStmt = default_is_stmt;
   BasicBlock = false;
   EndSequence = false;
@@ -71,7 +72,7 @@ void DWARFDebugLine::Row::reset(bool def
 
 void DWARFDebugLine::Row::dump(raw_ostream &OS) const {
   OS << format("0x%16.16" PRIx64 " %6u %6u", Address, Line, Column)
-     << format(" %6u %3u ", File, Isa)
+     << format(" %6u %3u %13u ", File, Isa, Discriminator)
      << (IsStmt ? " is_stmt" : "")
      << (BasicBlock ? " basic_block" : "")
      << (PrologueEnd ? " prologue_end" : "")
@@ -85,8 +86,9 @@ void DWARFDebugLine::LineTable::dump(raw
   OS << '\n';
 
   if (!Rows.empty()) {
-    OS << "Address            Line   Column File   ISA Flags\n"
-       << "------------------ ------ ------ ------ --- -------------\n";
+    OS << "Address            Line   Column File   ISA Discriminator Flags\n"
+       << "------------------ ------ ------ ------ --- ------------- "
+          "-------------\n";
     for (std::vector<Row>::const_iterator pos = Rows.begin(),
          end = Rows.end(); pos != end; ++pos)
       pos->dump(OS);
@@ -311,6 +313,10 @@ DWARFDebugLine::parseStatementTable(Data
         }
         break;
 
+      case DW_LNE_set_discriminator:
+        state.Discriminator = debug_line_data.getULEB128(offset_ptr);
+        break;
+
       default:
         // Length doesn't include the zero opcode byte or the length itself, but
         // it does include the sub_opcode, so we have to adjust for that below

Modified: llvm/trunk/lib/DebugInfo/DWARFDebugLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugLine.h?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugLine.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugLine.h Fri Feb 14 13:27:53 2014
@@ -112,6 +112,9 @@ public:
     // An unsigned integer whose value encodes the applicable instruction set
     // architecture for the current instruction.
     uint8_t Isa;
+    // An unsigned integer representing the DWARF path discriminator value
+    // for this location.
+    uint32_t Discriminator;
     // A boolean indicating that the current instruction is the beginning of a
     // statement.
     uint8_t IsStmt:1,

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Fri Feb 14 13:27:53 2014
@@ -137,6 +137,7 @@ static inline void EmitDwarfLineTable(MC
   unsigned Column = 0;
   unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
   unsigned Isa = 0;
+  unsigned Discriminator = 0;
   MCSymbol *LastLabel = NULL;
 
   // Loop through each MCLineEntry and encode the dwarf line number table.
@@ -154,6 +155,15 @@ static inline void EmitDwarfLineTable(MC
       MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1);
       MCOS->EmitULEB128IntValue(Column);
     }
+    if (Discriminator != it->getDiscriminator()) {
+      Discriminator = it->getDiscriminator();
+      unsigned Size =
+          MCOS->getContext().getAsmInfo()->getULEB128Size(Discriminator);
+      MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);
+      MCOS->EmitULEB128IntValue(Size + 1);
+      MCOS->EmitIntValue(dwarf::DW_LNE_set_discriminator, 1);
+      MCOS->EmitULEB128IntValue(Discriminator);
+    }
     if (Isa != it->getIsa()) {
       Isa = it->getIsa();
       MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1);

Modified: llvm/trunk/test/DebugInfo/X86/ending-run.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/ending-run.ll?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/ending-run.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/ending-run.ll Fri Feb 14 13:27:53 2014
@@ -4,9 +4,9 @@
 ; Check that the line table starts at 7, not 4, but that the first
 ; statement isn't until line 8.
 
-; CHECK-NOT: 0x0000000000000000      7      0      1   0  is_stmt
+; CHECK-NOT: 0x0000000000000000      7      0      1   0  0  is_stmt
 ; CHECK: 0x0000000000000000      7      0      1   0
-; CHECK: 0x0000000000000004      8     18      1   0  is_stmt prologue_end
+; CHECK: 0x0000000000000004      8     18      1   0  0  is_stmt prologue_end
 
 define i32 @callee(i32 %x) nounwind uwtable ssp {
 entry:

Modified: llvm/trunk/test/DebugInfo/X86/line-info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/line-info.ll?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/line-info.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/line-info.ll Fri Feb 14 13:27:53 2014
@@ -2,7 +2,7 @@
 ; RUN: llvm-dwarfdump %t | FileCheck %s
 
 ; CHECK: [[FILEID:[0-9]+]]]{{.*}}list0.h
-; CHECK: [[FILEID]]      0      1   0  is_stmt{{$}}
+; CHECK: [[FILEID]]      0      1   0  0 is_stmt{{$}}
 
 ; IR generated from clang -g -emit-llvm with the following source:
 ; list0.h:

Added: llvm/trunk/test/MC/ELF/discriminator.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/discriminator.s?rev=201427&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/discriminator.s (added)
+++ llvm/trunk/test/MC/ELF/discriminator.s Fri Feb 14 13:27:53 2014
@@ -0,0 +1,61 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s -filetype=obj -o %t.o
+# RUN: llvm-readobj -r %t.o | FileCheck %s
+# RUN: llvm-dwarfdump -debug-dump=line %t.o | FileCheck %s -check-prefix=DWARF-DUMP
+
+    .file 1 "foo.c"
+    .text
+    .globl foo
+    .type foo, @function
+    .align 4
+foo:
+    .loc 1 2 discriminator 1
+    ret
+    .size foo, .-foo
+
+        .section        .debug_info,"", at progbits
+.L.debug_info_begin0:
+        .long   34                      # Length of Unit
+        .short  4                       # DWARF version number
+        .long   .L.debug_abbrev_begin   # Offset Into Abbrev. Section
+        .byte   8                       # Address Size (in bytes)
+        .byte   1                       # Abbrev [1] 0xb:0x1b DW_TAG_compile_unit
+        .long   .Linfo_string0          # DW_AT_producer
+        .short  12                      # DW_AT_language
+        .long   .Linfo_string1          # DW_AT_name
+        .quad   0                       # DW_AT_low_pc
+        .long   0                       # DW_AT_stmt_list
+        .long   .Linfo_string2          # DW_AT_comp_dir
+                                        # DW_AT_APPLE_optimized
+        .section        .debug_abbrev,"", at progbits
+.L.debug_abbrev_begin:
+        .byte   1                       # Abbreviation Code
+        .byte   17                      # DW_TAG_compile_unit
+        .byte   0                       # DW_CHILDREN_no
+        .byte   37                      # DW_AT_producer
+        .byte   14                      # DW_FORM_strp
+        .byte   19                      # DW_AT_language
+        .byte   5                       # DW_FORM_data2
+        .byte   3                       # DW_AT_name
+        .byte   14                      # DW_FORM_strp
+        .byte   17                      # DW_AT_low_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   16                      # DW_AT_stmt_list
+        .byte   23                      # DW_FORM_sec_offset
+        .byte   27                      # DW_AT_comp_dir
+        .byte   14                      # DW_FORM_strp
+        .ascii  "\341\177"              # DW_AT_APPLE_optimized
+        .byte   25                      # DW_FORM_flag_present
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   0                       # EOM(3)
+.L.debug_abbrev_end:
+
+
+# CHECK:      Relocations [
+# CHECK:        Section ({{[^ ]+}}) .rel.debug_line {
+# CHECK-NEXT:     0x2D R_386_32 .text 0x0
+# CHECK-NEXT:   }
+
+# DWARF-DUMP: Address            Line   Column File   ISA Discriminator Flags
+# DWARF-DUMP: ------------------ ------ ------ ------ --- ------------- -------------
+# DWARF-DUMP: 0x0001021300000000     1      0      1   0             1  is_stmt

Modified: llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s (original)
+++ llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s Fri Feb 14 13:27:53 2014
@@ -17,6 +17,6 @@ L1:	leave
 // CHECK: file_names[  2]    0 0x00000000 0x00000000 t.s
 
 // We check that the source line number 100 is picked up before the "movl"
-// CHECK: Address            Line   Column File   ISA Flags
-// CHECK: ------------------ ------ ------ ------ --- -------------
-// CHECK: 0x0000000000000000    102      0      2   0  is_stmt
+// CHECK: Address            Line   Column File   ISA Discriminator Flags
+// CHECK: ------------------ ------ ------ ------ --- ------------- -------------
+// CHECK: 0x0000000000000000    102      0      2   0             0  is_stmt

Modified: llvm/trunk/test/MC/MachO/gen-dwarf.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/gen-dwarf.s?rev=201427&r1=201426&r2=201427&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/gen-dwarf.s (original)
+++ llvm/trunk/test/MC/MachO/gen-dwarf.s Fri Feb 14 13:27:53 2014
@@ -113,10 +113,10 @@ _x:	.long 1
 // CHECK:                 ---- ---------- ---------- ---------------------------
 // CHECK: file_names[  1]    1 0x00000000 0x00000000 gen-dwarf.s
 
-// CHECK: Address            Line   Column File   ISA Flags
-// CHECK: ------------------ ------ ------ ------ --- -------------
-// CHECK: 0x0000000000000000      6      0      1   0  is_stmt
-// CHECK: 0x0000000000000005      7      0      1   0  is_stmt
-// CHECK: 0x0000000000000006      8      0      1   0  is_stmt
-// CHECK: 0x0000000000000007     11      0      1   0  is_stmt
-// CHECK: 0x0000000000000008     11      0      1   0  is_stmt end_sequence
+// CHECK: Address            Line   Column File   ISA Discriminator Flags
+// CHECK: ------------------ ------ ------ ------ --- ------------- -------------
+// CHECK: 0x0000000000000000      6      0      1   0             0  is_stmt
+// CHECK: 0x0000000000000005      7      0      1   0             0  is_stmt
+// CHECK: 0x0000000000000006      8      0      1   0             0  is_stmt
+// CHECK: 0x0000000000000007     11      0      1   0             0  is_stmt
+// CHECK: 0x0000000000000008     11      0      1   0             0  is_stmt end_sequence





More information about the llvm-commits mailing list