Esempio n. 1
0
 /// <summary> Tryies to intercept the current exception.
 /// The intercepted expression stays available through the CurrentException property. </summary>
 /// <returns> False, if the exception was already intercepted or
 /// if it can not be intercepted. </returns>
 public bool InterceptCurrentException()
 {
     if (!(this.CorThread is ICorDebugThread2))
     {
         return(false);                                                   // Is the debuggee .NET 2.0?
     }
     if (this.CorThread.GetCurrentException() == null)
     {
         return(false);                                                          // Is there any exception
     }
     if (this.MostRecentStackFrame == null)
     {
         return(false);                                               // Is frame available?  It is not at StackOverflow
     }
     try {
         // Interception will expire the CorValue so keep permanent reference
         currentException.MakeValuePermanent();
         ((ICorDebugThread2)this.CorThread).InterceptCurrentException(this.MostRecentStackFrame.CorILFrame);
     } catch (COMException e) {
         // 0x80131C02: Cannot intercept this exception
         if ((uint)e.ErrorCode == 0x80131C02)
         {
             return(false);
         }
         // 0x80131C33: Interception of the current exception is not legal
         if ((uint)e.ErrorCode == 0x80131C33)
         {
             return(false);
         }
         // 0x80004005: Error HRESULT E_FAIL has been returned from a call to a COM component.
         // Use this to reproduce: new FileIOPermission(PermissionState.Unrestricted).Deny();
         if ((uint)e.ErrorCode == 0x80004005)
         {
             return(false);
         }
         throw;
     } catch (ArgumentException) {
         // May happen in release code with does not have any symbols
         return(false);
     }
     process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] { this /* needed */ }, null);
     process.WaitForPause();
     return(true);
 }
Esempio n. 2
0
        /// <summary> Tryies to intercept the current exception.
        /// The intercepted expression stays available through the CurrentException property. </summary>
        /// <returns> False, if the exception was already intercepted or
        /// if it can not be intercepted. </returns>
        public bool InterceptCurrentException()
        {
            if (!this.CorThread.Is <ICorDebugThread2>())
            {
                return(false);                                                    // Is the debuggee .NET 2.0?
            }
            if (this.CorThread.CurrentException == null)
            {
                return(false);                                                     // Is there any exception
            }
            if (this.MostRecentStackFrame == null)
            {
                return(false);                                               // Is frame available?  It is not at StackOverflow
            }
            try {
                // Interception will expire the CorValue so keep permanent reference
                currentException.MakeValuePermanent();
                this.CorThread.CastTo <ICorDebugThread2>().InterceptCurrentException(this.MostRecentStackFrame.CorILFrame.CastTo <ICorDebugFrame>());
            } catch (COMException e) {
                // 0x80131C02: Cannot intercept this exception
                if ((uint)e.ErrorCode == 0x80131C02)
                {
                    return(false);
                }
                // 0x80131C33: Interception of the current exception is not legal
                if ((uint)e.ErrorCode == 0x80131C33)
                {
                    return(false);
                }
                throw;
            } catch (ArgumentException) {
                // May happen in release code with does not have any symbols
                return(false);
            }

            Process.AsyncContinue(DebuggeeStateAction.Keep);
            Process.WaitForPause();
            return(true);
        }
