DbiModuleDescriptor.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===- DbiModuleDescriptor.cpp - PDB module information -------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
  9. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  10. #include "llvm/Support/BinaryStreamReader.h"
  11. #include "llvm/Support/Endian.h"
  12. #include "llvm/Support/Error.h"
  13. #include "llvm/Support/MathExtras.h"
  14. #include <cstdint>
  15. using namespace llvm;
  16. using namespace llvm::pdb;
  17. using namespace llvm::support;
  18. Error DbiModuleDescriptor::initialize(BinaryStreamRef Stream,
  19. DbiModuleDescriptor &Info) {
  20. BinaryStreamReader Reader(Stream);
  21. if (auto EC = Reader.readObject(Info.Layout))
  22. return EC;
  23. if (auto EC = Reader.readCString(Info.ModuleName))
  24. return EC;
  25. if (auto EC = Reader.readCString(Info.ObjFileName))
  26. return EC;
  27. return Error::success();
  28. }
  29. bool DbiModuleDescriptor::hasECInfo() const {
  30. return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
  31. }
  32. uint16_t DbiModuleDescriptor::getTypeServerIndex() const {
  33. return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
  34. ModInfoFlags::TypeServerIndexShift;
  35. }
  36. const SectionContrib &DbiModuleDescriptor::getSectionContrib() const {
  37. return Layout->SC;
  38. }
  39. uint16_t DbiModuleDescriptor::getModuleStreamIndex() const {
  40. return Layout->ModDiStream;
  41. }
  42. uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
  43. return Layout->SymBytes;
  44. }
  45. uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
  46. return Layout->C11Bytes;
  47. }
  48. uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
  49. return Layout->C13Bytes;
  50. }
  51. uint32_t DbiModuleDescriptor::getNumberOfFiles() const {
  52. return Layout->NumFiles;
  53. }
  54. uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const {
  55. return Layout->SrcFileNameNI;
  56. }
  57. uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const {
  58. return Layout->PdbFilePathNI;
  59. }
  60. StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; }
  61. StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; }
  62. uint32_t DbiModuleDescriptor::getRecordLength() const {
  63. uint32_t M = ModuleName.str().size() + 1;
  64. uint32_t O = ObjFileName.str().size() + 1;
  65. uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
  66. Size = alignTo(Size, 4);
  67. return Size;
  68. }