【问题标题】:How to get Visual Studio debugger to break without focus如何让 Visual Studio 调试器在没有焦点的情况下中断
【发布时间】:2016-04-27 18:18:33
【问题描述】:

我试图在我的(本机 C++)应用程序具有鼠标焦点时中断,通过切换到 Visual Studio 应用程序到 Ctrl-Alt-Break 或 Debug > Break All,我的应用程序不再做我正在尝试的事情继续。

例如,有没有办法让 Visual Studio 在 5 秒后中断?或者是否有某种调试 api,我可以编写脚本来触发 Break All,而无需将焦点切换到 Visual Studio 应用程序?

能够在没有焦点的情况下中断有助于poor man's profiling 并更好地理解与焦点相关的不熟悉代码。

【问题讨论】:

  • Visual Studio(尤其是 2015 年)有大量的分析工具,所以如果你的目标真的是进行分析,那么最好使用这些工具。
  • 这是一个受支持的调试方案,您必须在另一台机器上运行应用程序并使用远程调试器。
  • 你可以编辑你的断点的属性,也许你可以配置断点来做你想做的事情。

标签: c++ visual-studio debugging


【解决方案1】:

有两种方法可以在不将鼠标焦点更改为 Visual Studio 的情况下中断:

  1. 安装Remote Tools and debug from another machine

  2. 添加一个带有计时器的线程并在那里设置一个断点,例如将其添加到某处以每 5 秒中断一次:

    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();
    }
    

    您将需要这些标题:

    #include <thread>
    #include <chrono>
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多