Home | History | Annotate | Download | only in CodeView
      1 //===- ModuleSubstream.h ----------------------------------------*- C++ -*-===//
      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 #ifndef LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
     11 #define LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
     12 
     13 #include "llvm/DebugInfo/CodeView/CodeView.h"
     14 #include "llvm/DebugInfo/CodeView/StreamArray.h"
     15 #include "llvm/DebugInfo/CodeView/StreamRef.h"
     16 #include "llvm/Support/Endian.h"
     17 #include "llvm/Support/Error.h"
     18 
     19 namespace llvm {
     20 namespace codeview {
     21 
     22 // Corresponds to the `CV_DebugSSubsectionHeader_t` structure.
     23 struct ModuleSubsectionHeader {
     24   support::ulittle32_t Kind;   // codeview::ModuleSubstreamKind enum
     25   support::ulittle32_t Length; // number of bytes occupied by this record.
     26 };
     27 
     28 // Corresponds to the `CV_DebugSLinesHeader_t` structure.
     29 struct LineSubstreamHeader {
     30   support::ulittle32_t RelocOffset;  // Code offset of line contribution.
     31   support::ulittle16_t RelocSegment; // Code segment of line contribution.
     32   support::ulittle16_t Flags;        // See LineFlags enumeration.
     33   support::ulittle32_t CodeSize;     // Code size of this line contribution.
     34 };
     35 
     36 // Corresponds to the `CV_DebugSLinesFileBlockHeader_t` structure.
     37 struct LineFileBlockHeader {
     38   support::ulittle32_t NameIndex; // Index in DBI name buffer of filename.
     39   support::ulittle32_t NumLines;  // Number of lines
     40   support::ulittle32_t BlockSize; // Code size of block, in bytes.
     41   // The following two variable length arrays appear immediately after the
     42   // header.  The structure definitions follow.
     43   // LineNumberEntry   Lines[NumLines];
     44   // ColumnNumberEntry Columns[NumLines];
     45 };
     46 
     47 // Corresponds to `CV_Line_t` structure
     48 struct LineNumberEntry {
     49   support::ulittle32_t Offset; // Offset to start of code bytes for line number
     50   support::ulittle32_t Flags;  // Start:24, End:7, IsStatement:1
     51 };
     52 
     53 // Corresponds to `CV_Column_t` structure
     54 struct ColumnNumberEntry {
     55   support::ulittle16_t StartColumn;
     56   support::ulittle16_t EndColumn;
     57 };
     58 
     59 class ModuleSubstream {
     60 public:
     61   ModuleSubstream();
     62   ModuleSubstream(ModuleSubstreamKind Kind, StreamRef Data);
     63   static Error initialize(StreamRef Stream, ModuleSubstream &Info);
     64   uint32_t getRecordLength() const;
     65   ModuleSubstreamKind getSubstreamKind() const;
     66   StreamRef getRecordData() const;
     67 
     68 private:
     69   ModuleSubstreamKind Kind;
     70   StreamRef Data;
     71 };
     72 
     73 template <> struct VarStreamArrayExtractor<ModuleSubstream> {
     74   Error operator()(StreamRef Stream, uint32_t &Length,
     75                    ModuleSubstream &Info) const {
     76     if (auto EC = ModuleSubstream::initialize(Stream, Info))
     77       return EC;
     78     Length = Info.getRecordLength();
     79     return Error::success();
     80   }
     81 };
     82 
     83 typedef VarStreamArray<ModuleSubstream> ModuleSubstreamArray;
     84 }
     85 }
     86 
     87 #endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
     88