Ejemplo n.º 1
0
 public JsonResult CreateWorkPiece(long wId, long pId, string Name, string Title, string Definition)
 {
     try
     {
         using (business.Management.WorkManagement.WorkFunctions wm = new business.Management.WorkManagement.WorkFunctions())
         {
             WorkList newWPiece = new WorkList
             {
                 Name          = Name,
                 Title         = Title,
                 Definition    = Definition,
                 Register_Date = DateTime.Now,
                 State         = "Çalışılıyor",
                 Status        = true,
                 WLpersonalId  = pId
             };
             wm.addWorkPiece(newWPiece, wId);
             return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception)
     {
         return(Json(new { result = false }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 2
0
        public static bool ModifyWorkList(WorkList model)
        {
            string sql = string.Format(@"update {0} set [ProjectId]=@ProjectId,[ProjectName]=@ProjectName,[CompanyId]=@CompanyId,[CompanyName]=@CompanyName,[CusMemberId]=@CusMemberId,[CusCompanyId]=@CusCompanyId,[Name]=@Name,[Infos]=@Infos,[GetTime]=@GetTime,[NeedTime]=@NeedTime,[DoTime]=@DoTime,[UserId]=@UserId,[UserName]=@UserName,[Status]=@Status,[Length]=@Length,[IsDeleted]=@IsDeleted,[ModifyDate]=getdate(),[ModifyBy]=@ModifyBy
            where Id=@Id", TableName);

            return(DBAccess.ExecuteSqlWithEntity(sql, model));
        }
Ejemplo n.º 3
0
        public void Transform()
        {
            SetInitialValues();
            var wl = new WorkList <SsaIdentifier>();

            wl.AddRange(ssa.Identifiers);
            while (wl.TryGetWorkItem(out var sid) && !listener.IsCanceled())
            {
                var oldValue = ctx.GetValue(sid.Identifier);
                if (oldValue is InvalidConstant)
                {
                    continue;
                }

                var newValue = Evaluate(sid);
                if (!cmp.Equals(oldValue, newValue))
                {
                    ctx.SetValue(sid.Identifier, newValue);
                    foreach (var use in sid.Uses)
                    {
                        var uc   = new InstructionUseCollector();
                        var uses = uc.CollectUses(use);
                        wl.AddRange(uses.Keys.Select(id => ssa.Identifiers[id]));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static bool DeleteWorkList(WorkList model)
        {
            string sql = string.Format(@"update {0} set [ModifyDate]=getdate(),[ModifyBy]=@ModifyBy,[IsDeleted]=@IsDeleted
            where Id=@Id", TableName);

            return(DBAccess.ExecuteSqlWithEntity(sql, model));
        }
Ejemplo n.º 5
0
        public async Task PrepareWorkList()
        {
            if (WorkListLoaded)
            {
                return;
            }
            List <Work> list = Model.GetWorkList(CourseId);

            WorkList.Clear();
            foreach (Work work in list)
            {
                WorkList.Add(new WorkVM(work));
            }

            string id = CourseId;

            if (await Model.RefWorkList(CourseId) == MainModel.UpdateResult.Success)
            {
                if (id == CourseId)
                {
                    WorkList.Clear();
                    foreach (Work work in list)
                    {
                        WorkList.Add(new WorkVM(work));
                    }
                }
            }
            WorkListLoaded = true;
            RaisePropertyChanged("WorkList");
        }
Ejemplo n.º 6
0
 public bool Edit(int?id, string name)
 {
     if (id.HasValue && id != 0)
     {
         var list = dc.WorkLists.Where(w => w.WorkListId == id).SingleOrDefault();
         list.Name = name;
         dc.SaveChanges();
     }
     else
     {
         dc.WorkLists.Where(l => l.IsActive).ToList().ForEach(l =>
         {
             l.IsActive = false;
         });
         var      userID = User.Identity.GetUserId();
         var      _user  = dc.Users.Where(u => u.Id == userID).SingleOrDefault();
         WorkList wl     = new WorkList
         {
             IsActive = true,
             Name     = name,
             Date     = DateTime.Now,
             User     = _user
         };
         dc.WorkLists.Add(wl);
         dc.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 7
0
        private static void EvaluateDebuggerDisplayStringAndContinue(
            DkmClrValue value,
            WorkList workList,
            DkmInspectionContext inspectionContext,
            DkmClrType targetType,
            string str,
            CompletionRoutine <DkmEvaluateDebuggerDisplayStringAsyncResult> onCompleted,
            CompletionRoutine <Exception> onException)
        {
            DkmCompletionRoutine <DkmEvaluateDebuggerDisplayStringAsyncResult> completionRoutine =
                result =>
            {
                try
                {
                    onCompleted(result);
                }
                catch (Exception e)
                {
                    onException(e);
                }
            };

            if (str == null)
            {
                completionRoutine(default(DkmEvaluateDebuggerDisplayStringAsyncResult));
            }
            else
            {
                value.EvaluateDebuggerDisplayString(workList.InnerWorkList, inspectionContext, targetType, str, completionRoutine);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Asign index to work in worklist
 /// </summary>
 public void SetWorkIndex()
 {
     foreach (ISaveWork li in WorkList)
     {
         li.Index = WorkList.IndexOf(li);
     }
 }
Ejemplo n.º 9
0
        /// <summary> 生成 </summary>
        public T Spawn()
        {
            T unit = null;

            while (IdleList.Count > 0 && unit == null)
            {
                unit = IdleList[0];
                IdleList.RemoveAt(0);
            }

            if (unit == null)
            {
                unit = CreateNewUnit();
            }

            WorkList.Add(unit);
            OnBeforeSpawn(unit);

            IPoolable recyclable;

            if ((recyclable = unit as IPoolable) != null)
            {
                recyclable.OnSpawned();
            }
            OnAfterSpawn(unit);
            return(unit);
        }
Ejemplo n.º 10
0
        public JsonResult WorkListInfoEdit(string str, int projectId, string name, int id)
        {
            ResultInfo result    = new ResultInfo();
            var        account   = CookieOperate.AccountCookie;
            var        list      = JsonConvert.DeserializeObject <List <WorkListEdit> >(str);
            var        project   = ProjectManageDBOperate.GetModelById(projectId);
            var        cusMember = CustomerMemberDBOperate.GetModelById(account.AccountId);
            var        workList  = new WorkList()
            {
                ProjectId    = projectId,
                ProjectName  = project.Name,
                CompanyId    = CommonMethod.GetInt(ConfigSetting.eeeYoooId),
                CompanyName  = ConfigSetting.eeeYoooName,
                CusMemberId  = account.AccountId,
                CusCompanyId = cusMember.CusCompanyId,
                Name         = name,
                Id           = id,
                Status       = WorkListStatusEnum.NotStart.ToString(),
                Guid         = Guid.NewGuid().ToString(),
                CreateBy     = account.AccountName
            };
            var flag = WorkListBLL.AddWorkList(workList, list);

            if (flag)
            {
                result.Message = "操作成功"; result.IsSuccess = true;
            }
            else
            {
                result.Message = "操作成功";
            }
            return(Json(result));
        }
Ejemplo n.º 11
0
 void IDkmClrResultProvider.GetResult(DkmClrValue value, DkmWorkList workList, DkmClrType declaredType, DkmClrCustomTypeInfo declaredTypeInfo, DkmInspectionContext inspectionContext, ReadOnlyCollection<string> formatSpecifiers, string resultName, string resultFullName, DkmCompletionRoutine<DkmEvaluationAsyncResult> completionRoutine)
 {
     if (formatSpecifiers == null)
     {
         formatSpecifiers = Formatter.NoFormatSpecifiers;
     }
     if (resultFullName != null)
     {
         ReadOnlyCollection<string> otherSpecifiers;
         resultFullName = FullNameProvider.GetClrExpressionAndFormatSpecifiers(inspectionContext, resultFullName, out otherSpecifiers);
         foreach (var formatSpecifier in otherSpecifiers)
         {
             formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, formatSpecifier);
         }
     }
     var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationAsyncResult.CreateErrorResult(e)));
     wl.ContinueWith(
         () => GetRootResultAndContinue(
             value,
             wl,
             declaredType,
             declaredTypeInfo,
             inspectionContext,
             resultName,
             resultFullName,
             formatSpecifiers,
             result => wl.ContinueWith(() => completionRoutine(new DkmEvaluationAsyncResult(result)))));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Remove any storages in the ProcedureFlow <paramref name="flow"/> associated
        /// with the procedure <paramref name="proc"/> if they are dead.
        /// </summary>
        private bool RemoveLiveInStorages(Procedure proc, ProcedureFlow flow, WorkList <SsaState> wl)
        {
            var defs = proc.EntryBlock.Statements
                       .Select(s => s.Instruction as DefInstruction)
                       .Where(s => s != null)
                       .Select(s => s !.Identifier.Storage)
                       .ToHashSet();
            var  deadStgs = flow.BitsUsed.Keys.Except(defs).ToHashSet();
            bool changed  = false;

            foreach (var d in deadStgs)
            {
                flow.BitsUsed.Remove(d);
                changed = true;
            }
            if (changed)
            {
                foreach (Statement stm in program.CallGraph.CallerStatements(proc))
                {
                    if (!(stm.Instruction is CallInstruction ci))
                    {
                        continue;
                    }
                    var ssaCaller = this.procToSsa[stm.Block.Procedure];
                    if (RemoveDeadCallUses(ssaCaller, stm, ci, deadStgs))
                    {
                        wl.Add(ssaCaller);
                    }
                }
            }
            return(changed);
        }
Ejemplo n.º 13
0
        public override Dictionary <string, IDictionary <Address, IAddressable> > GetObjectPlacements(string fileExtension, DecompilerEventListener listener)
        {
            this.defaultFile     = Path.ChangeExtension(program.Name, fileExtension);
            this.defaultDataFile = Path.ChangeExtension(program.Name, "globals" + fileExtension);

            // Find the segment for each procedure
            var result = new Dictionary <string, IDictionary <Address, IAddressable> >();

            foreach (var proc in program.Procedures.Values)
            {
                PlaceObject(proc, defaultFile, result);
            }

            // Place all global objects.
            var wl = WorkList.Create(
                MakeGlobalWorkItems()
                .Concat(MakeSegmentWorkitems()));
            var objectTracer = new GlobalObjectTracer(program, wl, listener);

            while (wl.TryGetWorkItem(out var item))
            {
                var(field, addr) = item;
                var globalVar = new GlobalVariable(addr, field.DataType, program.NamingPolicy.GlobalName(field));
                PlaceObject(globalVar, defaultDataFile, result);
                objectTracer.TraceObject(field.DataType, addr);
            }
            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Remove any UseInstructions in the exit block of the procedure that
        /// can be proved to be dead out.
        /// </summary>
        /// <param name="ssa">SSA of the procedure whose exit block is to be examined.</param>
        /// <param name="wl">Worklist of SSA states.</param>
        /// <returns>True if any change was made to SSA.</returns>
        public bool RemoveUnusedDefinedValues(SsaState ssa, WorkList <SsaState> wl)
        {
            bool change = false;

            trace.Verbose("UVR: {0}", ssa.Procedure.Name);
            var(deadStms, deadStgs) = FindDeadStatementsInExitBlock(ssa, this.dataFlow[ssa.Procedure].BitsLiveOut);

            // Remove 'use' statements that are known to be dead from the exit block.
            foreach (var stm in deadStms)
            {
                trace.Verbose("UVR: {0}, deleting {1}", ssa.Procedure.Name, stm.Instruction);
                ssa.DeleteStatement(stm);
                change = true;
            }

            // If any instructions were removed, update the callers.
            if (!ssa.Procedure.Signature.ParametersValid && deadStms.Count > 0)
            {
                DeadCode.Eliminate(ssa);
                foreach (Statement stm in program.CallGraph.CallerStatements(ssa.Procedure))
                {
                    if (!(stm.Instruction is CallInstruction ci))
                    {
                        continue;
                    }
                    var ssaCaller = this.procToSsa[stm.Block.Procedure];
                    if (RemoveDeadCallDefinitions(ssaCaller, ci, deadStgs))
                    {
                        wl.Add(ssaCaller);
                    }
                }
            }
            return(change);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Collects weakly connected components from the ICFG and gathers
        /// them into Clusters.
        /// </summary>
        public List <Cluster> FindClusters()
        {
            var nodesLeft  = new HashSet <RtlBlock>(sr.ICFG.Nodes);
            var clusters   = new List <Cluster>();
            int totalCount = nodesLeft.Count;

            if (totalCount > 0)
            {
                listener.ShowProgress("Finding procedure candidates", 0, totalCount);
                var wl = WorkList.Create(nodesLeft);
                while (wl.TryGetWorkItem(out var node))
                {
                    if (listener.IsCanceled())
                    {
                        break;
                    }
                    var cluster = new Cluster();
                    clusters.Add(cluster);

                    BuildWCC(node, cluster, wl);
                    sr.BreakOnWatchedAddress(cluster.Blocks.Select(b => b.Address));
                    listener.ShowProgress("Finding procedure candidates", totalCount - nodesLeft.Count, totalCount);
                }
            }
            return(clusters);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Build the weakly connected component for a cluster by following
 /// both predecessors and successors in the graph. However, we never
 /// follow the predecessors of nodes that are marked directly called,
 /// and we never follow successors that are marked directly called
 /// (tail calls).
 /// </summary>
 /// <param name="node"></param>
 /// <param name="cluster"></param>
 /// <param name="wl"></param>
 private void BuildWCC(
     RtlBlock node,
     Cluster cluster,
     WorkList <RtlBlock> wl)
 {
     wl.Remove(node);
     cluster.Blocks.Add(node);
     foreach (var s in sr.ICFG.Successors(node))
     {
         if (wl.Contains(s))
         {
             // Only add if successor is not CALLed.
             if (!procedures.Contains(s.Address))
             {
                 BuildWCC(s, cluster, wl);
             }
         }
     }
     if (!procedures.Contains(node.Address))
     {
         // Only backtrack through predecessors if the node
         // is not CALLed.
         foreach (var p in sr.ICFG.Predecessors(node))
         {
             if (wl.Contains(p))
             {
                 BuildWCC(p, cluster, wl);
             }
         }
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// As far as possible, try fusing consecutive linear blocks in the
        /// cluster.
        /// </summary>
        /// <param name="cluster"></param>
        public void FuseLinearBlocks(Cluster cluster)
        {
            var wl = WorkList.Create(cluster.Blocks);

            while (wl.TryGetWorkItem(out var block))
            {
                if (sr.ICFG.Successors(block).Count != 1)
                {
                    continue;
                }
                var succ = sr.ICFG.Successors(block).First();
                if (sr.ICFG.Predecessors(succ).Count != 1)
                {
                    continue;
                }
                Debug.Assert(sr.ICFG.Predecessors(succ).First() == block, "Inconsistent graph");
                if (!(block.Instructions.Last().Instructions.Last() is RtlAssignment))
                {
                    continue;
                }

                // Move all instructions into predecessor.
                block.Instructions.AddRange(succ.Instructions);
                sr.ICFG.RemoveEdge(block, succ);
                var succSuccs = sr.ICFG.Successors(succ).ToList();
                foreach (var ss in succSuccs)
                {
                    sr.ICFG.RemoveEdge(succ, ss);
                    sr.ICFG.AddEdge(block, ss);
                }
                cluster.Blocks.Remove(succ);
                // May be more blocks.
                wl.Add(block);
            }
        }
Ejemplo n.º 18
0
        private void GetResultAndContinue(EvalResultDataItem dataItem, WorkList workList, DkmClrType declaredType, DkmInspectionContext inspectionContext, EvalResultDataItem parent, CompletionRoutine <DkmEvaluationResult> completionRoutine)
        {
            var value = dataItem.Value; // Value may have been replaced (specifically, for Nullable<T>).
            DebuggerDisplayInfo displayInfo;

            if (value.TryGetDebuggerDisplayInfo(out displayInfo))
            {
                var targetType = displayInfo.TargetType;
                var attribute  = displayInfo.Attribute;
                CompletionRoutine <Exception> onException =
                    e => completionRoutine(CreateEvaluationResultFromException(e, dataItem, inspectionContext));

                EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.Name,
                                                         displayName => EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.Value,
                                                                                                                 displayValue => EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.TypeName,
                                                                                                                                                                          displayType =>
                {
                    completionRoutine(GetResult(inspectionContext, dataItem, declaredType, displayName.Result, displayValue.Result, displayType.Result, parent));
                    workList.Execute();
                },
                                                                                                                                                                          onException),
                                                                                                                 onException),
                                                         onException);
            }
            else
            {
                completionRoutine(GetResult(inspectionContext, dataItem, declaredType, displayName: null, displayValue: null, displayType: null, parent: parent));
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Can delete a save work (set to null)
 /// </summary>
 /// <param name="_nb">Index of the work in the list to delete</param>
 public void DeleteWork(int _nb)
 {
     WorkList.RemoveAt(_nb);
     SetWorkIndex();
     UpdateSaveFile();
     EditLog.DeleteWorkLogLine(_nb);
 }
Ejemplo n.º 20
0
        private void GetChildrenAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmStackWalkFrame stackFrame, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine <DkmGetChildrenAsyncResult> completionRoutine)
        {
            var expansion = dataItem.Expansion;
            var rows      = ArrayBuilder <EvalResultDataItem> .GetInstance();

            int index = 0;

            if (expansion != null)
            {
                expansion.GetRows(this, rows, inspectionContext, dataItem, dataItem.Value, 0, initialRequestSize, visitAll: true, index: ref index);
            }
            var numRows = rows.Count;

            Debug.Assert(index >= numRows);
            Debug.Assert(initialRequestSize >= numRows);
            var initialChildren = new DkmEvaluationResult[numRows];
            var wl = new WorkList(workList, e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e)));

            GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, wl, inspectionContext, stackFrame,
                                            () => wl.ContinueWith(
                                                () =>
            {
                var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem));
                completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext));
                rows.Free();
            }));
            wl.Execute();
        }
Ejemplo n.º 21
0
        private void GetItemsAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, int startIndex, int count, DkmInspectionContext inspectionContext, DkmCompletionRoutine <DkmEvaluationEnumAsyncResult> completionRoutine)
        {
            var expansion = dataItem.Expansion;
            var value     = dataItem.Value;
            var rows      = ArrayBuilder <EvalResultDataItem> .GetInstance();

            if (expansion != null)
            {
                int index = 0;
                expansion.GetRows(this, rows, inspectionContext, dataItem, value, startIndex, count, visitAll: false, index: ref index);
            }
            var numRows = rows.Count;

            Debug.Assert(count >= numRows);
            var results = new DkmEvaluationResult[numRows];
            var wl      = new WorkList(workList, e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e)));

            GetEvaluationResultsAndContinue(rows, results, 0, numRows, wl, inspectionContext, value.StackFrame,
                                            () => wl.ContinueWith(
                                                () =>
            {
                completionRoutine(new DkmEvaluationEnumAsyncResult(results));
                rows.Free();
            }));
            wl.Execute();
        }
Ejemplo n.º 22
0
        private void GetChild(
            DkmEvaluationResult parent,
            WorkList workList,
            EvalResult row,
            DkmCompletionRoutine <DkmEvaluationAsyncResult> completionRoutine)
        {
            var inspectionContext = row.InspectionContext;

            if ((row.Kind != ExpansionKind.Default) || (row.Value == null))
            {
                CreateEvaluationResultAndContinue(
                    row,
                    workList,
                    row.InspectionContext,
                    parent.StackFrame,
                    child => completionRoutine(new DkmEvaluationAsyncResult(child)));
            }
            else
            {
                var typeDeclaringMember = row.TypeDeclaringMemberAndInfo;
                var name = (typeDeclaringMember.Type == null) ?
                           row.Name :
                           GetQualifiedMemberName(row.InspectionContext, typeDeclaringMember, row.Name, FullNameProvider);
                row.Value.GetResult(
                    workList.InnerWorkList,
                    row.DeclaredTypeAndInfo.ClrType,
                    row.DeclaredTypeAndInfo.Info,
                    row.InspectionContext,
                    Formatter.NoFormatSpecifiers,
                    name,
                    row.FullName,
                    result => workList.ContinueWith(() => completionRoutine(result)));
            }
        }
Ejemplo n.º 23
0
        void IDkmClrResultProvider.GetResult(DkmClrValue value, DkmWorkList workList, DkmClrType declaredType, DkmClrCustomTypeInfo declaredTypeInfo, DkmInspectionContext inspectionContext, ReadOnlyCollection <string> formatSpecifiers, string resultName, string resultFullName, DkmCompletionRoutine <DkmEvaluationAsyncResult> completionRoutine)
        {
            if (formatSpecifiers == null)
            {
                formatSpecifiers = Formatter.NoFormatSpecifiers;
            }
            if (resultFullName != null)
            {
                ReadOnlyCollection <string> otherSpecifiers;
                resultFullName = FullNameProvider.GetClrExpressionAndFormatSpecifiers(inspectionContext, resultFullName, out otherSpecifiers);
                foreach (var formatSpecifier in otherSpecifiers)
                {
                    formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, formatSpecifier);
                }
            }
            var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationAsyncResult.CreateErrorResult(e)));

            wl.ContinueWith(
                () => GetRootResultAndContinue(
                    value,
                    wl,
                    declaredType,
                    declaredTypeInfo,
                    inspectionContext,
                    resultName,
                    resultFullName,
                    formatSpecifiers,
                    result => wl.ContinueWith(() => completionRoutine(new DkmEvaluationAsyncResult(result)))));
        }
Ejemplo n.º 24
0
        private void GetResultAndContinue(
            EvalResult result,
            WorkList workList,
            DkmClrType declaredType,
            DkmClrCustomTypeInfo declaredTypeInfo,
            DkmInspectionContext inspectionContext,
            bool useDebuggerDisplay,
            CompletionRoutine <DkmEvaluationResult> completionRoutine)
        {
            var value = result.Value; // Value may have been replaced (specifically, for Nullable<T>).
            DebuggerDisplayInfo displayInfo;

            if (value.TryGetDebuggerDisplayInfo(out displayInfo))
            {
                var targetType = displayInfo.TargetType;
                var attribute  = displayInfo.Attribute;
                CompletionRoutine <Exception> onException =
                    e => completionRoutine(CreateEvaluationResultFromException(e, result, inspectionContext));

                var innerWorkList = workList.InnerWorkList;
                EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.Name,
                                                         displayName => EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.Value,
                                                                                                                 displayValue => EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.TypeName,
                                                                                                                                                                          displayType =>
                                                                                                                                                                          workList.ContinueWith(() =>
                                                                                                                                                                                                completionRoutine(GetResult(inspectionContext, result, declaredType, declaredTypeInfo, displayName.Result, displayValue.Result, displayType.Result, useDebuggerDisplay))),
                                                                                                                                                                          onException),
                                                                                                                 onException),
                                                         onException);
            }
            else
            {
                completionRoutine(GetResult(inspectionContext, result, declaredType, declaredTypeInfo, displayName: null, displayValue: null, displayType: null, useDebuggerDisplay: false));
            }
        }
