[llvm] r348965 - DebugInfo/DWARF: Pretty print subroutine types

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 11:53:03 PST 2018


Author: dblaikie
Date: Wed Dec 12 11:53:03 2018
New Revision: 348965

URL: http://llvm.org/viewvc/llvm-project?rev=348965&view=rev
Log:
DebugInfo/DWARF: Pretty print subroutine types

Doesn't handle varargs and other fun things, but it's a start. (also
doesn't print these strictly as valid C++ when it's a pointer to
function, it'll print as "void(int)*" instead of "void (*)(int)")

Modified:
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/trunk/test/tools/llvm-dwarfdump/X86/prettyprint_types.s

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=348965&r1=348964&r2=348965&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Wed Dec 12 11:53:03 2018
@@ -173,17 +173,34 @@ static void dumpTypeName(raw_ostream &OS
   case DW_TAG_ptr_to_member_type:
   case DW_TAG_reference_type:
   case DW_TAG_rvalue_reference_type:
+  case DW_TAG_subroutine_type:
     break;
   default:
     dumpTypeTagName(OS, T);
   }
 
   // Follow the DW_AT_type if possible.
-  dumpTypeName(OS, D.getAttributeValueAsReferencedDie(DW_AT_type));
+  DWARFDie TypeDie = D.getAttributeValueAsReferencedDie(DW_AT_type);
+  dumpTypeName(OS, TypeDie);
 
   switch (T) {
+  case DW_TAG_subroutine_type: {
+    if (!TypeDie)
+      OS << "void";
+    OS << '(';
+    bool First = true;
+    for (const DWARFDie &C : D.children()) {
+      if (C.getTag() == DW_TAG_formal_parameter) {
+        if (!First)
+          OS << ", ";
+        First = false;
+        dumpTypeName(OS, C.getAttributeValueAsReferencedDie(DW_AT_type));
+      }
+    }
+    OS << ')';
+    break;
+  }
   case DW_TAG_array_type: {
-
     Optional<uint64_t> Bound;
     for (const DWARFDie &C : D.children())
       if (C.getTag() == DW_TAG_subrange_type) {

Modified: llvm/trunk/test/tools/llvm-dwarfdump/X86/prettyprint_types.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/prettyprint_types.s?rev=348965&r1=348964&r2=348965&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/prettyprint_types.s (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/prettyprint_types.s Wed Dec 12 11:53:03 2018
@@ -22,6 +22,10 @@
 # Testing lower_bound, upper_bound, lower and upper, lower and count, and count separately.
 # CHECK:   DW_AT_type{{.*}}"int[1-][2][1-2][1-3][2]"
 
+# subroutine types
+# CHECK:   DW_AT_type{{.*}}"int()"
+# CHECK:   DW_AT_type{{.*}}"void(int)"
+# CHECK:   DW_AT_type{{.*}}"void(int, int)"
 	.section	.debug_str,"MS", at progbits,1
 .Lint_name:
 	.asciz	"int"
@@ -132,6 +136,25 @@
 	.byte	14                      # DW_FORM_strp
 	.byte	0                       # EOM(1)
 	.byte	0                       # EOM(2)
+	.byte	15                      # Abbreviation Code
+	.byte	0x15                    # DW_TAG_subroutine_type
+	.byte	0                       # DW_CHILDREN_no
+	.byte	73                      # DW_AT_type
+	.byte	19                      # DW_FORM_ref4
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	16                      # Abbreviation Code
+	.byte	0x15                    # DW_TAG_subroutine_type
+	.byte	1                       # DW_CHILDREN_yes
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	17                      # Abbreviation Code
+	.byte	0x5                     # DW_TAG_formal_parameter
+	.byte	0                       # DW_CHILDREN_no
+	.byte	73                      # DW_AT_type
+	.byte	19                      # DW_FORM_ref4
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
 	.byte	0                       # EOM(3)
 	.section	.debug_info,"", at progbits
 .Lcu_begin:
@@ -177,6 +200,22 @@
 	.byte	13                      #   DW_AT_subrange_type
 	.byte   2                       #     DW_AT_count
 	.byte	0                       # End Of Children Mark
+.Lsub_int_empty_type:
+	.byte	15                      # DW_TAG_subroutine_type
+	.long	.Lint_type - .Lcu_begin #   DW_AT_type
+.Lsub_void_int_type:
+	.byte	16                      # DW_TAG_subroutine_type
+	.byte	17                       #   DW_TAG_formal_parameter
+	.long	.Lint_type - .Lcu_begin #     DW_AT_type
+	.byte	0                       # End Of Children Mark
+.Lsub_void_int_int_type:
+	.byte	16                      # DW_TAG_subroutine_type
+	.byte	17                       #   DW_TAG_formal_parameter
+	.long	.Lint_type - .Lcu_begin #     DW_AT_type
+	.byte	17                       #   DW_TAG_formal_parameter
+	.long	.Lint_type - .Lcu_begin #     DW_AT_type
+	.byte	0                       # End Of Children Mark
+
 	.byte	3                       # DW_TAG_variable
 	.long	.Lint_type - .Lcu_begin #   DW_AT_type
 	.byte	3                       # DW_TAG_variable
@@ -189,5 +228,11 @@
 	.long	.Lptr_to_member_type - .Lcu_begin #   DW_AT_type
 	.byte	3                       # DW_TAG_variable
 	.long	.Larray_type - .Lcu_begin #   DW_AT_type
+	.byte	3                       # DW_TAG_variable
+	.long	.Lsub_int_empty_type - .Lcu_begin #   DW_AT_type
+	.byte	3                       # DW_TAG_variable
+	.long	.Lsub_void_int_type - .Lcu_begin #   DW_AT_type
+	.byte	3                       # DW_TAG_variable
+	.long	.Lsub_void_int_int_type - .Lcu_begin #   DW_AT_type
 	.byte	0                       # End Of Children Mark
 .Lunit_end:




More information about the llvm-commits mailing list