PDA

View Full Version : How to break in debugger in Q_ASSERT ?



Radagast
24th May 2010, 09:48
Hello!
I' m using Qt 4.6 + QtCreator + MinGW.
When an expression in Q_ASSERT evaluates to false my application just aborts with a message in the debug output, that is often meaningless. How can I make it to break into debugger to the line that contains the assert, so I can see the call stack?
I googled a lot, but found only
asm("int $0x3");
which is weird and won't work in x64.
Thanks in advance.

Lykurg
24th May 2010, 10:29
When an expression in Q_ASSERT evaluates to false my application just aborts with a message in the debug output, that is often meaningless
That's exactely like assert should work. And I can't say that the message is meaningless. It says in with line and in wich file the "error" occurs and then you can have a look at your statement and see why assert was triggered. If that is not enough you can have a look at Q_ASSERT_X to pass an option string which explains the error more. If you want to go in your debugger you can do that as an workaround:
if (condition)
{
// <- set your break point here.
}

Radagast
24th May 2010, 11:22
In MS Visual Studio I break in debugger on assertions, which is much more useful than what we have in Qt Creator.
And if Q_ASSERT fails not in my code, but in Qt, the info about line and file is useless.

squidge
24th May 2010, 14:42
On windows, you can write your own ASSERT-style macro to call DebugBreak() which is like INT 3 but works across all supported CPUs.

(INT 3 simply means "Breakpoint Interrupt". People use it because it is fast and easy to type whilst writing code. It's easier than typing non-sense code, or hoping the compiler doesn't optimise it out, and coping with the breakpoints becoming invalid or moving as you edit the code)