【问题标题】:Breakpoint in template is ignored, is there a workaround?模板中的断点被忽略,有解决方法吗?
【发布时间】:2014-08-29 19:46:54
【问题描述】:

每当我在模板中设置断点时,它都会被忽略。有解决方法吗? 示例:if (list.size() .. 处的断点被忽略。

template <typename ObjectType, typename ContainerType> 
ContainerType CListModelBase<ObjectType, ContainerType>::
                  sortListByColumn(const ContainerType &list, int column,
                                   Qt::SortOrder order)
{
   if (list.size() < 2) return list; // nothing to do
   // ... 
}

PS:对于 gdb,描述了这样的解决方法here

环境。 Win7、VC2013、QtCreator 3.1.1

【问题讨论】:

    标签: c++ qt-creator qt5.3 msvc12


    【解决方案1】:

    这是由于内联和其他各种优化导致调试器更难知道代码的地址。

    如果你不介意重新编译,你总是可以强制在生成的代码中放置一个断点:

    #include <intrin.h>
    
    ...
    
    __debugbreak();
    

    来源:[http://msdn.microsoft.com/en-us/library/f408b4et.aspx]

    【讨论】:

    • 交替 _asm int3;
    【解决方案2】:

    我使用的解决方法:编写自己的断言。

    我有一个断言版本,它是从 boost 断言简化而来的,

    a) 可以显示信息,甚至与断言无关

    b) 可以在一个简单的延迟循环中旋转

    -- 允许用户附加调试器并进行调查、回溯等

    c) 只能打印或退出或打印然后退出

    d) 允许用户手动恢复程序,就好像什么都没发生一样(除了大延迟)

    对于完全优化和未优化的,这样的断言可以减轻你的负担。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      相关资源
      最近更新 更多