private bool ExecutePosTest(string testId, string testDesc, 
                                string errorNum1, string errorNum2,
                                DebuggableAttribute.DebuggingModes actualModes,
                                MyDebuggingModes expectedModes)
    {
        bool retVal = true;
        string errorDesc;

        TestLibrary.TestFramework.BeginScenario(testDesc);
        try
        {
            if (actualModes != (DebuggableAttribute.DebuggingModes)expectedModes)
            {
                errorDesc = "Value of " + actualModes + " is not the value " + (int)expectedModes +
                            " as expected: Actually(" + (int)actualModes + ")";
                TestLibrary.TestFramework.LogError(errorNum1 + " TestId-" + testId, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError(errorNum2 + " TestId-" + testId, errorDesc);
            retVal = false;
        }

        return retVal;
    }
示例#2
0
        public AboutBox()
        {
            InitializeComponent();

            foreach (Assembly s in AppDomain.CurrentDomain.GetAssemblies())
            {
                string[] lvsi = new string[3];
                lvsi[0] = s.GetName().Name;
                lvsi[1] = s.GetName().FullName;
                lvsi[2] = s.GetName().Version.ToString();
                ListViewItem lvi = new ListViewItem(lvsi, 0);
                this.ListOfAssemblies.Items.Add(lvi);
            }

            AssemblyCopyrightAttribute   objCopyright   = AssemblyCopyrightAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyCopyrightAttribute)) as AssemblyCopyrightAttribute;
            AssemblyDescriptionAttribute objDescription = AssemblyDescriptionAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute)) as AssemblyDescriptionAttribute;
            AssemblyCompanyAttribute     objCompany     = AssemblyCompanyAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute)) as AssemblyCompanyAttribute;
            AssemblyTrademarkAttribute   objTrademark   = AssemblyTrademarkAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyTrademarkAttribute)) as AssemblyTrademarkAttribute;
            AssemblyProductAttribute     objProduct     = AssemblyProductAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute)) as AssemblyProductAttribute;
            AssemblyTitleAttribute       objTitle       = AssemblyTitleAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute)) as AssemblyTitleAttribute;
            GuidAttribute         objGuid         = GuidAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(GuidAttribute)) as GuidAttribute;
            DebuggableAttribute   objDebuggable   = DebuggableAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(DebuggableAttribute)) as DebuggableAttribute;
            CLSCompliantAttribute objCLSCompliant = CLSCompliantAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(CLSCompliantAttribute)) as CLSCompliantAttribute;

            AppName.Text        = objProduct.Product;
            BigTitle.Text       = objTitle.Title;
            ProdVer.Text        = QuestDesignerMain.Version;
            AppDesc.Text        = objDescription.Description;
            CopyrightLabel.Text = objCopyright.Copyright;
            SerialNo.Text       = objGuid.Value;
            Company.Text        = objCompany.Company;
        }
示例#3
0
        public static string GetBuildType(string assemblyName)
        {
            StringBuilder sb         = new StringBuilder();
            Assembly      assm       = Assembly.LoadFrom(assemblyName);
            var           attributes = assm.GetCustomAttributes(typeof(DebuggableAttribute), false);

            if (attributes.Length == 0)
            {
                sb.AppendLine($"{assemblyName} is a RELEASE Build....");
                return(sb.ToString());
            }

            foreach (Attribute attr in attributes)
            {
                if (attr is DebuggableAttribute)
                {
                    DebuggableAttribute d = attr as DebuggableAttribute;
                    sb.AppendLine($"Run time Optimizer is enabled : {!d.IsJITOptimizerDisabled}");
                    sb.AppendLine($"Run time Tracking is enabled : {d.IsJITTrackingEnabled}");
                    if (d.IsJITOptimizerDisabled)
                    {
                        sb.AppendLine($"{assemblyName} is a DEBUG Build....");
                        return(sb.ToString());
                    }

                    sb.AppendLine($"{assemblyName} is a RELEASE Build....");
                    return(sb.ToString());
                }
            }

            return(sb.ToString());
        }
