Horst Walter
Horst Walter

Reputation: 14081

Breakpoint in template is ignored, is there a workaround?

Whenever I set a breakpoint in a template it is ignored. Is there a workaround for this? Example: Breakpoint at if (list.size() .. ignored.

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: For gdb such a workaround is described here

Env. Win7, VC2013, QtCreator 3.1.1

Upvotes: 1

Views: 92

Answers (2)

2785528
2785528

Reputation: 5566

A Workaround I have used: write your own assert.

I have a version of assert, simplified from a boost assert, that

a) can display information, even unrelated to the assert

b) can spin in a simple delay loop

-- allowing the user to attach the debugger and investigate, back-trace, etc.

c) can print only or exit or print then exit

d) allows the user to manually resume the program as if nothing had happened (except a big delay)

For both fully-optimized and un-optimized, such an assert can ease your burden.

Upvotes: 1

slajoie
slajoie

Reputation: 450

This is caused by inlining and various other optimizations that make it harder for the debugger to know the address of the code.

If you don't mind recompiling, you can always force a break point to be placed in the generated code:

#include <intrin.h>

...

__debugbreak();

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

Upvotes: 2

Related Questions