LCOV - code coverage report
Current view: top level - lib/DebugInfo - DWARFDebugLoc.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 71 73 97.3 %
Date: 2015-01-30 11:55:44 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- DWARFDebugLoc.cpp -------------------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/DebugInfo/DWARFDebugLoc.h"
      11             : #include "llvm/Support/Compiler.h"
      12             : #include "llvm/Support/Dwarf.h"
      13             : #include "llvm/Support/Format.h"
      14             : #include "llvm/Support/raw_ostream.h"
      15             : 
      16             : using namespace llvm;
      17             : 
      18          97 : void DWARFDebugLoc::dump(raw_ostream &OS) const {
      19         122 :   for (const LocationList &L : Locations) {
      20          75 :     OS << format("0x%8.8x: ", L.Offset);
      21          25 :     const unsigned Indent = 12;
      22          87 :     for (const Entry &E : L.Entries) {
      23          62 :       if (&E != L.Entries.begin())
      24          38 :         OS.indent(Indent);
      25         186 :       OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
      26          62 :          << '\n';
      27          62 :       OS.indent(Indent) << "   Ending address offset: "
      28         186 :                         << format("0x%016" PRIx64, E.End) << '\n';
      29          62 :       OS.indent(Indent) << "    Location description: ";
      30         259 :       for (unsigned char Loc : E.Loc) {
      31         394 :         OS << format("%2.2x ", Loc);
      32             :       }
      33          62 :       OS << "\n\n";
      34             :     }
      35             :   }
      36          97 : }
      37             : 
      38          81 : void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
      39          81 :   uint32_t Offset = 0;
      40         293 :   while (data.isValidOffset(Offset+AddressSize-1)) {
      41          50 :     Locations.resize(Locations.size() + 1);
      42          50 :     LocationList &Loc = Locations.back();
      43          25 :     Loc.Offset = Offset;
      44             :     // 2.6.2 Location Lists
      45             :     // A location list entry consists of:
      46             :     while (true) {
      47             :       Entry E;
      48          87 :       RelocAddrMap::const_iterator AI = RelocMap.find(Offset);
      49             :       // 1. A beginning address offset. ...
      50          87 :       E.Begin = data.getUnsigned(&Offset, AddressSize);
      51         261 :       if (AI != RelocMap.end())
      52           4 :         E.Begin += AI->second.second;
      53             : 
      54          87 :       AI = RelocMap.find(Offset);
      55             :       // 2. An ending address offset. ...
      56          87 :       E.End = data.getUnsigned(&Offset, AddressSize);
      57         261 :       if (AI != RelocMap.end())
      58           4 :         E.End += AI->second.second;
      59             : 
      60             :       // The end of any given location list is marked by an end of list entry,
      61             :       // which consists of a 0 for the beginning address offset and a 0 for the
      62             :       // ending address offset.
      63          87 :       if (E.Begin == 0 && E.End == 0)
      64             :         break;
      65             : 
      66          62 :       unsigned Bytes = data.getU16(&Offset);
      67             :       // A single location description describing the location of the object...
      68         124 :       StringRef str = data.getData().substr(Offset, Bytes);
      69          62 :       Offset += Bytes;
      70          62 :       E.Loc.reserve(str.size());
      71          62 :       std::copy(str.begin(), str.end(), std::back_inserter(E.Loc));
      72          62 :       Loc.Entries.push_back(std::move(E));
      73             :     }
      74             :   }
      75         162 :   if (data.isValidOffset(Offset))
      76           1 :     llvm::errs() << "error: failed to consume entire .debug_loc section\n";
      77          81 : }
      78             : 
      79          94 : void DWARFDebugLocDWO::parse(DataExtractor data) {
      80          94 :   uint32_t Offset = 0;
      81         292 :   while (data.isValidOffset(Offset)) {
      82          10 :     Locations.resize(Locations.size() + 1);
      83          10 :     LocationList &Loc = Locations.back();
      84           5 :     Loc.Offset = Offset;
      85             :     dwarf::LocationListEntry Kind;
      86          17 :     while ((Kind = static_cast<dwarf::LocationListEntry>(
      87             :                 data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list_entry) {
      88             : 
      89           7 :       if (Kind != dwarf::DW_LLE_start_length_entry) {
      90           0 :         llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
      91           0 :                      << " not implemented\n";
      92          94 :         return;
      93             :       }
      94             : 
      95             :       Entry E;
      96             : 
      97           7 :       E.Start = data.getULEB128(&Offset);
      98           7 :       E.Length = data.getU32(&Offset);
      99             : 
     100           7 :       unsigned Bytes = data.getU16(&Offset);
     101             :       // A single location description describing the location of the object...
     102          14 :       StringRef str = data.getData().substr(Offset, Bytes);
     103           7 :       Offset += Bytes;
     104           7 :       E.Loc.resize(str.size());
     105          14 :       std::copy(str.begin(), str.end(), E.Loc.begin());
     106             : 
     107           7 :       Loc.Entries.push_back(std::move(E));
     108             :     }
     109             :   }
     110             : }
     111             : 
     112          94 : void DWARFDebugLocDWO::dump(raw_ostream &OS) const {
     113          99 :   for (const LocationList &L : Locations) {
     114          15 :     OS << format("0x%8.8x: ", L.Offset);
     115           5 :     const unsigned Indent = 12;
     116          12 :     for (const Entry &E : L.Entries) {
     117           7 :       if (&E != L.Entries.begin())
     118           2 :         OS.indent(Indent);
     119           7 :       OS << "Beginning address index: " << E.Start << '\n';
     120          14 :       OS.indent(Indent) << "                 Length: " << E.Length << '\n';
     121           7 :       OS.indent(Indent) << "   Location description: ";
     122          27 :       for (unsigned char Loc : E.Loc)
     123          40 :         OS << format("%2.2x ", Loc);
     124           7 :       OS << "\n\n";
     125             :     }
     126             :   }
     127          94 : }
     128             : 

Generated by: LCOV version 1.11