1 using System;
  2 using System.Collections;
  3 
  4 namespace cmsx.object
  5 {
  6     public enum DebugRecordCode : byte
  7     {
  8         fileInfo = 1ufunctionInfo = 2ulineInfo = 3ustartFunc = 4uendFunc = 5ubeginTry = 6uendTry = 7ucatch_ = 8ubeginCleanup = 9uendCleanup = 10uend = 11u
  9     }
 10 
 11     public const int maxDebugCodeStrLength = 12;
 12 
 13     public string DebugRecordCodeStr(DebugRecordCode debugRecordCode)
 14     {
 15         switch (debugRecordCode)
 16         {
 17             case DebugRecordCode.fileInfo:  return "FILEINFO";
 18             case DebugRecordCode.functionInfo: return "FUNCTIONINFO";
 19             case DebugRecordCode.lineInfo: return "LINEINFO";
 20             case DebugRecordCode.startFunc: return "STARTFUNC";
 21             case DebugRecordCode.endFunc: return "ENDFUNC";
 22             case DebugRecordCode.beginTry: return "BEGINTRY";
 23             case DebugRecordCode.endTry: return "ENDTRY";
 24             case DebugRecordCode.catch_: return "CATCH";
 25             case DebugRecordCode.beginCleanup: return "BEGINCLEANUP";
 26             case DebugRecordCode.endCleanup: return "ENDCLEANUP";
 27         }
 28         return "";
 29     }
 30 
 31     public class FunctionInfo
 32     {
 33         public nothrow FunctionInfo(uint functionSymbolIndex_const string& fullName_uint sourceFileNameId_uint frameSize_) : 
 34             functionSymbolIndex(functionSymbolIndex_)fullName(fullName_)sourceFileNameId(sourceFileNameId_)frameSize(frameSize_)
 35         {
 36         }
 37         public uint functionSymbolIndex;
 38         public string fullName;
 39         public uint sourceFileNameId;
 40         public uint frameSize;
 41     }
 42 
 43     public class LineInfo
 44     {
 45         public nothrow LineInfo(uint offset_uint lineNumber_) : offset(offset_)lineNumber(lineNumber_)
 46         {
 47         }
 48         public uint offset;
 49         public uint lineNumber;
 50     }
 51 
 52     public class FunctionTableEntry
 53     {
 54         public nothrow FunctionTableEntry(ulong start_ulong length_ulong mangledNameAddress_ulong fullNameAddress_ulong sourceFileNameAddress_
 55             ulong lineNumberTableStartAddress_ulong lineNumberTableEndAddress_ulong exceptionTableAddress_) : 
 56             start(start_)length(length_)mangledNameAddress(mangledNameAddress_)fullNameAddress(fullNameAddress_)sourceFileNameAddress(sourceFileNameAddress_)
 57             lineNumberTableStartAddress(lineNumberTableStartAddress_)lineNumberTableEndAddress(lineNumberTableEndAddress_)exceptionTableAddress(exceptionTableAddress_)
 58         {
 59         }
 60         public ulong start;
 61         public ulong length;
 62         public ulong mangledNameAddress;
 63         public ulong fullNameAddress;
 64         public ulong sourceFileNameAddress;
 65         public ulong lineNumberTableStartAddress;
 66         public ulong lineNumberTableEndAddress;
 67         public ulong exceptionTableAddress;
 68     }
 69 
 70     public bool operator==(const FunctionTableEntry& leftconst FunctionTableEntry& right)
 71     {
 72         return left.start == right.start;
 73     }
 74 
 75     public bool operator<(const FunctionTableEntry& leftconst FunctionTableEntry& right)
 76     {
 77         return left.start < right.start;
 78     }
 79 
 80     public class LineNumberTableLimits
 81     {
 82         public ulong startAddress;
 83         public ulong endAddress;
 84     }
 85 
 86     public class LineNumberTableEntry
 87     {
 88         public nothrow LineNumberTableEntry(uint offset_uint lineNumber_) : offset(offset_)lineNumber(lineNumber_)
 89         {
 90         }
 91         public uint offset;
 92         public uint lineNumber;
 93     }
 94 
 95     public bool operator==(const LineNumberTableEntry& leftconst LineNumberTableEntry& right)
 96     {
 97         return left.offset == right.offset;
 98     }
 99 
100     public bool operator<(const LineNumberTableEntry& leftconst LineNumberTableEntry& right)
101     {
102         return left.offset < right.offset;
103     }
104 
105     public class ExceptionBlock
106     {
107         public nothrow ExceptionBlock(ulong discriminator_) : discriminator(discriminator_)
108         {
109         }
110         public virtual default ~ExceptionBlock();
111         public ulong discriminator;
112     }
113 
114     public const ulong endBlockDiscriminator = 0u;
115     public const ulong handlerBlockDiscriminator = 1u;
116     public const ulong cleanupBlockDiscriminator = 2u;
117 
118     public class HandlerBlock : ExceptionBlock
119     {
120         public nothrow HandlerBlock(ulong catchedClassId_ulong handlerAddress_) : base(handlerBlockDiscriminator)catchedClassId(catchedClassId_)handlerAddress(handlerAddress_)
121         {
122         }
123         public ulong catchedClassId;
124         public ulong handlerAddress;
125     }
126 
127     public class CleanupBlock : ExceptionBlock
128     {
129         public nothrow CleanupBlock(ulong cleanupAddress_ulong parentTableAddress_) : base(cleanupBlockDiscriminator)cleanupAddress(cleanupAddress_)parentTableAddress(parentTableAddress_)
130         {
131         }
132         public ulong cleanupAddress;
133         public ulong parentTableAddress;
134     }
135 
136     public class DispatchTableEntry
137     {
138         public nothrow DispatchTableEntry(uint offset_uint length_ulong exceptionBlockTableAddress_DispatchBlock* dispatchBlock_) : 
139             offset(offset_)length(length_)exceptionBlockTableAddress(exceptionBlockTableAddress_)dispatchBlock(dispatchBlock_)
140         {
141         }
142         public uint offset;
143         public uint length;
144         public ulong exceptionBlockTableAddress;
145         public DispatchBlock* dispatchBlock;
146     }
147 
148     public bool operator==(const DispatchTableEntry& leftconst DispatchTableEntry& right)
149     {
150         return left.offset == right.offset;
151     }
152 
153     public bool operator<(const DispatchTableEntry& leftconst DispatchTableEntry& right)
154     {
155         return left.offset < right.offset;
156     }
157 
158     public class FunctionExceptionData
159     {
160         public nothrow FunctionExceptionData() : functionName()tryBlocks()cleanupDispatchBlocks()
161         {
162         }
163         public TryBlock* GetTryBlock(uint tryBlockId) const
164         {
165             for (const TryBlock& tryBlock : tryBlocks)
166             {
167                 if (tryBlock.id == tryBlockId) return &tryBlock;
168             }
169             return null;
170         }
171         public CleanupDispatchBlock* GetOpenCleanupDispatchBlock(uint cleanupBlockId) const
172         {
173             for (const CleanupDispatchBlock& cleanupDispatchBlock : cleanupDispatchBlocks)
174             {
175                 if (cleanupDispatchBlock.id == cleanupBlockId && cleanupDispatchBlock.length == 0u) return &cleanupDispatchBlock;
176             }
177             return null;
178         }
179         public nothrow bool IsEmpty() const
180         {
181             return tryBlocks.IsEmpty() && cleanupDispatchBlocks.IsEmpty();
182         }
183         public string functionName;
184         public uint frameSize;
185         public List<TryBlock> tryBlocks;
186         public List<CleanupDispatchBlock> cleanupDispatchBlocks;
187     }
188 
189     public abstract class DispatchBlock
190     {
191         public virtual default ~DispatchBlock();
192     }
193 
194     public class TryBlock : DispatchBlock
195     {
196         public nothrow TryBlock(uint id_uint parentId_uint offset_) : id(id_)parentId(parentId_)offset(offset_)length(0u)exceptionBlockTableAddress(0u)
197         {
198         }
199         public uint id;
200         public uint parentId;
201         public uint offset;
202         public uint length;
203         public List<HandlerBlock> handlerBlocks;
204         public ulong exceptionBlockTableAddress;
205     }
206 
207     public class CleanupDispatchBlock : DispatchBlock
208     {
209         public nothrow CleanupDispatchBlock(uint id_TryBlock* tryBlock_uint offset_) : id(id_)tryBlock(tryBlock_)offset(offset_)length(0u)
210         {
211         }
212         public uint id;
213         public uint offset;
214         public uint length;
215         public CleanupBlock cleanupBlock;
216         public TryBlock* tryBlock;
217     }
218 }