internal Exception(Thread thread) { creationTime = DateTime.Now; this.process = thread.Process; this.thread = thread; corValue = thread.CorThread.CurrentException; exceptionType = thread.CurrentExceptionType; Value runtimeValue = new Value(process, new IExpirable[] { process.PauseSession }, new IMutable[] {}, delegate { return(corValue); }); NamedValue nv = runtimeValue.GetMember("_message"); if (!nv.IsNull) { message = nv.AsString; } else { message = runtimeValue.Type.FullName; } if (thread.LastFunctionWithLoadedSymbols != null) { location = thread.LastFunctionWithLoadedSymbols.NextStatement; } callstack = ""; int callstackItems = 0; if (!nv.IsNull) { foreach (Function function in thread.Callstack) { if (callstackItems >= 100) { callstack += "...\n"; break; } SourcecodeSegment loc = function.NextStatement; callstack += function.Name + "()"; if (loc != null) { callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn; } callstack += "\n"; callstackItems++; } } type = runtimeValue.Type.FullName; }
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); }
internal Exception(Thread thread) { creationTime = DateTime.Now; this.process = thread.Process; this.thread = thread; corValue = thread.CorThread.CurrentException; exceptionType = thread.CurrentExceptionType; Value runtimeValue = new Value(process, new IExpirable[] {process.PauseSession}, new IMutable[] {}, delegate { return corValue; } ); NamedValue nv = runtimeValue.GetMember("_message"); if (!nv.IsNull) message = nv.AsString; else message = runtimeValue.Type.FullName; if (thread.LastFunctionWithLoadedSymbols != null) { location = thread.LastFunctionWithLoadedSymbols.NextStatement; } callstack = ""; int callstackItems = 0; if (!nv.IsNull) foreach(Function function in thread.Callstack) { if (callstackItems >= 100) { callstack += "...\n"; break; } SourcecodeSegment loc = function.NextStatement; callstack += function.Name + "()"; if (loc != null) { callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn; } callstack += "\n"; callstackItems++; } type = runtimeValue.Type.FullName; }
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; }
private bool _eoln(Value v, string name) { if (v.Type.FullName == "PABCSystem.Text") { Value sr = v.GetMember("sr"); Value sw = v.GetMember("sw"); if (!sr.IsNull) { MethodInfo mi = DebugUtils.GetMethod(sr.Type, "Peek"); int val = (int)mi.Invoke(sr, new Value[0]).PrimitiveValue; return val == 13; } else if (!sw.IsNull) throw new CommonEvaluationError(new System.Exception("Функция Eoln не может быть вызвана для текстового файла, открытого на запись")); else throw new CommonEvaluationError(new System.Exception(FILE_NOT_OPENED)); } throw new WrongTypeOfArgument(name); }
private long file_size(Value v, string name) { if (v.Type.FullName == "PABCSystem.TypedFile") { Value fi = v.GetMember("fi"); Value fs = v.GetMember("fs"); if (fi.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_ASSIGNED)); if (fs.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_OPENED)); return Convert.ToInt64(fs.GetMember("Length").PrimitiveValue) / Convert.ToInt64(v.GetMember("ElementSize").PrimitiveValue); } else if (v.Type.FullName == "PABCSystem.BinaryFile") { Value fi = v.GetMember("fi"); Value fs = v.GetMember("fs"); if (fi.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_ASSIGNED)); if (fs.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_OPENED)); return Convert.ToInt64(fs.GetMember("Length").PrimitiveValue); } throw new WrongTypeOfArgument(name); }
private bool _eof(Value v, string name) { if (v.Type.FullName == "PABCSystem.Text") { Value sr = v.GetMember("sr"); Value sw = v.GetMember("sw"); if (!sr.IsNull) return Convert.ToBoolean(sr.GetMember("EndOfStream").PrimitiveValue); else if (!sw.IsNull) throw new CommonEvaluationError(new System.Exception("Функция Eof не может быть вызвана для текстового файла, открытого на запись")); else throw new CommonEvaluationError(new System.Exception(FILE_NOT_OPENED)); } else if (v.Type.FullName == "PABCSystem.BinaryFile" || v.Type.FullName == "PABCSystem.TypedFile") { Value fi = v.GetMember("fi"); Value fs = v.GetMember("fs"); if (fi.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_ASSIGNED)); if (fs.IsNull) throw new CommonEvaluationError(new System.Exception(FILE_NOT_OPENED)); return Convert.ToInt64(fs.GetMember("Position").PrimitiveValue) == Convert.ToInt64(fs.GetMember("Length").PrimitiveValue); } throw new WrongTypeOfArgument(name); }
public static string MakeViewForCollection(Value v) { object cnt = v.GetMember("Count").PrimitiveValue; return "Count = " + cnt.ToString(); }
public static Value unbox(Value v) { return v.GetMember("m_value"); }
public static object GetEnumValue(Value v) { Value val = v.GetMember("value__"); if (val != null && val.IsPrimitive) return val.PrimitiveValue; return null; }