Xcode debugger - why can you only step through so far into Apple framework code?
I am used to setting breakpoints in my obj-c code in Xcode and then stepping into/out of my methods, but I don't fully understand what happens when I find myself stepping through Apple framework code.
Of cou开发者_如何学Pythonrse, we don't have the source and so all you can see is the disassembler code (I don't know much assembler btw)
If I (for the hell of it) just keep stepping through the assembly, then eventually I get booted out of the debugger stepping and in the stack frame pane, I just my app listed as running and the app in the simulator is now running and no longer paused.
I know this is a bit of a theoretical question, but why can't I endlessly keep stepping through the assembly code? My app is still running after all.
What you are experiencing is the run loop. The run loop is responsible for finding events for the application to process and sending them to the proper handler. It does this by calling the operating system to ask for the next event. If the system doesn't have any events pending for that application, it will put the application to sleep until it gets one. Then it will return the new event and the run loop will process it.
However, since the application passes control to the operating system to get the event, the debugger isn't allowed to see what is happening until after control returns to the application. Since it is in the process of stepping over the only instruction it sees, the debugger sees the application as running. Xcode reports this to you and activates the simulator so that you can see what it is doing while it runs.
As soon you perform an event in the simulator, the OS sees that there is an event pending for the application and wakes it up, returning control to the run loop. The debugger sees this as finishing the step over the last instruction and allows you to continue stepping normally. From this point, you could step through all of the event processing code the application uses, and, if you step into calls, possibly even get back into your code, before going back to the run loop to await the next event again.
精彩评论