public override string[] SuggestCodeCompletion(string code)
 {
     if (CanLoadInterpreter)
     {
         Value cmd = Eval.NewString(process, code);
         Eval.InvokeMethod(process, typeof(AbstractInterpreter), "SuggestCodeCompletion", interpreter, new Value[] { cmd });
         return(null);
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
        public static Value NewObject(Process process, DebugType debugType)
        {
            ICorDebugType  ppTypeArgs = null;
            ICorDebugValue ppArgs     = null;
            Eval           e          = new Eval(
                process,
                "New object: " + debugType.Token,
                delegate(ICorDebugEval corEval) { corEval.CastTo <ICorDebugEval2>().NewParameterizedObject
                                                      (debugType.GetDefaultConstructor(), (uint)debugType.GenericArguments.Count, ref ppTypeArgs, 0, ref ppArgs); }
                );

            return(e.EvaluateNow());
        }
예제 #3
0
 /// <summary> Invoke the ToString() method </summary>
 public string InvokeToString()
 {
     if (this.Type.IsPrimitive)
     {
         return(AsString);
     }
     if (this.Type.IsPointer)
     {
         return("0x" + this.PointerAddress.ToString("X"));
     }
     // if (!IsObject) // Can invoke on primitives
     return(Eval.InvokeMethod(Process, this.Type.AppDomainID, typeof(object), "ToString", this, new Value[] {}).AsString);
 }
        // return true if there was eval to setup and it was setup
        internal bool SetupNextEvaluation()
        {
            this.AssertPaused();

            while (pendingEvalsCollection.Count > 0)
            {
                Eval nextEval = pendingEvalsCollection.Dequeue();
                if (nextEval.SetupEvaluation(this.SelectedThread))
                {
                    activeEvals.Add(nextEval);
                    return(true);
                }
            }
            return(false);
        }
예제 #5
0
        // Box value type
        public Value Box(Thread evalThread)
        {
            byte[] rawValue = this.CorGenericValue.GetRawValue();
            // The type must not be a primive type (always true in current design)
            ICorDebugReferenceValue corRefValue = Eval.NewObjectNoConstructor(evalThread, this.Type).CorReferenceValue;

            // Make the reference to box permanent
            corRefValue = ((ICorDebugHeapValue2)corRefValue.Dereference()).CreateHandle(CorDebugHandleType.HANDLE_STRONG);
            // Create new value
            Value newValue = new Value(appDomain, corRefValue);

            // Copy the data inside the box
            newValue.CorGenericValue.SetRawValue(rawValue);
            return(newValue);
        }
예제 #6
0
        void HandleEvalComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugEval corEval, bool exception)
        {
            // Let the eval know that the CorEval has finished
            Eval eval = process.GetEval(corEval);

            eval.NotifyEvaluationComplete(!exception);
            process.NotifyEvaluationComplete(eval);

            if (process.SetupNextEvaluation())
            {
                ExitCallback_Continue();
            }
            else
            {
                ExitCallback_Paused();
            }
        }
        bool InjectInterpreter()
        {
            if (!DebuggerService.IsDebuggerLoaded)
            {
                PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorDebuggerNotLoaded"));
                return(false);
            }
            WindowsDebugger winDebugger = DebuggerService.CurrentDebugger as WindowsDebugger;

            if (winDebugger == null)
            {
                PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorIncompatibleDebugger"));
                return(false);
            }
            if (winDebugger.DebuggedProcess == null)
            {
                PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorNoProgramDebugged"));
                return(false);
            }
            process             = winDebugger.DebuggedProcess;
            process.Expired    += delegate { interpreter = null; };
            process.LogMessage -= OnDebuggerLogMessage;
            process.LogMessage += OnDebuggerLogMessage;

            Value assembly;
            // Boo.Lang.Interpreter.dll
            string path = Path.Combine(Path.GetDirectoryName(typeof(InterpreterContext).Assembly.Location), "Boo.Lang.Interpreter.dll");

            assembly = LoadAssembly(path);
            // Debugger.BooInterpreter.dll
            assembly = LoadAssembly(typeof(DebugeeInteractiveInterpreter).Assembly.Location);
            Value interpreterType = Eval.NewString(process, typeof(DebugeeInteractiveInterpreter).FullName);

            interpreter = Eval.InvokeMethod(process, typeof(Assembly), "CreateInstance", assembly, new Value[] { interpreterType });
            interpreter_localVariable = interpreter.GetMember("localVariable");
            RunCommand(
                "import System\n" +
                "import System.IO\n" +
                "import System.Text\n" +
                "interpreter.RememberLastValue = true\n" +
                "interpreter.Print = def(msg): System.Diagnostics.Debugger.Log(0xB00, \"DebugeeInterpreterContext.PrintLine\", msg)");

            return(true);
        }
예제 #8
0
 public void SetPrimitiveValue(Thread evalThread, object value)
 {
     if (this.Type.IsKnownType(KnownTypeCode.String))
     {
         this.SetValue(evalThread, Eval.NewString(evalThread, value.ToString()));
     }
     else
     {
         if (!this.Type.IsPrimitiveType())
         {
             throw new DebuggerException("Value is not a primitive type");
         }
         if (value == null)
         {
             throw new DebuggerException("Can not set primitive value to null");
         }
         CorGenericValue.SetValue(this.Type.GetDefinition().KnownTypeCode, value);
     }
 }
예제 #9
0
파일: Value.cs 프로젝트: softearth/dnSpy
        /// <summary> Invoke the ToString() method </summary>
        public string InvokeToString(int maxLength = int.MaxValue)
        {
            if (this.Type.IsPrimitive)
            {
                return(AsString(maxLength));
            }
            if (this.Type.FullName == typeof(string).FullName)
            {
                return(AsString(maxLength));
            }
            if (this.Type.IsPointer)
            {
                return("0x" + this.PointerAddress.ToString("X"));
            }
            // if (!IsObject) // Can invoke on primitives
            DebugMethodInfo methodInfo = (DebugMethodInfo)this.AppDomain.ObjectType.GetMethod("ToString", new DebugType[] {});

            return(Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString(maxLength));
        }
예제 #10
0
        /// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
        static void MethodInvokeStarter(Eval eval, MethodInfo method, Value thisValue, Value[] args)
        {
            List <ICorDebugValue> corArgs = new List <ICorDebugValue>();

            args = args ?? new Value[0];
            if (args.Length != method.ParameterCount)
            {
                throw new GetValueException("Invalid parameter count");
            }
            if (thisValue != null)
            {
                // if (!(thisValue.IsObject)) // eg Can evaluate on array
                if (!method.DeclaringType.IsInstanceOfType(thisValue))
                {
                    throw new GetValueException(
                              "Can not evaluate because the object is not of proper type.  " +
                              "Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
                              );
                }
                corArgs.Add(thisValue.CorValue);
            }
            foreach (Value arg in args)
            {
                // TODO: It is importatnt to pass the parameted in the correct form (boxed/unboxed)
                // This is just a good guess
                if (arg.Type.IsValueType)
                {
                    corArgs.Add(arg.CorGenericValue.CastTo <ICorDebugValue>());
                }
                else
                {
                    corArgs.Add(arg.CorValue);
                }
            }

            ICorDebugType[] genericArgs = method.DeclaringType.GenericArgumentsAsCorDebugType;
            eval.CorEval.CastTo <ICorDebugEval2>().CallParameterizedFunction(
                method.CorFunction,
                (uint)genericArgs.Length, genericArgs,
                (uint)corArgs.Count, corArgs.ToArray()
                );
        }
예제 #11
0
        public Value GetPermanentReference()
        {
            ICorDebugValue corValue = this.CorValue;

            if (this.Type.IsClass)
            {
                corValue = this.CorObjectValue.CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
            }
            if (this.Type.IsValueType || this.Type.IsPrimitive)
            {
                if (!corValue.Is <ICorDebugReferenceValue>())
                {
                    // Box the value type
                    if (this.Type.IsPrimitive)
                    {
                        // Get value type for the primive type
                        object o = this.PrimitiveValue;
                        corValue = Eval.NewObjectNoConstructor(DebugType.Create(process, null, this.Type.FullName)).RawCorValue;
                        this.SetPrimitiveValue(o);
                    }
                    else
                    {
                        corValue = Eval.NewObjectNoConstructor(this.Type).RawCorValue;
                    }
                    // Make the reference to box permanent
                    corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
                    // Create new value
                    Value newValue = new Value(process, new IExpirable[] {},
                                               new IMutable[] {}, delegate { return(corValue); });
                    // Copy the data inside the box
                    newValue.CorGenericValue.RawValue = this.CorGenericValue.RawValue;
                    return(newValue);
                }
                else
                {
                    // Make the reference to box permanent
                    corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
                }
            }
            return(new Value(process, new IExpirable[] {},
                             new IMutable[] {}, delegate { return corValue; }));
        }
예제 #12
0
        public void SetValue(Value newValue)
        {
            ICorDebugValue corValue    = this.CorValue;
            ICorDebugValue newCorValue = newValue.CorValue;

            if (corValue.Is <ICorDebugReferenceValue>())
            {
                if (newCorValue.Is <ICorDebugObjectValue>())
                {
                    ICorDebugValue box = Eval.NewObjectNoConstructor(newValue.Type).CorValue;
                    newCorValue = box;
                }
                corValue.CastTo <ICorDebugReferenceValue>().SetValue(newCorValue.CastTo <ICorDebugReferenceValue>().Value);
            }
            else
            {
                corValue.CastTo <ICorDebugGenericValue>().RawValue =
                    newCorValue.CastTo <ICorDebugGenericValue>().RawValue;
            }
        }
예제 #13
0
        /// <summary> Invoke the ToString() method </summary>
        public string InvokeToString(Thread evalThread, int maxLength = int.MaxValue)
        {
            if (this.IsNull)
            {
                return(AsString(maxLength));
            }
            if (this.Type.IsPrimitiveType())
            {
                return(AsString(maxLength));
            }
            if (this.Type.IsKnownType(KnownTypeCode.String))
            {
                return(AsString(maxLength));
            }
            if (this.Type.Kind == TypeKind.Pointer)
            {
                return("0x" + this.PointerAddress.ToString("X"));
            }
            // Can invoke on primitives
            IMethod methodInfo = (IMethod)this.AppDomain.ObjectType.GetMethods(m => m.Name == "ToString" && m.Parameters.Count == 0).Single();

            return(Eval.InvokeMethod(evalThread, methodInfo, this, new Value[] {}).AsString(maxLength));
        }
예제 #14
0
        Value Box()
        {
            byte[] rawValue = this.CorGenericValue.RawValue;
            // Box the value type
            ICorDebugValue corValue;

            if (this.Type.IsPrimitive)
            {
                // Get value type for the primive type
                corValue = Eval.NewObjectNoConstructor(DebugType.Create(process, null, this.Type.FullName)).CorValue;
            }
            else
            {
                corValue = Eval.NewObjectNoConstructor(this.Type).CorValue;
            }
            // Make the reference to box permanent
            corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
            // Create new value
            Value newValue = new Value(process, expression, corValue);

            // Copy the data inside the box
            newValue.CorGenericValue.RawValue = rawValue;
            return(newValue);
        }
예제 #15
0
        /// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
        static void MethodInvokeStarter(Eval eval, DebugMethodInfo method, Value thisValue, Value[] args)
        {
            List <ICorDebugValue> corArgs = new List <ICorDebugValue>();

            args = args ?? new Value[0];
            if (args.Length != method.ParameterCount)
            {
                throw new GetValueException("Invalid parameter count");
            }
            if (!method.IsStatic)
            {
                if (thisValue == null)
                {
                    throw new GetValueException("'this' is null");
                }
                if (thisValue.IsNull)
                {
                    throw new GetValueException("Null reference");
                }
                // if (!(thisValue.IsObject)) // eg Can evaluate on array
                if (!method.DeclaringType.IsInstanceOfType(thisValue))
                {
                    throw new GetValueException(
                              "Can not evaluate because the object is not of proper type.  " +
                              "Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
                              );
                }
                corArgs.Add(thisValue.CorValue);
            }
            for (int i = 0; i < args.Length; i++)
            {
                Value     arg       = args[i];
                DebugType paramType = (DebugType)method.GetParameters()[i].ParameterType;
                if (!arg.Type.CanImplicitelyConvertTo(paramType))
                {
                    throw new GetValueException("Inncorrect parameter type");
                }
                // Implicitely convert to correct primitve type
                if (paramType.IsPrimitive && args[i].Type != paramType)
                {
                    object oldPrimVal = arg.PrimitiveValue;
                    object newPrimVal = Convert.ChangeType(oldPrimVal, paramType.PrimitiveType);
                    arg = CreateValue(method.AppDomain, newPrimVal);
                }
                // It is importatnt to pass the parameted in the correct form (boxed/unboxed)
                if (paramType.IsValueType)
                {
                    corArgs.Add(arg.CorGenericValue);
                }
                else
                {
                    if (args[i].Type.IsValueType)
                    {
                        corArgs.Add(arg.Box().CorValue);
                    }
                    else
                    {
                        corArgs.Add(arg.CorValue);
                    }
                }
            }

            ICorDebugType[] genericArgs = ((DebugType)method.DeclaringType).GenericArgumentsAsCorDebugType;
            eval.CorEval2.CallParameterizedFunction(
                method.CorFunction,
                (uint)genericArgs.Length, genericArgs,
                (uint)corArgs.Count, corArgs.ToArray()
                );
        }
예제 #16
0
	    /// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
	    static void MethodInvokeStarter(Eval eval, MethodInfo method, Value thisValue, Value[] args)
		{
			List<ICorDebugValue> corArgs = new List<ICorDebugValue>();
			args = args ?? new Value[0];
			if (args.Length != method.ParameterCount) {
				throw new GetValueException("Invalid parameter count");
			}
			if (thisValue != null) {
				// if (!(thisValue.IsObject)) // eg Can evaluate on array
				if (!method.DeclaringType.IsInstanceOfType(thisValue)) {
					throw new GetValueException(
						"Can not evaluate because the object is not of proper type.  " + 
						"Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
					);
				}
				corArgs.Add(thisValue.CorValue);
			}
			foreach(Value arg in args) {
				// TODO: It is importatnt to pass the parameted in the correct form (boxed/unboxed)
				// This is just a good guess
				if (arg.Type.IsValueType) {
					corArgs.Add(arg.CorGenericValue.CastTo<ICorDebugValue>());
				} else {
					corArgs.Add(arg.CorValue);
				}
			}
			
			ICorDebugType[] genericArgs = method.DeclaringType.GenericArgumentsAsCorDebugType;
			eval.CorEval.CastTo<ICorDebugEval2>().CallParameterizedFunction(
				method.CorFunction,
				(uint)genericArgs.Length, genericArgs,
				(uint)corArgs.Count, corArgs.ToArray()
			);
		}
예제 #17
0
	    /// <exception cref="GetValueException">Can not evaluate in optimized code</exception>
	    static Eval CreateEval(Process process, string description, EvalStarter evalStarter)
		{
			ICorDebugEval corEval = CreateCorEval(process);
			
			Eval newEval = new Eval(process, description, corEval);
			
			try {
				evalStarter(newEval);
			} catch (COMException e) {
				if ((uint)e.ErrorCode == 0x80131C26) {
					throw new GetValueException("Can not evaluate in optimized code");
				} else if ((uint)e.ErrorCode == 0x80131C28) {
					throw new GetValueException("Object is in wrong AppDomain");
				} else if ((uint)e.ErrorCode == 0x8013130A) {
					// Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
					throw new GetValueException("Function does not have IL code");
				} else if ((uint)e.ErrorCode == 0x80131C23) {
					// The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
					// This can probably happen when we break and the thread is in native code
					throw new GetValueException("Thread is in GC unsafe point");
				} else if ((uint)e.ErrorCode == 0x80131C22) {
					// The operation is illegal because of a stack overflow.
					throw new GetValueException("Can not evaluate after stack overflow");
				} else if ((uint)e.ErrorCode == 0x80131313) {
					// Func eval cannot work. Bad starting point.
					// Reproduction circumstancess are unknown
					throw new GetValueException("Func eval cannot work. Bad starting point.");
				} else {
					#if DEBUG
						throw; // Expose for more diagnostics
					#else
						throw new GetValueException(e.Message);
					#endif
				}
			}
			
			process.NotifyEvaluationStarted(newEval);
			process.AsyncContinue(DebuggeeStateAction.Keep);
			
			return newEval;
		}
예제 #18
0
 internal void NotifyEvaluationStarted(Eval eval)
 {
     activeEvals.Add(eval);
 }
예제 #19
0
		internal void NotifyEvaluationStarted(Eval eval)
		{
			activeEvals.Add(eval);
		}
예제 #20
0
 /// <summary>
 /// Adds eval to a list of pending evals.
 /// </summary>
 internal void ScheduleEval(Eval eval)
 {
     pendingEvalsCollection.Enqueue(eval);
 }
예제 #21
0
파일: Eval.cs 프로젝트: KAW0/Alter-Native
		/// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
		static void MethodInvokeStarter(Eval eval, DebugMethodInfo method, Value thisValue, Value[] args)
		{
			List<ICorDebugValue> corArgs = new List<ICorDebugValue>();
			args = args ?? new Value[0];
			if (args.Length != method.ParameterCount) {
				throw new GetValueException("Invalid parameter count");
			}
			if (!method.IsStatic) {
				if (thisValue == null)
					throw new GetValueException("'this' is null");
				if (thisValue.IsNull)
					throw new GetValueException("Null reference");
				// if (!(thisValue.IsObject)) // eg Can evaluate on array
				if (!method.DeclaringType.IsInstanceOfType(thisValue)) {
					throw new GetValueException(
						"Can not evaluate because the object is not of proper type.  " + 
						"Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
					);
				}
				corArgs.Add(thisValue.CorValue);
			}
			for(int i = 0; i < args.Length; i++) {
				Value arg = args[i];
				DebugType paramType = (DebugType)method.GetParameters()[i].ParameterType;
				if (!arg.Type.CanImplicitelyConvertTo(paramType))
					throw new GetValueException("Inncorrect parameter type");
				// Implicitely convert to correct primitve type
				if (paramType.IsPrimitive && args[i].Type != paramType) {
					object oldPrimVal = arg.PrimitiveValue;
					object newPrimVal = Convert.ChangeType(oldPrimVal, paramType.PrimitiveType);
					arg = CreateValue(method.AppDomain, newPrimVal);
				}
				// It is importatnt to pass the parameted in the correct form (boxed/unboxed)
				if (paramType.IsValueType) {
					corArgs.Add(arg.CorGenericValue);
				} else {
					if (args[i].Type.IsValueType) {
						corArgs.Add(arg.Box().CorValue);
					} else {
						corArgs.Add(arg.CorValue);
					}
				}
			}
			
			ICorDebugType[] genericArgs = ((DebugType)method.DeclaringType).GenericArgumentsAsCorDebugType;
			eval.CorEval2.CallParameterizedFunction(
				method.CorFunction,
				(uint)genericArgs.Length, genericArgs,
				(uint)corArgs.Count, corArgs.ToArray()
			);
		}
예제 #22
0
 internal void NotifyEvaluationComplete(Eval eval)
 {
     activeEvals.Remove(eval);
 }
예제 #23
0
파일: Eval.cs 프로젝트: Paccc/SharpDevelop
		/// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
		static void MethodInvokeStarter(Eval eval, IMethod method, Value thisValue, Value[] args)
		{
			List<ICorDebugValue> corArgs = new List<ICorDebugValue>();
			args = args ?? new Value[0];
			if (args.Length != method.Parameters.Count) {
				throw new GetValueException("Invalid parameter count");
			}
			if (!method.IsStatic) {
				if (thisValue == null)
					throw new GetValueException("'this' is null");
				if (thisValue.IsNull)
					throw new GetValueException("Null reference");
				corArgs.Add(thisValue.CorValue);
			}
			for(int i = 0; i < args.Length; i++) {
				Value arg = args[i];
				IType paramType = method.Parameters[i].Type;
				if (!arg.IsNull &&
				    arg.Type.GetDefinition() != null &&
				    paramType.GetDefinition() != null &&
				    !arg.Type.GetDefinition().IsDerivedFrom(paramType.GetDefinition())) {
					throw new GetValueException("Inncorrect parameter type. Expected " + paramType.ToString());
				}
				// It is importatnt to pass the parameter in the correct form (boxed/unboxed)
				if (paramType.IsReferenceType == true) {
					if (!arg.IsReference)
						throw new DebuggerException("Reference expected as method argument");
					corArgs.Add(arg.CorValue);
				} else {
					corArgs.Add(arg.CorGenericValue); // Unbox
				}
			}
			
			ICorDebugType[] genericArgs = method.GetTypeArguments();
			
			eval.CorEval2.CallParameterizedFunction(
				method.ToCorFunction(),
				(uint)genericArgs.Length, genericArgs,
				(uint)corArgs.Count, corArgs.ToArray()
			);
		}
예제 #24
0
 /// <summary> Initializes a new instance of the class </summary>
 public EvalEventArgs(Eval eval) : base(eval.Process)
 {
     this.eval = eval;
 }
예제 #25
0
		/// <summary>
		/// Adds eval to a list of pending evals.
		/// </summary>
		internal void ScheduleEval(Eval eval)
		{
			pendingEvalsCollection.Enqueue(eval);
		}
예제 #26
0
		internal void NotifyEvaluationComplete(Eval eval)
		{
			activeEvals.Remove(eval);
		}
예제 #27
0
		/// <summary> Initializes a new instance of the class </summary>
		public EvalEventArgs(Eval eval): base(eval.Process)
		{
			this.eval = eval;
		}
예제 #28
0
		public static Value NewObject(Process process, DebugType debugType)
		{
			ICorDebugType ppTypeArgs=null;
			ICorDebugValue ppArgs=null;
			Eval e = new Eval(
				process,
				"New object: " + debugType.Token,
				delegate(ICorDebugEval corEval) { corEval.CastTo<ICorDebugEval2>().NewParameterizedObject
						(debugType.GetDefaultConstructor(),(uint)debugType.GenericArguments.Count,ref ppTypeArgs,0,ref ppArgs); }
			);
			return e.EvaluateNow();
		}