示例#4
0
        static void Main(string[] args)
        {
            // find out whether the CLR thinks optimizations are supposed to be on or off
            Assembly asm = Assembly.GetExecutingAssembly();

            object[] attrs = asm.GetCustomAttributes(typeof(DebuggableAttribute), false);
            if (attrs != null && attrs.Length >= 1)
            {
                for (int i = 0; i < attrs.Length; i++)
                {
                    DebuggableAttribute da = attrs[i] as DebuggableAttribute;
                    Console.WriteLine("IsJITOptimizerDisabled: {0}",
                                      da.IsJITOptimizerDisabled);
                    Console.WriteLine("IsJITTrackingEnabled: {0}", da.IsJITTrackingEnabled);
                }
            }
            else
            {
                Console.WriteLine("DebuggableAttribute not present.");
            }

            int nIters = 100000000;

            ProfileProperty(nIters);
            ProfileField(nIters);
            ProfileProperty(nIters);
            ProfileField(nIters);
        }
示例#5
0
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(DemoClass);
            // See if the Debuggable attribute is defined for this module.
            bool isDef = Attribute.IsDefined(clsType.Module,
                                             typeof(DebuggableAttribute));

            // Display the result.
            Console.WriteLine("The Debuggable attribute {0} " +
                              "defined for Module {1}.",
                              isDef ? "is" : "is not",
                              clsType.Module.Name);
            // If the attribute is defined, display the JIT settings.
            if (isDef)
            {
                // Retrieve the attribute itself.
                DebuggableAttribute dbgAttr = (DebuggableAttribute)
                                              Attribute.GetCustomAttribute(clsType.Module,
                                                                           typeof(DebuggableAttribute));
                if (dbgAttr != null)
                {
                    Console.WriteLine("JITTrackingEnabled is {0}.",
                                      dbgAttr.IsJITTrackingEnabled);
                    Console.WriteLine("JITOptimizerDisabled is {0}.",
                                      dbgAttr.IsJITOptimizerDisabled);
                }
                else
                {
                    Console.WriteLine("The Debuggable attribute " +
                                      "could not be retrieved.");
                }
            }
        }
示例#6
0
 private static DebugOutputType GetDebugOutputType(DebuggableAttribute debuggableAttribute)
 {
     return((debuggableAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) !=
            DebuggableAttribute.DebuggingModes.None
         ? DebugOutputType.Full
         : DebugOutputType.PdbOnly);
 }
示例#7
0
        protected override void OnStart(string[] args)
        {
            DebuggableAttribute att = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttribute <DebuggableAttribute>();

            if (att.IsJITTrackingEnabled)
            {
                //Debug模式才让线程停止10s,方便附加到进程调试
                Thread.Sleep(10000);
            }
            //配置信息读取
            ConfigInit.Init();
            //3.系统参数配置初始化
            MefConfig.Init();
            ConfigManager configManager = MefConfig.TryResolve <ConfigManager>();

            configManager.Init();
            QuartzHelper.InitScheduler();
            QuartzHelper.StartScheduler();
            // 保持web服务运行
            ThreadPool.QueueUserWorkItem((o) =>
            {
                //启动站点
                Startup.Start(SystemConfig.WebHost, SystemConfig.WebPort);
            });
        }
示例#8
0
        private void LoadInformation()
        {
            DebuggableAttribute debugAttribute = Assembly.GetCustomAttributes(false).OfType <DebuggableAttribute>().FirstOrDefault();

            var modules = Assembly.GetModules(false);

            if (modules.Length > 0)
            {
                PortableExecutableKinds portableExecutableKinds;
                ImageFileMachine        imageFileMachine;
                modules[0].GetPEKind(out portableExecutableKinds, out imageFileMachine);

                foreach (PortableExecutableKinds kind in Enum.GetValues(typeof(PortableExecutableKinds)))
                {
                    if ((portableExecutableKinds & kind) == kind && kind != PortableExecutableKinds.NotAPortableExecutableImage)
                    {
                        if (!String.IsNullOrEmpty(this.AssemblyKind))
                        {
                            this.AssemblyKind += Environment.NewLine;
                        }

                        this.AssemblyKind += "- " + PortableExecutableKindsNames[kind];
                    }
                }
                ////assemblyKindTextBox.Text = PortableExecutableKindsNames[portableExecutableKinds];
                this.TargetProcessor = ImageFileMachineNames[imageFileMachine];

                // Any CPU builds are reported as 32bit.
                // 32bit builds will have more value for PortableExecutableKinds
                if (imageFileMachine == ImageFileMachine.I386 && portableExecutableKinds == PortableExecutableKinds.ILOnly)
                {
                    this.TargetProcessor = "AnyCPU";
                }
            }

            if (debugAttribute != null)
            {
                this.JitTrackingEnabled = debugAttribute.IsJITTrackingEnabled;
                this.JitOptimized       = !debugAttribute.IsJITOptimizerDisabled;
                this.IgnoreSymbolStoreSequencePoints = (debugAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints) != DebuggableAttribute.DebuggingModes.None;
                this.EditAndContinueEnabled          = (debugAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.EnableEditAndContinue) != DebuggableAttribute.DebuggingModes.None;

                this.DebuggingFlags = debugAttribute.DebuggingFlags;
            }
            else
            {
                // No DebuggableAttribute means IsJITTrackingEnabled=false, IsJITOptimizerDisabled=false, IgnoreSymbolStoreSequencePoints=false, EnableEditAndContinue=false
                this.JitTrackingEnabled = false;
                this.JitOptimized       = true;
                this.IgnoreSymbolStoreSequencePoints = false;
                this.EditAndContinueEnabled          = false;
                this.DebuggingFlags = null;
            }

            this.AssemblyFullName = Assembly.FullName;

            this.FrameWorkVersion = Assembly.ImageRuntimeVersion;
        }