Ejemplo n.º 25
0
 private void PushEquality(WorkList wl, SymbolicValue v1, SymbolicValue v2)
 {
     if (v1 == v2)
     {
         return;
     }
     wl.Add(new EqPair(v1, v2));
 }
Ejemplo n.º 26
0
        static void MergeNodesBothDirections <T>(WorkList <T> dst, WorkList <T> src, Func <T, T, bool> merge) where T : class
        {
            // Merge as far as we can down using the given merge strategy
            MergeNodeSequenceUntilStrategyFails(dst, src, Position.Head, merge);

            // Then merge backwards..
            MergeNodeSequenceUntilStrategyFails(dst, src, Position.Tail, merge);
        }
Ejemplo n.º 27
0
 public BackwardSlicer(IBackWalkHost <RtlBlock, RtlInstruction> host)
 {
     this.host     = host;
     this.worklist = new WorkList <SliceState>();
     this.visited  = new HashSet <RtlBlock>();
     this.cmp      = new ExpressionValueComparer();
     this.simp     = new ExpressionSimplifier(host.SegmentMap, new EvalCtx(), null);
 }
Ejemplo n.º 28
0
        public List <Interval> BuildIntervals(DirectedGraph <StructureNode> graph, StructureNode entry)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            var intervalsInGraph = new List <Interval>();          // The sequence of intervals in this graph
            var headers          = new WorkList <StructureNode>(); // The sequence of interval header nodes
            var beenInH          = new HashSet <StructureNode>();  // The set of nodes that have been in the above sequence at some stage

            headers.Add(entry);
            beenInH.Add(entry);

            StructureNode header;

            while (headers.GetWorkItem(out header))
            {
                Interval newInt = new Interval(intervalID++, header);

                // Process each succesive node in the interval until no more nodes can be added to the interval.
                for (int i = 0; i < newInt.Nodes.Count; i++)
                {
                    StructureNode curNode = newInt.Nodes[i];

                    foreach (StructureNode succ in graph.Successors(curNode))
                    {
                        // Only further consider the current child if it isn't already in the interval
                        if (!newInt.Nodes.Contains(succ))
                        {
                            // If the current child has all its parents
                            // inside the interval, then add it to the interval. Remove it from the header
                            // sequence if it is on it.
                            if (IsSubSetOf(graph.Predecessors(succ), newInt))
                            {
                                newInt.AddNode(succ);
                                headers.Remove(succ);
                            }

                            // Otherwise, add it to the header sequence if it hasn't already been in it.
                            else if (!beenInH.Contains(succ))
                            {
                                headers.Add(succ);
                                beenInH.Add(succ);
                            }
                        }
                    }
                }

                // Add the new interval to the sequence of intervals
                intervalsInGraph.Add(newInt);
            }
            return(intervalsInGraph);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Create a save work (with a differential save algorithm)
        /// </summary>
        /// <param name="_name">Name of the work (must be different from existing ones)</param>
        /// <param name="_source">The Source path to save</param>
        /// <param name="_destination">The Target destination to save files in</param>
        public void CreateDifferencialWork(string _name, string _source, string _destination, List <Extension> _extension)
        {
            DifferencialSaveWork work = new DifferencialSaveWork(_name, _source, _destination, _extension, SaveWorkType.differencial);

            WorkList.Add(work);
            SetWorkIndex();
            UpdateSaveFile();
            EditLog.CreateWorkLogLine(work);
        }
