LCOV - code coverage report
Current view: top level - lib/DebugInfo/MSF - MSFCommon.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 30 90.0 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MSFCommon.cpp - Common types and functions for MSF files -----------===//
       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/MSF/MSFCommon.h"
      11             : #include "llvm/DebugInfo/MSF/MSFError.h"
      12             : #include "llvm/Support/Endian.h"
      13             : #include "llvm/Support/Error.h"
      14             : #include <cstdint>
      15             : #include <cstring>
      16             : 
      17             : using namespace llvm;
      18             : using namespace llvm::msf;
      19             : 
      20         103 : Error llvm::msf::validateSuperBlock(const SuperBlock &SB) {
      21             :   // Check the magic bytes.
      22         103 :   if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0)
      23             :     return make_error<MSFError>(msf_error_code::invalid_format,
      24           2 :                                 "MSF magic header doesn't match");
      25             : 
      26         306 :   if (!isValidBlockSize(SB.BlockSize))
      27             :     return make_error<MSFError>(msf_error_code::invalid_format,
      28           2 :                                 "Unsupported block size.");
      29             : 
      30             :   // We don't support directories whose sizes aren't a multiple of four bytes.
      31         202 :   if (SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
      32             :     return make_error<MSFError>(msf_error_code::invalid_format,
      33           0 :                                 "Directory size is not multiple of 4.");
      34             : 
      35             :   // The number of blocks which comprise the directory is a simple function of
      36             :   // the number of bytes it contains.
      37             :   uint64_t NumDirectoryBlocks =
      38         404 :       bytesToBlocks(SB.NumDirectoryBytes, SB.BlockSize);
      39             : 
      40             :   // The directory, as we understand it, is a block which consists of a list of
      41             :   // block numbers.  It is unclear what would happen if the number of blocks
      42             :   // couldn't fit on a single block.
      43         202 :   if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t))
      44             :     return make_error<MSFError>(msf_error_code::invalid_format,
      45           2 :                                 "Too many directory blocks.");
      46             : 
      47         200 :   if (SB.BlockMapAddr == 0)
      48             :     return make_error<MSFError>(msf_error_code::invalid_format,
      49           2 :                                 "Block 0 is reserved");
      50             : 
      51         297 :   if (SB.BlockMapAddr >= SB.NumBlocks)
      52             :     return make_error<MSFError>(msf_error_code::invalid_format,
      53           0 :                                 "Block map address is invalid.");
      54             : 
      55         252 :   if (SB.FreeBlockMapBlock != 1 && SB.FreeBlockMapBlock != 2)
      56             :     return make_error<MSFError>(
      57             :         msf_error_code::invalid_format,
      58           0 :         "The free block map isn't at block 1 or block 2.");
      59             : 
      60         297 :   return Error::success();
      61             : }
      62             : 
      63         416 : MSFStreamLayout llvm::msf::getFpmStreamLayout(const MSFLayout &Msf,
      64             :                                               bool IncludeUnusedFpmData,
      65             :                                               bool AltFpm) {
      66         416 :   MSFStreamLayout FL;
      67         832 :   uint32_t NumFpmIntervals = getNumFpmIntervals(Msf, IncludeUnusedFpmData);
      68         416 :   support::ulittle32_t FpmBlock = Msf.SB->FreeBlockMapBlock;
      69             :   assert(FpmBlock == 1 || FpmBlock == 2);
      70         416 :   if (AltFpm) {
      71             :     // If they requested the alternate FPM, then 2 becomes 1 and 1 becomes 2.
      72         124 :     FpmBlock = 3U - FpmBlock;
      73             :   }
      74        1286 :   for (uint32_t I = 0; I < NumFpmIntervals; ++I) {
      75         435 :     FL.Blocks.push_back(FpmBlock);
      76        1305 :     FpmBlock += msf::getFpmIntervalLength(Msf);
      77             :   }
      78             : 
      79         416 :   if (IncludeUnusedFpmData)
      80         382 :     FL.Length = NumFpmIntervals * Msf.SB->BlockSize;
      81             :   else
      82         675 :     FL.Length = divideCeil(Msf.SB->NumBlocks, 8);
      83             : 
      84         416 :   return FL;
      85             : }

Generated by: LCOV version 1.13