示例#9
0
        public static bool ReleaseMode()
        {
            // From https://dave-black.blogspot.com/2011/12/how-to-tell-if-assembly-is-debug-or.html

            bool HasDebuggableAttribute = false;
            var  IsJITOptimized         = false;
            var  IsJITTrackingEnabled   = false;
            var  BuildType         = "";
            var  DebugOutput       = "";
            var  ReflectedAssembly = Assembly.LoadFile(@"C:\src\TMDE\Git\RedisScalingTest\bin\Release\netcoreapp3.1\RedisScalingTest.dll");

            // var ReflectedAssembly = Assembly.LoadFile(@"path to the dll you are testing");
            object[] attribs = ReflectedAssembly.GetCustomAttributes(typeof(DebuggableAttribute), false);

            // If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build
            if (attribs.Length > 0)
            {
                // Just because the 'DebuggableAttribute' is found doesn't necessarily mean it's a
                // DEBUG build; we have to check the JIT Optimization flag i.e. it could have the
                // "generate PDB" checked but have JIT Optimization enabled
                DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;
                if (debuggableAttribute != null)
                {
                    HasDebuggableAttribute = true;
                    IsJITOptimized         = !debuggableAttribute.IsJITOptimizerDisabled;

                    // IsJITTrackingEnabled - Gets a value that indicates whether the runtime will
                    // track information during code generation for the debugger.
                    IsJITTrackingEnabled = debuggableAttribute.IsJITTrackingEnabled;
                    BuildType            = debuggableAttribute.IsJITOptimizerDisabled ? "Debug" : "Release";

                    // check for Debug Output "full" or "pdb-only"
                    DebugOutput = (debuggableAttribute.DebuggingFlags &
                                   DebuggableAttribute.DebuggingModes.Default) !=
                                  DebuggableAttribute.DebuggingModes.None
                                    ? "Full" : "pdb-only";
                }
            }
            else
            {
                IsJITOptimized = true;
                BuildType      = "Release";
            }

            // Output
            Debug.WriteLine("HasDebuggableAttribute", HasDebuggableAttribute);
            Debug.WriteLine("IsJITOptimized", IsJITOptimized);
            Debug.WriteLine("IsJITTrackingEnabled", IsJITTrackingEnabled);
            Debug.WriteLine("DebugOutput", DebugOutput);

            if (BuildType == "Release")
            {
                return(true);
            }

            return(false);
        }
