开发者

Setting Xcode breakpoint by code? (like pause() function)

I'm finding a way pausing program execution by code on Xcode As an example, I can stop execution with abort() C function. This p开发者_Go百科ops 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.


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.


Another method I often use in iOS programming is to include a breakpoint in an if statement. Like so:

if (your_condition) {

   //put an Xcode breakpoint here

}

That way I can conditionally call breakpoints in loops and other places that get called too often to have an unconditional breakpoint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