Ejemplo n.º 30
0
        public static WorkList GetInstance()
        {
            if (instance == null)
            {
                instance = new WorkList();
            }

            return(instance);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Removes all of the edges to a given vertex
        /// </summary>
        /// <param name="vertex">The vertex being removed</param>
        protected virtual void RemoveAllEdgesToVertex(object vertex)
        {
            WorkList wl = new WorkList(Successors(vertex));

            while (!wl.IsEmpty)
            {
                RemoveEdge(wl.NextItem() as Edge);
            }
        }
Ejemplo n.º 32
0
        public void BuildIntervals(DerivedGraph derGraph)
        {
            if (derGraph == null)
                throw new ArgumentNullException("derGraph");
            if (derGraph.Entry == null)
                throw new ArgumentException("cfg graph must be non-null.", "derGraph");

            var intSeq = derGraph.Intervals;	// The sequence of intervals in this graph
            var headerSeq = new WorkList<StructureNode>();	// The sequence of interval header nodes
            var beenInH = new List<StructureNode>();	// The set of nodes that have been in the above sequence at some stage

            headerSeq.Add(derGraph.Entry);

            beenInH.Add(derGraph.Entry);

            StructureNode header;
            while (headerSeq.GetWorkItem(out header))
            {
                var newInt = new Interval(intervalID++, header);

                // Process each succesive node in the interval until no more nodes can be added to the interval.
                for (int i = 0; i < newInt.Nodes.Count; i++)
                {
                    var curNode = newInt.Nodes[i];

                    // Process each child of the current node
                    for (int j = 0; j < curNode.OutEdges.Count; j++)
                    {
                        var succ = curNode.OutEdges[j];

                        // Only further consider the current child if it isn't already in the interval
                        if (!newInt.Nodes.Contains(succ))
                        {
                            // If the current child has all its parents
                            // inside the interval, then add it to the interval. Remove it from the header
                            // sequence if it is on it.
                            if (IsSubSetOf(succ.InEdges, newInt))
                            {
                                newInt.AddNode(succ);
                                headerSeq.Remove(succ);
                            }

                            // Otherwise, add it to the header sequence if it hasn't already been in it.
                            else if (!beenInH.Contains(succ))
                            {
                                headerSeq.Add(succ);
                                beenInH.Add(succ);
                            }
                        }
                    }
                }

                // Add the new interval to the sequence of intervals
                intSeq.Add(newInt);
            }
        }
Ejemplo n.º 33
0
 public void WlAdd()
 {
     WorkList<int> w = new WorkList<int>();
     w.Add(3);
     Assert.IsFalse(w.IsEmpty);
     int x;
     Assert.IsTrue(w.GetWorkItem(out x));
     Assert.AreEqual(3, x);
     Assert.IsTrue(w.IsEmpty);
 }
Ejemplo n.º 34
0
		private void Eliminate()
		{
			liveIds = new WorkList<SsaIdentifier>();
			HashSet<Statement> marks = new HashSet<Statement>();

			// Initially, just mark those statements that contain critical statements.
			// These are calls to other functions, functions (which have side effects) and use statements.
			// Critical instructions must never be considered dead.

            foreach (var stm in proc.Statements)
            {
                if (critical.IsCritical(stm.Instruction))
                {
                    if (trace.TraceInfo) Debug.WriteLineIf(trace.TraceInfo, string.Format("Critical: {0}", stm.Instruction));
                    marks.Add(stm);
                    stm.Instruction.Accept(this);		// mark all used identifiers as live.
                }
            }
			
			// Each identifier is live, so its defining statement is also live.

            SsaIdentifier sid;
			while (liveIds.GetWorkItem(out sid))
			{
				Statement def = sid.DefStatement;
				if (def != null)
				{
					if (!marks.Contains(def))
					{
						if (trace.TraceInfo) Debug.WriteLine(string.Format("Marked: {0}", def.Instruction));
                        marks.Add(def);
						sid.DefStatement.Instruction.Accept(this);
					}
				}
			}

			// We have now marked all the useful instructions in the code. Any non-marked
			// instruction is now useless and should be deleted.

			foreach (Block b in proc.ControlGraph.Blocks)
			{
				for (int iStm = 0; iStm < b.Statements.Count; ++iStm)
				{
					Statement stm = b.Statements[iStm];
					if (!marks.Contains(stm))
					{
						if (trace.TraceInfo) Debug.WriteLineIf(trace.TraceInfo, string.Format("Deleting: {0}", stm.Instruction));
						ssa.DeleteStatement(stm);
						--iStm;
					}
				}
			}

			AdjustApplicationsWithDeadReturnValues();
		}
Ejemplo n.º 35
0
 public void WlRemove()
 {
     WorkList<int> w = new WorkList<int>();
     w.Add(3);
     w.Add(2);
     Assert.IsFalse(w.IsEmpty);
     w.Remove(3);
     Assert.IsFalse(w.IsEmpty);
     w.Remove(2);
     Assert.IsTrue(w.IsEmpty);
     int x;
     Assert.IsFalse(w.GetWorkItem(out x));
 }
Ejemplo n.º 36
0
 void IDkmClrResultProvider.GetResult(DkmClrValue value, DkmWorkList workList, DkmClrType declaredType, DkmClrCustomTypeInfo declaredTypeInfo, DkmInspectionContext inspectionContext, ReadOnlyCollection<string> formatSpecifiers, string resultName, string resultFullName, DkmCompletionRoutine<DkmEvaluationAsyncResult> completionRoutine)
 {
     // TODO: Use full name
     var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationAsyncResult.CreateErrorResult(e)));
     GetRootResultAndContinue(
         value,
         wl,
         declaredType,
         declaredTypeInfo,
         inspectionContext,
         resultName,
         result => wl.ContinueWith(() => completionRoutine(new DkmEvaluationAsyncResult(result))));
     wl.Execute();
 }