示例#10
0
        private void btnVerificar_Click(object sender, EventArgs e)
        {
            txtDllDebug.Text   = "";
            txtDllRelease.Text = "";
            string diretorio = txtDiretorio.Text;

            if (!Directory.Exists(diretorio))
            {
                lblInfo.Text = "Diretório Inválido!";
                return;
            }

            var listaArquivosDeb = new List <string>();
            var listaArquivosRel = new List <string>();

            string[] filePaths = Directory.GetFiles(diretorio, "*.dll");
            string   nomeDll;

            foreach (string arquivos in filePaths)
            {
                var a = Assembly.LoadFile(arquivos);

                object[] attribs = a.GetCustomAttributes(typeof(DebuggableAttribute), false);

                if (attribs.Length <= 0)
                {
                    continue;
                }

                DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;

                if (debuggableAttribute == null)
                {
                    continue;
                }

                nomeDll = a.FullName.Split(',')[0] + " " + a.FullName.Split(',')[1];

                if (debuggableAttribute.IsJITOptimizerDisabled)//TRUE == DEBUG
                {
                    listaArquivosDeb.Add(nomeDll);
                }
                else
                {
                    listaArquivosRel.Add(nomeDll);
                }
            }
            foreach (var item in listaArquivosDeb)
            {
                txtDllDebug.AppendText(item + Environment.NewLine);
            }
            foreach (var item in listaArquivosRel)
            {
                txtDllRelease.AppendText(item + Environment.NewLine);
            }
        }
示例#11
0
        static bool SPCOptimizationsEnabled()
        {
            Assembly objectAssembly = Assembly.GetAssembly(typeof(object));

            object[] attribs = objectAssembly.GetCustomAttributes(typeof(DebuggableAttribute),
                                                                  false);
            DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;

            return((debuggableAttribute == null) || !debuggableAttribute.IsJITOptimizerDisabled);
        }
示例#12
0
 private static bool IsDebugMode()
 {
     object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute), false);
     if ((customAttributes != null) && (customAttributes.Length == 1))
     {
         DebuggableAttribute attribute = customAttributes[0] as DebuggableAttribute;
         return(attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled);
     }
     return(false);
 }
示例#13
0
        private static void UploadVersionToFtp()
        {
            while (PreloaderWindow.CurrentWindow == null)
            {
                Thread.Sleep(100);
            }

            try
            {
                Debug.WriteLine("Uploading command started", TraceCategory);
                PreloaderWindow.ShowFirstStep();

                object[]            customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute), false);
                DebuggableAttribute attribute        = customAttributes.FirstOrDefault() as DebuggableAttribute;
                bool isDebugConfiguration            = attribute != null && attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled;
                Debug.WriteLine("Is current configuration debug: " + isDebugConfiguration, TraceCategory);
                if (isDebugConfiguration)
                {
                    //Do nothing, then kill current process
                    //Process.GetCurrentProcess().Kill();
                }

                string executionFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (string.IsNullOrEmpty(executionFolder) || !Directory.Exists(executionFolder))
                {
                    throw new Exception("Failed to get directory of current executing assembly.");
                }

                string releaseArchiveFileName = Path.GetFileName(UpdateFilePath);
                if (string.IsNullOrEmpty(releaseArchiveFileName))
                {
                    throw new Exception("Failed to get name of release archive file.");
                }

                string releaseArchiveFilePath = Path.Combine(executionFolder, releaseArchiveFileName);
                if (string.IsNullOrEmpty(releaseArchiveFilePath) || !File.Exists(releaseArchiveFilePath))
                {
                    throw new Exception("Failed to get release archive file.");
                }

                WebClient client = new WebClient {
                    Credentials = new NetworkCredential(FtpUserName, FtpPassword)
                };
                client.UploadFile(UpdateFilePath, releaseArchiveFilePath);

                Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
                client.UploadString(VersionFilePath, currentVersion.ToString());
                Process.GetCurrentProcess().Kill();
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to upload version to FTP. " + e.Message, "Uploading error", MessageBoxButton.OK, MessageBoxImage.Error);
                Process.GetCurrentProcess().Kill();
            }
        }
示例#14
0
        /// <summary>
        /// Checks if the assembly is currently started in debug mode.
        /// </summary>
        /// <returns></returns>
        public Boolean IsDebugEnabled()
        {
            if (debugCheckHelper < 0)
            {
                Assembly            thisAssembly = Assembly.GetAssembly(typeof(AbstractApplicationContext));
                DebuggableAttribute debuggable   = (DebuggableAttribute)DebuggableAttribute.GetCustomAttribute(thisAssembly, typeof(DebuggableAttribute));

                debugCheckHelper = debuggable != null && debuggable.IsJITTrackingEnabled ? 1 : 0;
            }
            return(debugCheckHelper == 1);
        }
        /// <summary>
        ///  Indicates whether the Assembly has been compiled in "Release" mode.
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        public static bool IsReleaseMode(this Assembly assembly)
        {
            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true);
            if (attributes == null || attributes.Length == 0)
            {
                return(true);
            }

            DebuggableAttribute debug = (DebuggableAttribute)attributes[0];

            return((debug.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) == DebuggableAttribute.DebuggingModes.None);
        }
