Exemple #1
0
        /// <summary>
        /// Generates the final snapshot text representation.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateFinalSnapshotText(OutputBase output)
        {
            output.Headline("Final snapshot content");
            output.EmptyLine();

            if (programPointGraph != null && programPointGraph.End != null && programPointGraph.End.OutSet != null)
            {
                output.CommentLine("Number of memory locations: " + programPointGraph.End.OutSnapshot.NumMemoryLocations());

                Snapshot snapshot = getSnapshot(programPointGraph.End);
                if (snapshot != null)
                {
                    output.CommentLine("Number of variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyVariables.Count);
                    output.CommentLine("Number of control variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyControllVariables.Count);
                    output.CommentLine("Number of temporary variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyTemporaryVariables.Count);
                    output.CommentLine("Number of arrays: " + snapshot.Structure.Readonly.ArrayDescriptors.Count());
                    output.CommentLine("Number of objects: " + snapshot.Structure.Readonly.ObjectDescriptors.Count());

                    SnapshotTextGenerator generator = new SnapshotTextGenerator(output);
                    generator.GenerateSnapshotText(snapshot);
                }
                else
                {
                    output.EmptyLine();
                    output.ProgramPointInfo("", programPointGraph.End);
                }
            }
            else
            {
                output.Error("End point was not reached");
            }
        }
Exemple #2
0
        /// <summary>
        /// Generates the warnings report.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateWarnings(OutputBase output)
        {
            output.Headline("Warnings");
            output.EmptyLine();
            output.CommentLine("Total number of warnings: " + GetNumberOfWarnings());


            if (IsFirstPhaseStarted)
            {
                output.CommentLine("Number of analysis warnings in the first phase: " + (analysisWarnings.Count));
                output.CommentLine("Number of security warnings in the first phase: " + (securityWarnings.Count));
            }
            if (IsSecondPhaseStarted)
            {
                output.CommentLine("Number of warnings in the second phase: " + secondPhaseWarnings.Count);
            }

            if (IsFirstPhaseStarted)
            {
                GenerateWarningsOutput(output, analysisWarnings, "First phase analysis warnings");
                GenerateWarningsOutput(output, securityWarnings, "First phase security warnings");
            }
            if (IsSecondPhaseStarted)
            {
                GenerateWarningsOutput(output, secondPhaseWarnings, "Second phase analysis warnings", true);
            }
        }
Exemple #3
0
        public void GenerateSnapshotText(Snapshot snapshot)
        {
            this.snapshot = snapshot;
            this.result   = new StringBuilder();

            if (snapshot.CallLevel > Snapshot.GLOBAL_CALL_LEVEL)
            {
                output.EmptyLine();
                output.Headline2("Local variables");
                createRepresentation(snapshot.Structure.Readonly.ReadonlyLocalContext.ReadonlyVariables);
            }
            output.EmptyLine();
            output.Headline2("Global variables");
            createRepresentation(snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyVariables);

            if (snapshot.CallLevel > Snapshot.GLOBAL_CALL_LEVEL)
            {
                output.EmptyLine();
                output.Headline2("Local controls");
                createRepresentation(snapshot.Structure.Readonly.ReadonlyLocalContext.ReadonlyControllVariables);
            }

            output.EmptyLine();
            output.Headline2("Global controls");
            createRepresentation(snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyControllVariables);

            output.EmptyLine();
            output.Headline2("Objects");
            createObjectsRepresentation();


            /*output.EmptyLine();
             * output.Headline2("===ARRAYS===");
             * createArraysRepresentation();
             *
             *
             * output.EmptyLine();
             * output.Headline2("===ALIASES===");
             * createAliasesRepresentation();*/
        }
Exemple #4
0
        /// <summary>
        /// Generates the output of the analysis.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateOutput(OutputBase output)
        {
            output.EmptyLine();
            output.Headline("Analysis summary");

            if (Watch != null)
            {
                var ts = Watch.Elapsed;

                output.EmptyLine();
                output.Headline2("Time consumption");
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                output.CommentLine("Weverca analyzer time consumption: " + elapsedTime);

                if (IsFirstPhaseStarted)
                {
                    var ts1 = WatchFirstPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts1.Hours, ts1.Minutes, ts1.Seconds, ts1.Milliseconds);
                    output.CommentLine("First phase time consumption: " + elapsedTime);
                }
                if (IsSecondPhaseStarted)
                {
                    var ts2 = WatchSecondPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds);
                    output.CommentLine("Second phase time consumption: " + elapsedTime);
                }
            }

            if (FirstPhaseInitialMemory != 0)
            {
                output.EmptyLine();
                output.Headline2("Memory consumption");
                output.CommentLine(string.Format("Initial memory before the first phase: {0}",
                                                 OutputUtils.GetMemoryText(FirstPhaseInitialMemory)
                                                 ));

                if (IsFirstPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the first phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory - FirstPhaseInitialMemory)
                                                     ));
                }
                if (IsSecondPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the second phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory - FirstPhaseEndMemory)
                                                     ));
                }
            }

            output.EmptyLine();
            output.Headline2("Code statistics");

            if (controlFlowGraph != null)
            {
                List <BasicBlock> basicBlocks = controlFlowGraph.CollectAllBasicBlocks();
                output.CommentLine("The number of basic blocks of code is: " + basicBlocks.Count);
            }

            if (programPointGraph != null)
            {
                var programLines          = new Dictionary <string, HashSet <int> >();
                int numberOfProgramPoints = NumProgramPoints(new HashSet <ProgramPointGraph>(), programLines, programPointGraph);
                int numberOfProgramLines  = NumProgramLines(programLines);

                output.CommentLine("The number of processed lines of code is: " + numberOfProgramLines);
                output.CommentLine("The number of program points in the application is: " + numberOfProgramPoints);

                if (programPointGraph.End.OutSet != null)
                {
                    output.CommentLine("The number of memory locations in final snapshot is: " + programPointGraph.End.OutSnapshot.NumMemoryLocations());
                }
                else
                {
                    output.CommentLine("End program point was not reached");
                }
            }
            else
            {
                output.CommentLine("Program point graph was not built");
            }

            output.EmptyLine();
            output.Headline2("Warnings");
            output.CommentLine("Total number of warnings: " + GetNumberOfWarnings());
            if (IsFirstPhaseStarted)
            {
                output.CommentLine("Number of warnings in the first phase: " + (analysisWarnings.Count + securityWarnings.Count));
            }
            if (IsSecondPhaseStarted)
            {
                output.CommentLine("Number of warnings in the second phase: " + secondPhaseWarnings.Count);
            }
        }