Example #1
0
 private void reportSkippedCopy(ref ThreadProgress threadProgress, string destinationPath, int i)
 {
     threadProgress.DestinationPath = destinationPath == null?threadProgress.SourcePath:destinationPath;
     threadProgress.CountSkipped++;
     threadProgress.CurrentTimeStamp = System.DateTime.Now;
     threadProgress.SkippedBytes    += getFileSize(threadProgress.SourcePath);
     threadProgress.FlagCopy         = false;
     backgroundWorker_Copy.ReportProgress(i, threadProgress);
 }
Example #2
0
 private void reportSuccessCopy(ref ThreadProgress threadProgress, string destinationPath, int i)
 {
     threadProgress.DestinationPath = destinationPath;
     threadProgress.CountCopied++;
     threadProgress.CurrentTimeStamp = System.DateTime.Now;
     threadProgress.CopiedBytes     += getFileSize(threadProgress.DestinationPath);
     threadProgress.FlagCopy         = true;
     backgroundWorker_Copy.ReportProgress(i, threadProgress);
 }
Example #3
0
 private void resetThreadProgress(ref ThreadProgress threadProgress, int total, string collectedSourceLogFilePath, string toBeDeletedLogFilePath, string collectedDestinationLogFilePath)
 {
     threadProgress.CountTotal       = total;
     threadProgress.CountCopied      = 0;
     threadProgress.CountSkipped     = 0;
     threadProgress.CopiedBytes      = 0;
     threadProgress.SkippedBytes     = 0;
     threadProgress.StartTimeStamp   = System.DateTime.Now;
     threadProgress.CurrentTimeStamp = System.DateTime.Now;
     threadProgress.LogFilePath_CollectedSourcePaths      = collectedSourceLogFilePath;
     threadProgress.LogFilePath_ToBeDeleted               = toBeDeletedLogFilePath;
     threadProgress.LogFilePath_CollectedDestinationPaths = collectedDestinationLogFilePath;
 }
        private async Task ContinueTheChild(ThreadProgress state)
        {
            Debug.Assert(state.State == State.AtExec, "wrong vfork processing state");
            if (state.Newpid != 0)
            {
                uint inf = _process.InferiorByPid(state.Newpid);
                if (inf != 0)
                {
                    await _process.ConsoleCmdAsync("inferior " + inf.ToString(), allowWhileRunning : false);

                    await _process.MICommandFactory.ExecContinue();  // run the child
                }
            }
        }
 private async Task RunChildToMain(ThreadProgress state)
 {
     Debug.Assert(state.Newpid != 0, "Child process id not found.");
     if (state.Newpid != 0)
     {
         uint inf = _process.InferiorByPid(state.Newpid);
         if (inf != 0)
         {
             await _process.ConsoleCmdAsync("inferior " + inf.ToString());
             await SetBreakAtMain();
             state.State = State.AtExec;
             await _process.MICommandFactory.ExecContinue();  // run the child
         }
     }
 }
        private async Task RunChildToMain(ThreadProgress state)
        {
            Debug.Assert(state.Newpid != 0, "Child process id not found.");
            if (state.Newpid != 0)
            {
                uint inf = _process.InferiorByPid(state.Newpid);
                if (inf != 0)
                {
                    await _process.ConsoleCmdAsync("inferior " + inf.ToString(), allowWhileRunning : false);
                    await SetBreakAtMain();

                    state.State = State.AtExec;
                    await _process.MICommandFactory.ExecContinue();  // run the child
                }
            }
        }
        private async Task <bool> DetachFromChild(ThreadProgress state)
        {
            uint inf = _process.InferiorByPid(state.Newpid);

            if (inf == 0)
            {
                return(false);    // cannot process the child
            }
            await _process.ConsoleCmdAsync("inferior " + inf.ToString(), allowWhileRunning : false);

            await _process.MICommandFactory.TargetDetach();     // detach from the child

            await _process.ConsoleCmdAsync("inferior 1", allowWhileRunning : false);

            return(true);
        }
        private async Task <bool> DetachAndContinue(ThreadProgress state)
        {
            await DetachFromChild(state);

            AD7Engine.AddChildProcess(state.Newpid);
            string engineName;
            Guid   engineGuid;

            _process.Engine.GetEngineInfo(out engineName, out engineGuid);
            _launchOptions.BaseOptions.ProcessId          = state.Newpid;
            _launchOptions.BaseOptions.ProcessIdSpecified = true;
            _launchOptions.BaseOptions.ExePath            = state.Exe ?? _launchOptions.ExePath;
            HostDebugger.StartDebugChildProcess(_launchOptions.BaseOptions.ExePath, _launchOptions.GetOptionsString(), engineGuid);
            await _process.MICommandFactory.ExecContinue(); // continue the parent

            return(true);                                   // parent is running
        }
 private async Task ProcessChild(ThreadProgress state)
 {
     Debug.Assert(state.Newpid != 0, "Child process id not found.");
     if (state.Newpid != 0)
     {
         uint inf = _process.InferiorByPid(state.Newpid);
         if (inf != 0)
         {
             await _process.ConsoleCmdAsync("inferior " + inf.ToString());
             if (!string.IsNullOrEmpty(_mainBreak))
             {
                 await _process.MICommandFactory.BreakDelete(_mainBreak);
                 _mainBreak = null;
             }
             state.State = State.AtSignal;
             await _process.MICommandFactory.Signal("SIGSTOP");  // stop the child
         }
     }
 }
