how to programmatically break into debugger?
-
on mac in xcode, one can put "Debugger()" as a statement, and when it's hit, get into the debugger (say, if an assert fires while in debug mode)
on windows it's "DebugBreak()".however, when debugging using "Qt Creator" on mac, calling "Debugger()" only causes a message to be logged:
"Debugger() was called!"
in the mac gui QtCreator->Preferences->Debugger->GDB Extended, i'd'a thought there'd be a checkbox "Stop when Debugger() is called", but it ain't there.
i see "Stop when qWarning() is called", so i check that, then in my code i do this:
qWarning("Debugger");
but that, too, merely logs something and does't pause the app and put me in the debugger.
so... how?
-
-
__asm__("int $3\n" : : );
that did it!
-
okay this worked on mac, but it does NOT work on windows.
On Windows in MSDEV i could have this line:
DebugBreak();
but that doesn't cause the debugger to pause the app when debugging with Qt.
When i try to compile the above on Windows, i get this:
-
Hi, the principle is the same (same Intel x86 processor) but a different compiler, try:
__asm int 3;
Edit: googled a bit, I see that the above is kind of old and only works when you compile for 32-bit, there's a newer alternative which also works for Arm and 64-bit builds:
__debugbreak();
-