示例#1
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.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
                ILRuntimeDebugAdapter adapter = new ILRuntimeDebugAdapter(Console.OpenStandardInput(), Console.OpenStandardOutput());
                adapter.Protocol.LogMessage += (sender, e) =>
                {
                    Debug.WriteLine(e.Message);
                };
                adapter.Run();
            }
        }
示例#2
0
        private static void RunServer(ProgramArgs args)
        {
            Console.WriteLine(($"Waiting for connections on port {args.ServerPort}..."));
            ILRuntimeDebugAdapter 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 ILRuntimeDebugAdapter(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();
                }
            });

            listenThread.Name = "DebugServer listener thread";
            listenThread.Start();
            listenThread.Join();
        }
示例#3
0
 public DebuggedProcessVSCode(ILRuntimeDebugAdapter da, string host, int port)
     : base(host, port)
 {
     this.da = da;
 }