[PATCH] D44388: [ELF] Rework debug line parsing to use llvm::Error (LLD-side)

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 08:27:23 PDT 2018


jhenderson created this revision.
jhenderson added reviewers: ruiu, espindola.
Herald added subscribers: arichardson, emaste.

This is a companion change to https://reviews.llvm.org/D44382. That change changes the debug line parser interface to report LLVM errors, and to improve the error/warning reporting mechanism to not use fprintf(stderr, ...).

As noted in the description on https://reviews.llvm.org/D44382, these warnings were not using the errs() stream, and so were not always being flushed properly by LLD on shutdown. To test this, I have extended the bad-debug undefined symbol message case to show that a corresponding warning is printed, if the debug line cannot be parsed.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44388

Files:
  ELF/InputFiles.cpp
  test/ELF/Inputs/undef-bad-debug.s
  test/ELF/undef.s


Index: test/ELF/undef.s
===================================================================
--- test/ELF/undef.s
+++ test/ELF/undef.s
@@ -34,6 +34,7 @@
 # CHECK: >>> referenced by undef-debug.s:11 (dir{{/|\\}}undef-debug.s:11)
 # CHECK: >>>               {{.*}}.o:(.text.2+0x0)
 
+# CHECK: warning: parsing line table prologue at 0x00000000 should have ended at 0x00000038 but it ended at 0x00000037
 # CHECK: error: undefined symbol: zed6
 # CHECK: >>> referenced by {{.*}}tmp4.o:(.text+0x0)
 
Index: test/ELF/Inputs/undef-bad-debug.s
===================================================================
--- test/ELF/Inputs/undef-bad-debug.s
+++ test/ELF/Inputs/undef-bad-debug.s
@@ -1,7 +1,37 @@
 .section .text,"ax"
 sym:
     .quad zed6
-    
+
+.section .debug_line,"", at progbits
+    .long .Lunit_end - .Lunit_start # unit length
+.Lunit_start:
+    .short 4                        # version
+    .long .Lprologue_end - .Lprologue_start # prologue length
+.Lprologue_start:
+    .byte 1                         # minimum instruction length
+    .byte 1                         # maximum operatiosn per instruction
+    .byte 1                         # default is_stmt
+    .byte -5                        # line base
+    .byte 14                        # line range
+    .byte 13                        # opcode base
+    .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # standard opcode lengths
+    .asciz "dir"                    # include directories
+    .byte 0
+    .asciz "undef-bad-debug.s"      # file names
+    .byte 1, 0, 0
+    .byte 0
+    .byte 0                         # extraneous byte
+.Lprologue_end:
+    .byte 0, 9, 2                   # DW_LNE_set_address
+    .quad sym
+    .byte 3                         # DW_LNS_advance_line
+    .byte 10
+    .byte 1                         # DW_LNS_copy
+    .byte 2                         # DW_LNS_advance_pc
+    .byte 8
+    .byte 0, 1, 1                   # DW_LNE_end_sequence
+.Lunit_end:
+
 .section .debug_info,"", at progbits
     .long   .Lcu_end - .Lcu_start   # Length of Unit
 .Lcu_start:
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -124,8 +124,11 @@
   // The second parameter is offset in .debug_line section
   // for compilation unit (CU) of interest. We have only one
   // CU (object file), so offset is always 0.
-  const DWARFDebugLine::LineTable *LT =
-      DwarfLine->getOrParseLineTable(LineData, 0, Dwarf, nullptr);
+  auto LTOrErr = DwarfLine->getOrParseLineTable(LineData, 0, Dwarf, nullptr);
+  const DWARFDebugLine::LineTable *LT = LTOrErr.Table;
+  handleAllErrors(std::move(LTOrErr.Err),
+                  [&](DebugLineError &Err) { warn(Err.message()); },
+                  [&](ErrorInfoBase &Err) { error(Err.message()); });
   if (!LT)
     return;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44388.138015.patch
Type: text/x-patch
Size: 2849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180312/ec8fd224/attachment.bin>


More information about the llvm-commits mailing list