示例#16
0
        private static bool IsDebugBuild(Assembly assembly)
        {
            foreach (object attribute in assembly.GetCustomAttributes(false))
            {
                if (attribute is DebuggableAttribute)
                {
                    DebuggableAttribute _attribute = attribute as DebuggableAttribute;

                    return(_attribute.IsJITTrackingEnabled);
                }
            }
            return(false);
        }
示例#17
0
    public static bool IsDebugBuild(this AssemblyDefinition assemblyDefinition)
    {
        var debuggableAttributeDefinition = assemblyDefinition.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName == typeof(DebuggableAttribute).FullName);

        if (debuggableAttributeDefinition == null)
        {
            return(false);
        }

        var debuggableAttribute = new DebuggableAttribute((DebuggableAttribute.DebuggingModes)debuggableAttributeDefinition.ConstructorArguments[0].Value);

        return(debuggableAttribute.IsJITOptimizerDisabled);
    }
示例#18
0
        // TODO: probabably does not belong in this class.
        public void CaptureCurrentMachineInfo(Assembly assemblyWithCode, bool skipMachineStats)
        {
            this["Computer Name"] = Environment.MachineName;
            if (!skipMachineStats)
            {
                ComputerSpecs specs = new ComputerSpecs();
                this["Number of Processors"]        = specs.NumberOfProcessors;
                this["Processor Name "]             = specs.ProcessorName;
                this["Processor Mhz"]               = specs.ProcessorClockSpeedMhz;
                this["Memory MBytes"]               = specs.MemoryMBytes;
                this["L1 Cache KBytes"]             = specs.L1KBytes;
                this["L2 Cache KBytes"]             = specs.L2KBytes;
                this["Operating System"]            = specs.OperatingSystem;
                this["Operating System Version"]    = specs.OperatingSystemVersion;
                this["Stopwatch resolution (nsec)"] = (CodeTimer.ResolutionUsec * 1000.0).ToString("f3");
            }

            // Are we NGENed or JITTed?
            if (IsNGenedCodeLoaded(assemblyWithCode))
            {
                this["CompileType"] = "NGEN";
            }
            else
            {
                this["CompileType"] = "JIT";
            }

            // Are we Appdomain Shared, or not?
            MethodInfo currentMethod = Assembly.GetEntryAssembly().EntryPoint;
            LoaderOptimizationAttribute loaderAttribute = (LoaderOptimizationAttribute)System.Attribute.GetCustomAttribute(currentMethod, typeof(LoaderOptimizationAttribute));

            if (loaderAttribute != null && loaderAttribute.Value == LoaderOptimization.MultiDomain)
            {
                this["CodeSharing"] = "AppDomainShared";
            }
            else
            {
                this["CodeSharing"] = "AppDomainSpecific";
            }

            DebuggableAttribute debugAttribute = (DebuggableAttribute)System.Attribute.GetCustomAttribute(assemblyWithCode, typeof(System.Diagnostics.DebuggableAttribute));

            if (debugAttribute != null && debugAttribute.IsJITOptimizerDisabled)
            {
                this["CodeOptimization"] = "Unoptimized";
            }
            else
            {
                this["CodeOptimization"] = "Optimized";
            }
        }
示例#19
0
 /// <summary>
 /// Returns true if called assembly is builded as Debug release.
 /// </summary>
 /// <param name="assembly">Assembly to check for build mode.</param>
 public static bool IsAssemblyBuildAsDebug(Assembly assembly = null)
 {
     if (assembly == null)
     {
         return(false);
     }
     object[] customAttributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);
     if ((customAttributes != null) && (customAttributes.Length == 1))
     {
         DebuggableAttribute attribute = customAttributes[0] as DebuggableAttribute;
         return(attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled);
     }
     return(false);
 }
示例#20
0
        protected override void OnStart(string[] args)
        {
            DebuggableAttribute att = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttribute <DebuggableAttribute>();

            if (att.IsJITTrackingEnabled)
            {
                //Debug模式才让线程停止10s,方便附加到进程调试
                Thread.Sleep(10000);
            }
            //配置信息读取
            ConfigInit.InitConfig();
            QuartzHelper.InitScheduler();
            QuartzHelper.StartScheduler();
        }
