public override void FrameDisposed(int frameId, PexTrackingFrame frame) { Dump("in FrameDisposed====================="); Dump("frameId: " + frameId + " frame.method: " + frame.Method); Dump("end FrameDisposed====================="); Dump(""); methodStack.Pop(); }
private void processResult(PexTrackingFrame frame, Field f, TypeEx type, Term fieldValue) { //below handles non-array-type fields this.owner.FieldAccessObserver.AddResult( frame.Method, f, noIndices, fieldValue); }
private void processArrayResult(PexTrackingFrame frame, Field f, TypeEx type, Term initialElementValue, Term fieldValue, Term initialValue) { //below handles array-type fields if (type.Spec == TypeSpec.SzArray && //is array !this.TermManager.IsDefaultValue(fieldValue)) //is not null pointer { Term index = this.TermManager.Symbol(SzArrayIndexId.Instance); Term elementValue = frame.Thread.State.ReadSzArrayElement(type.ElementType.Layout, fieldValue, index); if (elementValue != initialElementValue) { this.explorationObserver.HandleMonitoredField( frame.Method, f, new Term[] { index }, this.TermManager.Widen(elementValue, type.ElementType.StackWidening), initialValue); //some complicated trick, no need to know } } }
public override void FrameDisposed(int frameId, PexTrackingFrame frame) { IThread thread = frame.Thread; IFrame caller = thread.CurrentFrame; Term[] arguments; //Tao's TODO add also reciever/argument object fields **read** by the method //Tao's TODO can we handle recurstive fields being accessed? if (frameId == trackedFrameId) { this.framesHandled++; if (caller != null && caller.IsCallInProgress) { // add instance field results TypeEx declaringType; if (frame.Method.TryGetDeclaringType(out declaringType)) { //we add the method in our database even if it doesn't write fields since //we want to know whether a mehtod is ever encountered or a method doesn't write any field this.owner.FieldAccessObserver.AddMonitoredMethod(frame.Method); /* * foreach (var f in declaringType.DeclaredStaticFields) * { * Term fieldValue = thread.State.ReadStaticField(f);//read the constraints of the final symbolic state after method execution * if (fieldValue != TermManager.Symbol(new PexTrackedStaticFieldId(f)))//filter out select(size, this) * processResult(frame, f, f.Type, fieldValue); * processArrayResult(frame, f, f.Type, fieldValue); * } */ Term[] initialFieldValues; Term[] initialFieldArrayValues; if (this.initialFieldValues.TryGetValue(frameId, out initialFieldValues) && this.initialFieldArrayValues.TryGetValue(frameId, out initialFieldArrayValues)) { Term receiver = frame.ReadArgument(0); var instanceFields = declaringType.InstanceFields; for (int i = 0; i < instanceFields.Length; i++) { var f = instanceFields[i]; Term fieldValue = thread.State.ReadObjectField(receiver, f); //read the constraints of the final symbolic state after method execution if (fieldValue != initialFieldValues[i]) //filter out select(size, this) { processResult(frame, f, f.Type, fieldValue); } if (initialFieldArrayValues[i] != null) { processArrayResult(frame, f, f.Type, initialFieldArrayValues[i], fieldValue); } } } //Tao's TODO add also **argument** object fields written by the method /* * TypeEx[] argumentTypes = frame.ArgumentTypes; * int argumentNum = argumentTypes.Length; * int argumentStartIndex = 0; * if (!frame.Method.IsStatic) * argumentStartIndex = 1; * for (int argumentIndex = argumentStartIndex; argumentIndex < argumentNum; argumentIndex++) * { * Term argument = frame.ReadArgument(argumentIndex); * //Note: the following line won't work when the argument declared argument types are different from the actual runtime argument types * foreach (var f in argumentTypes[argumentIndex].InstanceFields) * { * Term fieldValue = thread.State.ReadObjectField(argument, f); * processResult(frame, f, f.Type, fieldValue, argumentTypes[argumentIndex]); * } * } **/ } } IState state = thread.State; state.EndTrackingEffects(); this.trackedFrameId = -1; } this.methodsOnStack.Remove(frame.Method); this.depth = this.oldDepths[frameId]; // this should just decrement depth, but in a more robust way }
private void processArrayResult(PexTrackingFrame frame, Field f, TypeEx type, Term initialElementValue, Term fieldValue, Term initialValue) { //below handles array-type fields if (type.Spec == TypeSpec.SzArray &&//is array !this.TermManager.IsDefaultValue(fieldValue))//is not null pointer { Term index = this.TermManager.Symbol(SzArrayIndexId.Instance); Term elementValue = frame.Thread.State.ReadSzArrayElement(type.ElementType.Layout, fieldValue, index); if (elementValue != initialElementValue) this.explorationObserver.HandleMonitoredField( frame.Method, f, new Term[] { index }, this.TermManager.Widen(elementValue, type.ElementType.StackWidening), initialValue); //some complicated trick, no need to know } }
public override void FrameDisposed(int frameId, PexTrackingFrame frame) { IThread thread = frame.Thread; IFrame caller = thread.CurrentFrame; //Term[] arguments; //Tao's TODO add also reciever/argument object fields **read** by the method //Tao's TODO can we handle recurstive fields being accessed? if (frameId == trackedFrameId) { this.framesHandled++; if (caller != null && caller.IsCallInProgress) { // add instance field results TypeEx declaringType; if (frame.Method.TryGetDeclaringType(out declaringType)) { //we add the method in our database even if it doesn't write fields since //we want to know whether a mehtod is ever encountered or a method doesn't write any field this.pmd.AddMonitoredMethod(frame.Method); /* foreach (var f in declaringType.DeclaredStaticFields) { Term fieldValue = thread.State.ReadStaticField(f);//read the constraints of the final symbolic state after method execution if (fieldValue != TermManager.Symbol(new PexTrackedStaticFieldId(f)))//filter out select(size, this) processResult(frame, f, f.Type, fieldValue); processArrayResult(frame, f, f.Type, fieldValue); } */ Term[] initialFieldValues; Term[] initialFieldArrayValues; if (this.initialFieldValues.TryGetValue(frameId, out initialFieldValues) && this.initialFieldArrayValues.TryGetValue(frameId, out initialFieldArrayValues)) { Term receiver = frame.ReadArgument(0); var instanceFields = declaringType.InstanceFields; for (int i = 0; i < instanceFields.Length; i++) { var f = instanceFields[i]; Term fieldValue = thread.State.ReadObjectField(receiver, f);//read the constraints of the final symbolic state after method execution if (fieldValue != initialFieldValues[i])//filter out select(size, this) this.explorationObserver.HandleMonitoredField(frame.Method, f, noIndices, fieldValue, initialFieldArrayValues[i]); if (initialFieldArrayValues[i] != null) processArrayResult(frame, f, f.Type, initialFieldArrayValues[i], fieldValue, null); } } //Tao's TODO add also **argument** object fields written by the method /* TypeEx[] argumentTypes = frame.ArgumentTypes; int argumentNum = argumentTypes.Length; int argumentStartIndex = 0; if (!frame.Method.IsStatic) argumentStartIndex = 1; for (int argumentIndex = argumentStartIndex; argumentIndex < argumentNum; argumentIndex++) { Term argument = frame.ReadArgument(argumentIndex); //Note: the following line won't work when the argument declared argument types are different from the actual runtime argument types foreach (var f in argumentTypes[argumentIndex].InstanceFields) { Term fieldValue = thread.State.ReadObjectField(argument, f); processResult(frame, f, f.Type, fieldValue, argumentTypes[argumentIndex]); } } **/ } //Adding caller/calling mapping relationship pmd.AddMethodMapping(caller.Method, frame.Method); } IState state = thread.State; state.EndTrackingEffects(); this.trackedFrameId = -1; } this.methodsOnStack.Remove(frame.Method); this.depth = this.oldDepths[frameId]; // this should just decrement depth, but in a more robust way }