コード例 #1
0
        /// <summary>
        /// Starts the P# dynamic race detection process.
        /// </summary>
        /// <param name="args">Arguments</param>
        public void Start(string[] args)
        {
            StringCollection referencedAssemblies = new StringCollection();
            string           input = this.Configuration.AssemblyToBeAnalyzed;

            Assembly assembly = Assembly.LoadFrom(input);

            referencedAssemblies.Add(assembly.GetName().Name);

            AssemblyName[] assemblyName = assembly.GetReferencedAssemblies();
            foreach (AssemblyName item in assemblyName)
            {
                if (item.Name.Contains("mscorlib") || item.Name.Contains("System") ||
                    item.Name.Contains("NLog") || item.Name.Contains("System.Core"))
                {
                    continue;
                }

                referencedAssemblies.Add(item.Name);
            }

            string[] includedAssemblies = new string[referencedAssemblies.Count];
            referencedAssemblies.CopyTo(includedAssemblies, 0);

            // Starts profiling the access monitor.
            if (this.Configuration.EnableProfiling)
            {
                this.Profiler.StartMeasuringExecutionTime();
            }

            Profiler.StartMeasuringExecutionTime();

            ProcessStartInfo info = ControllerSetUp.GetMonitorableProcessStartInfo(
                AppDomain.CurrentDomain.BaseDirectory + "\\ThreadMonitor.exe",
                args,                            // arguments
                MonitorInstrumentationFlags.All, // monitor flags
                true,                            // track gc accesses

                null,                            // we don't monitor process at startup since it loads the DLL to monitor
                null,                            // user type

                null,                            // substitution assemblies
                null,                            // types to monitor
                null,                            // types to exclude monitor
                null,                            // namespaces to monitor
                null,                            // namespaces to exclude monitor
                includedAssemblies,
                null,                            //assembliesToExcludeMonitor to exclude monitor

                null, null, null, null, null, null,

                null,                     // clrmonitor log file name
                false,                    // clrmonitor  log verbose
                null,                     // crash on failure
                true,                     // protect all cctors
                false,                    // disable mscrolib suppressions
                ProfilerInteraction.Fail, // profiler interaction
                null, "", "");

            var process = new Process();

            process.StartInfo = info;
            process.Start();
            process.WaitForExit();

            // Stops profiling the access monitor.
            if (this.Configuration.EnableProfiling)
            {
                this.Profiler.StopMeasuringExecutionTime();
                IO.PrintLine("... Access monitoring runtime: '" +
                             this.Profiler.Results() + "' seconds.");
            }

            // Starts profiling the race detection.
            if (this.Configuration.EnableProfiling)
            {
                this.Profiler.StartMeasuringExecutionTime();
            }

            new RaceDetectionEngine(this.Configuration).Start();

            // Stops profiling the race detection.
            if (this.Configuration.EnableProfiling)
            {
                this.Profiler.StopMeasuringExecutionTime();
                IO.PrintLine("... Race detection runtime: '" +
                             this.Profiler.Results() + "' seconds.");
            }
        }
