1

I'm trying to understand how a functionality works and then rewrite this functionality by stepping through the code while it is running to see exactly what it is doing. However, I'm noticing that Xcode is not stepping through every line of code. There is an instance, and I noticed it in a block, where the debugger just skips when I continuously press the step into button. It will stop if I put a breakpoint in one of the lines in the block, proving that Xcode is not going through this line by line, and it means it must be running lots of code that is not shown to me.

How can I make Xcode step through every line of code?

1 Answers1

1

You need to add a breakpoint inside a block if it's being used in a dispatch_async or similar call. This is because that block of code is copied somewhere (usually a queue), and then executed separately. Often on a different thread.

Dave Wood
  • 13,143
  • 2
  • 59
  • 67
  • The problem is I don't know where all the code that is being run is. That's one of the reasons I'm stepping through it line by line because I want to know where all the code are. – Chengbin Zheng Jan 29 '15 at 00:28
  • Can you see what queue the code is being added too? You'll likely see something like: `dispatch_async(dispatch_get_main_queue(), ...` or `dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),...`. That first parameter is telling what queue is being used. Those two examples are built in queues, but it's possible the code creates it's own queue as well. The queue itself will execute code blocks added to it. – Dave Wood Jan 29 '15 at 00:33
  • It's nothing to do with threading; the debugger just doesn't follow the indirect call. `void inv(dispatch_block_t block){ block(); }; inv(^{ /* do something */}; );` would be the same. – jscs Jan 29 '15 at 00:37
  • Yes, all the async stuff are not stepped through unless I have a breakpoint in them. Any way to make xcode step through async stuff? – Chengbin Zheng Jan 29 '15 at 16:47