Mono.Debugger.Frontend.ExpressionParser.ParseLocation C# (CSharp) Method

ParseLocation() public method

public ParseLocation ( ScriptingContext context, string arg, SourceLocation &location ) : bool
context ScriptingContext
arg string
location Mono.Debugger.SourceLocation
return bool
        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;
        }

Same methods

ExpressionParser::ParseLocation ( Thread target, StackFrame frame, LocationType type, string arg ) : SourceLocation

Usage Example

示例#1
0
        /// <summary> Toggle breakpoint at given location </summary>
        public void ToggleBreakpoint(string filename, int line)
        {
            // Try to find a breakpoint at current location
            foreach (Event breakpoint in interpreter.Session.Events)
            {
                if (breakpoint is SourceBreakpoint)
                {
                    SourceLocation location = ((SourceBreakpoint)breakpoint).Location;
                    if (location != null &&
                        location.FileName == filename &&
                        location.Line == line)
                    {
                        interpreter.Session.DeleteEvent(breakpoint);
                        breakpointsStore.UpdateTree();
                        return;
                    }
                }
            }

            // Add breakpoint at current location
            if (interpreter.HasTarget && interpreter.HasCurrentThread)
            {
                try {
                    SourceLocation newLocation;
                    ExpressionParser.ParseLocation(interpreter.CurrentThread, interpreter.CurrentThread.CurrentFrame, line.ToString(), out newLocation);
                    Event newBreakpoint = interpreter.Session.InsertBreakpoint(ThreadGroup.Global, newLocation);
                    newBreakpoint.Activate(interpreter.CurrentThread);
                } catch {
                }
                breakpointsStore.UpdateTree();
                return;
            }
        }