コード例 #2
0
ファイル: Launcher.cs プロジェクト: sahilagnihotri/Chess
        private Process Run(bool openWindow, string[] assembliesToMonitor, EventHandler eh)
        {
            SafeDebug.AssumeNotNull(assembliesToMonitor, "assembliesToMonitor");
            // assemblies to instrument
            SafeSet <string> includedAssemblies = new SafeSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var a in assembliesToMonitor)
            {
                includedAssemblies.Add(a);
            }

            if (options.IncludedAssemblies != null)
            {
                foreach (var a in options.IncludedAssemblies)
                {
                    includedAssemblies.Add(a);
                }
            }

            // substitutions
            SafeSet <string> substitutionAssemblies = new SafeSet <string>(StringComparer.OrdinalIgnoreCase);
            Assembly         a1 = typeof(MCLauncher).Assembly;
            var dir             = Path.GetDirectoryName(a1.Location);

            // TODO: should check for existence and fail if required file not present
            substitutionAssemblies.Add(dir + "\\Microsoft.ManagedChess.ThreadingWrappers.dll");
            substitutionAssemblies.Add(dir + "\\Microsoft.ManagedChess.Framework35Wrappers.dll");
            if (File.Exists(dir + "\\Microsoft.ManagedChess.Framework4Wrappers.dll"))
            {
                substitutionAssemblies.Add(dir + "\\Microsoft.ManagedChess.Framework4Wrappers.dll");
                string[] newIncludedTypes = new string[options.IncludedTypes.Length + 1];
                int      i = 0;
                for (; i < options.IncludedTypes.Length; i++)
                {
                    newIncludedTypes[i] = options.IncludedTypes[i];
                }
                newIncludedTypes[i]   = "System.Threading.Tasks.ThreadPoolTaskScheduler";
                options.IncludedTypes = newIncludedTypes;
            }
            if (File.Exists(dir + "\\Microsoft.ManagedChess.MiniMPIWrappers.dll"))
            {
                substitutionAssemblies.Add(dir + "\\Microsoft.ManagedChess.MiniMPIWrappers.dll");
            }

            // make sure we wrap strings, since ER doesn't
            for (int i = 0; i < options.Arguments.Length; i++)
            {
                options.Arguments[i] = WrapString(options.Arguments[i]);
            }


            if (options.CheckAtomicity)
            {
                //// CheckAtomicity implies race detection
                //options.RaceDetection = true;
                // checkatomicity is encoded using observationmode and checkobservations
                options.ObservationMode   = "atom";
                options.CheckObservations = "fakefilename";
            }

            // tolerate deadlock for refinement or atomicity checking
            if (!string.IsNullOrEmpty(options.EnumerateObservations) || !string.IsNullOrEmpty(options.CheckObservations))
            {
                options.TolerateDeadlock = true;
            }

            // TODO
            bool trackAccesses = options.Finesse ||
                                 options.PreemptAccesses ||
                                 options.RaceDetection ||
                                 options.CheckAtomicity ||
                                 !String.IsNullOrEmpty(options.PreemptionVariables);

            // Best-first search requires gc tracking (BFS)
            bool gcTracking = trackAccesses || options.MonitorVolatile || options.BestFirst;

            // the following options imply that sober is needed
            if (options.RaceDetection || options.CheckAtomicity)
            {
                options.Sober = true;
            }

            // Method prioritization works exactly like DontPreemptMethods (BFS)
            bool enterLeave = options.Diagnose ||
                              (options.DontPreemptAssemblies != null && options.DontPreemptAssemblies.Length > 0) ||
                              (options.DontPreemptNamespaces != null && options.DontPreemptNamespaces.Length > 0) ||
                              (options.DontPreemptTypes != null && options.DontPreemptTypes.Length > 0) ||
                              (options.DontPreemptMethods != null && options.DontPreemptMethods.Length > 0) ||
                              (options.PrioritizeMethods != null && options.PrioritizeMethods.Length > 0);

            bool call = (options.Diagnose);

            // set up extended reflection
            //ProcessStartInfo dm = ControllerSetUp.GetMonitorableProcessStartInfo(