Esempio n. 3
0
		/// <summary> Tryies to intercept the current exception.
		/// The intercepted expression stays available through the CurrentException property. </summary>
		/// <returns> False, if the exception was already intercepted or 
		/// if it can not be intercepted. </returns>
		public bool InterceptException(Exception exception)
		{
			if (!(this.CorThread is ICorDebugThread2)) return false; // Is the debuggee .NET 2.0?
			if (this.CorThread.GetCurrentException() == null) return false; // Is there any exception
			if (this.MostRecentStackFrame == null) return false; // Is frame available?  It is not at StackOverflow
			
			// Intercepting an exception on an optimized/NGENed frame seems to sometimes
			// freeze the debugee (as of .NET 4.0, it was ok in .NET 2.0)
			// eg. Convert.ToInt64(ulong.MaxValue) causes such freeze
			StackFrame mostRecentUnoptimized = null;
			foreach(StackFrame sf in this.Callstack) {
				if (sf.MethodInfo.DebugModule.CorModule2.GetJITCompilerFlags() != 1) { // CORDEBUG_JIT_DEFAULT 
					mostRecentUnoptimized = sf;
					break;
				}
			}
			if (mostRecentUnoptimized == null) return false;
			
			if (exception == null)
				exception = currentException;
			
			try {
				// Interception will expire the CorValue so keep permanent reference
				exception.MakeValuePermanent();
				((ICorDebugThread2)this.CorThread).InterceptCurrentException(mostRecentUnoptimized.CorILFrame);
			} catch (COMException e) {
				// 0x80131C02: Cannot intercept this exception
				if ((uint)e.ErrorCode == 0x80131C02)
					return false;
				// 0x80131C33: Interception of the current exception is not legal
				if ((uint)e.ErrorCode == 0x80131C33)
					return false;
				// 0x80004005: Error HRESULT E_FAIL has been returned from a call to a COM component.
				// Use this to reproduce: new FileIOPermission(PermissionState.Unrestricted).Deny();
				if ((uint)e.ErrorCode == 0x80004005)
					return false;
				throw;
			} catch (ArgumentException) {
				// May happen in release code with does not have any symbols
				return false;
			}
			process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] { this /* needed */ }, null);
			process.WaitForPause();
			return true;
		}
Esempio n. 4
0
        /// <summary> Tryies to intercept the current exception.
        /// The intercepted expression stays available through the CurrentException property. </summary>
        /// <returns> False, if the exception was already intercepted or
        /// if it can not be intercepted. </returns>
        public bool InterceptException(Exception exception)
        {
            if (!(this.CorThread is ICorDebugThread2))
            {
                return(false);                                                   // Is the debuggee .NET 2.0?
            }
            if (this.CorThread.GetCurrentException() == null)
            {
                return(false);                                                          // Is there any exception
            }
            if (this.MostRecentStackFrame == null)
            {
                return(false);                                               // Is frame available?  It is not at StackOverflow
            }
            // Intercepting an exception on an optimized/NGENed frame seems to sometimes
            // freeze the debugee (as of .NET 4.0, it was ok in .NET 2.0)
            // eg. Convert.ToInt64(ulong.MaxValue) causes such freeze
            StackFrame mostRecentUnoptimized = null;

            foreach (StackFrame sf in this.Callstack)
            {
                if (sf.MethodInfo.DebugModule.CorModule2.GetJITCompilerFlags() != 1)                   // CORDEBUG_JIT_DEFAULT
                {
                    mostRecentUnoptimized = sf;
                    break;
                }
            }
            if (mostRecentUnoptimized == null)
            {
                return(false);
            }

            if (exception == null)
            {
                exception = currentException;
            }

            try {
                // Interception will expire the CorValue so keep permanent reference
                exception.MakeValuePermanent();
                ((ICorDebugThread2)this.CorThread).InterceptCurrentException(mostRecentUnoptimized.CorILFrame);
            } catch (COMException e) {
                // 0x80131C02: Cannot intercept this exception
                if ((uint)e.ErrorCode == 0x80131C02)
                {
                    return(false);
                }
                // 0x80131C33: Interception of the current exception is not legal
                if ((uint)e.ErrorCode == 0x80131C33)
                {
                    return(false);
                }
                // 0x80004005: Error HRESULT E_FAIL has been returned from a call to a COM component.
                // Use this to reproduce: new FileIOPermission(PermissionState.Unrestricted).Deny();
                if ((uint)e.ErrorCode == 0x80004005)
                {
                    return(false);
                }
                throw;
            } catch (ArgumentException) {
                // May happen in release code with does not have any symbols
                return(false);
            }
            process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] { this /* needed */ }, null);
            process.WaitForPause();
            return(true);
        }