LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - DwarfFile.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 44 45 97.8 %
Date: 2018-07-13 00:08:38 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/CodeGen/DwarfFile.cpp - Dwarf Debug Framework -----------------===//
       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 "DwarfFile.h"
      11             : #include "DwarfCompileUnit.h"
      12             : #include "DwarfDebug.h"
      13             : #include "DwarfUnit.h"
      14             : #include "llvm/ADT/SmallVector.h"
      15             : #include "llvm/CodeGen/AsmPrinter.h"
      16             : #include "llvm/CodeGen/DIE.h"
      17             : #include "llvm/IR/DebugInfoMetadata.h"
      18             : #include "llvm/MC/MCStreamer.h"
      19             : #include <algorithm>
      20             : #include <cstdint>
      21             : 
      22             : using namespace llvm;
      23             : 
      24       43578 : DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
      25      261468 :     : Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref) {}
      26             : 
      27        3150 : void DwarfFile::addUnit(std::unique_ptr<DwarfCompileUnit> U) {
      28        3150 :   CUs.push_back(std::move(U));
      29        3150 : }
      30             : 
      31          23 : void DwarfFile::emitStringOffsetsTableHeader(MCSection *Section) {
      32          23 :   if (StrPool.empty())
      33             :     return;
      34          46 :   Asm->OutStreamer->SwitchSection(Section);
      35             :   unsigned EntrySize = 4;
      36             :   // FIXME: DWARF64
      37             :   // We are emitting the header for a contribution to the string offsets
      38             :   // table. The header consists of an entry with the contribution's
      39             :   // size (not including the size of the length field), the DWARF version and
      40             :   // 2 bytes of padding.
      41          46 :   Asm->emitInt32(StrPool.size() * EntrySize + 4);
      42          23 :   Asm->emitInt16(Asm->getDwarfVersion());
      43          23 :   Asm->emitInt16(0);
      44             :   // Define the symbol that marks the start of the contribution. It is
      45             :   // referenced by most unit headers via DW_AT_str_offsets_base.
      46             :   // Split units do not use the attribute.
      47          23 :   if (StringOffsetsStartSym)
      48          38 :     Asm->OutStreamer->EmitLabel(StringOffsetsStartSym);
      49             : }
      50             : 
      51             : // Emit the various dwarf units to the unit section USection with
      52             : // the abbreviations going into ASection.
      53        2874 : void DwarfFile::emitUnits(bool UseOffsets) {
      54        9174 :   for (const auto &TheU : CUs)
      55        6300 :     emitUnit(TheU.get(), UseOffsets);
      56        2874 : }
      57             : 
      58        3183 : void DwarfFile::emitUnit(DwarfUnit *TheU, bool UseOffsets) {
      59             :   DIE &Die = TheU->getUnitDie();
      60        3183 :   MCSection *USection = TheU->getSection();
      61        6366 :   Asm->OutStreamer->SwitchSection(USection);
      62             : 
      63        3183 :   TheU->emitHeader(UseOffsets);
      64             : 
      65        3183 :   Asm->emitDwarfDIE(Die);
      66        3183 : }
      67             : 
      68             : // Compute the size and offset for each DIE.
      69        2874 : void DwarfFile::computeSizeAndOffsets() {
      70             :   // Offset from the first CU in the debug info section is 0 initially.
      71             :   unsigned SecOffset = 0;
      72             : 
      73             :   // Iterate over each compile unit and set the size and offsets for each
      74             :   // DIE within each compile unit. All offsets are CU relative.
      75        9174 :   for (const auto &TheU : CUs) {
      76             :     TheU->setDebugSectionOffset(SecOffset);
      77        3150 :     SecOffset += computeSizeAndOffsetsForUnit(TheU.get());
      78             :   }
      79        2874 : }
      80             : 
      81        3183 : unsigned DwarfFile::computeSizeAndOffsetsForUnit(DwarfUnit *TheU) {
      82             :   // CU-relative offset is reset to 0 here.
      83             :   unsigned Offset = sizeof(int32_t) +      // Length of Unit Info
      84        3183 :                     TheU->getHeaderSize(); // Unit-specific headers
      85             : 
      86             :   // The return value here is CU-relative, after laying out
      87             :   // all of the CU DIE.
      88        3183 :   return computeSizeAndOffset(TheU->getUnitDie(), Offset);
      89             : }
      90             : 
      91             : // Compute the size and offset of a DIE. The offset is relative to start of the
      92             : // CU. It returns the offset after laying out the DIE.
      93        3183 : unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
      94        3183 :   return Die.computeOffsetsAndAbbrevs(Asm, Abbrevs, Offset);
      95             : }
      96             : 
      97        2874 : void DwarfFile::emitAbbrevs(MCSection *Section) { Abbrevs.Emit(Asm, Section); }
      98             : 
      99             : // Emit strings into a string section.
     100        2874 : void DwarfFile::emitStrings(MCSection *StrSection, MCSection *OffsetSection,
     101             :                             bool UseRelativeOffsets) {
     102        2874 :   StrPool.emit(*Asm, StrSection, OffsetSection, UseRelativeOffsets);
     103        2874 : }
     104             : 
     105       81558 : bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
     106       81558 :   auto &ScopeVars = ScopeVariables[LS];
     107       81558 :   const DILocalVariable *DV = Var->getVariable();
     108       81558 :   if (unsigned ArgNum = DV->getArg()) {
     109             :     auto Cached = ScopeVars.Args.find(ArgNum);
     110       68223 :     if (Cached == ScopeVars.Args.end())
     111       68223 :       ScopeVars.Args[ArgNum] = Var;
     112             :     else {
     113           0 :       Cached->second->addMMIEntry(*Var);
     114             :       return false;
     115             :     }
     116             :   } else {
     117       13335 :     ScopeVars.Locals.push_back(Var);
     118             :   }    
     119       81558 :   return true;
     120             : }

Generated by: LCOV version 1.13