//            options.Finesse = true;

            ProcessStartInfo info = ControllerSetUp.GetMonitorableProcessStartInfo(
                options.FileName,
                options.Arguments,
                (((call)  ? MonitorInstrumentationFlags.MethodCalls | MonitorInstrumentationFlags.SpecialOnCalling
                        : MonitorInstrumentationFlags.None) |
                 (enterLeave? MonitorInstrumentationFlags.EnterLeaveMethod : MonitorInstrumentationFlags.None) |
                 (trackAccesses ? MonitorInstrumentationFlags.SpecialOnMemoryAccess :
                  options.MonitorVolatile ? MonitorInstrumentationFlags.SpecialOnVolatileMemoryAccess :
                  MonitorInstrumentationFlags.None) |
                 (options.Finesse ? MonitorInstrumentationFlags.SpecialOnNew : MonitorInstrumentationFlags.None) |
                 MonitorInstrumentationFlags.GeneralSubstitutionsOnDelegateBeginEndInvoke),
                gcTracking,

                null, // we don't monitor process at startup since it loads the DLL to monitor
                null, // ibid.

                substitutionAssemblies.ToArray(),
                options.IncludedTypes,
                options.ExcludedTypes,
                options.IncludedNamespaces,
                options.ExcludedNamespaces,
                includedAssemblies.ToArray(),
                options.ExcludedAssemblies,

                null,
                null, null, null,
                null, null,

                options.LogInstrumentation,
                false,
                options.TargetClr,
                !options.MonitorStaticConstructors,
                false,
                ProfilerInteraction.Fail,
                options.Driver, "", ""
                );

            info.CreateNoWindow = openWindow;

            // setup enviroment
            Microsoft.ManagedChess.EREngine.EnvironmentVars.SetEnvironmentVariables(
                info.EnvironmentVariables,
                options.PCT_Arguments,
                options.vb_bound,
                options.DeRandomized_PCT,
                options.Breaks,
                options.Properties,
                options.MonitorVolatile,
                trackAccesses,
                options.PreemptionVariables,
                options.MaxDelays,
                options.MaxPreemptions,
                options.LoadSchedule,
                options.ScheduleFile,
                options.ObservationMode,
                options.EnumerateObservations,
                options.CheckObservations,
                options.OutputPrefix,
                options.XmlCommandline,
                options.Continue,
                options.PrintTrace,
                options.PrintAllTraces,
                options.MonitorStaticConstructors,
                options.Finesse,
                options.Sober,
                options.PreemptAccesses,
                options.MaxExecs,
                options.MaxExecSteps,
                options.MaxChessTime,
                options.MaxExecTime,
                options.TargetRace,
                options.ChessTestClass,
                options.UnitTestName,
                options.Logging,
                options.ProcessorCount,
                options.FlipPreemptionSense,
                options.DontPreemptAssemblies, options.DontPreemptNamespaces,
                options.DontPreemptTypes, options.DontPreemptMethods,
                options.Diagnose,
                options.ShowProgress,
                // best-first search options (BFS)
                options.PrioritizeMethods,
                options.BestFirst,
                options.Dpor,
                options.Bounded,
                options.TolerateDeadlock,
                // debug info only
                includedAssemblies.ToArray()
                );

            Console.WriteLine("ManagedCHESS. Copyright (C) Microsoft Corporation, 2008.");

            if (ControllerEnvironment.CheckOtherProfilerAlreadyLoaded())
            {
                Console.WriteLine("Another profiler already loaded!");
                return(null);
            }

            // Console.WriteLine("launching application in instrumented process...");
            Console.WriteLine("Analyzing {0}  ...", info.Arguments);
            var process = new Process();

            process.StartInfo = info;
            if (eh != null)
            {
                process.EnableRaisingEvents = true;
                process.Exited += new EventHandler(eh);
            }
            if (process.Start())
            {
                return(process);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Starts the P# dynamic race detection process.
        /// </summary>
        /// <param name="args">Arguments</param>
        public void Start(string[] args)
        {
            StringCollection referencedAssemblies = new StringCollection();
            StringCollection excludedAssemblies   = new StringCollection();
            string           input = this.Configuration.AssemblyToBeAnalyzed;

            Assembly assembly = Assembly.LoadFrom(input);

            referencedAssemblies.Add(assembly.GetName().Name);

            AssemblyName[] assemblyName = assembly.GetReferencedAssemblies();
            foreach (AssemblyName item in assemblyName)
            {
                if (item.Name.Contains("mscorlib") || item.Name.Contains("System") || item.Name.Contains("Microsoft.PSharp") ||
                    item.Name.Contains("NLog") || item.Name.Contains("System.Core"))
                {
                    Console.WriteLine("Excluding " + item.Name);
                    excludedAssemblies.Add(item.Name);
                    continue;
                }
                Console.WriteLine("Including " + item.Name);
                referencedAssemblies.Add(item.Name);
            }

            string[] includedAssemblies = new string[referencedAssemblies.Count];
            string[] excluded           = new string[excludedAssemblies.Count];
            referencedAssemblies.CopyTo(includedAssemblies, 0);
            excludedAssemblies.CopyTo(excluded, 0);
            string[] excludedNamespaces = new string[] { "Microsoft.PSharp", "Microsoft.PSharp.Monitors", "Microsoft.PSharp.IO" };

            ProcessStartInfo info = ControllerSetUp.GetMonitorableProcessStartInfo(
                AppDomain.CurrentDomain.BaseDirectory + "\\ThreadMonitor.exe",
                args,                            // arguments
                MonitorInstrumentationFlags.All, // monitor flags
                true,                            // track gc accesses

                null,                            // we don't monitor process at startup since it loads the DLL to monitor
                null,                            // user type

                null,                            // substitution assemblies
                null,                            // types to monitor
                null,                            // types to exclude monitor
                null,                            // namespaces to monitor
                excludedNamespaces,              // namespaces to exclude monitor
                includedAssemblies,              // assemblies to monitor
                excluded,                        //assemblies to exclude monitor

                null, null, null, null, null, null,

                null,                     // clrmonitor log file name
                false,                    // clrmonitor  log verbose
                null,                     // crash on failure
                true,                     // protect all cctors
                false,                    // disable mscrolib suppressions
                ProfilerInteraction.Fail, // profiler interaction
                null, "", "");

            var process = new Process();

            process.StartInfo = info;
            process.Start();
            process.WaitForExit();
        }
コード例 #4
0
        static int Main(string[] args)
        {
            //For debugging purpose only
            //GraphXMLTester.TestInstructionGraphXML(args[0], args[1]);
            //bool btrue = true;
            //if (btrue)
            //    return 0;
            //End of for debugging purpose only

            Console.WriteLine("Tracing: A .NET program tracer demo application");
            Console.WriteLine("Copyright (c) Microsoft Corporation. All rights reserved.");
            Console.WriteLine("(c) Microsoft Corporation. All rights reserved.");
            Console.WriteLine();
            Console.WriteLine("usage: sample.tracing.exe <application to trace> <mode> <optional current asselbly>");
            Console.WriteLine("0: Gathers side effects");
            Console.WriteLine("1: Gathers def-use coverage");
            Console.WriteLine();

            if (args == null || (args.Length != 2 && args.Length != 3))
            {
                Console.WriteLine("Incorrect arguments!!! Please check usage");
                return(-1);
            }

            string[] assembliesToMonitor = null;
            if (args[1] == "0")
            {
                System.Environment.SetEnvironmentVariable("DUCOVER_MODE", "0");
                assembliesToMonitor = new string[] { "*" };
            }
            else if (args[1] == "1")
            {
                System.Environment.SetEnvironmentVariable("DUCOVER_MODE", "1");

                if (args.Length == 3)
                {
                    assembliesToMonitor = new string[] { GetShortNameFromAssembly(args[2]) };
                }
                else
                {
                    assembliesToMonitor = new string[] { GetShortNameFromAssembly(args[0]) };
                }
            }
            else
            {
                Console.WriteLine("Incorrect value for Mode. Only 0 or 1 is allowed");
                return(-1);
            }

            var envvar = System.Environment.GetEnvironmentVariable("DUCOVER_STORE");

            if (envvar == null)
            {
                Console.WriteLine("Environment variable DUCOVER_STORE is not set. Please set it to a valid directory!!!");
                return(-1);
            }

            if (args.Length == 3)
            {
                System.Environment.SetEnvironmentVariable(DUCoverConstants.DUCoverAssemblyVar, GetShortNameFromAssembly(args[2]));
            }
            else
            {
                System.Environment.SetEnvironmentVariable(DUCoverConstants.DUCoverAssemblyVar, GetShortNameFromAssembly(args[0]));
            }

            //Create directory if not exists
            if (!Directory.Exists(envvar))
            {
                Directory.CreateDirectory(envvar);
            }

            // set up the environment variables for the instrumented process
            var userAssembly = Metadata <Tracer> .Assembly;
            var userType     = Metadata <Tracer> .Type;

            //Is it runnning in NUnit mode. Check for environment variable.
            ProcessStartInfo startInfo;
            var nunitpath = System.Environment.GetEnvironmentVariable(DUCoverConstants.DUCoverNUnitEnvPath);

            if (nunitpath == null)
            {
                startInfo = new ProcessStartInfo(args[0], null);
            }
            else
            {
                startInfo = new ProcessStartInfo(nunitpath, args[0]);
            }
            startInfo.UseShellExecute = false;

            //While running in Mode 0, all assemblies including mscorlib needs to be monitored.
            List <string> ignoreList = new List <string>();

            ignoreList.Add(Metadata <_ThreadContext> .Assembly.ShortName);
            ignoreList.Add(userAssembly.ShortName);
            ignoreList.Add("System.Security");
            ignoreList.Add("System.Threading");
            ignoreList.Add("NLog");
            ignoreList.Add("Microsoft.VisualStudio.QualityTools.UnitTestFramework");
            if (args[1] == "1")
            {
                ignoreList.Add(Metadata <Object> .Assembly.ShortName);
                ignoreList.Add("System");
                ignoreList.Add("System.Core");
                ignoreList.Add("System.Data");
                ignoreList.Add("System.Xml");
            }

            if (args.Length == 3)
            {
                ignoreList.Add(GetShortNameFromAssembly(args[0]));
            }

            //Do not monitor NUnit
            if (nunitpath != null)
            {
                ignoreList.Add(nunitpath);
                ignoreList.Add("nunit.framework");
                ignoreList.Add("nunit.framework.extensions");
                ignoreList.Add("Microsoft.Pex.Framework");
                ignoreList.Add("Microsoft.ExtendedReflection");
            }

            var assembliesToIgnore = new string[ignoreList.Count];

            Array.Copy(ignoreList.ToArray(), assembliesToIgnore, ignoreList.Count);

            ControllerSetUp.SetMonitoringEnvironmentVariables(
                startInfo.EnvironmentVariables,
                MonitorInstrumentationFlags.All,
                false,
                userAssembly.Location,
                userType.FullName,
                null, // substitutions assemblies
                null, // types to monitor
                null, // types to exclude to monitor
                null, // namespaces to monitor
                new string[] {
                "System.Threading",
                "System.AppDomain",
                "System.Security",
                "System.IO"
            },                       // namespace to exclude to monitor
                assembliesToMonitor, // assemblies to monitor
                assembliesToIgnore,  //assemblies to ignore
                null,                // types to project
                null, null, null,
                null, null,
                null,                     // log file name
                false,                    // crash on failure
                null,                     // target clr version
                true,                     // protect all .cctors
                false,                    // disable mscorlib supressions
                ProfilerInteraction.Fail, // allow loading external profiler
                null
                );

            try
            {
                using (var process = Process.Start(startInfo))
                {
                    process.WaitForExit();
                    return(process.ExitCode);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(TracingExitCodes.UnexpectedException);
            }
        }