LLVM  4.0.0
ModInfo.cpp
Go to the documentation of this file.
1 //===- ModInfo.cpp - PDB module information -------------------------------===//
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 
13 #include "llvm/Support/Endian.h"
14 #include "llvm/Support/Error.h"
16 #include <cstdint>
17 
18 using namespace llvm;
19 using namespace llvm::msf;
20 using namespace llvm::pdb;
21 using namespace llvm::support;
22 
23 ModInfo::ModInfo() = default;
24 
25 ModInfo::ModInfo(const ModInfo &Info) = default;
26 
27 ModInfo::~ModInfo() = default;
28 
30  StreamReader Reader(Stream);
31  if (auto EC = Reader.readObject(Info.Layout))
32  return EC;
33 
34  if (auto EC = Reader.readZeroString(Info.ModuleName))
35  return EC;
36 
37  if (auto EC = Reader.readZeroString(Info.ObjFileName))
38  return EC;
39  return Error::success();
40 }
41 
42 bool ModInfo::hasECInfo() const {
43  return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
44 }
45 
46 uint16_t ModInfo::getTypeServerIndex() const {
47  return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
48  ModInfoFlags::TypeServerIndexShift;
49 }
50 
51 uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
52 
53 uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
54  return Layout->SymBytes;
55 }
56 
57 uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
58 
59 uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
60 
61 uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
62 
63 uint32_t ModInfo::getSourceFileNameIndex() const {
64  return Layout->SrcFileNameNI;
65 }
66 
67 uint32_t ModInfo::getPdbFilePathNameIndex() const {
68  return Layout->PdbFilePathNI;
69 }
70 
71 StringRef ModInfo::getModuleName() const { return ModuleName; }
72 
73 StringRef ModInfo::getObjFileName() const { return ObjFileName; }
74 
75 uint32_t ModInfo::getRecordLength() const {
76  uint32_t M = ModuleName.str().size() + 1;
77  uint32_t O = ObjFileName.str().size() + 1;
78  uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
79  Size = alignTo(Size, 4);
80  return Size;
81 }
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:664
Error readZeroString(StringRef &Dest)
The header preceeding each entry in the Module Info substream of the DBI stream.
Definition: RawTypes.h:215
static ErrorSuccess success()
Create a success value.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > StandardNames)
initialize - Initialize the set of available library functions based on the specified target triple...
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Error readObject(const T *&Dest)
Definition: StreamReader.h:53