LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - DebugStringTableSubsection.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 36 39 92.3 %
Date: 2017-09-14 15:23:50 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DebugStringTableSubsection.cpp - CodeView String Table -------------===//
       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/CodeView/DebugStringTableSubsection.h"
      11             : #include "llvm/ADT/StringRef.h"
      12             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      13             : #include "llvm/Support/BinaryStreamReader.h"
      14             : #include "llvm/Support/BinaryStreamWriter.h"
      15             : #include "llvm/Support/Error.h"
      16             : #include <algorithm>
      17             : #include <cassert>
      18             : #include <cstdint>
      19             : 
      20             : using namespace llvm;
      21             : using namespace llvm::codeview;
      22             : 
      23         529 : DebugStringTableSubsectionRef::DebugStringTableSubsectionRef()
      24        1587 :     : DebugSubsectionRef(DebugSubsectionKind::StringTable) {}
      25             : 
      26         220 : Error DebugStringTableSubsectionRef::initialize(BinaryStreamRef Contents) {
      27         440 :   Stream = Contents;
      28         660 :   return Error::success();
      29             : }
      30             : 
      31           2 : Error DebugStringTableSubsectionRef::initialize(BinaryStreamReader &Reader) {
      32           2 :   return Reader.readStreamRef(Stream);
      33             : }
      34             : 
      35             : Expected<StringRef>
      36        1905 : DebugStringTableSubsectionRef::getString(uint32_t Offset) const {
      37        7620 :   BinaryStreamReader Reader(Stream);
      38        3810 :   Reader.setOffset(Offset);
      39        1905 :   StringRef Result;
      40        5715 :   if (auto EC = Reader.readCString(Result))
      41           0 :     return std::move(EC);
      42             :   return Result;
      43             : }
      44             : 
      45         232 : DebugStringTableSubsection::DebugStringTableSubsection()
      46         696 :     : DebugSubsection(DebugSubsectionKind::StringTable) {}
      47             : 
      48         200 : uint32_t DebugStringTableSubsection::insert(StringRef S) {
      49         600 :   auto P = Strings.insert({S, StringSize});
      50             : 
      51             :   // If a given string didn't exist in the string table, we want to increment
      52             :   // the string table size.
      53         200 :   if (P.second)
      54         140 :     StringSize += S.size() + 1; // +1 for '\0'
      55         200 :   return P.first->second;
      56             : }
      57             : 
      58         470 : uint32_t DebugStringTableSubsection::calculateSerializedSize() const {
      59         470 :   return StringSize;
      60             : }
      61             : 
      62         147 : Error DebugStringTableSubsection::commit(BinaryStreamWriter &Writer) const {
      63         147 :   uint32_t Begin = Writer.getOffset();
      64         147 :   uint32_t End = Begin + StringSize;
      65             : 
      66             :   // Write a null string at the beginning.
      67         441 :   if (auto EC = Writer.writeCString(StringRef()))
      68           0 :     return EC;
      69             : 
      70         814 :   for (auto &Pair : Strings) {
      71         113 :     StringRef S = Pair.getKey();
      72         113 :     uint32_t Offset = Begin + Pair.getValue();
      73         226 :     Writer.setOffset(Offset);
      74         339 :     if (auto EC = Writer.writeCString(S))
      75           0 :       return EC;
      76             :     assert(Writer.getOffset() <= End);
      77             :   }
      78             : 
      79         294 :   Writer.setOffset(End);
      80             :   assert((End - Begin) == StringSize);
      81         441 :   return Error::success();
      82             : }
      83             : 
      84         529 : uint32_t DebugStringTableSubsection::size() const { return Strings.size(); }
      85             : 
      86          31 : uint32_t DebugStringTableSubsection::getStringId(StringRef S) const {
      87          31 :   auto Iter = Strings.find(S);
      88             :   assert(Iter != Strings.end());
      89          31 :   return Iter->second;
      90             : }

Generated by: LCOV version 1.13