Example #1
0
        ////////////////////////////////////////////////////////////////////////////////
        //
        // CorDebugger private implement part
        //
        ////////////////////////////////////////////////////////////////////////////////

        // called by constructors during initialization
        private void InitFromVersion(string debuggerVersion)
        {
            if (debuggerVersion.StartsWith("v1"))
            {
                // ICorDebug before V2 did not cooperate well with COM-intop. MDbg's managed
                // wrappers over ICorDebug only work on V2 and beyond.
                throw new ArgumentException("Can't debug a version 1 CLR process (\"" + debuggerVersion +
                    "\").  Run application in a version 2 CLR, or use a version 1 debugger instead.");
            }

            bool fUseV2 = false;
            ICorDebug rawDebuggingAPI = null;
            try
            {
                CLRMetaHost mh = new CLRMetaHost();
                CLRRuntimeInfo rti = mh.GetRuntime(debuggerVersion);
                rawDebuggingAPI = rti.GetLegacyICorDebugInterface();
            }
            catch (NotImplementedException)
            {
                fUseV2 = true;
            }
            catch (EntryPointNotFoundException)
            {
                fUseV2 = true;
            }

            if (fUseV2)
            {
                // fallback to v2 method

                try
                {
                    rawDebuggingAPI = NativeMethods.CreateDebuggingInterfaceFromVersion((int)CorDebuggerVersion.Whidbey, debuggerVersion);
                }
                catch (ArgumentException)
                {
                    // This can commonly happen if:
                    // 1) the debuggee is missing a config file 
                    // 2) the debuggee has a config file for a not-installed CLR.
                    // 
                    // Give a more descriptive error. 
                    // We explicitly don't pass the inner exception because:
                    // - it's uninteresting. It's really just from a pinvoke and so there are no
                    //    extra managed frames.
                    // - MDbg's error reporting will call Exception.GetBaseException() and so just
                    //    grab the inner exception.
                    throw new ArgumentException("Failed to create debugging services for version '" + debuggerVersion + "'");
                }
            }
            Debug.Assert(rawDebuggingAPI != null);
            InitFromICorDebug(rawDebuggingAPI);
        }