/// <summary> /// Gets the string representation of the collection - dump of all indexes and theirs data. /// </summary> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <returns>String representation of the collection.</returns> internal string GetRepresentation(SnapshotData data, SnapshotData infos) { StringBuilder result = new StringBuilder(); GetRepresentation(data, infos, result); return(result.ToString()); }
/// <summary> /// Creates new data instance and copies data from this collection to the new one. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <returns>New data instance and copies data from this collection to the new one.</returns> public SnapshotData Copy(Snapshot snapshot) { SnapshotData data = new SnapshotData(snapshot); data.IndexData = new Dictionary <MemoryIndex, MemoryEntry>(IndexData); return(data); }
/// <summary> /// Creates the new data instance empty collection with no data. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <returns>New data instance empty collection with no data.</returns> public static SnapshotData CreateEmpty(Snapshot snapshot) { SnapshotData data = new SnapshotData(snapshot); data.IndexData = new Dictionary <MemoryIndex, MemoryEntry>(); return(data); }
/// <summary> /// Gets the string representation of local level of stack. /// </summary> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <returns>String representation of local variables.</returns> internal string GetLocalRepresentation(SnapshotData data, SnapshotData infos) { StringBuilder result = new StringBuilder(); for (int x = 1; x < stack.Length; x++) { stack[x].GetRepresentation(data, infos, result); } return(result.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="MergeWorker"/> class. /// </summary> /// <param name="targetSnapshot">The target snapshot.</param> /// <param name="sourceSnapshots">The source snapshots.</param> /// <param name="isCallMerge">if set to <c>true</c> [is call merge].</param> public MergeWorker(Snapshot targetSnapshot, List <Snapshot> sourceSnapshots, bool isCallMerge = false) { Data = SnapshotData.CreateEmpty(targetSnapshot); Structure = SnapshotStructure.CreateEmpty(targetSnapshot); Structure.Data = Data; this.targetSnapshot = targetSnapshot; this.sourceSnapshots = sourceSnapshots; this.isCallMerge = isCallMerge; }
/// <summary> /// Gets the string representation of the collection - dump of all indexes and theirs data. /// </summary> /// <param name="container">The container.</param> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <param name="result">The result.</param> internal static void GetRepresentation(ReadonlyIndexContainer container, SnapshotData data, SnapshotData infos, StringBuilder result) { GetIndexRepresentation(container.UnknownIndex, data, infos, result); foreach (var item in container.Indexes) { MemoryIndex index = item.Value; GetIndexRepresentation(index, data, infos, result); } }
/// <summary> /// Initializes a new instance of the <see cref="MergeInfoWorker"/> class. /// </summary> /// <param name="targetSnapshot">The target snapshot.</param> /// <param name="sourceSnapshots">The source snapshots.</param> /// <param name="isCallMerge">if set to <c>true</c> [is call merge].</param> public MergeInfoWorker(Snapshot targetSnapshot, List <Snapshot> sourceSnapshots, bool isCallMerge = false) { Infos = SnapshotData.CreateEmpty(targetSnapshot); Structure = targetSnapshot.Structure; Structure.Data = Infos; Structure.Locked = true; this.targetSnapshot = targetSnapshot; this.sourceSnapshots = sourceSnapshots; this.isCallMerge = isCallMerge; }
/// <summary> /// Gets string representation of all objects and fields in memory model. /// </summary> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <returns>String representation of all objects and fields in memory model.</returns> internal string GetFieldsRepresentation(SnapshotData data, SnapshotData infos) { StringBuilder result = new StringBuilder(); foreach (var item in ObjectDescriptors) { IndexContainer.GetRepresentation(item.Value, data, infos, result); result.AppendLine(); } return(result.ToString()); }
/// <summary> /// Widens the data of given memory index in this data container. /// </summary> /// <param name="oldData">The old data.</param> /// <param name="index">The index.</param> /// <param name="assistant">The assistant.</param> public void DataWiden(SnapshotData oldData, MemoryIndex index, MemoryAssistantBase assistant) { MemoryEntry newEntry = null; if (!this.IndexData.TryGetValue(index, out newEntry)) { newEntry = EmptyEntry; } MemoryEntry oldEntry = null; if (!oldData.IndexData.TryGetValue(index, out oldEntry)) { oldEntry = EmptyEntry; } MemoryIndex testIndex = ControlIndex.Create(".return", 6); if (testIndex.Equals(index)) { } if (!oldEntry.Equals(newEntry)) { MemoryEntry widenedEntry = assistant.Widen(oldEntry, newEntry); CollectComposedValuesVisitor newVisitor = new CollectComposedValuesVisitor(); newVisitor.VisitMemoryEntry(newEntry); CollectComposedValuesVisitor widenedVisitor = new CollectComposedValuesVisitor(); widenedVisitor.VisitMemoryEntry(widenedEntry); if (newVisitor.Arrays.Count != widenedVisitor.Arrays.Count) { snapshot.DestroyArray(index); } if (newVisitor.Objects.Count != widenedVisitor.Objects.Count) { snapshot.Structure.SetObjects(index, null); } SetMemoryEntry(index, assistant.Widen(oldEntry, new MemoryEntry(widenedVisitor.Values))); } }
/// <summary> /// Compares data of single memory index within this and given data container. /// </summary> /// <param name="oldData">The old data.</param> /// <param name="index">The index.</param> /// <returns>True whether compared data are the same.</returns> public bool DataEquals(SnapshotData oldData, MemoryIndex index) { MemoryEntry newEntry = null; if (!this.IndexData.TryGetValue(index, out newEntry)) { newEntry = EmptyEntry; } MemoryEntry oldEntry = null; if (!oldData.IndexData.TryGetValue(index, out oldEntry)) { oldEntry = EmptyEntry; } return(oldEntry.Equals(newEntry)); }
/// <summary> /// Gets the string representation of the collection - dump of all indexes and theirs data. /// </summary> /// <param name="index">The index.</param> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <param name="result">The result.</param> internal static void GetIndexRepresentation(MemoryIndex index, SnapshotData data, SnapshotData infos, StringBuilder result) { result.AppendFormat("{0}: {{ ", index); MemoryEntry dataEntry, infoEntry; if (data.TryGetMemoryEntry(index, out dataEntry)) { result.Append(dataEntry.ToString()); } if (infos.TryGetMemoryEntry(index, out infoEntry)) { result.Append(" INFO: "); result.Append(infoEntry.ToString()); } result.AppendLine(" }"); }
/// <summary> /// Simplifies memory entries which is bigget than simplify limit and compares data of this data collection object with the given one. /// </summary> /// <param name="oldData">The old data.</param> /// <param name="simplifyLimit">The simplify limit.</param> /// <param name="assistant">The assistant.</param> /// <returns>True whether compared data are the same.</returns> public bool DataEqualsAndSimplify(SnapshotData oldData, int simplifyLimit, MemoryAssistantBase assistant) { bool areEquals = true; HashSet <MemoryIndex> indexes = new HashSet <MemoryIndex>(); HashSetTools.AddAll(indexes, this.IndexData.Keys); HashSetTools.AddAll(indexes, oldData.IndexData.Keys); foreach (MemoryIndex index in indexes) { if (!DataEqualsAndSimplify(oldData, index, simplifyLimit, assistant)) { areEquals = false; } } return(areEquals); }
/// <summary> /// Creates new structure object as copy of this structure which contains the same data as this instace. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <param name="snapshotData">The snapshot data.</param> /// <returns>New copy of this structure which contains the same data as this instace.</returns> public SnapshotStructure Copy(Snapshot snapshot, SnapshotData snapshotData) { SnapshotStructure data = new SnapshotStructure(snapshot); data.Data = snapshotData; data.ArrayDescriptors = new Dictionary <AssociativeArray, ArrayDescriptor>(ArrayDescriptors); data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>(ObjectDescriptors); data.IndexData = new Dictionary <MemoryIndex, IndexData>(IndexData); data.FunctionDecl = new DeclarationContainer <FunctionValue>(FunctionDecl); data.ClassDecl = new DeclarationContainer <TypeValue>(ClassDecl); data.Variables = new VariableStack(Variables); data.ContolVariables = new VariableStack(ContolVariables); data.Temporary = new MemoryStack <IndexSet <TemporaryIndex> >(Temporary); data.Arrays = new MemoryStack <IndexSet <AssociativeArray> >(Arrays); data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >(CallArrays); return(data); }
/// <summary> /// Creates new structure object as copy of this structure and adds new local level into memory stacks. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <param name="snapshotData">The snapshot data.</param> /// <returns>New copy of this structure and adds new local level into memory stacks.</returns> public SnapshotStructure CopyAndAddLocalLevel(Snapshot snapshot, SnapshotData snapshotData) { SnapshotStructure data = new SnapshotStructure(snapshot); data.Data = snapshotData; data.ArrayDescriptors = new Dictionary <AssociativeArray, ArrayDescriptor>(ArrayDescriptors); data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>(ObjectDescriptors); data.IndexData = new Dictionary <MemoryIndex, IndexData>(IndexData); data.FunctionDecl = new DeclarationContainer <FunctionValue>(FunctionDecl); data.ClassDecl = new DeclarationContainer <TypeValue>(ClassDecl); data.Variables = new VariableStack(Variables, data.createIndexContainer(VariableIndex.CreateUnknown(Variables.Length))); data.ContolVariables = new VariableStack(ContolVariables, data.createIndexContainer(ControlIndex.CreateUnknown(ContolVariables.Length))); data.Temporary = new MemoryStack <IndexSet <TemporaryIndex> >(Temporary, new IndexSet <TemporaryIndex>()); data.Arrays = new MemoryStack <IndexSet <AssociativeArray> >(Arrays, new IndexSet <AssociativeArray>()); data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >(CallArrays); return(data); }
/// <summary> /// Creates the structure with memory stack with global level only. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <param name="snapshotData">The snapshot data.</param> /// <returns>New structure with memory stack with global level only.</returns> public static SnapshotStructure CreateGlobal(Snapshot snapshot, SnapshotData snapshotData) { SnapshotStructure data = new SnapshotStructure(snapshot); data.Data = snapshotData; data.ArrayDescriptors = new Dictionary <AssociativeArray, ArrayDescriptor>(); data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>(); data.IndexData = new Dictionary <MemoryIndex, IndexData>(); data.Variables = data.createMemoryStack(VariableIndex.CreateUnknown(Snapshot.GLOBAL_CALL_LEVEL)); data.ContolVariables = data.createMemoryStack(ControlIndex.CreateUnknown(Snapshot.GLOBAL_CALL_LEVEL)); data.FunctionDecl = new DeclarationContainer <FunctionValue>(); data.ClassDecl = new DeclarationContainer <TypeValue>(); data.Temporary = new MemoryStack <IndexSet <TemporaryIndex> >(new IndexSet <TemporaryIndex>()); data.Arrays = new MemoryStack <IndexSet <AssociativeArray> >(new IndexSet <AssociativeArray>()); data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >(); return(data); }
/// <summary> /// Compares data of this data collection object with the given one. /// </summary> /// <param name="oldData">The old data.</param> /// <returns>True whether compared data are the same.</returns> public bool DataEquals(SnapshotData oldData) { if (this.IndexData.Count != oldData.IndexData.Count) { return(false); } HashSet <MemoryIndex> indexes = new HashSet <MemoryIndex>(); HashSetTools.AddAll(indexes, this.IndexData.Keys); HashSetTools.AddAll(indexes, oldData.IndexData.Keys); foreach (MemoryIndex index in indexes) { if (!DataEquals(oldData, index)) { return(false); } } return(true); }
/// <summary> /// Simplify data of single memory index if exceeds given simplify limit and compares it with the data inside given data container. /// </summary> /// <param name="oldData">The old data.</param> /// <param name="index">The index.</param> /// <param name="simplifyLimit">The simplify limit.</param> /// <param name="assistant">The assistant.</param> /// <returns>True whether compared data are the same.</returns> public bool DataEqualsAndSimplify(SnapshotData oldData, MemoryIndex index, int simplifyLimit, MemoryAssistantBase assistant) { MemoryEntry newEntry = null; if (!this.IndexData.TryGetValue(index, out newEntry)) { newEntry = EmptyEntry; } MemoryEntry oldEntry = null; if (!oldData.IndexData.TryGetValue(index, out oldEntry)) { oldEntry = EmptyEntry; } if (oldEntry.Equals(newEntry)) { return(true); } else if (newEntry.Count > simplifyLimit) { MemoryIndex testIndex = ControlIndex.Create(".return", 6); if (testIndex.Equals(index)) { } MemoryEntry simplifiedEntry = assistant.Simplify(newEntry); SetMemoryEntry(index, simplifiedEntry); return(oldEntry.Equals(simplifiedEntry)); } else { return(false); } }
/// <summary> /// Gets the string representation of the collection - dump of all indexes and theirs data. /// </summary> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <param name="result">The result.</param> internal void GetRepresentation(SnapshotData data, SnapshotData infos, StringBuilder result) { GetRepresentation(this, data, infos, result); }
/// <summary> /// Gets the string representation of global level of stack. /// </summary> /// <param name="data">The data.</param> /// <param name="infos">The infos.</param> /// <returns>String representation of global variables.</returns> internal string GetGlobalRepresentation(SnapshotData data, SnapshotData infos) { return(Global.GetRepresentation(data, infos)); }