mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-24 20:00:37 +00:00
docs: image url
This commit is contained in:
@@ -18,7 +18,7 @@ var point = Point()
|
||||
|
||||
在`init` 方法内第一行处加 断点,如下所示
|
||||
|
||||
<img src="./../assets/SwiftStructMemoryLayoutDemo1.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/SwiftStructMemoryLayoutDemo1.png" style="zoom:25%">
|
||||
|
||||
实验2:struct 内不自己加 init
|
||||
|
||||
@@ -32,7 +32,7 @@ var point = Point()
|
||||
|
||||
在`var point = Point()`处加 断点,如下所示
|
||||
|
||||
<img src="./../assets/StructMemoryLayoutDemo2.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/StructMemoryLayoutDemo2.png" style="zoom:25%">
|
||||
|
||||
现象:可以看到加不加自定义初始化器的汇编代码基本相同。
|
||||
|
||||
@@ -129,13 +129,13 @@ test()
|
||||
|
||||
断点打在 `var point1 = Point(x: 10, y: 20)` 处,查看汇编
|
||||
|
||||
<img src="./../assets/SwiftValuePassDemo1.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/SwiftValuePassDemo1.png" style="zoom:25%">
|
||||
|
||||
乍一看如果不认识的话,先找字面量(立即数),比如红色框内的 `0xa`,就是 10,`0x14` 就是20。[之前](./109.md)学过寄存器的设计,64位寄存器是兼容32位寄存器的。红色框内将 `0xa`,也就是 10 保存到 `%edi ` 寄存器内部,也就是保存到 `%rdi` 中,将 `0x14` 也就是20,保存到 `%esi` 也就是保存到 `%rsi` 寄存器中。
|
||||
|
||||
LLDB 模式下输入 `si` 进入 init 方法内部。
|
||||
|
||||
<img src="./../assets/SwiftValuePassDemo2.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/SwiftValuePassDemo2.png" style="zoom:25%">
|
||||
|
||||
可以查看到将 `%rsi` 里的10 保存到 `%rdx` 中了;将 `%rdi` 里的20 保存到 `%rax` 中了。这也就是 struct `init` 方法做的事情。
|
||||
|
||||
@@ -251,11 +251,11 @@ testReferenceType()
|
||||
|
||||
下断点,可以看到下面的汇编:
|
||||
|
||||
<img src="./../assets/ClassReferenceTypeMemoryLayoutDemo1.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/ClassReferenceTypeMemoryLayoutDemo1.png" style="zoom:25%">
|
||||
|
||||
在调用(汇编的 call)完 `allocating_init` 方法后,方法返回值用 `%rax` 保存的。然后打印出 `%rax` 寄存器的值,查看内存信息如下
|
||||
|
||||
<img src="./../assets/ClassReferenceTypeMemoryLayoutDemo2.png" style="zoom:25%">
|
||||
<img src="https://raw.githubusercontent.com/FantasticLBP/knowledge-kit/master/assets/ClassReferenceTypeMemoryLayoutDemo2.png" style="zoom:25%">
|
||||
|
||||
红色框代表类信息的地址,蓝色框代表引用计数,绿色框代表10,黄色框代表20.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user