Ejemplo n.º 37
0
 public DataType BuildOverlappedStructure(List<StructureField> fields)
 {
     List<StructureType> types = new List<StructureType>();
     int commonOffset = CommonOffset(fields);
     StructureField field;
     WorkList<StructureField> worklist = new WorkList<StructureField>(fields);
     while (worklist.GetWorkItem(out field))
     {
         StructureType s = FindStructureToFitIn(field, commonOffset, types);
         if (s == null)
         {
             s = new StructureType();
             types.Add(s);
         }
         s.Fields.Add(new StructureField(field.Offset - commonOffset, field.DataType));
     }
     return Normalize(types);
 }
Ejemplo n.º 38
0
		public void ReplaceDefinitionsWithOutParameter(Identifier id, Identifier idOut)
		{
			this.idOut = idOut;
			wl = new WorkList<Identifier>();
			wl.Add(id);
			var visited = new HashSet<Statement>();

			while (wl.GetWorkItem(out id))
			{
				ssa = ssaIds[id];
				stmDef = ssa.DefStatement;
				if (stmDef != null && !visited.Contains(stmDef))
				{
					visited.Add(stmDef);
					iStmDef = stmDef.Block.Statements.IndexOf(stmDef);
					stmDef.Instruction = stmDef.Instruction.Accept(this);
				}
			}
		}
