Esempio n. 1
0
        void SetJITCompilerFlags()
        {
            if (Process.DebugMode != DebugModeFlag.Default)
            {
                // translate DebugModeFlags to JITCompilerFlags
                CorDebugJITCompilerFlags jcf = MapDebugModeToJITCompilerFlags(Process.DebugMode);

                try
                {
                    this.JITCompilerFlags = jcf;

                    // Flags may succeed but not set all bits, so requery.
                    CorDebugJITCompilerFlags jcfActual = this.JITCompilerFlags;

                                        #if DEBUG
                    if (jcf != jcfActual)
                    {
                        Console.WriteLine("Couldn't set all flags. Actual flags:" + jcfActual.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Actual flags:" + jcfActual.ToString());
                    }
                                        #endif
                }
                catch (COMException ex)
                {
                    // we'll ignore the error if we cannot set the jit flags
                    Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the current compiler flag settings that the common language runtime
        /// (CLR) uses to select the correct precompiled (that is, native) image to
        /// be loaded into this process.
        /// </summary>
        /// <remarks>
        /// Use the <see cref="SetDesiredNGENCompilerFlags(CorDebugJITCompilerFlags)" />
        /// method to set the flags that the CLR will use to select the correct
        /// pre-compiled image to load.
        /// </remarks>
        public unsafe int GetDesiredNGENCompilerFlags(out CorDebugJITCompilerFlags pdwFlags)
        {
            uint flags   = default;
            int  hResult = Calli(_this, This[0]->GetDesiredNGENCompilerFlags, &flags);

            pdwFlags = (CorDebugJITCompilerFlags)flags;
            return(hResult);
        }
Esempio n. 3
0
        void SetJITCompilerFlags()
        {
            // ad CORDEBUG_JIT_ENABLE_ENC:
            // see issue #553 on GitHub: "ExecutionEngineException or AccessViolationException (CLR 2.0)
            // when debugging a program that uses System.Data.OleDb"
            // System.Data.dll (partially) is a C++/CLI assembly and EnC is not supported there.
            // trying to set CORDEBUG_JIT_ENABLE_ENC succeeds at first, but leads to strange exceptions afterwards.
            // CORDEBUG_JIT_ENABLE_ENC should only be set for managed-only modules with User Code.
            CorDebugJITCompilerFlags flags;

            if (this.Process.Options.SuppressJITOptimization)
            {
                flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION;
            }
            else
            {
                flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;
            }

            try
            {
                this.JITCompilerFlags = flags;
            }
            catch (COMException ex)
            {
                Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
            }

            CorDebugJITCompilerFlags actual = this.JITCompilerFlags;

            if (flags != actual)
            {
                this.Process.TraceMessage("Couldn't set JIT flags to {0}. Actual flags: {1}", flags, actual);
            }
            else
            {
                this.Process.TraceMessage("JIT flags: {0}", actual);
            }
        }
Esempio n. 4
0
        void SetJITCompilerFlags()
        {
            CorDebugJITCompilerFlags flags;

            if (this.Process.Options.EnableEditAndContinue)
            {
                flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_ENABLE_ENC;
            }
            else if (this.Process.Options.SuppressJITOptimization)
            {
                flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION;
            }
            else
            {
                flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;
            }

            try
            {
                this.JITCompilerFlags = flags;
            }
            catch (COMException ex)
            {
                Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
            }

            CorDebugJITCompilerFlags actual = this.JITCompilerFlags;

            if (flags != actual)
            {
                this.Process.TraceMessage("Couldn't set JIT flags to {0}. Actual flags: {1}", flags, actual);
            }
            else
            {
                this.Process.TraceMessage("JIT flags: {0}", actual);
            }
        }
Esempio n. 5
0
		void SetJITCompilerFlags()
		{
			CorDebugJITCompilerFlags flags;
			if (this.Process.Options.EnableEditAndContinue) {
				flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_ENABLE_ENC;
			} else if (this.Process.Options.SuppressJITOptimization) {
				flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION;
			} else {
				flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;
			}

			try
			{
				this.JITCompilerFlags = flags;
			}
			catch (COMException ex)
			{
				Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
			}
			
			CorDebugJITCompilerFlags actual = this.JITCompilerFlags;
			if (flags != actual)
				this.Process.TraceMessage("Couldn't set JIT flags to {0}. Actual flags: {1}", flags, actual);
			else
				this.Process.TraceMessage("JIT flags: {0}", actual);
		}
Esempio n. 6
0
 internal void InitializeCachedValues()
 {
     // Cache the value so it's possible to read it even when the process is running
     CachedJITCompilerFlags = CorModule.JITCompilerFlags;
 }
Esempio n. 7
0
 /// <summary>
 /// Sets the flags that must be embedded in a precompiled image in order for
 /// the runtime to load that image into the current process.
 /// </summary>
 /// <param name="pdwFlags"></param>
 /// <returns></returns>
 /// <remarks>
 /// This method specifies the flags that must be embedded in a precompiled
 /// image so that the runtime will load that image into this process. The
 /// flags set by this method are used only to select the correct precompiled
 /// image. If no such image exists, the runtime will load the Microsoft
 /// intermediate language (MSIL) image and the just-in-time (JIT) compiler
 /// instead. In that case, the debugger must still use the
 /// <see cref="CorDebugModule2.SetJITCompilerFlags" /> method to set the flags
 /// as desired for the JIT compilation.
 ///
 /// If an image is loaded, but some JIT compiling must take place for that image
 /// (which will be the case if the image contains generics), the compiler flags
 /// specified by this method will apply to the extra JIT compilation.
 ///
 /// This method must be called during the <c>ICorDebugManagedCallback::CreateProcess</c>
 /// callback. Attempts to call the it afterwards will fail. Also, attempts to set
 /// flags that are either not defined in the <see cref="CorDebugJITCompilerFlags" />
 /// enumeration or are not legal for the given process will fail.
 /// </remarks>
 public unsafe int SetDesiredNGENCompilerFlags(CorDebugJITCompilerFlags pdwFlags)
 => Calli(_this, This[0]->SetDesiredNGENCompilerFlags, (uint)pdwFlags);
Esempio n. 8
0
        // Populate the module window with the current list.
        // Called on UI thread.
        protected override void RefreshToolWindowInternal()
        {
            ListView.ListViewItemCollection items = listView1.Items;
            items.Clear();

            ListViewItem[] temp = null;

            // Go to worker thread to collect information

            MainForm.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess proc)
            {
                Debug.Assert(proc != null);
                Debug.Assert(!proc.IsRunning);


                temp    = new ListViewItem[proc.Modules.Count];
                int idx = 0;

                foreach (MDbgModule m in proc.Modules)
                {
                    var sbFlags = new StringBuilder();

                    if (m.SymReader == null)
                    {
                        sbFlags.Append("[No symbols]");
                    }
                    else
                    {
                        sbFlags.Append("[Symbols]");
                    }

                    string fullname  = m.CorModule.Name;
                    string directory =
                        Path.GetDirectoryName(fullname);
                    string name = Path.GetFileName(fullname);

                    bool fIsDynamic = m.CorModule.IsDynamic;
                    if (fIsDynamic)
                    {
                        sbFlags.Append("[Dynamic] ");
                    }

                    CorDebugJITCompilerFlags flags =
                        m.CorModule.JITCompilerFlags;

                    bool fNotOptimized = (flags &
                                          CorDebugJITCompilerFlags.
                                          CORDEBUG_JIT_DISABLE_OPTIMIZATION) ==
                                         CorDebugJITCompilerFlags.
                                         CORDEBUG_JIT_DISABLE_OPTIMIZATION;
                    if (fNotOptimized)
                    {
                        sbFlags.Append("[Not-optimized] ");
                    }
                    else
                    {
                        sbFlags.Append("[Optimized] ");
                    }

                    // Columns: Id, Name, Path, Flags
                    temp[idx++] = new ListViewItem(
                        new[]
                    {
                        m.Number.ToString(), name, directory
                        ,
                        sbFlags.ToString()
                    }
                        );
                }
            });                                                     // end worker


            if (temp != null)
            {
                foreach (ListViewItem x in temp)
                {
                    items.Add(x);
                }
            }
        }
Esempio n. 9
0
		internal void InitializeCachedValues() {
			// Cache the value so it's possible to read it even when the process is running
			jitFlags = module.JITCompilerFlags;
		}
Esempio n. 10
0
		void SetJITCompilerFlags()
		{
			if (Process.DebugMode != DebugModeFlag.Default) {
				// translate DebugModeFlags to JITCompilerFlags
				CorDebugJITCompilerFlags jcf = MapDebugModeToJITCompilerFlags(Process.DebugMode);

				try
				{
					this.JITCompilerFlags = jcf;

					// Flags may succeed but not set all bits, so requery.
					CorDebugJITCompilerFlags jcfActual = this.JITCompilerFlags;
					
					#if DEBUG
					if (jcf != jcfActual)
						Console.WriteLine("Couldn't set all flags. Actual flags:" + jcfActual.ToString());
					else
						Console.WriteLine("Actual flags:" + jcfActual.ToString());
					#endif
				}
				catch (COMException ex)
				{
					// we'll ignore the error if we cannot set the jit flags
					Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
				}
			}
		}
        internal VirtualSourceViewerForm(MainForm parent, MDbgFunction function)
        {
            m_function = function;
            Debug.Assert(function != null);

            // Now actually right in text. do this first so that we can get the current font.
            BeginInit(parent);

            // Get fonts
            FontCache cache;
            {
                Font fontCurrent = richText.Font;
                var  emphasis    = new Font(
                    fontCurrent.FontFamily,
                    fontCurrent.Size,
                    FontStyle.Bold
                    );

                cache = new FontCache(emphasis);
            }

            // Underlying writer to the window.
            var rawWriter = new RawWriter(cache);

            // Il2Native mapping can be used to find out what IL offsets we can actually stop on.
            Il2NativeIterator il2nativeIterator = null;

            // Actual IL disassembly in string form.
            ILDasmIterator ilDasm = null;

            // Iterator through sequence points and source files.
            SequencePointIterator seqIterator = null;

            string fullName = "?";
            int    token    = 0;

            ulong nativeStartAddress           = 0;
            CorDebugJITCompilerFlags codeFlags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;

            // Make cross-thread call to worker thread to collect raw information.
            // This needs to access MDbg and so can't be done on our UI thread.
            parent.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess proc)
            {
                Debug.Assert(proc != null);
                Debug.Assert(!proc.IsRunning);
                Debug.Assert(function.Module.Process == proc);

                // Get some properties about this function to display.
                token = function.CorFunction.Token;
                nativeStartAddress =
                    function.CorFunction.NativeCode.Address;
                codeFlags =
                    function.CorFunction.NativeCode.CompilerFlags;


                CorCode ilCode = function.CorFunction.ILCode;
                Debug.Assert(ilCode.IsIL);
                byte[] code = ilCode.GetCode();
                fullName    = function.FullName;

                // This does the real disassembly work.
                string[] lines = null;                                                   // strings of IL.
                ILDisassembler.Disassemble(code,
                                           function.Module.Importer,
                                           out lines,
                                           out m_il2RowMapping);

                ilDasm = new ILDasmIterator(rawWriter, m_il2RowMapping,
                                            lines);

                IL2NativeMap[] il2nativeMapping =
                    function.CorFunction.NativeCode.
                    GetILToNativeMapping();
                il2nativeIterator = new Il2NativeIterator(rawWriter,
                                                          il2nativeMapping,
                                                          code);

                // Get sequence points
                ISymbolMethod symMethod = function.SymMethod;

                // Sequence point information
                int[] seqIlOffsets  = null;
                string[] seqPaths   = null;
                int[] seqStartLines = null,
                seqEndLines         = null,
                seqStartColumns     = null,
                seqEndColumns       = null;
                int seqCount        = 0;

                if (symMethod != null)
                {
                    seqCount         = symMethod.SequencePointCount;
                    seqIlOffsets     = new int[seqCount];
                    var seqDocuments = new ISymbolDocument[seqCount];
                    seqPaths         = new string[seqCount];
                    seqStartLines    = new int[seqCount];
                    seqEndLines      = new int[seqCount];
                    seqStartColumns  = new int[seqCount];
                    seqEndColumns    = new int[seqCount];

                    symMethod.GetSequencePoints(seqIlOffsets,
                                                seqDocuments,
                                                seqStartLines,
                                                seqStartColumns,
                                                seqEndLines,
                                                seqEndColumns);

                    for (int i = 0; i < seqCount; i++)
                    {
                        seqPaths[i] = seqDocuments[i].URL;
                    }
                }
                seqIterator = new SequencePointIterator(rawWriter,
                                                        parent,
                                                        seqIlOffsets,
                                                        seqPaths,
                                                        seqStartLines,
                                                        seqStartColumns,
                                                        seqEndLines,
                                                        seqEndColumns);
            }
                                                          ); // end worker call

            // We assume sequence points are sorted by IL offset. We assert that in the iterators below.
            // Now we need to go through and stitch the IL + Source together.
            // This also works even if we have no source (since that's just the degenerate case of 0 sequence points)

            // Print out header information
            Debug.Assert(token != 0);
            rawWriter.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                              "> Function name:{0} (token={1:x})", fullName, token));
            rawWriter.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                              "> Native Code Address =0x{0:x}, flags={1}", nativeStartAddress, codeFlags));

            // Walk through the IL in order and write out interleaved IL and Sequence Points.
            while (!seqIterator.IsDone)
            {
                // Add IL snippets that occur before this sequence point.
                WriteIlAndNative(ilDasm, il2nativeIterator, seqIterator.IlOffset);

                seqIterator.WriteSource();
                seqIterator.Next();
            }
            // Write the IL that's after the last sequence point
            WriteIlAndNative(ilDasm, il2nativeIterator, ilDasm.IlLength);


            // Set the text.
            InitLines(null, rawWriter.Lines, rawWriter.FormatList);

            EndInit(fullName);
        }
