protected EE.EvaluationResult DoAssignWorker(ScriptingContext context, TargetObject obj, out object result) { Expression resolved = null; try { if (!DoAssign(context, obj)) { result = String.Format( "Expression `{0}' is not an lvalue", Name); return(EE.EvaluationResult.InvalidExpression); } result = null; return(EE.EvaluationResult.Ok); } catch (InvocationException ex) { result = ex.Exception; return(EE.EvaluationResult.Exception); } catch (ScriptingException ex) { result = ex.Message; return(EE.EvaluationResult.InvalidExpression); } catch (EvaluationTimeoutException) { result = null; return(EE.EvaluationResult.Timeout); } catch (Exception ex) { result = String.Format( "Cannot resolve expression `{0}': {1}", Name, ex); return(EE.EvaluationResult.InvalidExpression); } }
public static EE.EvaluationResult HandleDebuggerDisplay(Interpreter interpreter, Thread thread, TargetStructObject instance, DebuggerDisplayAttribute attr, int timeout, out string name, out string type) { ScriptingContext expr_context = new ScriptingContext(interpreter); expr_context.CurrentThread = thread; expr_context.CurrentLanguage = instance.Type.Language; expr_context.ImplicitInstance = instance; EE.EvaluationResult result = expr_context.HandleDebuggerDisplay( thread, instance, attr.Value, timeout, out name); if (result != EE.EvaluationResult.Ok) { type = null; return(result); } if (String.IsNullOrEmpty(attr.Type)) { type = null; return(EE.EvaluationResult.Ok); } return(expr_context.HandleDebuggerDisplay( thread, instance, attr.Type, timeout, out type)); }
public override void PrintFrame(ScriptingContext context, StackFrame frame) { context.Print(frame); bool native = false; if (!PrintSource(context.Interpreter, frame)) { native = true; } if (native) { AssemblerLine insn = frame.Thread.DisassembleInstruction( frame.Method, frame.TargetAddress); if (insn != null) { context.Interpreter.PrintInstruction(insn); } else { throw new ScriptingException( "Cannot disassemble instruction at address {0}.", frame.TargetAddress); } } }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { StackFrame frame = context.CurrentFrame; TargetAddress address = EvaluateAddress (context); return context.CurrentLanguage.CreatePointer (frame, address); }
protected override TargetType DoEvaluateType(ScriptingContext context) { TargetPointerType ptype = expr.EvaluateType (context) as TargetPointerType; if (ptype != null) return ptype; return context.CurrentLanguage.PointerType; }
protected override Expression DoResolve(ScriptingContext context) { expr = expr.Resolve (context); if (expr == null) return null; resolved = true; return this; }
public void ShowDisplays(StackFrame frame) { ScriptingContext context = new ScriptingContext(this); context.CurrentFrame = frame; foreach (Display d in Session.Displays) { context.ShowDisplay(d); } }
protected override object DoEvaluate(ScriptingContext context) { F.Expression resolved = Expression.Resolve(context); if (resolved == null) { throw new ScriptingException( "Cannot resolve expression `{0}'", Name); } return(resolved.Evaluate(context)); }
protected override bool DoAssign(ScriptingContext context, TargetObject obj) { F.Expression resolved = Expression.Resolve(context); if (resolved == null) { throw new ScriptingException( "Cannot resolve expression `{0}'", Name); } resolved.Assign(context, obj); return(true); }
public override TargetAddress EvaluateAddress(ScriptingContext context) { PointerExpression pexpr = expr as PointerExpression; if (pexpr != null) return pexpr.EvaluateAddress (context); TargetObject obj = expr.EvaluateObject (context); if ((obj == null) || !obj.HasAddress) throw new ScriptingException ( "Cannot take address of expression `{0}'", expr.Name); return obj.GetAddress (context.CurrentThread); }
public SourceLocation ParseLocation(Thread target, StackFrame frame, LocationType type, string arg) { ScriptingContext context = new ScriptingContext(Interpreter); context.CurrentThread = target; context.CurrentFrame = frame; try { return(DoParse(context, type, arg)); } catch (ScriptingException ex) { throw new TargetException(TargetError.LocationInvalid, ex.Message); } }
protected SourceLocation DoParseExpression(ScriptingContext context, LocationType type, string arg) { F.Expression expr = context.ParseExpression(arg); MethodExpression mexpr = expr.ResolveMethod(context, type); if (mexpr != null) { return(mexpr.EvaluateSource(context)); } else { return(context.FindMethod(arg)); } }
public static TargetClassObject CheckTypeProxy(Interpreter interpreter, Thread thread, TargetStructObject obj) { if (obj.Type.DebuggerTypeProxyAttribute == null) { return(null); } ScriptingContext expr_context = new ScriptingContext(interpreter); expr_context.CurrentThread = thread; expr_context.CurrentLanguage = obj.Type.Language; expr_context.ImplicitInstance = obj; return(expr_context.CheckTypeProxy(obj)); }
protected override object DoExecute(ScriptingContext context) { Backtrace backtrace = null; if ((mode == Backtrace.Mode.Default) && (max_frames == -1)) backtrace = CurrentThread.CurrentBacktrace; if (backtrace == null) backtrace = CurrentThread.GetBacktrace (mode, max_frames); for (int i = 0; i < backtrace.Count; i++) { string prefix = i == backtrace.CurrentFrameIndex ? "(*)" : " "; context.Print ("{0} {1}", prefix, backtrace [i]); EmonicInterpreter.backtraceData bt = new EmonicInterpreter.backtraceData(); bt.frameNumber = backtrace[i].Level; bt.currentFrame = i == backtrace.CurrentFrameIndex; if (backtrace[i].Method != null) { bt.method = backtrace[i].Method.Name; if (bt.method == null) bt.method = ""; } else { if (backtrace[i].Name == null) bt.method = ""; else { bt.method = backtrace[i].Name.ToString(); if (bt.method == null) bt.method = ""; } } if (backtrace[i].SourceAddress != null && backtrace[i].SourceAddress.SourceFile != null) bt.file = backtrace[i].SourceAddress.SourceFile.FileName; else bt.file = ""; if (backtrace[i].SourceAddress != null) bt.lineNumber = backtrace[i].SourceAddress.Row; else bt.lineNumber = -1; if (i+1 < backtrace.Count) bt.moreData = true; else bt.moreData = false; EmonicInterpreter.backtraceList.Add(bt); } return backtrace; }
protected SourceLocation DoParse(ScriptingContext context, LocationType type, string arg) { if (type != LocationType.Default) { return(DoParseExpression(context, type, arg)); } SourceLocation location; if (ParseLocation(context, arg, out location)) { return(location); } return(DoParseExpression(context, type, arg)); }
public EE.AsyncResult Assign(StackFrame frame, TargetObject obj, EE.EvaluationCallback callback) { AsyncResult async = new AsyncResult(this); ST.ThreadPool.QueueUserWorkItem(delegate { ScriptingContext context = new ScriptingContext(Parser.Interpreter); context.InterruptionHandler = async; context.CurrentFrame = frame; object data; EE.EvaluationResult result = DoAssignWorker( context, obj, out data); callback(result, data); async.WaitHandle.Set(); }); return(async); }
protected SourceLocation FindFile(ScriptingContext context, string filename, int line) { SourceFile file = Session.FindFile(filename); if (file == null) { throw new ScriptingException("Cannot find source file `{0}'.", filename); } MethodSource source = file.FindMethod(line); if (source == null) { throw new ScriptingException( "Cannot find method corresponding to line {0} in `{1}'.", line, file.Name); } return(new SourceLocation(source, file, line)); }
public bool ParseLocation(ScriptingContext context, string arg, out SourceLocation location) { int line; int pos = arg.IndexOf(':'); if (pos >= 0) { string filename = arg.Substring(0, pos); try { line = (int)UInt32.Parse(arg.Substring(pos + 1)); } catch { throw new ScriptingException("Expected filename:line"); } location = FindFile(context, filename, line); return(true); } try { line = (int)UInt32.Parse(arg); } catch { location = null; return(false); } StackFrame frame = context.CurrentFrame; if ((frame == null) || (frame.SourceLocation == null) || (frame.SourceLocation.FileName == null)) { throw new ScriptingException( "Current stack frame doesn't have source code"); } location = FindFile(context, frame.SourceLocation.FileName, line); return(true); }
protected EE.EvaluationResult DoEvaluateWorker(ScriptingContext context, out object result) { Expression resolved = null; try { result = DoEvaluate(context); return(EE.EvaluationResult.Ok); } catch (InvocationException ex) { result = ex.Exception; return(EE.EvaluationResult.Exception); } catch (ScriptingException ex) { result = ex.Message; return(EE.EvaluationResult.InvalidExpression); } catch (EvaluationTimeoutException) { result = null; return(EE.EvaluationResult.Timeout); } catch (Exception ex) { result = String.Format( "Cannot resolve expression `{0}': {1}", Name, ex); return(EE.EvaluationResult.InvalidExpression); } }
public EE.AsyncResult Evaluate(StackFrame frame, EE.EvaluationFlags flags, EE.EvaluationCallback callback) { AsyncResult async = new AsyncResult(this); ST.ThreadPool.QueueUserWorkItem(delegate { ScriptingContext context = new ScriptingContext(Parser.Interpreter); context.InterruptionHandler = async; context.CurrentFrame = frame; if ((flags & EE.EvaluationFlags.NestedBreakStates) != 0) { context.ScriptingFlags |= ScriptingFlags.NestedBreakStates; } object data; EE.EvaluationResult result = DoEvaluateWorker(context, out data); callback(result, data); async.WaitHandle.Set(); }); return(async); }
public string EvaluateExpression(ScriptingContext context, string text, DisplayFormat format) { F.Expression expression = context.ParseExpression (text); try { expression = expression.Resolve (context); } catch (ScriptingException ex) { throw new ScriptingException ("Cannot resolve expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException ("Cannot resolve expression `{0}'.", text); } try { object retval = expression.Evaluate (context); return context.FormatObject (retval, format); } catch (ScriptingException ex) { throw new ScriptingException ("Cannot evaluate expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException ("Cannot evaluate expression `{0}'.", text); } }
public string EvaluateExpression(ScriptingContext context, string text, DisplayFormat format) { F.Expression expression = context.ParseExpression(text); try { expression = expression.Resolve(context); } catch (ScriptingException ex) { throw new ScriptingException("Cannot resolve expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException("Cannot resolve expression `{0}'.", text); } try { object retval = expression.Evaluate(context); return(context.FormatObject(retval, format)); } catch (ScriptingException ex) { throw new ScriptingException("Cannot evaluate expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException("Cannot evaluate expression `{0}'.", text); } }
public static TargetObject TryCast(ScriptingContext context, TargetObject source, TargetClassType target_type) { if (source.Type == target_type) return source; TargetClassObject sobj = Convert.ToClassObject (context.CurrentThread, source); if (sobj == null) return null; TargetClassObject result = TryParentCast (context, sobj, sobj.Type, target_type); if (result != null) return result; return TryCurrentCast (context, sobj, target_type); }
protected override Expression DoResolve(ScriptingContext context) { resolved = true; return this; }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { if ((context.CurrentLanguage == null) || !context.CurrentLanguage.CanCreateInstance (typeof (bool))) throw new ScriptingException ("Cannot instantiate value '{0}' in the current frame's language", Name); return context.CurrentLanguage.CreateInstance (context.CurrentThread, val); }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { TargetObject obj; if (right is NullExpression) { StackFrame frame = context.CurrentFrame; TargetType ltype = left.EvaluateType (context); obj = context.CurrentLanguage.CreateNullObject (frame.Thread, ltype); } else obj = right.EvaluateObject (context); left.Assign (context, obj); return obj; }
static TargetClassObject TryParentCast(ScriptingContext context, TargetClassObject source, TargetClassType source_type, TargetClassType target_type) { if (source_type == target_type) return source; if (!source_type.HasParent) return null; TargetClassType parent_type = source_type.GetParentType (context.CurrentThread); source = TryParentCast (context, source, parent_type, target_type); if (source == null) return null; return source.GetParentObject (context.CurrentThread) as TargetClassObject; }
protected override TargetType DoEvaluateType(ScriptingContext context) { TargetObject obj = EvaluateObject (context); if (obj == null) return null; return obj.Type; }
static bool TryParentCast(ScriptingContext context, TargetClassType source_type, TargetClassType target_type) { if (source_type == target_type) return true; if (!source_type.HasParent) return false; TargetClassType parent_type = source_type.GetParentType (context.CurrentThread); return TryParentCast (context, parent_type, target_type); }
protected override object DoEvaluate(ScriptingContext context) { long lvalue = GetValue (context, left); long rvalue = GetValue (context, right); try { long retval = DoEvaluate (context, lvalue, rvalue); return new NumberExpression (retval); } catch (DivideByZeroException) { throw new ScriptingException ("DivisionByZero"); } catch { throw new ScriptingException ("Cannot evaluate expression `{0}'", Name); } }
protected long DoEvaluate(ScriptingContext context, long lvalue, long rvalue) { switch (kind) { case Kind.Mult: return lvalue * rvalue; case Kind.Plus: return lvalue + rvalue; case Kind.Minus: return lvalue - rvalue; case Kind.Div: return lvalue / rvalue; } throw new ScriptingException ("Unknown binary operator kind: {0}", kind); }
public string[] SymbolCompleter(ScriptingContext context, string text) { try { var method_list = new List <string> (); string[] namespaces = context.GetNamespaces(); Module[] modules = context.CurrentProcess.Modules; foreach (Module module in modules) { if (!module.SymbolsLoaded || !module.SymbolTable.HasMethods) { continue; } SourceFile[] sources = module.Sources; if (sources == null) { continue; } foreach (SourceFile sf in sources) { foreach (MethodSource method in sf.Methods) { if (method.Name.StartsWith(text)) { int parameter_start = method.Name.IndexOf('('); if (parameter_start != -1) { method_list.Add(method.Name.Substring(0, parameter_start)); } else { method_list.Add(method.Name); } } if (namespaces != null) { foreach (string n in namespaces) { if (n != "" && method.Name.StartsWith(String.Concat(n, ".", text))) { int parameter_start = method.Name.IndexOf('('); if (parameter_start != -1) { method_list.Add(method.Name.Substring(n.Length + 1, parameter_start - n.Length - 1)); } else { method_list.Add(method.Name.Substring(n.Length + 1)); } } } } } } } return(method_list.ToArray()); } catch { return(null); } }
protected override Expression DoResolve(ScriptingContext context) { Expression expr = base.DoResolve (context); if (expr == null) return null; if (var.Type.Kind != TargetObjectKind.Class) throw new ScriptingException ( "`base' is only allowed in a class."); if (!((TargetClassType) var.Type).HasParent) throw new ScriptingException ( "Current class has no base class."); return expr; }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { TargetVariable var = DoEvaluateVariable (context); if (var == null) return null; TargetObject obj = var.GetObject (context.CurrentFrame); if (obj == null) return null; TargetClassObject cobj = (TargetClassObject) obj; return cobj.GetParentObject (context.CurrentThread); }
public static bool TryCast(ScriptingContext context, TargetType source, TargetClassType target_type) { if (source == target_type) return true; TargetClassType stype = Convert.ToClassType (source); if (stype == null) return false; return TryParentCast (context, stype, target_type); }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { return exc; }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { TargetType target_type = target.EvaluateType (context); TargetObject obj = DoCast (context, expr, target_type); if (obj == null) throw new ScriptingException ( "Cannot cast from `{0}' to `{1}'.", expr.Name, target.Name); return obj; }
protected override TargetObject DoEvaluateObject(ScriptingContext context) { bool cond; try { cond = (bool) this.test.Evaluate (context); } catch (Exception e) { throw new ScriptingException ( "Cannot convert {0} to a boolean for conditional: {1}", this.test, e); } return cond ? true_expr.EvaluateObject (context) : false_expr.EvaluateObject (context); }
static TargetClassObject TryCurrentCast(ScriptingContext context, TargetClassObject source, TargetClassType target_type) { TargetClassObject current = source.GetCurrentObject (context.CurrentThread); if (current == null) return null; return TryParentCast (context, current, current.Type, target_type); }
protected abstract object DoEvaluate(ScriptingContext context);
protected override Expression DoResolve(ScriptingContext context) { left = left.Resolve (context); if (left == null) return null; right = right.Resolve (context); if (right == null) return null; resolved = true; return this; }
public abstract void PrintFrame(ScriptingContext context, StackFrame frame);
TargetObject DoCast(ScriptingContext context, Expression expr, TargetType target_type) { TargetObject source = expr.EvaluateObject (context); if (source == null) return null; if (target_type is TargetObjectType) { if (((source is TargetClassObject) && !source.Type.IsByRef) || (source is TargetFundamentalObject)) return target_type.Language.CreateBoxedObject (context.CurrentThread, source); if (source is TargetObjectObject) return source; throw new ScriptingException ( "Cannot box object `{0}': not a value-type", expr.Name); } if (target_type is TargetPointerType) { TargetAddress address; PointerExpression pexpr = expr as PointerExpression; if (pexpr != null) address = pexpr.EvaluateAddress (context); else { TargetPointerType ptype = expr.EvaluateType (context) as TargetPointerType; if ((ptype == null) || ptype.IsTypesafe) return null; pexpr = new AddressOfExpression (expr); pexpr.Resolve (context); address = pexpr.EvaluateAddress (context); } return ((TargetPointerType) target_type).GetObject (address); } if (target_type is TargetFundamentalType) { TargetFundamentalObject fobj = expr.EvaluateObject (context) as TargetFundamentalObject; if (fobj == null) return null; TargetFundamentalType ftype = target_type as TargetFundamentalType; return Convert.ExplicitFundamentalConversion (context, fobj, ftype); } TargetClassType ctype = Convert.ToClassType (target_type); TargetClassObject source_cobj = Convert.ToClassObject (context.CurrentThread, source); if (source_cobj == null) throw new ScriptingException ( "Variable {0} is not a class type.", expr.Name); return TryCast (context, source_cobj, ctype); }
private long GetValue(ScriptingContext context, Expression expr) { object val = expr.Evaluate (context); again: if (val is int) return (long) (int) val; else if (val is uint) return (long) (uint) val; else if (val is ulong) return (long) (ulong) val; else if (val is long) return (long) val; else if (val is TargetPointerObject) { TargetPointerObject pobj = (TargetPointerObject) val; return pobj.GetAddress (context.CurrentThread).Address; } else if (val is TargetFundamentalObject) { TargetFundamentalObject fobj = (TargetFundamentalObject) val; val = fobj.GetObject (context.CurrentThread); if (!(val is TargetFundamentalObject)) goto again; } throw new ScriptingException ("Cannot evaluate expression `{0}'", expr.Name); }
protected override Expression DoResolve(ScriptingContext context) { exc = context.CurrentFrame.ExceptionObject; if (exc == null) throw new ScriptingException ("No current exception."); resolved = true; return this; }
protected override object DoEvaluate(ScriptingContext context) { return val; }
protected override Expression DoResolve(ScriptingContext context) { this.test = this.test.Resolve (context); if (this.test == null) return null; this.true_expr = this.true_expr.Resolve (context); if (this.true_expr == null) return null; this.false_expr = this.false_expr.Resolve (context); if (this.false_expr == null) return null; resolved = true; return this; }
protected abstract bool DoAssign(ScriptingContext context, TargetObject obj);
public void ShowDisplays(StackFrame frame) { ScriptingContext context = new ScriptingContext (this); context.CurrentFrame = frame; foreach (Display d in Session.Displays) context.ShowDisplay (d); }
public override TargetAddress EvaluateAddress(ScriptingContext context) { NumberExpression result = (NumberExpression) Evaluate (context); return result.EvaluateAddress (context); }