Example #10
0
        private async Task ProcessChild(ThreadProgress state)
        {
            Debug.Assert(state.Newpid != 0, "Child process id not found.");
            if (state.Newpid != 0)
            {
                uint inf = _process.InferiorByPid(state.Newpid);
                if (inf != 0)
                {
                    await _process.ConsoleCmdAsync("inferior " + inf.ToString(), allowWhileRunning : false);

                    if (!string.IsNullOrEmpty(_mainBreak))
                    {
                        await _process.MICommandFactory.BreakDelete(_mainBreak);

                        _mainBreak = null;
                    }
                    state.State = State.AtSignal;
                    await _process.MICommandFactory.Signal("SIGSTOP");  // stop the child
                }
            }
        }
Example #11
0
        public async Task <bool> Stopped(Results results, int tid)
        {
            string         reason = results.TryFindString("reason");
            ThreadProgress s      = StateFromTid(tid);

            if (reason == "fork")
            {
                s                  = new ThreadProgress();
                s.State            = State.AtFork;
                s.Newpid           = results.FindInt("newpid");
                _threadStates[tid] = s;
                await _process.Step(tid, VisualStudio.Debugger.Interop.enum_STEPKIND.STEP_OUT, VisualStudio.Debugger.Interop.enum_STEPUNIT.STEP_LINE);

                return(true);
            }
            else if (reason == "vfork")
            {
                s                  = new ThreadProgress();
                s.State            = State.AtVfork;
                s.Newpid           = results.FindInt("newpid");
                _threadStates[tid] = s;
                await _process.MICommandFactory.SetOption("schedule-multiple", "on");

                await _process.MICommandFactory.Catch("exec", onlyOnce : true);

                var thread = await _process.ThreadCache.GetThread(tid);

                await _process.Continue(thread);

                return(true);
            }

            if (s == null)
            {
                return(false);   // no activity being tracked on this thread
            }

            switch (s.State)
            {
            case State.AtFork:
                await ProcessChild(s);

                break;

            case State.AtVfork:
                await _process.MICommandFactory.SetOption("schedule-multiple", "off");

                if ("exec" == results.TryFindString("reason"))
                {
                    // The process doesn't handle the SIGSTOP correctly (just ignores it) when the process is at the start of program
                    // (after exec). Let it run some code so that it will correctly respond to the SIGSTOP.
                    s.Exe = results.TryFindString("new-exec");
                    await RunChildToMain(s);
                }
                else
                {
                    // sometimes gdb misses the breakpoint at exec and execution will proceed to a breakpoint in the child
                    _process.Logger.WriteLine("Missed catching the exec after vfork. Spawning the child's debugger.");
                    s.State = State.AtExec;
                    goto missedExec;
                }
                break;

            case State.AtSignal:        // both child and parent are stopped
                s.State = State.Complete;
                return(await DetachAndContinue(s));

            case State.AtExec:
missedExec:
                if (tid == s.Newtid)        // stopped in the child
                {
                    await ProcessChild(s);
                }
                else     // sometime the parent will get a spurious signal before the child hits main
                {
                    await ContinueTheChild(s);
                }
                break;

            case State.Complete:
                _threadStates.Remove(tid);
                if (reason == "signal-received" && results.TryFindString("signal-name") == "SIGSTOP")
                {
                    // SIGSTOP was propagated to the parent
                    await _process.MICommandFactory.Signal("SIGCONT");

                    return(true);
                }
                return(false);

            default:
                return(false);
            }
            return(true);
        }
 private async Task ContinueTheChild(ThreadProgress state)
 {
     Debug.Assert(state.State == State.AtExec, "wrong vfork processing state");
     if (state.Newpid != 0)
     {
         uint inf = _process.InferiorByPid(state.Newpid);
         if (inf != 0)
         {
             await _process.ConsoleCmdAsync("inferior " + inf.ToString());
             await _process.MICommandFactory.ExecContinue();  // run the child
         }
     }
 }
        public async Task<bool> Stopped(Results results, int tid)
        {
            string reason = results.TryFindString("reason");
            ThreadProgress s = StateFromTid(tid);

            if (reason == "fork")
            {
                s = new ThreadProgress();
                s.State = State.AtFork;
                s.Newpid = results.FindInt("newpid");
                _threadStates[tid] = s;
                await _process.Step(tid, VisualStudio.Debugger.Interop.enum_STEPKIND.STEP_OUT, VisualStudio.Debugger.Interop.enum_STEPUNIT.STEP_LINE);
                return true;
            }
            else if (reason == "vfork")
            {
                s = new ThreadProgress();
                s.State = State.AtVfork;
                s.Newpid = results.FindInt("newpid");
                _threadStates[tid] = s;
                await _process.MICommandFactory.SetOption("schedule-multiple", "on");
                await _process.MICommandFactory.Catch("exec", onlyOnce: true);
                var thread = await _process.ThreadCache.GetThread(tid);
                await _process.Continue(thread);
                return true;
            }

            if (s == null)
            {
                return false;   // no activity being tracked on this thread
            }

            switch (s.State)
            {
                case State.AtFork:
                    await ProcessChild(s);
                    break;
                case State.AtVfork:
                    await _process.MICommandFactory.SetOption("schedule-multiple", "off");
                    if ("exec" == results.TryFindString("reason"))
                    {
                        // The process doesn't handle the SIGSTOP correctly (just ignores it) when the process is at the start of program 
                        // (after exec). Let it run some code so that it will correctly respond to the SIGSTOP.
                        s.Exe = results.TryFindString("new-exec");
                        await RunChildToMain(s);
                    }
                    else
                    {
                        // sometimes gdb misses the breakpoint at exec and execution will proceed to a breakpoint in the child
                        _process.Logger.WriteLine("Missed catching the exec after vfork. Spawning the child's debugger.");
                        s.State = State.AtExec;
                        goto missedExec;
                    }
                    break;
                case State.AtSignal:    // both child and parent are stopped
                    s.State = State.Complete;
                    return await DetachAndContinue(s);
                case State.AtExec:
                missedExec:
                    if (tid == s.Newtid)    // stopped in the child
                    {
                        await ProcessChild(s);
                    }
                    else // sometime the parent will get a spurious signal before the child hits main
                    {
                        await ContinueTheChild(s);
                    }
                    break;
                case State.Complete:
                    _threadStates.Remove(tid);
                    if (reason == "signal-received" && results.TryFindString("signal-name") == "SIGSTOP")
                    {
                        // SIGSTOP was propagated to the parent
                        await _process.MICommandFactory.Signal("SIGCONT");
                        return true;
                    }
                    return false;
                default:
                    return false;
            }
            return true;
        }
 private async Task<bool> DetachFromChild(ThreadProgress state)
 {
     uint inf = _process.InferiorByPid(state.Newpid);
     if (inf == 0)
         return false;    // cannot process the child
     await _process.ConsoleCmdAsync("inferior " + inf.ToString());
     await _process.MICommandFactory.TargetDetach();     // detach from the child
     await _process.ConsoleCmdAsync("inferior 1");
     return true;
 }
 private async Task<bool> DetachAndContinue(ThreadProgress state)
 {
     await DetachFromChild(state);
     AD7Engine.AddChildProcess(state.Newpid);
     string engineName;
     Guid engineGuid;
     _process.Engine.GetEngineInfo(out engineName, out engineGuid);
     _launchOptions.BaseOptions.ProcessId = state.Newpid;
     _launchOptions.BaseOptions.ProcessIdSpecified = true;
     _launchOptions.BaseOptions.ExePath = state.Exe ?? _launchOptions.ExePath;
     HostDebugger.StartDebugChildProcess(_launchOptions.BaseOptions.ExePath, _launchOptions.GetOptionsString(), engineGuid);
     await _process.MICommandFactory.ExecContinue();     // continue the parent
     return true;   // parent is running
 }