(Summary of articles on underlying principles of iOS)

(iOS)

This article mainly introduces three methods of source exploration

  • 1.Symbol breakpointFollow the process directly
  • 2, through thePress and hold the control+step into
  • 3. Assembly and process

Let’s talk more about how these three methods find the source library where the function is located. What about alloc

1.Symbol breakpointFollow the process directly

  • Break by notation on alloc

    • Choose breakpointsSymbolic Breakpoint

- Symbol breakpoint input 'alloc'! [image](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/57ee224d77394090a59adad909eac9b3~tplv-k3u1fbpfcp-zoom-1.image) Copy the codeCopy the code
  • mainIn theCJLPersonWe add a break point at

Before you go to this breakpoint, you need to close the new symbol breakpoint above. The reason is that there are many calls to alloc, and if you open it, you will not be able to accurately locate itCJLPersontheallocmethodsThe following is the closed state of the symbolic breakpoint

  • Run the program, broken in the CJLPerson section

    • Open theAlloc marks a breakpoint, the breakpoint state is

- Continue executing the copy codeCopy the code

The following is a stack call where the alloc symbol is broken. From the following figure, you can see that the source of alloc is locatedlibobjc.A.dylibLibraries (you need to go to Apple’s corresponding open source site to download the objc source code for further exploration)

2, through thePress and hold the control+step into

  • mainIn theCJLPersonPut a breakpoint at, run the program, it breaks atCJLPersonlocation

  • Hold down thecontrolTo selectstep into⬇ ️ key

  • After entering, the following content is displayed

  • Again the nextobjc_allocSymbol breakpoint, symbol breakpoint is displayed afterobjc_allocWhere the source code library

(You need to go to Apple’s corresponding open source site to download the objc source code for further exploration)

3. Assembly and process

  • mainIn theCJLPersonPut a breakpoint at, run the program, it breaks atCJLPersonlocation

  • Xcode toolbar selectionDebug –> Debug Workflow –> Always Show Disassembly, this option means to always display disassembly, that is, through assembly and flow

  • Hold down thecontrol, click on thestep intoThe ⬇️ key is executed to the following figureCallq, corresponding to objc_alloc

  • Hold down thecontrol, click on thestep into⬇️ key to enter, see the breakpoint broken inobjc_allocPart of the

  • Through the sameobjc_allocTo know where the source code is located

(You need to go to Apple’s corresponding open source site to download the objc source code for further exploration)

Note (the following is provided by Apple source download address) : 1, Apple all open source source summary address, according to the corresponding version to find the corresponding source, take MAC 10.15 as an example: MacOS –> 10.15 –> select 10.15 –> search objC 2, Apple more direct source download address, directly search the source name you want to download, such as objC: directly search objC –> objC4 / –> select the corresponding objC version