none
Visual Studio 2012, 2015 thaw threads accidentally. Why?

    Question

  • I am a developer of Visual Studio Extension. My customers develop the DLL which is loaded into the multi-processes.

    The customer wants to debug the C++ function located in the above dll. And the customer uses the Visual Studio 2010, 2012 or 2015 to attach to these processes at the same time.

    The function is executed by multi-threads among multi-processes. The customer wants to insert a breakpoint into the source code.

    I am developing the Visual Studio Extension which causes the process break only when the specified number of threads hits the breakpoint. This number is specified by the customer.

    For example, the customer specifies the number '4' and the thread A, B, C and D hits the breakpoint in this order.

    When the A, B and C hits, my extension freezes the current thread and set the 'ref EnvDTE.dbgExecutionAction ExecutionAction' to dbgExecutionActionGo in the handler 'DebuggerEventsClass.OnEnterBreakMode'.

    https://docs.microsoft.com/en-us/dotnet/api/envdte.debuggereventsclass.onenterbreakmode?view=visualstudiosdk-2017

    When D hits, my extension doesn't change the 'ref EnvDTE.dbgExecutionAction ExecutionAction' and thaws all the freezed threads.

        [The pard of my sample which generate this phenomenon]
        
            private int _cnt = 0;
            private List<EnvDTE.Thread> _threadsList = new List<EnvDTE.Thread>();
            public EnvDTE.DTE DTE{ get { return Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(global::EnvDTE.DTE)) as global::EnvDTE.DTE; } }

            private void S_DebuggerEvents_OnEnterBreakMode(EnvDTE.dbgEventReason Reason, ref EnvDTE.dbgExecutionAction ExecutionAction)
            {
                _cnt++;
                DTE.Debugger.CurrentThread.Freeze();
                _threadsList.Add(DTE.Debugger.CurrentThread);
                if (_cnt < getCustomerSpecifiedNum())
                {
                    ExecutionAction = EnvDTE.dbgExecutionAction.dbgExecutionActionGo;
                }
                else
                {
                    _cnt = 0;

                    foreach(EnvDTE.Thread thread in _threadsList)
                    {
                        thread.Thaw();
                    }

                    _threadsList.Clear();
                }
            }


    In the end, the threads A, B, C and D stop at the same breakpoint and the customer can debug each thread easily by changing the active thread.

    In Visual Studio 2010, my extension works completely. But in Visual Studio 2012 or 2015, sometimes the threads are not located at the breakpoint.

    So it seems that the threads are thawed accidentally. This phenomenon occurs when you do the following settings in [Tools]->[Options]->[Debugging]->[General].

       Check: [Break all processes when one process breaks]

    How can I get around it?
    Wednesday, July 11, 2018 9:59 AM