Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:39

0001 //===- DebugSubsectionRecord.h ----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONRECORD_H
0010 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONRECORD_H
0011 
0012 #include "llvm/DebugInfo/CodeView/CodeView.h"
0013 #include "llvm/Support/BinaryStreamArray.h"
0014 #include "llvm/Support/BinaryStreamRef.h"
0015 #include "llvm/Support/Endian.h"
0016 #include "llvm/Support/Error.h"
0017 #include "llvm/Support/MathExtras.h"
0018 #include <cstdint>
0019 #include <memory>
0020 
0021 namespace llvm {
0022 
0023 class BinaryStreamWriter;
0024 
0025 namespace codeview {
0026 
0027 class DebugSubsection;
0028 
0029 // Corresponds to the `CV_DebugSSubsectionHeader_t` structure.
0030 struct DebugSubsectionHeader {
0031   support::ulittle32_t Kind;   // codeview::DebugSubsectionKind enum
0032   support::ulittle32_t Length; // number of bytes occupied by this record.
0033 };
0034 
0035 class DebugSubsectionRecord {
0036 public:
0037   DebugSubsectionRecord();
0038   DebugSubsectionRecord(DebugSubsectionKind Kind, BinaryStreamRef Data);
0039 
0040   static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info);
0041 
0042   uint32_t getRecordLength() const;
0043   DebugSubsectionKind kind() const;
0044   BinaryStreamRef getRecordData() const;
0045 
0046 private:
0047   DebugSubsectionKind Kind = DebugSubsectionKind::None;
0048   BinaryStreamRef Data;
0049 };
0050 
0051 class DebugSubsectionRecordBuilder {
0052 public:
0053   DebugSubsectionRecordBuilder(std::shared_ptr<DebugSubsection> Subsection);
0054 
0055   /// Use this to copy existing subsections directly from source to destination.
0056   /// For example, line table subsections in an object file only need to be
0057   /// relocated before being copied into the PDB.
0058   DebugSubsectionRecordBuilder(const DebugSubsectionRecord &Contents);
0059 
0060   uint32_t calculateSerializedLength() const;
0061   Error commit(BinaryStreamWriter &Writer, CodeViewContainer Container) const;
0062 
0063 private:
0064   /// The subsection to build. Will be null if Contents is non-empty.
0065   std::shared_ptr<DebugSubsection> Subsection;
0066 
0067   /// The bytes of the subsection. Only non-empty if Subsection is null.
0068   /// FIXME: Reduce the size of this.
0069   DebugSubsectionRecord Contents;
0070 };
0071 
0072 } // end namespace codeview
0073 
0074 template <> struct VarStreamArrayExtractor<codeview::DebugSubsectionRecord> {
0075   Error operator()(BinaryStreamRef Stream, uint32_t &Length,
0076                    codeview::DebugSubsectionRecord &Info) {
0077     // FIXME: We need to pass the container type through to this function.  In
0078     // practice this isn't super important since the subsection header describes
0079     // its length and we can just skip it.  It's more important when writing.
0080     if (auto EC = codeview::DebugSubsectionRecord::initialize(Stream, Info))
0081       return EC;
0082     Length = alignTo(Info.getRecordLength(), 4);
0083     return Error::success();
0084   }
0085 };
0086 
0087 namespace codeview {
0088 
0089 using DebugSubsectionArray = VarStreamArray<DebugSubsectionRecord>;
0090 
0091 } // end namespace codeview
0092 
0093 } // end namespace llvm
0094 
0095 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONRECORD_H