Ejemplo n.º 39
0
    public InterProcGenKill(Implementation impl, Program program) {
      Contract.Requires(program != null);
      Contract.Requires(impl != null);
      this.program = program;
      procICFG = new Dictionary<string/*!*/, ICFG/*!*/>();
      name2Proc = new Dictionary<string/*!*/, Procedure/*!*/>();
      workList = new WorkList();
      this.callers = new Dictionary<string/*!*/, List<WorkItem/*!*/>/*!*/>();
      this.callGraph = new Graph<string/*!*/>();
      this.procPriority = new Dictionary<string/*!*/, int>();
      this.maxBlocksInProc = 0;
      this.mainImpl = impl;

      Dictionary<string/*!*/, Implementation/*!*/>/*!*/ name2Impl = new Dictionary<string/*!*/, Implementation/*!*/>();
      varsLiveAtExit.Clear();
      varsLiveAtEntry.Clear();
      varsLiveSummary.Clear();

      foreach (var decl in program.TopLevelDeclarations) {
        Contract.Assert(decl != null);
        if (decl is Implementation) {
          Implementation/*!*/ imp = (Implementation/*!*/)cce.NonNull(decl);
          name2Impl[imp.Name] = imp;
        } else if (decl is Procedure) {
          Procedure/*!*/ proc = cce.NonNull(decl as Procedure);
          name2Proc[proc.Name] = proc;
        }
      }

      ICFG/*!*/ mainICFG = new ICFG(mainImpl);
      Contract.Assert(mainICFG != null);
      procICFG.Add(mainICFG.impl.Name, mainICFG);
      callGraph.AddSource(mainICFG.impl.Name);

      List<ICFG/*!*/>/*!*/ procsToConsider = new List<ICFG/*!*/>();
      procsToConsider.Add(mainICFG);

      while (procsToConsider.Count != 0) {
        ICFG/*!*/ p = procsToConsider[0];
        Contract.Assert(p != null);
        procsToConsider.RemoveAt(0);

        foreach (string/*!*/ callee in p.procsCalled.Keys) {
          Contract.Assert(callee != null);
          if (!name2Impl.ContainsKey(callee))
            continue;

          callGraph.AddEdge(p.impl.Name, callee);

          if (maxBlocksInProc < p.nodes.Count) {
            maxBlocksInProc = p.nodes.Count;
          }

          if (!callers.ContainsKey(callee)) {
            callers.Add(callee, new List<WorkItem/*!*/>());
          }
          foreach (Block/*!*/ b in p.procsCalled[callee]) {
            Contract.Assert(b != null);
            callers[callee].Add(new WorkItem(p, b));
          }

          if (procICFG.ContainsKey(callee))
            continue;
          ICFG/*!*/ ncfg = new ICFG(name2Impl[callee]);
          Contract.Assert(ncfg != null);
          procICFG.Add(callee, ncfg);
          procsToConsider.Add(ncfg);
        }
      }

      bool acyclic;
      List<string>/*!*/ sortedNodes;
      callGraph.TarjanTopSort(out acyclic, out sortedNodes);

      Contract.Assert(acyclic);

      int cnt = 0;
      for (int i = sortedNodes.Count - 1; i >= 0; i--) {
        string s = sortedNodes[i];
        if (s == null)
          continue;
        procPriority.Add(s, cnt);
        cnt++;
      }

    }
Ejemplo n.º 40
0
        void IDkmClrResultProvider.GetChildren(DkmEvaluationResult evaluationResult, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine)
        {
            var dataItem = evaluationResult.GetDataItem<EvalResultDataItem>();
            if (dataItem == null)
            {
                // We don't know about this result.  Call next implementation
                evaluationResult.GetChildren(workList, initialRequestSize, inspectionContext, completionRoutine);
                return;
            }

            var expansion = dataItem.Expansion;
            if (expansion == null)
            {
                var enumContext = DkmEvaluationResultEnumContext.Create(0, evaluationResult.StackFrame, inspectionContext, new EnumContextDataItem(evaluationResult));
                completionRoutine(new DkmGetChildrenAsyncResult(new DkmEvaluationResult[0], enumContext));
                return;
            }

            // Evaluate children with InspectionContext that is not the root.
            inspectionContext = inspectionContext.With(NotRoot);

            var rows = ArrayBuilder<EvalResult>.GetInstance();
            int index = 0;
            expansion.GetRows(this, rows, inspectionContext, dataItem, dataItem.Value, 0, initialRequestSize, visitAll: true, index: ref index);
            var numRows = rows.Count;
            Debug.Assert(index >= numRows);
            Debug.Assert(initialRequestSize >= numRows);
            var initialChildren = new DkmEvaluationResult[numRows];
            CompletionRoutine<Exception> onException = e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e));
            var wl = new WorkList(workList, onException);
            wl.ContinueWith(() =>
                GetEvaluationResultsAndContinue(evaluationResult, rows, initialChildren, 0, numRows, wl, inspectionContext,
                    () =>
                    wl.ContinueWith(
                        () =>
                        {
                            var enumContext = DkmEvaluationResultEnumContext.Create(index, evaluationResult.StackFrame, inspectionContext, new EnumContextDataItem(evaluationResult));
                            completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext));
                            rows.Free();
                        }),
                    onException));
        }
Ejemplo n.º 41
0
 private void GetEvaluationResultsAndContinue(ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine completionRoutine)
 {
     if (index < numRows)
     {
         CreateEvaluationResultAndContinue(rows[index], workList, inspectionContext, stackFrame,
             result => workList.ContinueWith(
                 () =>
                 {
                     results[index] = result;
                     GetEvaluationResultsAndContinue(rows, results, index + 1, numRows, workList, inspectionContext, stackFrame, completionRoutine);
                 }));
     }
     else
     {
         completionRoutine();
     }
 }
Ejemplo n.º 42
0
 private void GetChildrenAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmStackWalkFrame stackFrame, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine)
 {
     var expansion = dataItem.Expansion;
     var rows = ArrayBuilder<EvalResultDataItem>.GetInstance();
     int index = 0;
     if (expansion != null)
     {
         expansion.GetRows(this, rows, inspectionContext, dataItem, dataItem.Value, 0, initialRequestSize, visitAll: true, index: ref index);
     }
     var numRows = rows.Count;
     Debug.Assert(index >= numRows);
     Debug.Assert(initialRequestSize >= numRows);
     var initialChildren = new DkmEvaluationResult[numRows];
     var wl = new WorkList(workList, e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e)));
     GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, wl, inspectionContext, stackFrame,
         () => wl.ContinueWith(
             () =>
             {
                 var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem));
                 completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext));
                 rows.Free();
             }));
     wl.Execute();
 }
Ejemplo n.º 43
0
        private void GetResultAndContinue(
            EvalResultDataItem dataItem,
            WorkList workList,
            DkmClrType declaredType,
            DkmClrCustomTypeInfo declaredTypeInfo,
            DkmInspectionContext inspectionContext,
            EvalResultDataItem parent,
            CompletionRoutine<DkmEvaluationResult> completionRoutine)
        {
            var value = dataItem.Value; // Value may have been replaced (specifically, for Nullable<T>).
            DebuggerDisplayInfo displayInfo;
            if (value.TryGetDebuggerDisplayInfo(out displayInfo))
            {
                var targetType = displayInfo.TargetType;
                var attribute = displayInfo.Attribute;
                CompletionRoutine<Exception> onException =
                    e => completionRoutine(CreateEvaluationResultFromException(e, dataItem, inspectionContext));

                EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.Name,
                    displayName => EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.Value,
                        displayValue => EvaluateDebuggerDisplayStringAndContinue(value, workList, inspectionContext, targetType, attribute.TypeName,
                            displayType =>
                            {
                                completionRoutine(GetResult(inspectionContext, dataItem, declaredType, declaredTypeInfo, displayName.Result, displayValue.Result, displayType.Result, parent));
                            },
                            onException),
                        onException),
                    onException);
            }
            else
            {
                completionRoutine(GetResult(inspectionContext, dataItem, declaredType, declaredTypeInfo, displayName: null, displayValue: null, displayType: null, parent: parent));
            }
        }
Ejemplo n.º 44
0
 private void GetEvaluationResultsAndContinue(
     DkmEvaluationResult parent,
     ArrayBuilder<EvalResult> rows,
     DkmEvaluationResult[] results,
     int index,
     int numRows,
     WorkList workList,
     DkmInspectionContext inspectionContext,
     CompletionRoutine onCompleted,
     CompletionRoutine<Exception> onException)
 {
     DkmCompletionRoutine<DkmEvaluationAsyncResult> completionRoutine =
         result =>
         {
             try
             {
                 results[index] = result.Result;
                 GetEvaluationResultsAndContinue(parent, rows, results, index + 1, numRows, workList, inspectionContext, onCompleted, onException);
             }
             catch (Exception e)
             {
                 onException(e);
             }
         };
     if (index < numRows)
     {
         GetChild(
             parent,
             workList,
             rows[index],
             child => workList.ContinueWith(() => completionRoutine(child)));
     }
     else
     {
         onCompleted();
     }
 }
Ejemplo n.º 45
0
		private State [] BuildDfaTable(Node n)
		{
			List<State> dStates = new List<State>();

			// Create the default, error state.

			State err = new State(new BitArray(n.FirstPos.Length), charClasses);
			AddState(dStates, err);

			// Create the initial state.

			State s0 = new State(n.FirstPos, charClasses);
			AddState(dStates, s0);

			// Start the worklist.

            WorkList<State> worklist = new WorkList<State>();
			worklist.Add(s0);
            State t;
			while (worklist.GetWorkItem(out t))
			{
				Debug.WriteLine(t.ToString());
				for (int a = 0; a != charClasses; ++a)
				{
					// Create U, a state consisting of the positions in 
					// FollowPos(p) where p is any position in t that has 
					// an 'a'.

					State u = new State(new BitArray(positions.Count), charClasses);
					for (int p = 0; p != t.Positions.Length; ++p)
					{
						if (!t.Positions[p])
							continue;
						ByteNode pp = (ByteNode) positions[p];
						if (pp.Any || alphabet[pp.startByte] == a)
						{
							u.Positions.Or(pp.FollowPos);
						}
						t.Accepts |= pp.Accepts;
					}

					if (IsEmptySet(u.Positions))
					{
						u = null;
					}
					else
					{
						State uu = FindState(dStates, u.Positions);
						if (uu == null)
						{
							AddState(dStates, u);
							worklist.Add(u);
						}
						else
						{
							u = uu;
						}
					}
					t.NextState[a] = u;
				}
				Debug.WriteLine("t complete: " + t);
			}
            return dStates.ToArray(); 
		}
