[llvm] r329381 - [debug_loc] Fix typo in DWARFExpression constructor

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 6 01:49:57 PDT 2018


Author: labath
Date: Fri Apr  6 01:49:57 2018
New Revision: 329381

URL: http://llvm.org/viewvc/llvm-project?rev=329381&view=rev
Log:
[debug_loc] Fix typo in DWARFExpression constructor

Summary:
The positions of the DwarfVersion and AddressSize arguments were
reversed, which caused parsing for dwarf opcodes which contained
address-size-dependent operands (such as DW_OP_addr). Amusingly enough,
none of the address-size asserts fired, as dwarf version was always 4,
which is a valid address size.

I ran into this when constructing weird inputs for the DWARF verifier. I
I add a test case as hand-written dwarf -- I am not sure how to trigger
this differently, as having a DW_OP_addr inside a location list is a
fairly non-standard thing to do.

Fixing this error exposed a bug in the debug_loc.dwo parser, which was
always being constructed with an address size of 0. I fix that as well
by following the pattern in the non-dwo parser of picking up the address
size from the first compile unit (which is technically not correct, but
probably good enough in practice).

Reviewers: JDevlieghere, aprantl, dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45324

Added:
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_loc-OP_addr.s
Modified:
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=329381&r1=329380&r2=329381&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Fri Apr  6 01:49:57 2018
@@ -672,7 +672,7 @@ const DWARFDebugLoc *DWARFContext::getDe
     return Loc.get();
 
   Loc.reset(new DWARFDebugLoc);
-  // assume all compile units have the same address byte size
+  // Assume all compile units have the same address byte size.
   if (getNumCompileUnits()) {
     DWARFDataExtractor LocData(*DObj, DObj->getLocSection(), isLittleEndian(),
                                getCompileUnitAtIndex(0)->getAddressByteSize());
@@ -685,9 +685,13 @@ const DWARFDebugLocDWO *DWARFContext::ge
   if (LocDWO)
     return LocDWO.get();
 
-  DataExtractor LocData(DObj->getLocDWOSection().Data, isLittleEndian(), 0);
   LocDWO.reset(new DWARFDebugLocDWO());
-  LocDWO->parse(LocData);
+  // Assume all compile units have the same address byte size.
+  if (getNumCompileUnits()) {
+    DataExtractor LocData(DObj->getLocDWOSection().Data, isLittleEndian(),
+                          getCompileUnitAtIndex(0)->getAddressByteSize());
+    LocDWO->parse(LocData);
+  }
   return LocDWO.get();
 }
 

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp?rev=329381&r1=329380&r2=329381&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp Fri Apr  6 01:49:57 2018
@@ -33,7 +33,7 @@ static void dumpExpression(raw_ostream &
                            const MCRegisterInfo *MRI) {
   DWARFDataExtractor Extractor(StringRef(Data.data(), Data.size()),
                                IsLittleEndian, AddressSize);
-  DWARFExpression(Extractor, AddressSize, dwarf::DWARF_VERSION).print(OS, MRI);
+  DWARFExpression(Extractor, dwarf::DWARF_VERSION, AddressSize).print(OS, MRI);
 }
 
 void DWARFDebugLoc::LocationList::dump(raw_ostream &OS, bool IsLittleEndian,

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_loc-OP_addr.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_loc-OP_addr.s?rev=329381&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_loc-OP_addr.s (added)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_loc-OP_addr.s Fri Apr  6 01:49:57 2018
@@ -0,0 +1,58 @@
+# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj | llvm-dwarfdump - | FileCheck %s
+#
+# CHECK: DW_TAG_variable
+# CHECK-NEXT: DW_AT_name ("a")
+# CHECK-NEXT: DW_AT_location
+# CHECK-NEXT: [0x0000000000000000,  0x0000000000000001): DW_OP_addr 0xdeadbeefbaadf00d
+
+	.section	.debug_str,"MS", at progbits,1
+.Linfo_producer:
+	.asciz	"hand-written DWARF"
+.Lname_a:
+	.asciz	"a"
+
+	.section	.debug_loc,"", at progbits
+.Ldebug_loc0:
+	.quad	0
+	.quad	1
+	.short	.Lloc0_end-.Lloc0_start # Loc expr size
+.Lloc0_start:
+	.byte	3                       # DW_OP_addr
+        .quad 0xdeadbeefbaadf00d
+.Lloc0_end:
+	.quad	0
+	.quad	0
+
+	.section	.debug_abbrev,"", at progbits
+	.byte	1                       # Abbreviation Code
+	.byte	17                      # DW_TAG_compile_unit
+	.byte	1                       # DW_CHILDREN_yes
+	.byte	37                      # DW_AT_producer
+	.byte	14                      # DW_FORM_strp
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	5                       # Abbreviation Code
+	.byte	52                      # DW_TAG_variable
+	.byte	0                       # DW_CHILDREN_no
+	.byte	3                       # DW_AT_name
+	.byte	14                      # DW_FORM_strp
+	.byte	2                       # DW_AT_location
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	0                       # EOM(3)
+
+	.section	.debug_info,"", at progbits
+.Lcu_begin0:
+	.long	.Lcu_end0-.Lcu_start0   # Length of Unit
+.Lcu_start0:
+	.short	4                       # DWARF version number
+	.long	.debug_abbrev           # Offset Into Abbrev. Section
+	.byte	8                       # Address Size (in bytes)
+	.byte	1                       # Abbrev [1] DW_TAG_compile_unit
+	.long	.Linfo_producer         # DW_AT_producer
+	.byte	5                       # Abbrev [5] DW_TAG_variable
+	.long	.Lname_a                # DW_AT_name
+	.long	.Ldebug_loc0            # DW_AT_location
+	.byte	0                       # End Of Children Mark
+.Lcu_end0:




More information about the llvm-commits mailing list