Home | History | Annotate | Line # | Download | only in CodeView
      1 //===- DebugChecksumsSubsection.h -------------------------------*- C++ -*-===//
      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 
      9 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
     10 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
     11 
     12 #include "llvm/ADT/ArrayRef.h"
     13 #include "llvm/ADT/DenseMap.h"
     14 #include "llvm/ADT/StringRef.h"
     15 #include "llvm/DebugInfo/CodeView/CodeView.h"
     16 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
     17 #include "llvm/Support/Allocator.h"
     18 #include "llvm/Support/BinaryStreamArray.h"
     19 #include "llvm/Support/BinaryStreamReader.h"
     20 #include "llvm/Support/BinaryStreamRef.h"
     21 #include "llvm/Support/Error.h"
     22 #include <cstdint>
     23 #include <vector>
     24 
     25 namespace llvm {
     26 
     27 namespace codeview {
     28 
     29 class DebugStringTableSubsection;
     30 
     31 struct FileChecksumEntry {
     32   uint32_t FileNameOffset;    // Byte offset of filename in global stringtable.
     33   FileChecksumKind Kind;      // The type of checksum.
     34   ArrayRef<uint8_t> Checksum; // The bytes of the checksum.
     35 };
     36 
     37 } // end namespace codeview
     38 
     39 template <> struct VarStreamArrayExtractor<codeview::FileChecksumEntry> {
     40 public:
     41   using ContextType = void;
     42 
     43   Error operator()(BinaryStreamRef Stream, uint32_t &Len,
     44                    codeview::FileChecksumEntry &Item);
     45 };
     46 
     47 namespace codeview {
     48 
     49 class DebugChecksumsSubsectionRef final : public DebugSubsectionRef {
     50   using FileChecksumArray = VarStreamArray<codeview::FileChecksumEntry>;
     51   using Iterator = FileChecksumArray::Iterator;
     52 
     53 public:
     54   DebugChecksumsSubsectionRef()
     55       : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {}
     56 
     57   static bool classof(const DebugSubsectionRef *S) {
     58     return S->kind() == DebugSubsectionKind::FileChecksums;
     59   }
     60 
     61   bool valid() const { return Checksums.valid(); }
     62 
     63   Error initialize(BinaryStreamReader Reader);
     64   Error initialize(BinaryStreamRef Stream);
     65 
     66   Iterator begin() const { return Checksums.begin(); }
     67   Iterator end() const { return Checksums.end(); }
     68 
     69   const FileChecksumArray &getArray() const { return Checksums; }
     70 
     71 private:
     72   FileChecksumArray Checksums;
     73 };
     74 
     75 class DebugChecksumsSubsection final : public DebugSubsection {
     76 public:
     77   explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings);
     78 
     79   static bool classof(const DebugSubsection *S) {
     80     return S->kind() == DebugSubsectionKind::FileChecksums;
     81   }
     82 
     83   void addChecksum(StringRef FileName, FileChecksumKind Kind,
     84                    ArrayRef<uint8_t> Bytes);
     85 
     86   uint32_t calculateSerializedSize() const override;
     87   Error commit(BinaryStreamWriter &Writer) const override;
     88   uint32_t mapChecksumOffset(StringRef FileName) const;
     89 
     90 private:
     91   DebugStringTableSubsection &Strings;
     92 
     93   DenseMap<uint32_t, uint32_t> OffsetMap;
     94   uint32_t SerializedSize = 0;
     95   BumpPtrAllocator Storage;
     96   std::vector<FileChecksumEntry> Checksums;
     97 };
     98 
     99 } // end namespace codeview
    100 
    101 } // end namespace llvm
    102 
    103 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H
    104