Programmatically set breakpoint in C++ code

Is there a way that I can programmatically hit a breakpoint in my C++ code. I am looking for the lldb equivalent of the DebugBreak function on windows.

__asm volatile ("int3");

Should work on any debugger, not just lldb.
Also on Windows, you should generally use __debugbreak() instead of DebugBreak, as the latter is a kernel-level call, whereas you generally want a user-level breakpoint. The difference is that the user breakpoint gives a nicer callstack.

Richard Mitton
richard@codersnotes.com

Of course this only works for x86 32 and 64 bit targets so you will need to #ifdef it out for other architectures.

llvm's clang already has an intrinsic __builtin_debugger(), and

https://github.com/scottt/debugbreak

provides a wrapper for the equivalent on ARM/Thumb - including a Python script to awkwardly step past
such a breakpoint when using gdb - and there's always raising sigtrap for a hosted (not freestanding) C++ program.

David Earlam

Greg Clayton wrote:
Of course this only works for x86 32 and 64 bit targets so you will
need to #ifdef it out for other architectures.

> __asm volatile ("int3");
>
> Should work on any debugger, not just lldb.
> Also on Windows, you should generally use __debugbreak() instead of
DebugBreak, as the latter is a kernel-level call, whereas you generally
want a user-level breakpoint. The difference is that the user
breakpoint gives a nicer callstack.
>
> Richard Mitton
>
> richard@codersnotes.com
>> Is there a way that I can programmatically hit a breakpoint in my
C++ code. I am looking for the lldb equivalent of the DebugBreak
function on windows.

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.