示例#21
0
        private bool processCanBeDebugged()
        {
            object[] attribs = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute), true);
            if ((attribs != null) && (attribs.Length == 1))
            {
                DebuggableAttribute attribute = attribs[0] as DebuggableAttribute;

                if (attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#22
0
        private static bool?Read(DebuggableAttribute debuggableAttribute, string propertyName)
        {
            // the properties are implemented (https://github.com/dotnet/coreclr/pull/6153)
            // but not exposed in corefx Contracs due to .NET Standard versioning problems (https://github.com/dotnet/corefx/issues/13717)
            // so we need to use reflection to read this simple property...
            var propertyInfo = typeof(DebuggableAttribute).GetProperty(propertyName);

            if (debuggableAttribute == null || propertyInfo == null)
            {
                return(null);
            }

            return((bool)propertyInfo.GetValue(debuggableAttribute));
        }
示例#23
0
        public static TryIsDebugResponse TryIsDebug(Assembly assembly)
        {
            var response = new TryIsDebugResponse
            {
                Result = new IsDebugResult
                {
                    IsJITOptimized         = true,
                    HasDebuggableAttribute = false,
                    DebugOutput            = DebugOutputType.Undefined
                }
            };

            CustomAttributeTypedArgument debuggingModesArgument;

            try
            {
                var reflectedAttribute = CustomAttributeData.GetCustomAttributes(assembly)
                                         .FirstOrDefault(data => data.AttributeType == typeof(DebuggableAttribute));

                if (reflectedAttribute == null)
                {
                    return(response);
                }

                debuggingModesArgument = reflectedAttribute.ConstructorArguments
                                         .FirstOrDefault(argument => argument.ArgumentType == typeof(DebuggableAttribute.DebuggingModes));
            }
            catch (Exception exception)
            {
                response.ErrorMessage = $"Could not load {assembly.FullName}. Reason: {exception.Message}";
                return(response);
            }

            var argumentIntValue = debuggingModesArgument.Value as int?;

            if (argumentIntValue != null)
            {
                var debuggableAttribute = new DebuggableAttribute((DebuggableAttribute.DebuggingModes)argumentIntValue.Value);

                response.Result.HasDebuggableAttribute = true;
                response.Result.IsJITOptimized         = !debuggableAttribute.IsJITOptimizerDisabled;

                // check for Debug Output "full" or "pdb-only"
                var output = GetDebugOutputType(debuggableAttribute);
                response.Result.DebugOutput = output;
            }

            return(response);
        }
示例#24
0
        bool IfDebuggable()
        {
            bool es = false;

            object[] attribs = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute), true);
            if ((attribs != null) && (attribs.Length == 1))
            {
                DebuggableAttribute attribute = attribs[0] as DebuggableAttribute;

                if (attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled)
                {
                    es = true;
                }
            }
            return(es);
        }
示例#25
0
        private void LoadInformation()
        {
            DebuggableAttribute debugAttribute = Assembly.GetCustomAttributes <DebuggableAttribute>().FirstOrDefault();

            if (debugAttribute != null)
            {
                JitTrackingEnabled     = debugAttribute.IsJITTrackingEnabled;
                JitOptimized           = !debugAttribute.IsJITOptimizerDisabled;
                EditAndContinueEnabled = (debugAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.EnableEditAndContinue) != DebuggableAttribute.DebuggingModes.None;
            }
            else
            {
                // No DebuggableAttribute means IsJITTrackingEnabled=false, IsJITOptimizerDisabled=false, EnableEditAndContinue=false
                JitTrackingEnabled     = false;
                JitOptimized           = true;
                EditAndContinueEnabled = false;
            }
        }
