Can I create a breakpoint in code in iOS, like `__asm{int 3}` on VC++, and continue execution after it's been hit?

Viewed 6173

I'm trying to put the equivalent of asm{int 3} (or similar) into my iPhone program. My goal is to have Xcode stop exactly on the offending line, without having to fiddle with the call stack (so _Debugger doesn't sound like it would do, not that I could find which framework it's in anyway...), and leave me able to resume execution (which is why I'm not happy with assert).

(I'm used to both these behaviours on other systems, and I'd like to reproduce them on iOS.)

My best attempt so far has been this:

asm volatile("bkpt 1");

This stops Xcode on the line in question, but when I try to continue with Cmd+Alt+P, Xcode appears to run the BKPT again. And if I use Shift+Cmd+O, I just get this:

Watchdog has expired.  Remote device was disconnected?  Debugging session terminated.

(Needless to say, the remote device IS still connected.)

I don't have a huge amount of experience with iOS, Mac, ARM, gdb, or gcc's asm stuff. So I'm stumped already. Is there some way of getting iOS and Xcode to do what I want?

(I don't know if it makes a difference but judging by the instruction size my program is ARM code.)

9 Answers

To force xcode to break, use

kill(getpid(), SIGSTOP)

You can then step out/up and use lldb per usual. When you're done, you can hit continue and it works just like a breakpoint set from the Xcode GUI.

Tested with Swift 5 and Xcode 11.3

Direct equivalent of x86 int3 / int 3 in arm / arm64 is

#if TARGET_CPU_ARM | TARGET_CPU_ARM64 | TARGET_CPU_ARM64E
asm volatile("trap");
#endif
Related