Ejemplo n.º 46
0
        public List<Interval> BuildIntervals(DirectedGraph<StructureNode> graph, StructureNode entry)
        {
            if (graph == null)
                throw new ArgumentNullException("graph");
            if (entry == null)
                throw new ArgumentNullException("entry");

            var intervalsInGraph = new List<Interval>();	// The sequence of intervals in this graph
            var headers = new WorkList<StructureNode>();	// The sequence of interval header nodes
            var beenInH = new HashSet<StructureNode>();	    // The set of nodes that have been in the above sequence at some stage

            headers.Add(entry);
            beenInH.Add(entry);

            StructureNode header;
            while (headers.GetWorkItem(out header))
            {
                Interval newInt = new Interval(intervalID++, header);

                // Process each succesive node in the interval until no more nodes can be added to the interval.
                for (int i = 0; i < newInt.Nodes.Count; i++)
                {
                    StructureNode curNode = newInt.Nodes[i];

                    foreach (StructureNode succ in graph.Successors(curNode))
                    {
                        // Only further consider the current child if it isn't already in the interval
                        if (!newInt.Nodes.Contains(succ))
                        {
                            // If the current child has all its parents
                            // inside the interval, then add it to the interval. Remove it from the header
                            // sequence if it is on it.
                            if (IsSubSetOf(graph.Predecessors(succ), newInt))
                            {
                                newInt.AddNode(succ);
                                headers.Remove(succ);
                            }

                            // Otherwise, add it to the header sequence if it hasn't already been in it.
                            else if (!beenInH.Contains(succ))
                            {
                                headers.Add(succ);
                                beenInH.Add(succ);
                            }
                        }
                    }
                }

                // Add the new interval to the sequence of intervals
                intervalsInGraph.Add(newInt);
            }
            return intervalsInGraph;
        }
Ejemplo n.º 47
0
    public void Dump(TextWriter tw) {
      HashSet seen = new HashSet();
      WorkList wl = new WorkList();
    
      Console.WriteLine("LastSymbolId:{0}", this.idCounter);
      foreach(IUniqueKey function in this.termMap.Keys2(this.constRoot)) {
        SymbolicValue target = this[this.constRoot, function];

        tw.WriteLine("{0} = {1}", Function2String(function), target);

        wl.Add(target);
      }

      while ( ! wl.IsEmpty() ) {
        SymbolicValue v = (SymbolicValue)wl.Pull();
        if ( ! seen.Add(v)) continue;

        foreach(IUniqueKey function in this.termMap.Keys2(v)) {
          SymbolicValue target = this[v, function];
          tw.WriteLine("{0}({2}) = {1}", Function2String(function), target, v);

          wl.Add(target);
        }

      }

      tw.WriteLine("**Abstract value map");
      foreach (SymbolicValue v in seen) {
        AbstractValue aval = this[v];
        if (!this.elementLattice.IsTop(aval)) {
          tw.WriteLine("{0} -> {1}", v, aval);
        }
      }
    }
Ejemplo n.º 48
0
 private void PushEquality(WorkList wl, SymbolicValue v1, SymbolicValue v2) {
   if (v1 == v2) return;
   wl.Add(new EqPair(v1, v2));
 }
Ejemplo n.º 49
0
    public void AssumeEqual(ISymValue v1, ISymValue v2) {

      WorkList wl = new WorkList();
      SymbolicValue v1rep = Find(v1);
      SymbolicValue v2rep = Find(v2);
      PushEquality(wl, v1rep, v2rep);

      if (!wl.IsEmpty()) {
        // TODO: there's an opportunity for optimizing the number
        // of necessary updates that we need to record, since the induced
        // updates of the equality may end up as duplicates.
        AddEqualityUpdate(v1rep, v2rep);
      }
      DrainEqualityWorkList(wl);
    }
Ejemplo n.º 50
0
    private void DrainEqualityWorkList(WorkList wl) {
      while ( ! wl.IsEmpty() ) {

        EqPair eqpair = (EqPair)wl.Pull();
        SymbolicValue v1rep = Find(eqpair.v1);
        SymbolicValue v2rep = Find(eqpair.v2);
        if (v1rep == v2rep) continue;

        // always map new to older var
        if (v1rep.UniqueId < v2rep.UniqueId) {
          SymbolicValue temp = v1rep;
          v1rep = v2rep;
          v2rep = temp;
        }

        // perform congruence closure here:
        foreach(IUniqueKey f in this.Functions(v1rep)) {
          SymbolicValue target = this.LookupWithoutManifesting(v2rep, f);
          if (target == null) {
            this[v2rep, f] = this[v1rep,f];
          }
          else {
            PushEquality(wl, this[v1rep,f], target);
          }
        }
        MathematicalLattice.Element av1 = this[v1rep];
        MathematicalLattice.Element av2 = this[v2rep];
        // merge term map of v1 into v2
        foreach(IUniqueKey eterm in this.eqTermMap.Keys2(v1rep)) {
          this.eqTermMap = this.eqTermMap.Add(v2rep, eterm, null);
        }
        this.forwMap = this.forwMap.Add(v1rep, v2rep);
        this[v2rep] = this.elementLattice.Meet(av1,av2);
      }
    }
Ejemplo n.º 51
0
 private void CreateEvaluationResultAndContinue(EvalResultDataItem dataItem, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine<DkmEvaluationResult> completionRoutine)
 {
     switch (dataItem.Kind)
     {
         case ExpansionKind.Error:
             completionRoutine(DkmFailedEvaluationResult.Create(
                 inspectionContext,
                 StackFrame: stackFrame,
                 Name: dataItem.Name,
                 FullName: dataItem.FullName,
                 ErrorMessage: dataItem.DisplayValue,
                 Flags: DkmEvaluationResultFlags.None,
                 Type: null,
                 DataItem: null));
             break;
         case ExpansionKind.NativeView:
             {
                 var value = dataItem.Value;
                 var name = Resources.NativeView;
                 var fullName = dataItem.FullName;
                 var display = dataItem.Name;
                 DkmEvaluationResult evalResult;
                 if (value.IsError())
                 {
                     evalResult = DkmFailedEvaluationResult.Create(
                         inspectionContext,
                         stackFrame,
                         Name: name,
                         FullName: fullName,
                         ErrorMessage: display,
                         Flags: dataItem.Flags,
                         Type: null,
                         DataItem: dataItem);
                 }
                 else
                 {
                     // For Native View, create a DkmIntermediateEvaluationResult.
                     // This will allow the C++ EE to take over expansion.
                     var process = inspectionContext.RuntimeInstance.Process;
                     var cpp = process.EngineSettings.GetLanguage(new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp));
                     evalResult = DkmIntermediateEvaluationResult.Create(
                         inspectionContext,
                         stackFrame,
                         Name: name,
                         FullName: fullName,
                         Expression: display,
                         IntermediateLanguage: cpp,
                         TargetRuntime: process.GetNativeRuntimeInstance(),
                         DataItem: dataItem);
                 }
                 completionRoutine(evalResult);
             }
             break;
         case ExpansionKind.NonPublicMembers:
             completionRoutine(DkmSuccessEvaluationResult.Create(
                 inspectionContext,
                 stackFrame,
                 Name: Resources.NonPublicMembers,
                 FullName: dataItem.FullName,
                 Flags: dataItem.Flags,
                 Value: null,
                 EditableValue: null,
                 Type: string.Empty,
                 Category: DkmEvaluationResultCategory.Data,
                 Access: DkmEvaluationResultAccessType.None,
                 StorageType: DkmEvaluationResultStorageType.None,
                 TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                 Address: dataItem.Value.Address,
                 CustomUIVisualizers: null,
                 ExternalModules: null,
                 DataItem: dataItem));
             break;
         case ExpansionKind.StaticMembers:
             completionRoutine(DkmSuccessEvaluationResult.Create(
                 inspectionContext,
                 stackFrame,
                 Name: Formatter.StaticMembersString,
                 FullName: dataItem.FullName,
                 Flags: dataItem.Flags,
                 Value: null,
                 EditableValue: null,
                 Type: string.Empty,
                 Category: DkmEvaluationResultCategory.Class,
                 Access: DkmEvaluationResultAccessType.None,
                 StorageType: DkmEvaluationResultStorageType.None,
                 TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                 Address: dataItem.Value.Address,
                 CustomUIVisualizers: null,
                 ExternalModules: null,
                 DataItem: dataItem));
             break;
         case ExpansionKind.RawView:
             completionRoutine(DkmSuccessEvaluationResult.Create(
                 inspectionContext,
                 stackFrame,
                 Name: Resources.RawView,
                 FullName: dataItem.FullName,
                 Flags: dataItem.Flags,
                 Value: null,
                 EditableValue: dataItem.EditableValue,
                 Type: string.Empty,
                 Category: DkmEvaluationResultCategory.Data,
                 Access: DkmEvaluationResultAccessType.None,
                 StorageType: DkmEvaluationResultStorageType.None,
                 TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                 Address: dataItem.Value.Address,
                 CustomUIVisualizers: null,
                 ExternalModules: null,
                 DataItem: dataItem));
             break;
         case ExpansionKind.DynamicView:
         case ExpansionKind.ResultsView:
             completionRoutine(DkmSuccessEvaluationResult.Create(
                 inspectionContext,
                 stackFrame,
                 dataItem.Name,
                 dataItem.FullName,
                 dataItem.Flags,
                 dataItem.DisplayValue,
                 EditableValue: null,
                 Type: string.Empty,
                 Category: DkmEvaluationResultCategory.Method,
                 Access: DkmEvaluationResultAccessType.None,
                 StorageType: DkmEvaluationResultStorageType.None,
                 TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                 Address: dataItem.Value.Address,
                 CustomUIVisualizers: null,
                 ExternalModules: null,
                 DataItem: dataItem));
             break;
         case ExpansionKind.TypeVariable:
             completionRoutine(DkmSuccessEvaluationResult.Create(
                 inspectionContext,
                 stackFrame,
                 dataItem.Name,
                 dataItem.FullName,
                 dataItem.Flags,
                 dataItem.DisplayValue,
                 EditableValue: null,
                 Type: dataItem.DisplayValue,
                 Category: DkmEvaluationResultCategory.Data,
                 Access: DkmEvaluationResultAccessType.None,
                 StorageType: DkmEvaluationResultStorageType.None,
                 TypeModifierFlags: DkmEvaluationResultTypeModifierFlags.None,
                 Address: dataItem.Value.Address,
                 CustomUIVisualizers: null,
                 ExternalModules: null,
                 DataItem: dataItem));
             break;
         case ExpansionKind.PointerDereference:
         case ExpansionKind.Default:
             // This call will evaluate DebuggerDisplayAttributes.
             GetResultAndContinue(
                 dataItem,
                 workList,
                 declaredType: DkmClrType.Create(dataItem.Value.Type.AppDomain, dataItem.DeclaredTypeAndInfo.Type),
                 declaredTypeInfo: dataItem.DeclaredTypeAndInfo.Info,
                 inspectionContext: inspectionContext,
                 parent: dataItem.Parent,
                 completionRoutine: completionRoutine);
             break;
         default:
             throw ExceptionUtilities.UnexpectedValue(dataItem.Kind);
     }
 }
