在OC
对象调用实例方法的时候最终都会转为 objc_msgSend
例如在viewController 对象调用如下方法:
[self testString:@"哈哈" intValue:100 stringValue:@"溜溜"];
在实例对象调用的时候会被转为
objc_msgSend(self,@selector(testString:intValue:stringValue:),@"哈哈",100,@"溜溜");
在arm64架构显示汇编如下:
LLDB_stady`objc_msgSend:
-> 0x1000f2978 <+0>: nop
0x1000f297c <+4>: ldr x16, #0x16b4 ; (void *)0x0000000196d75bc0: objc_msgSend
0x1000f2980 <+8>: br x16
在arm64架构查看寄存器
(lldb) register read
General Purpose Registers:
x0 = 0x0000000154549790
x1 = 0x00000001000f2b08 "testString:intValue:stringValue:"
x2 = 0x00000001000f4078 @
x3 = 0x0000000000000064
x4 = 0x00000001000f4098 @
x5 = 0x000000016fd11c40
x6 = 0x0000000000000000
x7 = 0x0000000000000250
x8 = 0x00000001000f4078 @
x9 = 0x00000001000f4098 @
x10 = 0x00000001000f4f08 "testString:intValue:stringValue:"
x11 = 0x0000000154549790
x12 = 0x0028be000028be00
x13 = 0x0000000000000000
x14 = 0x0000000022a28888
x15 = 0x0000000154600000
x16 = 0x000000019779564c libsystem_pthread.dylib`pthread_mutex_unlock
x17 = 0x00000001878b3500 UIKit`-[UIViewController viewDidLoad]
x18 = 0x0000000000000000
x19 = 0x000000019e05ffe0 UIKit`_UIApplicationLinkedOnVersion
x20 = 0x0000000154549790
x21 = 0x00000001882055fc "countByEnumeratingWithState:objects:count:"
x22 = 0x000000018820586a "count"
x23 = 0x000000019d3a8000 UIKit`_UIFocusEngine._smallSoundPool
x24 = 0x0000000000000000
x25 = 0x0000000000000010
x26 = 0x0000000000000001
x27 = 0x0000000000000018
x28 = 0x0000000000000000
fp = 0x000000016fd11e40
lr = 0x00000001000f2370 LLDB_stady`-[ViewController viewDidLoad] + 116 at ViewController.m:69:1
sp = 0x000000016fd11e20
pc = 0x00000001000f2978 LLDB_stady`symbol stub for: objc_msgSend
cpsr = 0x60000000
查看具体参数
(lldb) po 0x0000000154549790
<ViewController: 0x154549790>
(lldb) po $x0
<ViewController: 0x154549790>
x1 = 0x00000001000f2b08 "testString:intValue:stringValue:"
(lldb) po $x2
哈哈
(lldb) po $x3
100
(lldb) po $x4
溜溜