Ejemplo n.º 1
0
        internal SourceBreakpoint(DebuggerSession session, int index, ThreadGroup group,
					   SourceLocation location)
            : base(EventType.Breakpoint, index, location.Name, group)
        {
            this.session = session;
            this.location = location;
        }
Ejemplo n.º 2
0
 public SourceExpression(SourceLocation location)
 {
     this.location = location;
     resolved = true;
 }
Ejemplo n.º 3
0
        protected bool FindFile(ScriptingContext context, string filename, int line)
        {
            SourceFile file = context.Interpreter.Session.FindFile (filename);
            if (file == null)
                throw new ScriptingException (
                    "Cannot find source file `{0}'.", filename);

            location = new SourceLocation (file, line);
            return true;
        }
Ejemplo n.º 4
0
        protected override bool DoResolve(ScriptingContext context)
        {
            int line = -1;
            int pos = Argument.IndexOf (':');
            if (pos >= 0) {
                string filename = Argument.Substring (0, pos);
                try {
                    line = (int) UInt32.Parse (Argument.Substring (pos+1));
                } catch {
                    throw new ScriptingException ("Expected filename:line");
                }

                return FindFile (context, filename, line);
            }

            if (Argument == "") {
                StackFrame frame = context.CurrentFrame;

                if (frame.SourceAddress == null)
                    return false;

                if (frame.SourceLocation != null)
                    location = frame.SourceLocation;
                else
                    address = frame.SourceAddress;

                return true;
            }

            try {
                line = (int) UInt32.Parse (Argument);
            } catch {
            }

            if (line != -1) {
                location = context.CurrentLocation;
                if (location.FileName == null)
                    throw new ScriptingException (
                        "Location doesn't have any source code.");

                return FindFile (context, location.FileName, line);
            }

            MethodExpression mexpr;
            try {
                Expression expr = ParseExpression (context);
                if (expr == null)
                    return false;

                mexpr = expr.ResolveMethod (context, type);
            } catch {
                mexpr = null;
            }

            if (mexpr != null) {
                TargetFunctionType func;
                try {
                    func = mexpr.EvaluateMethod (context, type, null);
                } catch {
                    func = null;
                }

                if (func != null)
                    method = func.GetSourceCode ();

                location = mexpr.EvaluateSource (context);
            } else
                location = context.FindMethod (Argument);

            if (location == null)
                throw new ScriptingException (
                    "Location doesn't have any source code.");

            return true;
        }
Ejemplo n.º 5
0
        protected override bool DoResolve(ScriptingContext context)
        {
            if (global) {
                if (local)
                    throw new ScriptingException (
                        "Cannot use both -local and -global.");

                if (Group != null)
                    throw new ScriptingException (
                        "Cannot use both -group and -global.");

                tgroup = ThreadGroup.Global;
            } else if (local) {
                if (Group != null)
                    throw new ScriptingException (
                        "Cannot use both -group and -local.");

                tgroup = context.Interpreter.GetThreadGroup (Group, false);
            } else if (Group != null) {
                tgroup = context.Interpreter.GetThreadGroup (Group, false);
            } else {
                tgroup = ThreadGroup.Global;
            }

            if (context.Interpreter.HasTarget) {
                context.CurrentProcess = context.Interpreter.GetProcess (p_index);
                context.CurrentThread = context.Interpreter.GetThread (t_index);
            }

            if (!gui && !lazy && context.Interpreter.HasTarget) {
                Thread thread = context.CurrentThread;
                if (!thread.IsStopped)
                    throw new TargetException (TargetError.NotStopped);

                Backtrace backtrace = thread.GetBacktrace ();

                StackFrame frame;
                if (f_index == -1)
                    frame = backtrace.CurrentFrame;
                else {
                    if (f_index >= backtrace.Count)
                        throw new ScriptingException (
                            "No such frame: {0}", f_index);

                    frame = backtrace [f_index];
                }

                context.CurrentFrame = frame;

                if (context.Interpreter.ExpressionParser.ParseLocation (context, Argument, out location))
                    return true;
            }

            uint line;
            int pos = Argument.IndexOf (':');
            if (pos == 0)
                throw new ScriptingException ("Invalid breakpoint expression");
            else if (pos > 0) {
                string tmp = Argument.Substring (pos+1);
                if (!UInt32.TryParse (tmp, out line))
                    throw new ScriptingException ("Invalid breakpoint expression");
                return true;
            }

            if (UInt32.TryParse (Argument, out line)) {
                if (!context.Interpreter.HasTarget)
                    throw new ScriptingException ("Cannot insert breakpoint by line: no current source file.");
                return true;
            }

            Expression expr = context.ParseExpression (Argument);
            if (expr is PointerExpression) {
                address = ((PointerExpression) expr).EvaluateAddress (context);
                return true;
            }

            if (!context.Interpreter.HasTarget)
                return true;

            MethodExpression mexpr;
            try {
                mexpr = expr.ResolveMethod (context, type);
            } catch {
                mexpr = null;
            }

            if (mexpr != null)
                location = mexpr.EvaluateSource (context);
            else {
                location = context.FindMethod (Argument);
                if (location != null)
                    return true;

                address = context.CurrentProcess.LookupSymbol (Argument);
                if (!address.IsNull)
                    return true;
            }

            if (lazy || gui)
                return true;

            if (location == null)
                throw new ScriptingException ("No such method: `{0}'.", Argument);

            return true;
        }