Esempio n. 12
0
		void SetJITCompilerFlags()
		{
			// ad CORDEBUG_JIT_ENABLE_ENC:
			// see issue #553 on GitHub: "ExecutionEngineException or AccessViolationException (CLR 2.0)
			// when debugging a program that uses System.Data.OleDb"
			// System.Data.dll (partially) is a C++/CLI assembly and EnC is not supported there.
			// trying to set CORDEBUG_JIT_ENABLE_ENC succeeds at first, but leads to strange exceptions afterwards.
			// CORDEBUG_JIT_ENABLE_ENC should only be set for managed-only modules with User Code.
			CorDebugJITCompilerFlags flags;
			if (this.Process.Options.SuppressJITOptimization) {
				flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION;
			} else {
				flags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT;
			}

			try
			{
				this.JITCompilerFlags = flags;
			}
			catch (COMException ex)
			{
				Console.WriteLine(string.Format("Failed to set flags with hr=0x{0:x}", ex.ErrorCode));
			}
			
			CorDebugJITCompilerFlags actual = this.JITCompilerFlags;
			if (flags != actual)
				this.Process.TraceMessage("Couldn't set JIT flags to {0}. Actual flags: {1}", flags, actual);
			else
				this.Process.TraceMessage("JIT flags: {0}", actual);
		}