internal SampleStackFrame(SampleDebugAdapter adapter, SampleModule module, string functionName, IEnumerable <SampleFunctionArgument> args, string fileName, int line, int column)
            : base(adapter)
        {
            this.childScopes = new List <SampleScope>();

            this.localsScope = new SampleScope(this.Adapter, "Locals", false);

            this.Module       = module;
            this.FunctionName = functionName;
            this.FileName     = fileName;
            this.Line         = line;
            this.Column       = column;

            if (args != null && args.Any())
            {
                this.Args      = args.ToList();
                this.argsScope = new SampleScope(this.Adapter, "Arguments", false);

                foreach (SampleFunctionArgument arg in args)
                {
                    SimpleVariable variable = new SimpleVariable(
                        adapter: this.Adapter,
                        name: arg.Name,
                        type: arg.Type,
                        value: arg.Value);

                    this.argsScope.AddVariable(variable);
                }
            }
            else
            {
                this.Args = Enumerable.Empty <SampleFunctionArgument>().ToList();;
            }
        }
        public SimpleVariable(SampleDebugAdapter adapter, string name, string type, string value)
            : base(adapter, name, type)
        {
            this.value = value;

            this.children = new List <SampleVariable>();
        }
        internal ExceptionManager(SampleDebugAdapter adapter)
        {
            this.adapter = adapter;
            this.exceptionCategorySettings = new Dictionary <string, ExceptionCategorySettings>();

            this.adapter.RegisterDirective <ThrowArgs>("throw", this.DoThrow);
        }
Ejemplo n.º 4
0
        internal SampleScope(SampleDebugAdapter adapter, string name, bool expensive)
            : base(adapter)
        {
            this.variables = new List <SampleVariable>();

            this.Name      = name;
            this.expensive = expensive;
        }
        internal ModuleManager(SampleDebugAdapter adapter)
        {
            this.adapter       = adapter;
            this.loadedModules = new List <SampleModule>();

            this.adapter.RegisterDirective <LoadModuleArgs>("LoadModule", this.DoLoadModule);
            this.adapter.RegisterDirective <UnloadModuleArgs>("UnloadModule", this.DoUnloadModule);
        }
Ejemplo n.º 6
0
        public SampleSourceManager(SampleDebugAdapter adapter)
        {
            this.adapter       = adapter;
            this.loadedSources = new List <SampleSource>();

            this.adapter.RegisterDirective <SourceArgs>("LoadSource", this.DoLoadSource);
            this.adapter.RegisterDirective <SourceArgs>("UnloadSource", this.DoUnloadSource);
        }
Ejemplo n.º 7
0
        private static void Main(string[] args)
        {
            CommandLineParser parser    = new CommandLineParser(typeof(ProgramArgs));
            ProgramArgs       arguments = null;

            try
            {
                arguments = (ProgramArgs)parser.Parse(args);
            }
            catch (CommandLineArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                parser.WriteUsageToConsole();
                return;
            }

            if (arguments.Debug)
            {
                Console.WriteLine("Waiting for debugger...");
                while (true)
                {
                    if (Debugger.IsAttached)
                    {
                        Console.WriteLine("Debugger attached!");
                        break;
                    }

                    Thread.Sleep(100);
                }
            }

            if (arguments.StepOnEnter && arguments.ServerPort == 0)
            {
                Console.WriteLine("Continue-on-Enter requires server mode.");
                return;
            }

            if (arguments.ServerPort != 0)
            {
                // Server mode - listen on a network socket
                RunServer(arguments);
            }
            else
            {
                // Standard mode - run with the adapter connected to the process's stdin and stdout
                SampleDebugAdapter adapter = new SampleDebugAdapter(Console.OpenStandardInput(), Console.OpenStandardOutput());
                adapter.Protocol.LogMessage += (sender, e) => Debug.WriteLine(e.Message);
                adapter.Run();
            }
        }
        internal ThreadManager(SampleDebugAdapter adapter)
        {
            this.adapter = adapter;
            this.threads = new List <SampleThread>();

            this.adapter.RegisterDirective <StartThreadArgs>("StartThread", this.DoStartThread);
            this.adapter.RegisterDirective <EndThreadArgs>("EndThread", this.DoEndThread);

            this.adapter.RegisterDirective <PushStackFrameArgs>("PushStackFrame", this.DoPushStackFrame);
            this.adapter.RegisterDirective <PopStackFrameArgs>("PopStackFrame", this.DoPopStackFrame);

            this.adapter.RegisterDirective <DefineScopeArgs>("DefineScope", this.DoDefineScope);

            this.adapter.RegisterDirective <DefineVariableArgs>("DefineVariable", this.DoDefineVariable);
        }
 public WrapperVariable(SampleDebugAdapter adapter, string name, string type, Func <string> valueGetter, Func <IReadOnlyCollection <SampleVariable> > childrenGetter = null)
     : base(adapter, name, type)
 {
     this.valueGetter    = valueGetter;
     this.childrenGetter = childrenGetter;
 }
 protected SampleVariable(SampleDebugAdapter adapter, string name, string type)
     : base(adapter)
 {
     this.Name = name;
     this.Type = type;
 }
        internal BreakpointManager(SampleDebugAdapter adapter)
        {
            this.adapter = adapter;

            this.breakpoints = new HashSet <int>();
        }
Ejemplo n.º 12
0
        private static void RunServer(ProgramArgs args)
        {
            Console.WriteLine(Invariant($"Waiting for connections on port {args.ServerPort}..."));
            SampleDebugAdapter adapter = null;

            Thread listenThread = new Thread(() =>
            {
                TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), args.ServerPort);
                listener.Start();

                while (true)
                {
                    Socket clientSocket = listener.AcceptSocket();
                    Thread clientThread = new Thread(() =>
                    {
                        Console.WriteLine("Accepted connection");

                        using (Stream stream = new NetworkStream(clientSocket))
                        {
                            adapter = new SampleDebugAdapter(stream, stream);
                            adapter.Protocol.LogMessage      += (sender, e) => Console.WriteLine(e.Message);
                            adapter.Protocol.DispatcherError += (sender, e) =>
                            {
                                Console.Error.WriteLine(e.Exception.Message);
                            };
                            adapter.Run();
                            adapter.Protocol.WaitForReader();

                            adapter = null;
                        }

                        Console.WriteLine("Connection closed");
                    });

                    clientThread.Name = "DebugServer connection thread";
                    clientThread.Start();
                }
            });

            Thread keypressThread;

            if (args.StepOnEnter)
            {
                Console.WriteLine("Will step when ENTER is pressed.");
                keypressThread = new Thread(() =>
                {
                    ConsoleKeyInfo keyInfo;

                    while (true)
                    {
                        keyInfo = Console.ReadKey();
                        if (keyInfo.Key == ConsoleKey.Enter && adapter != null)
                        {
                            Console.WriteLine("Forcing step");
                            adapter.ExitBreakCore(0, true);
                        }
                    }
                });

                keypressThread.Name = "Keypress listener thread";
                keypressThread.Start();
            }

            listenThread.Name = "DebugServer listener thread";
            listenThread.Start();
            listenThread.Join();
        }