コード例 #1
0
        Value LoadAssembly(string path)
        {
            Value assemblyPath = Eval.NewString(process, path);
            Value assembly     = Eval.InvokeMethod(process, typeof(Assembly), "LoadFrom", null, new Value[] { assemblyPath });

            return(assembly);
        }
コード例 #2
0
 public override void RunCommand(string code)
 {
     if (CanLoadInterpreter)
     {
         Value cmd = Eval.NewString(process, code);
         Eval.InvokeMethod(process, typeof(InteractiveInterpreter), "LoopEval", interpreter, new Value[] { cmd });
     }
 }
コード例 #3
0
//		public static MethodInfo GetFromName(Process process, uint? domainID, System.Type type, string methodName, int paramCount)
//		{
//			if (type.IsNested) throw new DebuggerException("Not implemented for nested types");
//			if (type.IsGenericType) throw new DebuggerException("Not implemented for generic types");
//			if (type.IsGenericParameter) throw new DebuggerException("Type can not be generic parameter");
//
//			DebugType debugType = DebugType.Create(process, domainID, type.FullName);
//			if (debugType == null) {
//				throw new DebuggerException("Type " + type.FullName + " not found");
//			}
//
//			foreach(MethodInfo methodInfo in debugType.GetMethods(methodName)) {
//				if (methodInfo.ParameterCount == paramCount) {
//					return methodInfo;
//				}
//			}
//			throw new DebuggerException("Method " + methodName + " not found");
//		}

        /// <summary>
        /// Synchronously invoke the method of an a given object
        /// </summary>
        public Value Invoke(Value objectInstance, Value[] arguments)
        {
            return(Eval.InvokeMethod(
                       this,
                       this.IsStatic ? null : objectInstance,
                       arguments ?? new Value[0]
                       ));
        }
コード例 #4
0
        /// <summary> Synchronously invoke the method </summary>
        public static Value InvokeMethod(Value objectInstance, MethodInfo methodInfo, params Value[] arguments)
        {
            CheckObject(objectInstance, methodInfo);

            return(Eval.InvokeMethod(
                       methodInfo,
                       methodInfo.IsStatic ? null : objectInstance,
                       arguments ?? new Value[0]
                       ));
        }
コード例 #5
0
        /// <summary> Synchronously invoke the method </summary>
        public static Value InvokeMethod(Thread evalThread, Value objectInstance, IMethod methodInfo, params Value[] arguments)
        {
            CheckObject(objectInstance, methodInfo);

            return(Eval.InvokeMethod(
                       evalThread,
                       (IMethod)methodInfo,
                       methodInfo.IsStatic ? null : objectInstance,
                       arguments ?? new Value[0]
                       ));
        }
コード例 #6
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);
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        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);
        }
コード例 #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
        /// <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));
        }