Ejemplo n.º 6
0
        public int InsertBreakEvent(DL.BreakEvent be, bool enable)
        {
            CancelRuntimeInvokes();
            DL.Breakpoint bp = be as DL.Breakpoint;
            MD.Event      ev = null;

            if (bp != null)
            {
                MD.SourceLocation   location = new MD.SourceLocation(bp.FileName, bp.Line);
                MD.SourceBreakpoint sbp      = new MD.SourceBreakpoint(session, ThreadGroup.Global, location);
                mdbAdaptor.InitializeBreakpoint(sbp);
                session.AddEvent(sbp);
                ev = sbp;
            }
            else if (be is Catchpoint)
            {
                lock (pendingCatchpoints) {
                    Catchpoint    cp  = (Catchpoint)be;
                    ML.TargetType exc = null;
                    if (process != null)
                    {
                        foreach (Module mod in process.Modules)
                        {
                            exc = mod.Language.LookupType(cp.ExceptionName);
                            if (exc != null)
                            {
                                break;
                            }
                        }
                    }
                    if (exc != null)
                    {
                        ev = session.InsertExceptionCatchPoint(process.MainThread, ThreadGroup.Global, exc);
                    }
                    else
                    {
                        pendingCatchpoints.Add(cp);
                        return(-1);
                    }
                }
            }

            ev.IsEnabled = enable;

            if (!initializing)
            {
                lock (debugger) {
                    mdbAdaptor.ActivateEvent(ev);
                }
            }

            if (bp != null && !running && !initializing && activeThread.CurrentFrame != null && !string.IsNullOrEmpty(bp.ConditionExpression) && bp.BreakIfConditionChanges)
            {
                // Initial expression evaluation
                MdbEvaluationContext ctx = new MdbEvaluationContext(activeThread, activeThread.CurrentFrame, null, SessionOptions.EvaluationOptions);
                ML.TargetObject      ob  = EvaluateExp(ctx, bp.ConditionExpression);
                if (ob != null)
                {
                    lastConditionValue [ev.Index] = evaluator.TargetObjectToExpression(ctx, ob).Value;
                }
            }

            events [ev.Index] = be;
            return(ev.Index);
        }
Ejemplo n.º 7
0
 void compute_source()
 {
     lock (this) {
         if (has_source)
             return;
         has_source = true;
         if ((method == null) || !method.HasSource || !method.HasLineNumbers)
             return;
         source = method.LineNumberTable.Lookup (address);
         if (source == null)
             return;
         if (method.MethodSource.IsDynamic)
             return;
         location = new SourceLocation (
             method.MethodSource, source.SourceFile, source.Row);
     }
 }
Ejemplo n.º 8
0
        internal StackFrame(Thread thread, FrameType type, TargetAddress address,
				     TargetAddress stack_ptr, TargetAddress frame_address,
				     Registers registers, Method method, SourceAddress source)
            : this(thread, type, address, stack_ptr, frame_address, registers, method)
        {
            this.source = source;
            if (method.HasSource && !method.MethodSource.IsDynamic)
                location = new SourceLocation (
                    method.MethodSource, source.SourceFile, source.Row);
            has_source = true;
        }
Ejemplo n.º 9
0
        internal StackFrame(Thread thread, FrameType type, TargetAddress address,
				     TargetAddress stack_ptr, TargetAddress frame_address,
				     Registers registers, TargetFunctionType function,
				     SourceLocation location)
            : this(thread, type, address, stack_ptr, frame_address, registers)
        {
            this.function = function;
            this.language = function.DeclaringType.Language;
            this.name = new Symbol (function.FullName, address, 0);
            this.location = location;
        }
Ejemplo n.º 10
0
 protected Event ParseEvent(XPathNavigator navigator, int index, ThreadGroup group)
 {
     if (navigator.Name == "Location") {
         SourceLocation location = new SourceLocation (this, navigator);
         return new SourceBreakpoint (this, index, group, location);
     } else if (navigator.Name == "Expression") {
         string expression = navigator.GetAttribute ("expression", "");
         LocationType type = (LocationType) Enum.Parse (
             typeof (LocationType), navigator.GetAttribute ("type", ""));
         return new ExpressionBreakpoint (this, index, group, type, expression);
     } else if (navigator.Name == "Exception") {
         string exc = navigator.GetAttribute ("type", "");
         bool unhandled = Boolean.Parse (navigator.GetAttribute ("unhandled", ""));
         return new ExceptionCatchPoint (index, group, exc, unhandled);
     } else if (navigator.Name == "MainMethod") {
         return new MainMethodBreakpoint (this);
     } else
         throw new InternalError ();
 }
