private bool DoDefineScope(DefineScopeArgs args, StringBuilder output)
        {
            SampleThread thread = this.GetThread(args.ThreadId);

            if (thread == null)
            {
                output.AppendLine(Invariant($"Error: Invalid thread id '{args.ThreadId}'!"));
                return(false);
            }

            SampleStackFrame frame = thread.GetTopStackFrame();

            if (frame == null)
            {
                output.AppendLine(Invariant($"Error: Thread '{args.ThreadId}' has no stack frames!"));
                return(false);
            }

            if (frame.AllScopes.Any(s => String.Equals(s.Name, args.Name, StringComparison.OrdinalIgnoreCase)))
            {
                output.AppendLine(Invariant($"Error: Selected stack frame already has a scope called '{args.Name}'!"));
                return(false);
            }

            SampleScope scope = new SampleScope(this.adapter, args.Name, args.Expensive);

            frame.AddScope(scope);

            return(true);
        }
Ejemplo n.º 2
0
        protected override ConfigurationDoneResponse HandleConfigurationDoneRequest(ConfigurationDoneArguments arguments)
        {
            this.defaultThread = this.ThreadManager.StartThread(0, "Main Thread");

            this.defaultThread.PushStackFrame(new SampleStackFrame(
                                                  adapter: this,
                                                  module: null,
                                                  functionName: "ScriptMain",
                                                  args: null,
                                                  fileName: this.Source.Path,
                                                  line: this.LineToClient(0),
                                                  column: 0));

            if (this.stopAtEntry)
            {
                // Clear the event so we'll break at startup
                this.RequestStop(StoppedEvent.ReasonValue.Step);
            }

            this.debugThread      = new SysThread(this.DebugThreadProc);
            this.debugThread.Name = "Debug Loop Thread";
            this.debugThread.Start();

            return(new ConfigurationDoneResponse());
        }
 internal void EndThread(SampleThread thread)
 {
     this.threads.Remove(thread);
     this.adapter.Protocol.SendEvent(
         new ThreadEvent(
             reason: ThreadEvent.ReasonValue.Exited,
             threadId: thread.Id));
 }
        internal StackTraceResponse HandleStackTraceRequest(StackTraceArguments args)
        {
            SampleThread thread = this.GetThread(args.ThreadId);

            if (thread == null)
            {
                throw new ProtocolException(Invariant($"Invalid thread id '{args.ThreadId}'!"));
            }

            return(thread.HandleStackTraceRequest(args));
        }
        internal SampleThread StartThread(int id, string name)
        {
            SampleThread newThread = new SampleThread(id, name);

            this.threads.Add(newThread);
            this.adapter.Protocol.SendEvent(
                new ThreadEvent(
                    reason: ThreadEvent.ReasonValue.Started,
                    threadId: id));

            return(newThread);
        }
        private bool DoPopStackFrame(PopStackFrameArgs args, StringBuilder output)
        {
            SampleThread targetThread = this.GetThread(args.ThreadId);

            if (targetThread == null)
            {
                output.AppendLine(Invariant($"Error: Unknown thread id '{args.ThreadId}'!"));
                return(false);
            }

            targetThread.PopStackFrame();
            return(true);
        }
        private bool DoPushStackFrame(PushStackFrameArgs args, StringBuilder output)
        {
            List <SampleFunctionArgument> stackArgs = null;

            if (args.ArgName != null && args.ArgName.Length > 0)
            {
                if (args.ArgType == null || args.ArgType.Length != args.ArgName.Length ||
                    args.ArgValue == null || args.ArgValue.Length != args.ArgName.Length)
                {
                    output.AppendLine("Error: Must have same number of -argName, -argType, and -argValue arguments!");
                    return(false);
                }

                stackArgs = new List <SampleFunctionArgument>();
                for (int i = 0; i < args.ArgName.Length; i++)
                {
                    stackArgs.Add(new SampleFunctionArgument(args.ArgType[i], args.ArgName[i], args.ArgValue[i]));
                }
            }

            SampleModule module = null;

            if (!String.IsNullOrEmpty(args.ModuleId))
            {
                module = this.adapter.ModuleManager.GetModuleById(args.ModuleId);
                if (module == null)
                {
                    output.AppendLine(Invariant($"Error: Unknown module id '{args.ModuleId}'!"));
                    return(false);
                }
            }

            SampleThread targetThread = this.GetThread(args.ThreadId);

            if (targetThread == null)
            {
                output.AppendLine(Invariant($"Error: Unknown thread id '{args.ThreadId}'!"));
                return(false);
            }

            targetThread.PushStackFrame(new SampleStackFrame(this.adapter, module, args.Name, stackArgs, this.adapter.Source.Path, 0, 0));

            return(true);
        }
        private bool DoEndThread(EndThreadArgs args, StringBuilder output)
        {
            if (args.Id == 0)
            {
                output.AppendLine("Error: Main thread cannot be ended!");
                return(false);
            }

            SampleThread thread = this.threads.FirstOrDefault(t => t.Id == args.Id);

            if (thread == null)
            {
                output.AppendLine(Invariant($"Error: No thread with id '{args.Id}'!"));
                return(false);
            }

            this.EndThread(thread);

            return(true);
        }
        private bool DoThrow(ThrowArgs args, StringBuilder output)
        {
            SampleThread thread = this.adapter.ThreadManager.GetThread(args.ThreadId);

            if (thread == null)
            {
                output.AppendLine(Invariant($"Unknown thread id '{args.ThreadId}'!"));
                return(false);
            }

            if (this.HasPendingException)
            {
                output.AppendLine("Exception is already pending!");
                return(false);
            }

            if (!args.ExceptionId.Contains("/"))
            {
                output.AppendLine("Expected ExceptionId to be of form 'Category/Exception'!");
                return(false);
            }

            ExceptionBreakMode breakMode = ExceptionBreakMode.Always;

            if (args.Type != null)
            {
                switch (args.Type.Value)
                {
                case ExceptionType.Caught:
                    breakMode = ExceptionBreakMode.Always;
                    break;

                case ExceptionType.Uncaught:
                    breakMode = ExceptionBreakMode.Unhandled;
                    break;

                case ExceptionType.UserUncaught:
                    // UserUncaught means the exception was caught in non-user code, so if JMC is turned off, treat it like any other
                    //  caught exception.
                    breakMode = (this.adapter.IsJustMyCodeOn ?? false) ? ExceptionBreakMode.UserUnhandled : ExceptionBreakMode.Always;
                    break;
                }
            }

            if (this.shouldThrow(args.ExceptionId, breakMode))
            {
                // Our configuration includes this exception - report it to the host
                this.PendingExceptionThread = args.ThreadId;
                this.pendingException       = new ExceptionInfoResponse(
                    exceptionId: args.ExceptionId,
                    breakMode: breakMode,
                    description: args.Description,
                    code: args.Code);
            }
            else
            {
                output.AppendLine(Invariant($"Ignoring exception '{args.ExceptionId}' due to configuration."));
            }

            return(true);
        }