Ejemplo n.º 52
0
        private void GetResultAndContinue(
            EvalResult result,
            WorkList workList,
            DkmClrType declaredType,
            DkmClrCustomTypeInfo declaredTypeInfo,
            DkmInspectionContext inspectionContext,
            bool useDebuggerDisplay,
            CompletionRoutine<DkmEvaluationResult> completionRoutine)
        {
            var value = result.Value; // Value may have been replaced (specifically, for Nullable<T>).
            DebuggerDisplayInfo displayInfo;
            if (value.TryGetDebuggerDisplayInfo(out displayInfo))
            {
                var targetType = displayInfo.TargetType;
                var attribute = displayInfo.Attribute;
                CompletionRoutine<Exception> onException =
                    e => completionRoutine(CreateEvaluationResultFromException(e, result, inspectionContext));

                var innerWorkList = workList.InnerWorkList;
                EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.Name,
                    displayName => EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.Value,
                        displayValue => EvaluateDebuggerDisplayStringAndContinue(value, innerWorkList, inspectionContext, targetType, attribute.TypeName,
                            displayType =>
                                workList.ContinueWith(() =>
                                    completionRoutine(GetResult(inspectionContext, result, declaredType, declaredTypeInfo, displayName.Result, displayValue.Result, displayType.Result, useDebuggerDisplay))),
                            onException),
                        onException),
                    onException);
            }
            else
            {
                completionRoutine(GetResult(inspectionContext, result, declaredType, declaredTypeInfo, displayName: null, displayValue: null, displayType: null, useDebuggerDisplay: false));
            }
        }
Ejemplo n.º 53
0
        private void GetRootResultAndContinue(
            DkmClrValue value,
            WorkList workList,
            DkmClrType declaredType,
            DkmClrCustomTypeInfo declaredTypeInfo,
            DkmInspectionContext inspectionContext,
            string name,
            CompletionRoutine<DkmEvaluationResult> completionRoutine)
        {
            var type = value.Type.GetLmrType();
            if (type.IsTypeVariables())
            {
                Debug.Assert(type.Equals(declaredType.GetLmrType()));
                var declaredTypeAndInfo = new TypeAndCustomInfo(type, declaredTypeInfo);
                var expansion = new TypeVariablesExpansion(declaredTypeAndInfo);
                var dataItem = new EvalResultDataItem(
                    ExpansionKind.Default,
                    name,
                    typeDeclaringMemberAndInfo: default(TypeAndCustomInfo),
                    declaredTypeAndInfo: declaredTypeAndInfo,
                    parent: null,
                    value: value,
                    displayValue: null,
                    expansion: expansion,
                    childShouldParenthesize: false,
                    fullName: null,
                    childFullNamePrefixOpt: null,
                    formatSpecifiers: Formatter.NoFormatSpecifiers,
                    category: DkmEvaluationResultCategory.Data,
                    flags: DkmEvaluationResultFlags.ReadOnly,
                    editableValue: null,
                    inspectionContext: inspectionContext);

                Debug.Assert(dataItem.Flags == (DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.Expandable));

                // Note: We're not including value.EvalFlags in Flags parameter
                // below (there shouldn't be a reason to do so).
                completionRoutine(DkmSuccessEvaluationResult.Create(
                    InspectionContext: inspectionContext,
                    StackFrame: value.StackFrame,
                    Name: Resources.TypeVariablesName,
                    FullName: dataItem.FullName,
                    Flags: dataItem.Flags,
                    Value: "",
                    EditableValue: null,
                    Type: "",
                    Category: dataItem.Category,
                    Access: value.Access,
                    StorageType: value.StorageType,
                    TypeModifierFlags: value.TypeModifierFlags,
                    Address: value.Address,
                    CustomUIVisualizers: null,
                    ExternalModules: null,
                    DataItem: dataItem));
            }
            else if ((inspectionContext.EvaluationFlags & DkmEvaluationFlags.ResultsOnly) != 0)
            {
                var dataItem = ResultsViewExpansion.CreateResultsOnlyRow(
                    inspectionContext,
                    name,
                    declaredType,
                    declaredTypeInfo,
                    value,
                    this.Formatter);
                CreateEvaluationResultAndContinue(
                    dataItem,
                    workList,
                    inspectionContext,
                    value.StackFrame,
                    completionRoutine);
            }
            else if ((inspectionContext.EvaluationFlags & DkmEvaluationFlags.DynamicView) != 0)
            {
                var dataItem = DynamicViewExpansion.CreateMembersOnlyRow(
                    inspectionContext,
                    name,
                    value,
                    this.Formatter);
                CreateEvaluationResultAndContinue(
                    dataItem,
                    workList,
                    inspectionContext,
                    value.StackFrame,
                    completionRoutine);
            }
            else
            {
                var dataItem = ResultsViewExpansion.CreateResultsOnlyRowIfSynthesizedEnumerable(
                    inspectionContext,
                    name,
                    declaredType,
                    declaredTypeInfo,
                    value,
                    this.Formatter);
                if (dataItem != null)
                {
                    CreateEvaluationResultAndContinue(
                        dataItem,
                        workList,
                        inspectionContext,
                        value.StackFrame,
                        completionRoutine);
                }
                else
                {
                    ReadOnlyCollection<string> formatSpecifiers;
                    var fullName = this.Formatter.TrimAndGetFormatSpecifiers(name, out formatSpecifiers);
                    dataItem = CreateDataItem(
                        inspectionContext,
                        name,
                        typeDeclaringMemberAndInfo: default(TypeAndCustomInfo),
                        declaredTypeAndInfo: new TypeAndCustomInfo(declaredType.GetLmrType(), declaredTypeInfo),
                        value: value,
                        parent: null,
                        expansionFlags: ExpansionFlags.All,
                        childShouldParenthesize: this.Formatter.NeedsParentheses(fullName),
                        fullName: fullName,
                        formatSpecifiers: formatSpecifiers,
                        category: DkmEvaluationResultCategory.Other,
                        flags: value.EvalFlags,
                        evalFlags: inspectionContext.EvaluationFlags);
                    GetResultAndContinue(dataItem, workList, declaredType, declaredTypeInfo, inspectionContext, parent: null, completionRoutine: completionRoutine);
                }
            }
        }