示例#26
0
        public static void PositiveTest6()
        {
            Type clsType = typeof(GetCustomAttribute);
            Type attributeType;

            attributeType = typeof(DebuggableAttribute);
            DebuggableAttribute dbgAttr = (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false);

            Assert.True(dbgAttr != null);

            attributeType = typeof(AssemblyDescriptionAttribute);
            dbgAttr       = (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false);
            Assert.True(dbgAttr == null);

            AssemblyDescriptionAttribute asmdbgAttr = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false);

            Assert.True(asmdbgAttr == null);
        }
 private void ProcessDebugBuild(object[] attributes)
 {
     foreach (Attribute attribute in attributes)
     {
         if (attribute is DebuggableAttribute)
         {
             DebuggableAttribute debuggableAttribute = attribute as DebuggableAttribute;
             if (debuggableAttribute.IsJITOptimizerDisabled == false)
             {
                 Assert.Fail("IsJITOptimizerDisabled should be set to true for Debug builds.");
             }
             if (debuggableAttribute.IsJITTrackingEnabled == false)
             {
                 Assert.Fail("IsJITTrackingEnabled should be set to true for Debug builds.");
             }
         }
     }
 }
示例#28
0
        /// <summary>
        /// Check if the assembly was compiled as release version
        /// </summary>
        /// <param name="assembly">assembly to check</param>
        /// <returns></returns>
        static public bool IsReleaseVersion(Assembly assembly)
        {
            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true);
            if (attributes == null || attributes.Length == 0)
            {
                return(true);
            }

            DebuggableAttribute d = (DebuggableAttribute)attributes[0];

            if ((d.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) == DebuggableAttribute.DebuggingModes.None)
            {
                return(true);
            }
            //if ((d.DebuggingFlags & DebuggableAttribute.DebuggingModes.DisableOptimizations) == DebuggableAttribute.DebuggingModes.None)
            //    return true;
            //if ((d.DebuggingFlags & DebuggableAttribute.DebuggingModes.EnableEditAndContinue) == DebuggableAttribute.DebuggingModes.None)
            //    return true;
            return(false);
        }
示例#29
0
 private static int AdjustWndProcFlagsFromMetadata(int wndProcFlags)
 {
     if ((wndProcFlags & 2) != 0)
     {
         Assembly entryAssembly = Assembly.GetEntryAssembly();
         if ((entryAssembly != null) && Attribute.IsDefined(entryAssembly, typeof(DebuggableAttribute)))
         {
             Attribute[] customAttributes = Attribute.GetCustomAttributes(entryAssembly, typeof(DebuggableAttribute));
             if (customAttributes.Length > 0)
             {
                 DebuggableAttribute attribute = (DebuggableAttribute)customAttributes[0];
                 if (attribute.IsJITTrackingEnabled)
                 {
                     wndProcFlags |= 0x10;
                 }
             }
         }
     }
     return(wndProcFlags);
 }
示例#30
0
        internal static int GetBuildType(string AssemblyName)
        {
            Assembly assm = Assembly.LoadFrom(AssemblyName);

            object[] attributes = assm.GetCustomAttributes(typeof(DebuggableAttribute), false);

            if (attributes.Length == 0)
            {
                Console.WriteLine($"{AssemblyName} is a RELEASE Build....");

                return(0);
            }

            foreach (Attribute attr in attributes)
            {
                if (attr is DebuggableAttribute)
                {
                    DebuggableAttribute d = attr as DebuggableAttribute;

                    Console.WriteLine($"Run time Optimizer is enabled : {!d.IsJITOptimizerDisabled}");

                    Console.WriteLine($"Run time Tracking is enabled : {d.IsJITTrackingEnabled}");

                    if (d.IsJITOptimizerDisabled == true)
                    {
                        Console.WriteLine(String.Format("{0} is a DEBUG Build....", AssemblyName));

                        return(1);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("{0} is a RELEASE Build....", AssemblyName));

                        return(0);
                    }
                }
            }

            return(3);
        }
示例#31
0
        /// <summary>
        /// Are we running a debug version?
        /// </summary>
        /// <param name="assembly">The executing assembly.</param>
        /// <returns>True if the assembly was compiled as debug.</returns>
        public static bool IsDebug(Assembly assembly)
        {
            object[] attribs = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);

            // If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build
            if (attribs.Length > 0)
            {
                // Just because the 'DebuggableAttribute' is found doesn't necessarily mean
                // it's a DEBUG build; we have to check the JIT Optimization flag
                // i.e. it could have the "generate PDB" checked but have JIT Optimization enabled
                DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;
                if (debuggableAttribute != null)
                {
                    if (debuggableAttribute.IsJITOptimizerDisabled || debuggableAttribute.IsJITTrackingEnabled)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }