how to programmatically break into debugger?
-
wrote on 12 Dec 2018, 19:18 last edited by
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?
-
wrote on 31 Jan 2019, 23:11 last edited by
-
wrote on 12 Dec 2018, 20:29 last edited by
Hi, the trick on Intel x86 processors is to inject an int 3 instruction in your code, try something like:
__asm__("int $3\n" : : );
-
wrote on 12 Dec 2018, 22:47 last edited by
__asm__("int $3\n" : : );
that did it!
-
wrote on 31 Jan 2019, 20:20 last edited by
-
wrote on 31 Jan 2019, 20:51 last edited by hskoglund
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();
-
wrote on 31 Jan 2019, 23:11 last edited by