FindMethod() public method

public FindMethod ( string name ) : SourceLocation
name string
return Mono.Debugger.SourceLocation
Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        protected override Expression DoResolve(ScriptingContext context)
        {
            if (context.HasFrame) {
                StackFrame frame = context.CurrentFrame;
                if ((frame.Method != null) && frame.Method.IsLoaded) {
                    TargetVariable var = GetVariableByName (frame, name);
                    if (var != null)
                        return new VariableAccessExpression (var);
                }

                Expression expr = Lookup (context, frame);
                if (expr != null)
                    return expr;

                TargetAddress address = context.CurrentProcess.LookupSymbol (name);
                if (!address.IsNull)
                    return new NumberExpression (address.Address);
            } else if (context.ImplicitInstance != null) {
                MemberExpression member = StructAccessExpression.FindMember (
                    context.CurrentThread, context.ImplicitInstance.Type,
                    context.ImplicitInstance, name, true, true);
                if (member != null)
                    return member;

                string[] namespaces = context.GetNamespaces () ?? new string [0];
                foreach (string ns in namespaces) {
                    string full_name = MakeFQN (ns, name);
                    member = StructAccessExpression.FindMember (
                        context.CurrentThread, context.ImplicitInstance.Type,
                        context.ImplicitInstance, full_name, true, true);
                    if (member != null)
                        return member;
                }
            }

            SourceLocation location = context.FindMethod (name);
            if (location != null)
                return new SourceExpression (location);

            Expression texpr = DoResolveType (context);
            if (texpr != null)
                return texpr;

            throw new ScriptingException ("No symbol `{0}' in current context.", Name);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
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;
            }
        }