/// <summary> /// Deserializes a trace entry from the given binary reader (the type byte is assumed have been read already). /// </summary> /// <typeparam name="T">Trace entry type.</typeparam> /// <param name="reader">Binary reader containing the trace data.</param> /// <returns></returns> private static T Deserialize <T>(FastBinaryReader reader) where T : TraceEntry, new() { var traceEntry = new T(); traceEntry.Init(reader); return(traceEntry); }
/// <summary> /// Deserializes an entire trace entry from the given binary reader. /// </summary> /// <typeparam name="T">Trace entry type.</typeparam> /// <param name="reader">Binary reader containing the trace data.</param> /// <returns></returns> public static TraceEntry DeserializeNextEntry(FastBinaryReader reader) { // Read depending on type TraceEntryTypes entryType = (TraceEntryTypes)reader.ReadByte(); switch (entryType) { case TraceEntryTypes.ImageMemoryAccess: return(Deserialize <Microwalk.TraceEntryTypes.ImageMemoryAccess>(reader)); case TraceEntryTypes.HeapMemoryAccess: return(Deserialize <Microwalk.TraceEntryTypes.HeapMemoryAccess>(reader)); case TraceEntryTypes.StackMemoryAccess: return(Deserialize <Microwalk.TraceEntryTypes.StackMemoryAccess>(reader)); case TraceEntryTypes.Allocation: return(Deserialize <Microwalk.TraceEntryTypes.Allocation>(reader)); case TraceEntryTypes.Free: return(Deserialize <Microwalk.TraceEntryTypes.Free>(reader)); case TraceEntryTypes.Branch: return(Deserialize <Microwalk.TraceEntryTypes.Branch>(reader)); default: throw new TraceFormatException($"Unknown trace entry type."); } }
/// <summary> /// Reads the image data from the given stream. /// </summary> /// <param name="reader">Binary stream reader.</param> public ImageFileInfo(FastBinaryReader reader) { Id = reader.ReadInt32(); StartAddress = reader.ReadUInt64(); EndAddress = reader.ReadUInt64(); int nameLength = reader.ReadInt32(); Name = reader.ReadString(nameLength); Interesting = reader.ReadBoolean(); }
/// <summary> /// Loads a trace prefix file. /// </summary> /// <param name="reader">Binary reader to read the trace prefix.</param> public TracePrefixFile(FastBinaryReader reader) : base(reader) { // Read image file information int imageFileCount = reader.ReadInt32(); ImageFiles = new Dictionary <int, ImageFileInfo>(); for (int i = 0; i < imageFileCount; ++i) { var imageFile = new ImageFileInfo(reader); ImageFiles.Add(imageFile.Id, imageFile); } }
/// <summary> /// Reads trace data. /// </summary> /// <param name="reader">Binary reader containing the trace data.</param> protected TraceFile(FastBinaryReader reader) { // Read entries int entryCount = reader.ReadInt32(); List <TraceEntry> entries = new List <TraceEntry>(entryCount); for (int i = 0; i < entryCount; ++i) { var entry = TraceEntry.DeserializeNextEntry(reader); if (entry.EntryType == TraceEntry.TraceEntryTypes.Allocation) { Allocations.Add(((TraceEntryTypes.Allocation)entry).Id, (TraceEntryTypes.Allocation)entry); } entries.Add(entry); } Entries = entries; }
/// <summary> /// Loads a trace prefix file from the given byte buffer. /// </summary> /// <param name="buffer">Buffer containing the trace data.</param> /// <param name="allocations">Optional. Allocation lookup table, indexed by IDs.</param> public TracePrefixFile(Memory <byte> buffer, Dictionary <int, Allocation> allocations = null) : base(allocations) { // Read image file information var reader = new FastBinaryReader(buffer); int imageFileCount = reader.ReadInt32(); ImageFiles = new Dictionary <int, ImageFileInfo>(); for (int i = 0; i < imageFileCount; ++i) { var imageFile = new ImageFileInfo(reader); ImageFiles.Add(imageFile.Id, imageFile); } // Set internal buffer _buffer = buffer.Slice(reader.Position); }
/// <summary> /// Reads trace data. /// </summary> /// <param name="prefix">The previously loaded prefix file.</param> /// <param name="reader">Binary reader containing the trace data.</param> public TraceFile(TracePrefixFile prefix, FastBinaryReader reader) : this(reader) { // Set prefix Prefix = prefix; }
public TraceFileEnumerator(Memory <byte> buffer) { _reader = new FastBinaryReader(buffer); Reset(); }
/// <summary> /// Initializes the trace entry from the given binary reader. /// </summary> /// <param name="reader">Binary reader containing the trace data.</param> protected abstract void Init(FastBinaryReader reader);