<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">At the moment the DWARF APIs lack of fine-grained error reporting makes the ObjectYAML tools not well suited to this. As I mentioned in another thread related to my YAML tools, I would actually like to feed fine-grained error reporting using llvm::Error through the DWARF APIs in the future. Adding that support would allow the ObjectYAML tools to exercise cases like this either via llvm-dwarfdump, or just by round-tripping YAML->binary->YAML.<div class=""><br class=""></div><div class="">Similar to discussions that have revolved around libObject, if we had fine-grained error reporting and API calls to "validate" the data, we could build an llvm-objvalidate tool that could be used to test these kinds of conditions using the YAML-encoded object files. That would be a similar solution to what David suggested with having all parsing failures testable with llvm-dwarfdump, and I think that is a good goal to strive for.</div><div class=""><br class=""></div><div class="">Today we have woefully insufficient testing of failure cases in the DWARF parser, and I've encountered some odd edge cases (crashes and infinite loops) with malformed DWARF files during my development of the YAML tools which I hope to work on fixing.<br class=""><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 5, 2017, at 2:57 PM, David Blaikie via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Jan 5, 2017 at 2:35 PM Greg Clayton 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">clayborg added inline comments.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
================<br class="gmail_msg">
Comment at: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp:1228<br class="gmail_msg">
+  // the DWARFDie::end() iterator.<br class="gmail_msg">
+  EXPECT_EQ(DWARFDie::iterator(Null), Null.end());<br class="gmail_msg">
+}<br class="gmail_msg">
----------------<br class="gmail_msg">
It isn't possible with the DWARF APIs currently without adding code that no one would want.<br class="gmail_msg">
<br class="gmail_msg">
I was able to use DwarfGenerator to generate a DWARF file that was close that I saved to disk. I then used obj2yaml to make a yaml file, edited it and got what we need:<br class="gmail_msg">
```<br class="gmail_msg">
--- !mach-o<br class="gmail_msg">
FileHeader:<br class="gmail_msg">
  magic:           0xFEEDFACF<br class="gmail_msg">
  cputype:         0x01000007<br class="gmail_msg">
  cpusubtype:      0x00000003<br class="gmail_msg">
  filetype:        0x00000001<br class="gmail_msg">
  ncmds:           2<br class="gmail_msg">
  sizeofcmds:      248<br class="gmail_msg">
  flags:           0x00000000<br class="gmail_msg">
  reserved:        0x00000000<br class="gmail_msg">
LoadCommands:<br class="gmail_msg">
  - cmd:             LC_SEGMENT_64<br class="gmail_msg">
    cmdsize:         232<br class="gmail_msg">
    segname:         ''<br class="gmail_msg">
    vmaddr:          0<br class="gmail_msg">
    vmsize:          27<br class="gmail_msg">
    fileoff:         280<br class="gmail_msg">
    filesize:        27<br class="gmail_msg">
    maxprot:         7<br class="gmail_msg">
    initprot:        7<br class="gmail_msg">
    nsects:          2<br class="gmail_msg">
    flags:           0<br class="gmail_msg">
    Sections:<br class="gmail_msg">
      - sectname:        __debug_abbrev<br class="gmail_msg">
        segname:         __DWARF<br class="gmail_msg">
        addr:            0x0000000000000000<br class="gmail_msg">
        size:            5<br class="gmail_msg">
        offset:          0x00000118<br class="gmail_msg">
        align:           0<br class="gmail_msg">
        reloff:          0x00000000<br class="gmail_msg">
        nreloc:          0<br class="gmail_msg">
        flags:           0x02000000<br class="gmail_msg">
        reserved1:       0x00000000<br class="gmail_msg">
        reserved2:       0x00000000<br class="gmail_msg">
        reserved3:       0x00000000<br class="gmail_msg">
      - sectname:        __debug_info<br class="gmail_msg">
        segname:         __DWARF<br class="gmail_msg">
        addr:            0x000000000000000D<br class="gmail_msg">
        size:            14<br class="gmail_msg">
        offset:          0x00000125<br class="gmail_msg">
        align:           0<br class="gmail_msg">
        reloff:          0x00000000<br class="gmail_msg">
        nreloc:          0<br class="gmail_msg">
        flags:           0x02000000<br class="gmail_msg">
        reserved1:       0x00000000<br class="gmail_msg">
        reserved2:       0x00000000<br class="gmail_msg">
        reserved3:       0x00000000<br class="gmail_msg">
  - cmd:             LC_VERSION_MIN_MACOSX<br class="gmail_msg">
    cmdsize:         16<br class="gmail_msg">
    version:         1048576<br class="gmail_msg">
    sdk:             0<br class="gmail_msg">
DWARF:<br class="gmail_msg">
  debug_abbrev:<br class="gmail_msg">
    - Code:            0x00000001<br class="gmail_msg">
      Tag:             DW_TAG_compile_unit<br class="gmail_msg">
      Children:        DW_CHILDREN_yes<br class="gmail_msg">
      Attributes:<br class="gmail_msg">
  debug_info:<br class="gmail_msg">
    - Length:          10<br class="gmail_msg">
      Version:         4<br class="gmail_msg">
      AbbrOffset:      0<br class="gmail_msg">
      AddrSize:        8<br class="gmail_msg">
      Entries:<br class="gmail_msg">
        - AbbrCode:        0x00000001<br class="gmail_msg">
          Values:<br class="gmail_msg">
        - AbbrCode:        0x00000000<br class="gmail_msg">
          Values:<br class="gmail_msg">
...<br class="gmail_msg">
```<br class="gmail_msg">
<br class="gmail_msg">
Are you OK if I have this text in a "const char *" variable and use the yaml2obj APIs to create an in memory file and then parse that DWARF and then test this? I can't really use FileCheck to test this internal iteration API. Let me know if you are ok with this approach?<br class="gmail_msg"></blockquote><div class=""><br class="">Chris - any ideas here? This seems like a canonical example of the sort of test coverage we want and neither of the directions being pursued seem to be covering it.<br class=""><br class="">Are there avenues in either that would help here?<br class=""><br class="">Honestly I'd be OK expanding LLVM's DWARF generation APIs to support this - but eventually for these parser tests we'll want to expand them to cover invalid DWARF which will be harder to justify/express there, perhaps.<br class=""><br class="">- Dave<br class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D28303" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D28303</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></div></body></html>