LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - DwarfFile.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 46 48 95.8 %
Date: 2017-09-14 15:23:50 Functions: 10 10 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       32947 : DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
      25      263582 :     : Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref) {}
      26             : 
      27         765 : void DwarfFile::addUnit(std::unique_ptr<DwarfCompileUnit> U) {
      28         765 :   CUs.push_back(std::move(U));
      29         765 : }
      30             : 
      31             : // Emit the various dwarf units to the unit section USection with
      32             : // the abbreviations going into ASection.
      33         748 : void DwarfFile::emitUnits(bool UseOffsets) {
      34        3009 :   for (const auto &TheU : CUs)
      35        1530 :     emitUnit(TheU.get(), UseOffsets);
      36         748 : }
      37             : 
      38         790 : void DwarfFile::emitUnit(DwarfUnit *TheU, bool UseOffsets) {
      39        1580 :   DIE &Die = TheU->getUnitDie();
      40         790 :   MCSection *USection = TheU->getSection();
      41        1580 :   Asm->OutStreamer->SwitchSection(USection);
      42             : 
      43         790 :   TheU->emitHeader(UseOffsets);
      44             : 
      45         790 :   Asm->emitDwarfDIE(Die);
      46         790 : }
      47             : 
      48             : // Compute the size and offset for each DIE.
      49         748 : void DwarfFile::computeSizeAndOffsets() {
      50             :   // Offset from the first CU in the debug info section is 0 initially.
      51         748 :   unsigned SecOffset = 0;
      52             : 
      53             :   // Iterate over each compile unit and set the size and offsets for each
      54             :   // DIE within each compile unit. All offsets are CU relative.
      55        3009 :   for (const auto &TheU : CUs) {
      56        1530 :     TheU->setDebugSectionOffset(SecOffset);
      57         765 :     SecOffset += computeSizeAndOffsetsForUnit(TheU.get());
      58             :   }
      59         748 : }
      60             : 
      61         790 : unsigned DwarfFile::computeSizeAndOffsetsForUnit(DwarfUnit *TheU) {
      62             :   // CU-relative offset is reset to 0 here.
      63             :   unsigned Offset = sizeof(int32_t) +      // Length of Unit Info
      64         790 :                     TheU->getHeaderSize(); // Unit-specific headers
      65             : 
      66             :   // The return value here is CU-relative, after laying out
      67             :   // all of the CU DIE.
      68        1580 :   return computeSizeAndOffset(TheU->getUnitDie(), Offset);
      69             : }
      70             : 
      71             : // Compute the size and offset of a DIE. The offset is relative to start of the
      72             : // CU. It returns the offset after laying out the DIE.
      73         790 : unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
      74         790 :   return Die.computeOffsetsAndAbbrevs(Asm, Abbrevs, Offset);
      75             : }
      76             : 
      77         748 : void DwarfFile::emitAbbrevs(MCSection *Section) { Abbrevs.Emit(Asm, Section); }
      78             : 
      79             : // Emit strings into a string section.
      80         748 : void DwarfFile::emitStrings(MCSection *StrSection, MCSection *OffsetSection) {
      81         748 :   StrPool.emit(*Asm, StrSection, OffsetSection);
      82         748 : }
      83             : 
      84       16334 : bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
      85       32668 :   SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS];
      86       16334 :   const DILocalVariable *DV = Var->getVariable();
      87             :   // Variables with positive arg numbers are parameters.
      88       16334 :   if (unsigned ArgNum = DV->getArg()) {
      89             :     // Keep all parameters in order at the start of the variable list to ensure
      90             :     // function types are correct (no out-of-order parameters)
      91             :     //
      92             :     // This could be improved by only doing it for optimized builds (unoptimized
      93             :     // builds have the right order to begin with), searching from the back (this
      94             :     // would catch the unoptimized case quickly), or doing a binary search
      95             :     // rather than linear search.
      96       27486 :     auto I = Vars.begin();
      97       42303 :     while (I != Vars.end()) {
      98       15392 :       unsigned CurNum = (*I)->getVariable()->getArg();
      99             :       // A local (non-parameter) variable has been found, insert immediately
     100             :       // before it.
     101        7696 :       if (CurNum == 0)
     102             :         break;
     103             :       // A later indexed parameter has been found, insert immediately before it.
     104        6950 :       if (CurNum > ArgNum)
     105             :         break;
     106        4939 :       if (CurNum == ArgNum) {
     107           0 :         (*I)->addMMIEntry(*Var);
     108           0 :         return false;
     109             :       }
     110        4939 :       ++I;
     111             :     }
     112       13743 :     Vars.insert(I, Var);
     113       13743 :     return true;
     114             :   }
     115             : 
     116        2591 :   Vars.push_back(Var);
     117        2591 :   return true;
     118             : }

Generated by: LCOV version 1.13