1

I am trying to break while my (native C++) application has mouse focus, and by switching to the Visual Studio application to Ctrl-Alt-Break or Debug > Break All, my application is no longer doing the thing I am trying to break on.

Is there a way to get Visual Studio to break after 5 seconds has elapsed for example? Or is there some kind of debugging api that I can write a script to trigger a Break All without me switching focus to the Visual Studio application?

Being able to break without focus could help with poor man's profiling and better understanding unfamiliar code related to focus.

Community
  • 1
  • 1
JDiMatteo
  • 12,022
  • 5
  • 54
  • 65
  • Visual Studio (especially 2015) has a ton of profiling tools, so if your goal is really to do profiling you would be better off using those. – BJ Myers Apr 27 '16 at 18:42
  • 3
    It is a supported debugging scenario, you have to run the app on another machine and use the remote debugger. – Hans Passant Apr 27 '16 at 18:58
  • You can edit your breakpoint's properties, perhaps you can configure the breakpoint to do what you want to achieve. – Chris O Apr 28 '16 at 02:10

1 Answers1

-1

There are two ways to break without changing mouse focus to Visual Studio:

  1. Install Remote Tools and debug from another machine, OR

  2. Add a thread with a timer and set a break point there, e.g. add this somewhere to break every 5 seconds:

    static bool debug_timer_started = false;
    if ( !debug_timer_started )
    {
      debug_timer_started = true;
      std::thread([]
      {
        static int seconds = 5;
        static bool keep_going = true;
        while ( keep_going )
        {
          /* set break point on this line: */ std::this_thread::sleep_for(std::chrono::seconds(seconds));
        }
      }).detach();
    }
    

    You will need these headers:

    #include <thread>
    #include <chrono>
    
JDiMatteo
  • 12,022
  • 5
  • 54
  • 65