Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/DebugInfo/MSF/MSFCommon.cpp
Line
Count
Source (jump to first uncovered line)
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
103
  // Check the magic bytes.
22
103
  if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0)
23
1
    return make_error<MSFError>(msf_error_code::invalid_format,
24
1
                                "MSF magic header doesn't match");
25
102
26
102
  
if (102
!isValidBlockSize(SB.BlockSize)102
)
27
1
    return make_error<MSFError>(msf_error_code::invalid_format,
28
1
                                "Unsupported block size.");
29
101
30
101
  // We don't support directories whose sizes aren't a multiple of four bytes.
31
101
  
if (101
SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0101
)
32
0
    return make_error<MSFError>(msf_error_code::invalid_format,
33
0
                                "Directory size is not multiple of 4.");
34
101
35
101
  // The number of blocks which comprise the directory is a simple function of
36
101
  // the number of bytes it contains.
37
101
  uint64_t NumDirectoryBlocks =
38
101
      bytesToBlocks(SB.NumDirectoryBytes, SB.BlockSize);
39
101
40
101
  // The directory, as we understand it, is a block which consists of a list of
41
101
  // block numbers.  It is unclear what would happen if the number of blocks
42
101
  // couldn't fit on a single block.
43
101
  if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t))
44
1
    return make_error<MSFError>(msf_error_code::invalid_format,
45
1
                                "Too many directory blocks.");
46
100
47
100
  
if (100
SB.BlockMapAddr == 0100
)
48
1
    return make_error<MSFError>(msf_error_code::invalid_format,
49
1
                                "Block 0 is reserved");
50
99
51
99
  
if (99
SB.BlockMapAddr >= SB.NumBlocks99
)
52
0
    return make_error<MSFError>(msf_error_code::invalid_format,
53
0
                                "Block map address is invalid.");
54
99
55
99
  
if (99
SB.FreeBlockMapBlock != 1 && 99
SB.FreeBlockMapBlock != 254
)
56
0
    return make_error<MSFError>(
57
0
        msf_error_code::invalid_format,
58
0
        "The free block map isn't at block 1 or block 2.");
59
99
60
99
  return Error::success();
61
99
}
62
63
MSFStreamLayout llvm::msf::getFpmStreamLayout(const MSFLayout &Msf,
64
                                              bool IncludeUnusedFpmData,
65
416
                                              bool AltFpm) {
66
416
  MSFStreamLayout FL;
67
416
  uint32_t NumFpmIntervals = getNumFpmIntervals(Msf, IncludeUnusedFpmData);
68
416
  support::ulittle32_t FpmBlock = Msf.SB->FreeBlockMapBlock;
69
416
  assert(FpmBlock == 1 || FpmBlock == 2);
70
416
  if (
AltFpm416
) {
71
124
    // If they requested the alternate FPM, then 2 becomes 1 and 1 becomes 2.
72
124
    FpmBlock = 3U - FpmBlock;
73
124
  }
74
851
  for (uint32_t I = 0; 
I < NumFpmIntervals851
;
++I435
) {
75
435
    FL.Blocks.push_back(FpmBlock);
76
435
    FpmBlock += msf::getFpmIntervalLength(Msf);
77
435
  }
78
416
79
416
  if (IncludeUnusedFpmData)
80
191
    FL.Length = NumFpmIntervals * Msf.SB->BlockSize;
81
416
  else
82
225
    FL.Length = divideCeil(Msf.SB->NumBlocks, 8);
83
416
84
416
  return FL;
85
416
}