public override Task <DebugResult> Attach(dynamic args)
        {
            string name = getString(args, "name");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes == null)
            {
                return(Task.FromResult(new DebugResult(8001, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name })));
            }

            if (processes.Length == 0)
            {
                return(Task.FromResult(new DebugResult(8001, "Could not find target name '{_name}'. Is it running?", new { _name = name })));
            }

            if (processes.Length > 1)
            {
                return(Task.FromResult(new DebugResult(8002, "Multiple targets with name '{_name}' running. Unable to connect.", new { _name = name })));
            }

            var process = processes [0];

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Debugger.Connect(attachInfo.Address, attachInfo.Port);
            return(Task.FromResult(CreateDebugResult("UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n")));
        }
Esempio n. 2
0
        public override void Attach(Response response, dynamic args)
        {
            string name = getString(args, "name");

            SetExceptionBreakpoints(args.__exceptionOptions);

            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes.Length == 0)
            {
                SendErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            UnityProcessInfo process;

            if (processes.Length == 1)
            {
                process = processes[0];
            }
            else
            {
                if (name.Contains("Editor"))
                {
                    string pathToEditorInstanceJson = getString(args, "path");
                    var    jObject   = JObject.Parse(File.ReadAllText(pathToEditorInstanceJson.TrimStart('/')));
                    var    processId = jObject["process_id"].ToObject <int>();
                    process = processes.First(p => p.Id == processId);
                }
                else
                {
                    SendErrorResponse(response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.\n" +
                                      "Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.", new { _name = name });

                    SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect.\n" +
                               "Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.");

                    foreach (var p in processes)
                    {
                        SendOutput("stdout", "UnityDebug: Found Unity process '" + p.Name + "' (" + p.Id + ")\n");
                    }

                    return;
                }
            }

            SendOutput("stdout", "UnityDebug: Process ID" + process.Id);

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Connect(attachInfo.Address, attachInfo.Port);

            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + "):" + attachInfo.Port + "\n");
            SendResponse(response);
        }
        public override void Attach(Response response, dynamic args)
        {
            Log.Write($"UnityDebug: Attach: {response} ; {args}");
            string name = GetString(args, "name");

            SetExceptionBreakpoints(args.__exceptionOptions);

            Log.Write($"UnityDebug: Searching for Unity process '{name}'");
            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes.Length == 0)
            {
                Log.Write($"Could not find target name '{name}'.");
                SetErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            UnityProcessInfo process;

            if (processes.Length == 1)
            {
                process = processes[0];
            }
            else
            {
                if (!name.Contains("Editor"))
                {
                    TooManyInstances(response, name, processes);
                    return;
                }

                string pathToEditorInstanceJson = GetString(args, "path");
                pathToEditorInstanceJson = CleanPath(pathToEditorInstanceJson);
                if (!File.Exists(pathToEditorInstanceJson))
                {
                    TooManyInstances(response, name, processes);
                    return;
                }

                var jObject   = JObject.Parse(File.ReadAllText(pathToEditorInstanceJson));
                var processId = jObject["process_id"].ToObject <int>();
                process = processes.First(p => p.Id == processId);
            }

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Connect(attachInfo.Address, attachInfo.Port);

            Log.Write($"UnityDebug: Attached to Unity process '{process.Name}' ({process.Id})");
            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n");
            SetResponse(response);
        }
        public override void Attach(Response response, dynamic args)
        {
            string name = getString(args, "name");

            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes == null)
            {
                SendErrorResponse(response, 8001, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name });
                return;
            }

            if (processes.Length == 0)
            {
                SendErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            if (processes.Length > 1)
            {
                SendErrorResponse(response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.", new { _name = name });

                SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect");

                foreach (var p in processes)
                {
                    SendOutput("stdout", "UnityDebug: Found Unity process '" + p.Name + "' (" + p.Id + ")\n");
                }

                return;
            }

            var process = processes [0];

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Debugger.Connect(attachInfo.Address, attachInfo.Port);

            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n");
            SendResponse(response);
        }
Esempio n. 5
0
        UnityProcessInfo FindProcess(string name)
        {
            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes.Length <= 0)
            {
                Log.Write($"Could not find target name '{name}'.");
                SendErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it  running?", new { _name = name });
                return(null);
            }

            if (processes.Length > 1)
            {
                TooManyInstances(response, name, processes);
                return(null);
            }

            return(processes[0]);
        }