views:

23

answers:

1

I'm finding a way pausing program execution by code on Xcode As an example, I can stop execution with abort() C function. This pops Xcode debugger up.

However, this exits program completely, so I'm finding a way to pause execution. So I can resume execution after checking execution states.

This is required for handling light-weight errors. I tried pause() C function, but it doesn't work. The execution aborted instead of pausing.

A: 

If you want to be able to break on a specific function whenever there's an error, then define a function like so:

void BREAK_HERE_Eonil(void) {
    NSLog(@"Set a breakpoint on BREAK_HERE_Eonil to debug.\n");
}

Call BREAK_HERE_Eonil() whenever you would like to enter the debugger. Set a breakpoint on BREAK_HERE_Eonil() in Xcode. Now, run under the debugger. Whenever you hit this function, you'll break into the debugger.

You might also be able to use the old Debugger() call; Xcode has an option under the Run menu to "Stop on Debugger()/DebugStr()".

You can also just run your app under the debugger and hit the big pause button in the debugger window whenever you want to break in.

Jeremy W. Sherman
Brilliant technique! Thanks for answer!
Eonil