Ejemplo n.º 11
0
 //
 // Breakpoints
 //
 public Event InsertBreakpoint(ThreadGroup group, SourceLocation location)
 {
     Breakpoint bpt = new SourceBreakpoint (this, group, location);
     AddEvent (bpt);
     return bpt;
 }
		public int InsertBreakEvent (DL.BreakEvent be, bool enable)
		{
			CancelRuntimeInvokes ();
			DL.Breakpoint bp = be as DL.Breakpoint;
			MD.Event ev = null;
			
			if (bp != null) {
				MD.SourceLocation location = new MD.SourceLocation (bp.FileName, bp.Line);
				MD.SourceBreakpoint sbp = new MD.SourceBreakpoint (session, ThreadGroup.Global, location);
				mdbAdaptor.InitializeBreakpoint (sbp);
				session.AddEvent (sbp);
				ev = sbp;
			}
			else if (be is Catchpoint) {
				lock (pendingCatchpoints) {
					Catchpoint cp = (Catchpoint) be;
					ML.TargetType exc = null;
					if (process != null) {
						foreach (Module mod in process.Modules) {
							exc = mod.Language.LookupType (cp.ExceptionName);
							if (exc != null)
								break;
						}
					}
					if (exc != null)
						ev = session.InsertExceptionCatchPoint (process.MainThread, ThreadGroup.Global, exc);
					else {
						pendingCatchpoints.Add (cp);
						return -1;
					}
				}
			}
			
			ev.IsEnabled = enable;
			
			if (!initializing) {
				lock (debugger) {
					mdbAdaptor.ActivateEvent (ev);
				}
			}
						                    
			if (bp != null && !running && !initializing && activeThread.CurrentFrame != null && !string.IsNullOrEmpty (bp.ConditionExpression) && bp.BreakIfConditionChanges) {
				// Initial expression evaluation
				MdbEvaluationContext ctx = new MdbEvaluationContext (activeThread, activeThread.CurrentFrame, null, SessionOptions.EvaluationOptions);
				ML.TargetObject ob = EvaluateExp (ctx, bp.ConditionExpression);
				if (ob != null)
					lastConditionValue [ev.Index] = evaluator.TargetObjectToExpression (ctx, ob).Value;
			}
			
			events [ev.Index] = be;
			return ev.Index;
		}
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
        protected override bool DoResolve(ScriptingContext context)
        {
            // set whole method in a try-catch block: if anything goes wrong, an invalid breakpoint
            // number is set and the semaphore is released.
            try {
                if (global) {
                    if (local)
                        throw new ScriptingException (
                                                      "Cannot use both -local and -global.");

                    if (Group != null)
                        throw new ScriptingException (
                                                      "Cannot use both -group and -global.");

                    tgroup = ThreadGroup.Global;
                } else if (local) {
                    if (Group != null)
                        throw new ScriptingException (
                                                      "Cannot use both -group and -local.");

                    tgroup = context.Interpreter.GetThreadGroup (Group, false);
                } else if (Group != null) {
                    tgroup = context.Interpreter.GetThreadGroup (Group, false);
                } else {
                    tgroup = ThreadGroup.Global;
                }

                if (context.Interpreter.HasTarget) {
                    context.CurrentProcess = context.Interpreter.GetProcess (p_index);
                    context.CurrentThread = context.Interpreter.GetThread (t_index);

                    Mono.Debugger.Thread thread = context.CurrentThread;
                    if (!thread.IsStopped)
                        throw new Mono.Debugger.TargetException (TargetError.NotStopped);

                    Backtrace backtrace = thread.GetBacktrace ();

                    StackFrame frame;
                    if (f_index == -1)
                        frame = backtrace.CurrentFrame;
                    else {
                        if (f_index >= backtrace.Count)
                            throw new ScriptingException (
                                                          "No such frame: {0}", f_index);

                        frame = backtrace [f_index];
                    }

                    context.CurrentFrame = frame;

                    if (ExpressionParser.ParseLocation (
                                                        thread, thread.CurrentFrame, Argument, out location))
                    return true;
                }

                if (Argument.IndexOf (':') > 0)
                    return true;

                try {
                    UInt32.Parse (Argument);
                    return true;
                } catch {
                }

                Expression expr = context.Interpreter.ExpressionParser.Parse (Argument);
                if (expr == null)
                    throw new ScriptingException ("Cannot resolve expression `{0}'.", Argument);

                if (expr is PointerExpression) {
                    address = ((PointerExpression) expr).EvaluateAddress (context);
                    return true;
                }

                if (!context.Interpreter.HasTarget)
                    return true;

                MethodExpression mexpr;
                try {
                    mexpr = expr.ResolveMethod (context, type);
                } catch {
                    if (lazy)
                        return true;
                    throw new ScriptingException ("No such method: `{0}'.", Argument);
                }

                if (mexpr != null)
                    location = mexpr.EvaluateSource (context);
                else
                    location = context.FindMethod (Argument);

                if (lazy)
                    return true;

                if (location == null)
                    throw new ScriptingException ("No such method: `{0}'.", Argument);

                return true;
            } catch {
                EmonicInterpreter.breakpointNumber = -1;
                EmonicInterpreter.breakpointSem.Release();
                throw;
            }
        }