Ejemplo n.º 54
0
 private void GetChild(
     DkmEvaluationResult parent,
     WorkList workList,
     EvalResult row,
     DkmCompletionRoutine<DkmEvaluationAsyncResult> completionRoutine)
 {
     var inspectionContext = row.InspectionContext;
     if ((row.Kind != ExpansionKind.Default) || (row.Value == null))
     {
         CreateEvaluationResultAndContinue(
             row,
             workList,
             row.InspectionContext,
             parent.StackFrame,
             child => completionRoutine(new DkmEvaluationAsyncResult(child)));
     }
     else
     {
         var typeDeclaringMember = row.TypeDeclaringMemberAndInfo;
         var name = (typeDeclaringMember.Type == null) ?
             row.Name :
             GetQualifiedMemberName(row.InspectionContext, typeDeclaringMember, row.Name, FullNameProvider);
         row.Value.GetResult(
             workList.InnerWorkList,
             row.DeclaredTypeAndInfo.ClrType,
             row.DeclaredTypeAndInfo.Info,
             row.InspectionContext,
             Formatter.NoFormatSpecifiers,
             name,
             row.FullName,
             result => workList.ContinueWith(() => completionRoutine(result)));
     }
 }
Ejemplo n.º 55
0
        private static void EvaluateDebuggerDisplayStringAndContinue(
            DkmClrValue value,
            WorkList workList,
            DkmInspectionContext inspectionContext,
            DkmClrType targetType,
            string str,
            CompletionRoutine<DkmEvaluateDebuggerDisplayStringAsyncResult> onCompleted,
            CompletionRoutine<Exception> onException)
        {
            DkmCompletionRoutine<DkmEvaluateDebuggerDisplayStringAsyncResult> completionRoutine =
                result =>
                {
                    try
                    {
                        onCompleted(result);
                    }
                    catch (Exception e)
                    {
                        onException(e);
                    }

                    workList.Execute();
                };
            if (str == null)
            {
                completionRoutine(default(DkmEvaluateDebuggerDisplayStringAsyncResult));
            }
            else
            {
                value.EvaluateDebuggerDisplayString(workList.InnerWorkList, inspectionContext, targetType, str, completionRoutine);
            }
        }
 /// <summary>
 /// Must follow field edges of value types backwards as well
 /// </summary>
 public Variable GetLocalMappingToLoc(ISymValue loc) {
   WorkList refparams = new WorkList();
   WorkList fields = new WorkList();
   fields.Add(loc);
   while (! fields.IsEmpty()) {
     ISymValue sv = (ISymValue)fields.Pull();
     foreach (EGraphTerm eterm in egraph.EqTerms(sv)) {
       if ( !(eterm.Function is StackVariable)) {
         Variable v = eterm.Function as Variable;
         if (v != null) {
           return v;
         }
         Field f = eterm.Function as Field;
         if (f != null && f.DeclaringType.IsValueType) {
           if (eterm.Args.Length>0) {
             fields.Add(eterm.Args[0]);
           }
         }
         if (eterm.Function == ValueOf && eterm.Args.Length>0) {
           // could be that we are looking at a ref parameter
           refparams.Add(eterm.Args[0]);
         }
       }
     }
   }
   while (! refparams.IsEmpty()) {
     ISymValue sv = (ISymValue)refparams.Pull();
     foreach (EGraphTerm eterm in egraph.EqTerms(sv)) {
       if ( !(eterm.Function is StackVariable)) {
         Variable v = eterm.Function as Variable;
         if (v != null && (v.Type is Reference || v.Type is Pointer)) {
           return v;
         }
       }
     }
   }
   return null;
 }
Ejemplo n.º 57
0
 private void GetItemsAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, int startIndex, int count, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmEvaluationEnumAsyncResult> completionRoutine)
 {
     var expansion = dataItem.Expansion;
     var value = dataItem.Value;
     var rows = ArrayBuilder<EvalResultDataItem>.GetInstance();
     if (expansion != null)
     {
         int index = 0;
         expansion.GetRows(this, rows, inspectionContext, dataItem, value, startIndex, count, visitAll: false, index: ref index);
     }
     var numRows = rows.Count;
     Debug.Assert(count >= numRows);
     var results = new DkmEvaluationResult[numRows];
     var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e)));
     GetEvaluationResultsAndContinue(rows, results, 0, numRows, wl, inspectionContext, value.StackFrame,
         () => wl.ContinueWith(
             () =>
             {
                 completionRoutine(new DkmEvaluationEnumAsyncResult(results));
                 rows.Free();
             }));
     wl.Execute();
 }
Ejemplo n.º 58
0
        void IDkmClrResultProvider.GetItems(DkmEvaluationResultEnumContext enumContext, DkmWorkList workList, int startIndex, int count, DkmCompletionRoutine<DkmEvaluationEnumAsyncResult> completionRoutine)
        {
            var enumContextDataItem = enumContext.GetDataItem<EnumContextDataItem>();
            if (enumContextDataItem == null)
            {
                // We don't know about this result.  Call next implementation
                enumContext.GetItems(workList, startIndex, count, completionRoutine);
                return;
            }

            var evaluationResult = enumContextDataItem.Result;
            var dataItem = evaluationResult.GetDataItem<EvalResultDataItem>();
            var expansion = dataItem.Expansion;
            if (expansion == null)
            {
                completionRoutine(new DkmEvaluationEnumAsyncResult(new DkmEvaluationResult[0]));
                return;
            }

            var inspectionContext = enumContext.InspectionContext;

            var rows = ArrayBuilder<EvalResult>.GetInstance();
            int index = 0;
            expansion.GetRows(this, rows, inspectionContext, dataItem, dataItem.Value, startIndex, count, visitAll: false, index: ref index);
            var numRows = rows.Count;
            Debug.Assert(count >= numRows);
            var results = new DkmEvaluationResult[numRows];
            CompletionRoutine<Exception> onException = e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e));
            var wl = new WorkList(workList, onException);
            wl.ContinueWith(() =>
                GetEvaluationResultsAndContinue(evaluationResult, rows, results, 0, numRows, wl, inspectionContext,
                    () =>
                    wl.ContinueWith(
                        () =>
                        {
                            completionRoutine(new DkmEvaluationEnumAsyncResult(results));
                            rows.Free();
                        }),
                    onException));
        }
Ejemplo n.º 59
0
 private static void EvaluateDebuggerDisplayStringAndContinue(
     DkmClrValue value,
     WorkList workList,
     DkmInspectionContext inspectionContext,
     DkmClrType targetType,
     string str,
     CompletionRoutine<DkmEvaluateDebuggerDisplayStringAsyncResult> onCompleted,
     CompletionRoutine<Exception> onException)
 {
     DkmCompletionRoutine<DkmEvaluateDebuggerDisplayStringAsyncResult> completionRoutine =
         result =>
         {
             try
             {
                 onCompleted(result);
             }
             catch (Exception e) when (ExpressionEvaluatorFatalError.ReportNonFatalException(e, DkmComponentManager.ReportCurrentNonFatalException))
             {
                 onException(e);
             }
         };
     if (str == null)
     {
         completionRoutine(default(DkmEvaluateDebuggerDisplayStringAsyncResult));
     }
     else
     {
         value.EvaluateDebuggerDisplayString(workList.InnerWorkList, inspectionContext, targetType, str, completionRoutine);
     }
 }
Ejemplo n.º 60
0
        private void PlacePhiFunctions()
        {
            var defVars = LocateAllDefinedVariables(AOrig);
            MarkTemporariesDeadIn(AOrig);

            // For each defined variable in block n, collect the places where it is defined

            foreach (var a in defVars)
            {
                // Create a worklist W of all the blocks that define a.

                var W = new WorkList<Block>();
                foreach (Block b in SsaState.DomGraph.ReversePostOrder.Keys)
                {
                    byte bits;
                    AOrig[SsaState.RpoNumber(b)].TryGetValue(a, out bits);
                    if ((bits & BitDefined) != 0)
                        W.Add(b);
                }
                Block n;
                while (W.GetWorkItem(out n))
                {
                    foreach (Block y in SsaState.DomGraph.DominatorFrontier(n))
                    {
                        // Only add phi functions if there is no
                        // phi already and variable is not deadIn.

                        var dict = AOrig[SsaState.RpoNumber(y)];
                        byte bits;
                        dict.TryGetValue(a, out bits);
                        if ((bits & (BitHasPhi | BitDeadIn)) == 0)
                        {
                            bits |= BitHasPhi;
                            dict[a] = bits;
                            InsertPhiStatement(y, a);
                            if ((bits & BitDefined) == 0)
                            {
                                W.Add(y);
                            }
                        }
                    }
                }
            }
        }