Skip to content
  1. Jan 10, 2017
  2. Dec 21, 2016
    • Greg Clayton's avatar
      Add the ability for DWARFDie objects to get the parent DWARFDie. · c880b734
      Greg Clayton authored
      In order for the llvm DWARF parser to be used in LLDB we will need to be able to get the parent of a DIE. This patch adds that functionality by changing the DWARFDebugInfoEntry class to store a depth field instead of a sibling index. Using a depth field allows us to easily calculate the sibling and the parent without increasing the size of DWARFDebugInfoEntry.
      
      I tested llvm-dsymutil on a debug version of clang where this fully parses DWARF in over 1200 .o files to verify there was no serious regression in performance.
      
      Added a full suite of unit tests to test this functionality.
      
      Differential Revision: https://reviews.llvm.org/D27995
      
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290274 91177308-0d34-0410-b5e6-96231b3b80d8
      c880b734
  3. Dec 13, 2016
    • Greg Clayton's avatar
      Make a DWARFDIE class that can help avoid using the wrong DWARFUnit when extracting attributes · adb170fc
      Greg Clayton authored
      Many places pass around a DWARFDebugInfoEntryMinimal and a DWARFUnit. It is easy to get things wrong by using the wrong DWARFUnit with a DWARFDebugInfoEntryMinimal. This patch creates a DWARFDie class that contains the DWARFUnit and DWARFDebugInfoEntryMinimal objects so that they can't get out of sync. All attribute extraction has been moved out of DWARFDebugInfoEntryMinimal and into DWARFDie. DWARFDebugInfoEntryMinimal was also renamed to DWARFDebugInfoEntry.
      
      DWARFDie objects are temporary objects that are used by clients and contain 2 pointers that you always need to have anyway. Keeping them grouped will avoid errors and simplify many of the attribute extracting APIs by not having to pass in a DWARFUnit.
      
      Differential Revision: https://reviews.llvm.org/D27634
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289565 91177308-0d34-0410-b5e6-96231b3b80d8
      adb170fc
  4. Dec 08, 2016
    • Greg Clayton's avatar
      Make a DWARF generator so we can unit test DWARF APIs with gtest. · 777b5c3c
      Greg Clayton authored
      The only tests we have for the DWARF parser are the tests that use llvm-dwarfdump and expect output from textual dumps.
      
      More DWARF parser modification are coming in the next few weeks and I wanted to add tests that can verify that we can encode and decode all form types, as well as test some other basic DWARF APIs where we ask DIE objects for their children and siblings.
      
      DwarfGenerator.cpp was added in the lib/CodeGen directory. This file contains the code necessary to easily create DWARF for tests:
      
      dwarfgen::Generator DG;
      Triple Triple("x86_64--");
      bool success = DG.init(Triple, Version);
      if (!success)
        return;
      dwarfgen::CompileUnit &CU = DG.addCompileUnit();
      dwarfgen::DIE CUDie = CU.getUnitDIE();
      
      CUDie.addAttribute(DW_AT_name, DW_FORM_strp, "/tmp/main.c");
      CUDie.addAttribute(DW_AT_language, DW_FORM_data2, DW_LANG_C);
      
      dwarfgen::DIE SubprogramDie = CUDie.addChild(DW_TAG_subprogram);
      SubprogramDie.addAttribute(DW_AT_name, DW_FORM_strp, "main");
      SubprogramDie.addAttribute(DW_AT_low_pc, DW_FORM_addr, 0x1000U);
      SubprogramDie.addAttribute(DW_AT_high_pc, DW_FORM_addr, 0x2000U);
      
      dwarfgen::DIE IntDie = CUDie.addChild(DW_TAG_base_type);
      IntDie.addAttribute(DW_AT_name, DW_FORM_strp, "int");
      IntDie.addAttribute(DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
      IntDie.addAttribute(DW_AT_byte_size, DW_FORM_data1, 4);
      
      dwarfgen::DIE ArgcDie = SubprogramDie.addChild(DW_TAG_formal_parameter);
      ArgcDie.addAttribute(DW_AT_name, DW_FORM_strp, "argc");
      // ArgcDie.addAttribute(DW_AT_type, DW_FORM_ref4, IntDie);
      ArgcDie.addAttribute(DW_AT_type, DW_FORM_ref_addr, IntDie);
      
      StringRef FileBytes = DG.generate();
      MemoryBufferRef FileBuffer(FileBytes, "dwarf");
      auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
      EXPECT_TRUE((bool)Obj);
      DWARFContextInMemory DwarfContext(*Obj.get());
      This code is backed by the AsmPrinter code that emits DWARF for the actual compiler.
      
      While adding unit tests it was discovered that DIEValue that used DIEEntry as their values had bugs where DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref8, and DW_FORM_ref_udata forms were not supported. These are all now supported. Added support for DW_FORM_string so we can emit inlined C strings.
      
      Centralized the code to unique abbreviations into a new DIEAbbrevSet class and made both the dwarfgen::Generator and the llvm::DwarfFile classes use the new class.
      
      Fixed comments in the llvm::DIE class so that the Offset is known to be the compile/type unit offset.
      
      DIEInteger now supports more DW_FORM values.
      
      There are also unit tests that cover:
      
      Encoding and decoding all form types and values
      Encoding and decoding all reference types (DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref8, DW_FORM_ref_udata, DW_FORM_ref_addr) including cross compile unit references with that go forward one compile unit and backward on compile unit.
      
      Differential Revision: https://reviews.llvm.org/D27326
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289010 91177308-0d34-0410-b5e6-96231b3b80d8
      777b5c3c
  5. Nov 15, 2016
    • Greg Clayton's avatar
      Improve DWARF parsing speed by improving DWARFAbbreviationDeclaration · b07cdeae
      Greg Clayton authored
      This patch gets a DWARF parsing speed improvement by having DWARFAbbreviationDeclaration instances know if they have a fixed byte size. If an abbreviation has a fixed byte size that can be calculated given a DWARFUnit, then parsing a DIE becomes two steps: parse ULEB128 abbrev code, and then add constant size to the offset.
      
      This patch also adds a fixed byte size to each DWARFAbbreviationDeclaration::AttributeSpec so that attributes can quickly skip their values if needed without the need to lookup the fixed for size.
      
      Notable improvements:
      
      - DWARFAbbreviationDeclaration::findAttributeIndex() now returns an Optional<uint32_t> instead of a uint32_t and we no longer have to look for the magic -1U return value
      - Optional<uint32_t> DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute attr) const;
      - DWARFAbbreviationDeclaration now has a getAttributeValue() function that extracts an attribute value given a DIE offset that takes advantage of the DWARFAbbreviationDeclaration::AttributeSpec::ByteSize
      - bool DWARFAbbreviationDeclaration::getAttributeValue(const uint32_t DIEOffset, const dwarf::Attribute Attr, const DWARFUnit &U, DWARFFormValue &FormValue) const;
      - A DWARFAbbreviationDeclaration instance can return a fixed byte size for itself so DWARF parsing is faster:
      - Optional<size_t> DWARFAbbreviationDeclaration::getFixedAttributesByteSize(const DWARFUnit &U) const;
      - Any functions that used to take a "const DWARFUnit *U" that would crash if U was NULL now take a "const DWARFUnit &U" and are only called with a valid DWARFUnit
      
      Differential Revision: https://reviews.llvm.org/D26567
      
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286924 91177308-0d34-0410-b5e6-96231b3b80d8
      b07cdeae
  6. Nov 11, 2016
    • Greg Clayton's avatar
      Clean up DWARFFormValue by reducing duplicated code and removing... · f5acbc29
      Greg Clayton authored
      Clean up DWARFFormValue by reducing duplicated code and removing DWARFFormValue::getFixedFormSizes()
      
      In preparation for a follow on patch that improves DWARF parsing speed, clean up DWARFFormValue so that we have can get the fixed byte size of a form value given a DWARFUnit or given the version, address byte size and dwarf32/64.
      
      This patch cleans up code so that everyone is using one of the new DWARFFormValue functions:
      
      static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, const DWARFUnit *U = nullptr);
      static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, uint16_t Version, uint8_t AddrSize, bool Dwarf32);
      
      This patch changes DWARFFormValue::skipValue() to rely on the output of DWARFFormValue::getFixedByteSize(...) instead of duplicating the code in each function. This will reduce the number of changes we need to make to DWARF to fewer places in DWARFFormValue when we add support for new form.
      
      This patch also starts to support DWARF64 so that we can get correct byte sizes for forms that vary according the DWARF 32/64.
      
      To reduce the code duplication a new FormSizeHelper pure virtual class was created that can be created as a FormSizeHelperDWARFUnit when you have a DWARFUnit, or FormSizeHelperManual where you manually specify the DWARF version, address byte size and DWARF32/DWARF64. There is now a single implementation of a function that gets the fixed byte size (instead of two where one took a DWARFUnit and one took the DWARF version, address byte size and DWARFFormat enum) and one function to skip the form values.
      
      https://reviews.llvm.org/D26526
      
      
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286597 91177308-0d34-0410-b5e6-96231b3b80d8
      f5acbc29
  7. Oct 31, 2016
    • Greg Clayton's avatar
      Modify DWARFFormValue to remember the DWARFUnit that it was decoded with. · 1a30f4b7
      Greg Clayton authored
      Modifying DWARFFormValue to remember the DWARFUnit that it was encoded with can simplify the usage of instances of this class. Previously users would have to try and pass in the same DWARFUnit that was used to decode the form value and there was a possibility that a different DWARFUnit might be supplied to the functions that extract values (strings, CU relative references, addresses) and cause problems. This fixes this potential issue by storing the DWARFUnit inside the DWARFFormValue so that this mistake can't be made. Instances of DWARFFormValue are not stored permanently and are used as temporary values, so the increase in size of an instance of DWARFFormValue isn't a big deal. This makes decoding form values more bullet proof and is a change that will be used by future modifications.
      
      https://reviews.llvm.org/D26052
      
      
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285594 91177308-0d34-0410-b5e6-96231b3b80d8
      1a30f4b7
  8. Oct 28, 2016
  9. Oct 27, 2016
  10. Oct 05, 2016
  11. Oct 04, 2016
  12. Nov 17, 2015
  13. May 19, 2015
    • Alexey Samsonov's avatar
      [DWARF parser] Add basic support for DWZ DWARF multifile extensions. · 4ca606f2
      Alexey Samsonov authored
      This change implements basic support for DWARF alternate sections
      proposal: http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open
      
      LLVM tools now understand new forms: DW_FORM_GNU_ref_alt and
      DW_FORM_GNU_strp_alt, which are used as references to .debug_info and
      .debug_str sections respectively, stored in a separate file, and
      possibly shared between different executables / shared objects.
      
      llvm-dwarfdump and llvm-symbolizer don't yet know how to access this
      alternate debug file (usually pointed by .gnu_debugaltlink section),
      but they can at lease properly parse and dump regular files, which
      refer to it.
      
      This change should fix crashes of llvm-dwarfdump and llvm-symbolizer on
      files produced by running "dwz" tool. Such files are already installed
      on some modern Linux distributions.
      
      git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237721 91177308-0d34-0410-b5e6-96231b3b80d8
      4ca606f2
  14. Jan 30, 2015
  15. Jan 14, 2015
  16. Jan 06, 2015
  17. Dec 19, 2014
  18. Dec 15, 2014
  19. Oct 23, 2014
  20. Oct 10, 2014
  21. Oct 06, 2014
  22. Sep 22, 2014
  23. Sep 05, 2014
  24. Sep 04, 2014
  25. Jun 13, 2014
  26. May 17, 2014
  27. May 15, 2014
  28. Apr 18, 2014
  29. Apr 15, 2014
  30. Mar 13, 2014
  31. Oct 28, 2013