[llvm] 02b6a3c - [DebugInfo] Handle generic type DW_OP_convert ops in dsymutil

David Stenberg via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 04:18:14 PDT 2020


Author: David Stenberg
Date: 2020-03-16T12:16:37+01:00
New Revision: 02b6a3c3499fbc896d07eb643b8f1bcd6cbcf55d

URL: https://github.com/llvm/llvm-project/commit/02b6a3c3499fbc896d07eb643b8f1bcd6cbcf55d
DIFF: https://github.com/llvm/llvm-project/commit/02b6a3c3499fbc896d07eb643b8f1bcd6cbcf55d.diff

LOG: [DebugInfo] Handle generic type DW_OP_convert ops in dsymutil

Summary:
This is a preparatory change for allowing LLVM to emit DW_OP_convert
operations converting to the generic type.

If DW_OP_convert's operand is 0, it converts the top of the stack to the
generic type, as specified by DWARFv5 section 2.5.1.6:

"[...] takes one operand, which is an unsigned LEB128 integer that
 represents the offset of a debugging information entry in the current
 compilation unit, or value 0 which represents the generic type."

This adds support for such operations to dsymutil.

Reviewers: aprantl, markus, friss, JDevlieghere

Reviewed By: aprantl, JDevlieghere

Subscribers: hiraditya, llvm-commits

Tags: #debug-info, #llvm

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

Added: 
    

Modified: 
    llvm/lib/DWARFLinker/DWARFLinker.cpp
    llvm/test/tools/dsymutil/Inputs/op-convert.ll
    llvm/test/tools/dsymutil/Inputs/op-convert.macho.x86_64
    llvm/test/tools/dsymutil/X86/op-convert.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 66da6265ca53..8464c04f801e 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -923,15 +923,20 @@ void DWARFLinker::DIECloner::cloneExpression(
         OutputBuffer.push_back(Op.getRawOperand(0));
         RefOffset = Op.getRawOperand(1);
       }
-      auto RefDie = Unit.getOrigUnit().getDIEForOffset(RefOffset);
-      uint32_t RefIdx = Unit.getOrigUnit().getDIEIndex(RefDie);
-      CompileUnit::DIEInfo &Info = Unit.getInfo(RefIdx);
       uint32_t Offset = 0;
-      if (DIE *Clone = Info.Clone)
-        Offset = Clone->getOffset();
-      else
-        Linker.reportWarning("base type ref doesn't point to DW_TAG_base_type.",
-                             File);
+      // Look up the base type. For DW_OP_convert, the operand may be 0 to
+      // instead indicate the generic type. The same holds for
+      // DW_OP_reinterpret, which is currently not supported.
+      if (RefOffset > 0 || Op.getCode() != dwarf::DW_OP_convert) {
+        auto RefDie = Unit.getOrigUnit().getDIEForOffset(RefOffset);
+        uint32_t RefIdx = Unit.getOrigUnit().getDIEIndex(RefDie);
+        CompileUnit::DIEInfo &Info = Unit.getInfo(RefIdx);
+        if (DIE *Clone = Info.Clone)
+          Offset = Clone->getOffset();
+        else
+          Linker.reportWarning(
+              "base type ref doesn't point to DW_TAG_base_type.", File);
+      }
       uint8_t ULEB[16];
       unsigned RealSize = encodeULEB128(Offset, ULEB, ULEBsize);
       if (RealSize > ULEBsize) {

diff  --git a/llvm/test/tools/dsymutil/Inputs/op-convert.ll b/llvm/test/tools/dsymutil/Inputs/op-convert.ll
index 10dd3febfeb1..a53599ff95e5 100644
--- a/llvm/test/tools/dsymutil/Inputs/op-convert.ll
+++ b/llvm/test/tools/dsymutil/Inputs/op-convert.ll
@@ -9,6 +9,7 @@ entry:
   call void @llvm.dbg.value(metadata i8 42, metadata !17, metadata !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value)), !dbg !12
   call void @llvm.dbg.value(metadata i8 %x, metadata !11, metadata !DIExpression()), !dbg !12
   call void @llvm.dbg.value(metadata i8 %x, metadata !13, metadata !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value)), !dbg !15
+  call void @llvm.dbg.value(metadata i8 51, metadata !18, metadata !DIExpression(DW_OP_LLVM_convert_generic, DW_OP_stack_value)), !dbg !15
   ret i8 %x, !dbg !16
 }
 
@@ -43,3 +44,4 @@ attributes #1 = { nounwind readnone speculatable }
 !15 = !DILocation(line: 3, column: 14, scope: !7)
 !16 = !DILocation(line: 4, column: 3, scope: !7)
 !17 = !DILocalVariable(name: "c", scope: !7, file: !1, line: 3, type: !14)
+!18 = !DILocalVariable(name: "d", scope: !7, file: !1, line: 3, type: !14)

diff  --git a/llvm/test/tools/dsymutil/Inputs/op-convert.macho.x86_64 b/llvm/test/tools/dsymutil/Inputs/op-convert.macho.x86_64
index c4d85a312359..e0866fb1e001 100644
Binary files a/llvm/test/tools/dsymutil/Inputs/op-convert.macho.x86_64 and b/llvm/test/tools/dsymutil/Inputs/op-convert.macho.x86_64 
diff er

diff  --git a/llvm/test/tools/dsymutil/X86/op-convert.test b/llvm/test/tools/dsymutil/X86/op-convert.test
index 638b2249619c..a03869865599 100644
--- a/llvm/test/tools/dsymutil/X86/op-convert.test
+++ b/llvm/test/tools/dsymutil/X86/op-convert.test
@@ -26,6 +26,10 @@ CHECK-NEXT:     [0x0000000000001000,  0x0000000000001002): DW_OP_breg5 RDI+0, DW
 CHECK-NEXT:     [0x0000000000001002,  0x0000000000001003): DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_convert (0x0000002a) "DW_ATE_signed_8", DW_OP_convert (0x00000031) "DW_ATE_signed_32", DW_OP_stack_value)
 CHECK-NEXT:     DW_AT_name	("y")
 
+CHECK:     DW_TAG_variable
+CHECK-NEXT:     DW_AT_location	(DW_OP_constu 0x33, DW_OP_convert 0x0, DW_OP_stack_value)
+CHECK-NEXT:     DW_AT_name	("d")
+
 CHECK:     DW_TAG_variable
 CHECK-NEXT:     DW_AT_location	(DW_OP_constu 0x2a, DW_OP_convert (0x00000031) "DW_ATE_signed_32", DW_OP_stack_value)
 CHECK-NEXT:     DW_AT_name	("c")


        


More information about the llvm-commits mailing list