Exemplo n.º 1
0
        public override void Attach(Response response, dynamic arguments)
        {
            LogStart();
            InitializeLogging(arguments);

            string workingDir = arguments.workingDir;

            if (!string.IsNullOrEmpty(workingDir) && Directory.Exists(workingDir))
            {
                Environment.CurrentDirectory = workingDir;
            }

            string target    = arguments.target;
            int    processId = 0;

            if (string.IsNullOrWhiteSpace(target) || !int.TryParse(target, out processId) || Process.GetProcessById(processId) == null)
            {
                SendErrorResponse(response, ErrorCodes.TargetDoesNotExist, $"Could not attach to '{target}' as it does not exist.");
            }

            string debuggerEnginePath = arguments.windbgpath;
            var    sources            = ParseSources(arguments);

            InitializeDebugger(debuggerEnginePath, sources);

            var result = _api.Attach(processId);

            if (!string.IsNullOrEmpty(result))
            {
                SendErrorResponse(response, ErrorCodes.FailedToAttach, result);
            }
            else
            {
                SendResponse(response);
            }

            LogFinish();
        }