<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Excellent point, we’d need to check that too.<div class=""><br class=""></div><div class="">How about “error: CU has no DIE” and “error: Root DIE is not a unit DIE”?</div><div class=""><br class=""></div><div class="">— Jonas<br class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 28, 2017, at 5:47 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I think this error might be more general: CU contains no DIEs. This check doesn't verify that the root DIE Is actually a unit DIE (type_unit, compile_unit, or partial_unit).<br class=""><br class="">Dunno about the best phrasing "unit is empty, does not contain a root unit DIE" or somesuch. That doesn't seem the best phrasing - open to ideas.<br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Sep 28, 2017 at 8:16 AM Jonas Devlieghere via Phabricator <<a href="mailto:reviews@reviews.llvm.org" class="">reviews@reviews.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">JDevlieghere created this revision.<br class="">
<br class="">
This patch adds a check to the DWARF verifier to detect CUs without a<br class="">
unit DIE.<br class="">
<br class="">
<br class="">
Repository:<br class="">
  rL LLVM<br class="">
<br class="">
<a href="https://reviews.llvm.org/D38363" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/D38363</a><br class="">
<br class="">
Files:<br class="">
  lib/DebugInfo/DWARF/DWARFVerifier.cpp<br class="">
  test/tools/llvm-dwarfdump/X86/empty-CU.s<br class="">
<br class="">
<br class="">
Index: test/tools/llvm-dwarfdump/X86/empty-CU.s<br class="">
===================================================================<br class="">
--- /dev/null<br class="">
+++ test/tools/llvm-dwarfdump/X86/empty-CU.s<br class="">
@@ -0,0 +1,21 @@<br class="">
+# RUN: llvm-mc %s -filetype obj -triple x86_64-apple-darwin -o - \<br class="">
+# RUN: | not llvm-dwarfdump --verify --debug-info - \<br class="">
+# RUN: | FileCheck %s<br class="">
+# CHECK: Error: Compilation unit without unit DIE.<br class="">
+<br class="">
+        .section        __DWARF,__debug_info,regular,debug<br class="">
+.long 8  # CU length<br class="">
+.short 3 # Version<br class="">
+.long 0  # Abbrev offset<br class="">
+.byte 4  # AddrSize<br class="">
+.byte 1  # Abbrev 1<br class="">
+.long 7  # Unit lengthh...<br class="">
+.short 3<br class="">
+.long 0<br class="">
+.byte 4<br class="">
+        .section        __DWARF,__debug_abbrev,regular,debug<br class="">
+.byte 1    # Abbrev code<br class="">
+.byte 0x11 # TAG_compile_unit<br class="">
+.byte 0    # no children<br class="">
+.byte 0    # no attributes<br class="">
+.byte 0<br class="">
Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp<br class="">
===================================================================<br class="">
--- lib/DebugInfo/DWARF/DWARFVerifier.cpp<br class="">
+++ lib/DebugInfo/DWARF/DWARFVerifier.cpp<br class="">
@@ -179,9 +179,14 @@<br class="">
     }<br class="">
   }<br class="">
<br class="">
-  DieRangeInfo RI;<br class="">
-  DWARFDie Die = Unit.getUnitDIE(/* ExtractUnitDIEOnly = */ false);<br class="">
-  NumUnitErrors += verifyDieRanges(Die, RI);<br class="">
+  if (DWARFDie Die = Unit.getUnitDIE(/* ExtractUnitDIEOnly = */ false)) {<br class="">
+    DieRangeInfo RI;<br class="">
+    NumUnitErrors += verifyDieRanges(Die, RI);<br class="">
+  } else {<br class="">
+    OS << "Error: Compilation unit without unit DIE.\n";<br class="">
+    NumUnitErrors++;<br class="">
+  }<br class="">
+<br class="">
   return NumUnitErrors == 0;<br class="">
 }<br class="">
<br class="">
<br class="">
<br class="">
</blockquote></div></div>
</div></blockquote></div><br class=""></div></div></body></html>