โค๏ธ Swift Compiler _ LLVM
LLVM์ 2000๋ ์ผ๋ฆฌ๋ ธ์ด ๋ํ์์ Chris Lattner ์ธ ๋ช ๋ช ์ผ๋ก ๊ตฌ์ฑ๋ ์ฐ๊ตฌ ํ์์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ ์ ์ ๋ฐ ๋์ ์ปดํ์ผ์ ๋ชจ๋ ์ง์ํ ์ ์๋ ํ๋์ ์ธ ์ปดํ์ผ ์ ๋ต์ ์ ๊ณตํ๊ธฐ ์ํ ์ฐ๊ตฌ ํ๋ก์ ํธ๋ก ์์๋์๋ค. intermediate / binary ๊ธฐ๊ณ ์ฝ๋๋ฅผ ๊ตฌ์ฑ, ์ต์ ํ, ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ํ๋ก๊ทธ๋๋จธ๊ฐ ์์ฑํ ์ฝ๋๋ฅผ ์ปดํจํฐ๊ฐ ์ฝ์ ์ ์๋ intermediate, binary ์ฝ๋๋ก ์ปดํ์ผ ํ๋๋ฐ ์ฌ์ฉ๋๋ค.
๐ ์ปดํจํฐ์ ํ๋์จ์ด๋ Binary Code๋ง ์ฝ์ ์ ์๋ค. ๋๋ฌธ์ ์ฐ๋ฆฌ๊ฐ ์์ฑํ ์ฝ๋๋ค์ ํ๋์จ์ด๊ฐ ์ฝ์ ์ ์๊ฒ ๋ฐ๊ฟ์ฃผ๋ ์์ ์ ๊ฑฐ์ณ์ผ ํ๋๋ฐ ์ด๋ Intermediate Representation, ์ฆ ์ค๊ฐํํ์ ์ฌ์ฉํ ์ ์๋ค. ์ด ์ฝ๋๋ ์์ค ์ฝ๋๋ฅผ ํํํ๊ธฐ ์ํด ๊ฑฐ์น๋, ์ปดํ์ผ๋ฌ๋ ์ฝ๋ ์ต์ ํ ๋๊ตฌ์ ์ํด ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉ๋๋ ๋ฐ์ดํฐ ๊ตฌ์กฐ ํน์ ์ฝ๋์ด๋ค. ์ต์ ํ, ๋ณํ ๋ฑ ์ถ๊ฐ์ ์ธ ์ฒ๋ฆฌ๋ฅผ ์ํด ์ค๊ณ๋์ด ์์ผ๋ฉฐ, ์ ํ๋(์ ๋ณด์ ์์ค ์ ๋ฌด)์ ๋ ๋ฆฝ์ฑ์ ์ค์์ํ๋ค. ์ถ์์ ์ธ ํ๋ก๊ทธ๋จ ํํ์ด๋ค.
์ค๊ฐ ํํ - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์ . ์ค๊ฐ ํํ(intermediate representation, IR)์ ์์ค ์ฝ๋๋ฅผ ํํํ๊ธฐ ์ํด ์ปดํ์ผ๋ฌ๋ ๊ฐ์ ๋จธ์ ์ ์ํด ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉ๋๋ ๋ฐ์ดํฐ ๊ตฌ์กฐ ๋๋ ์ฝ๋์ด๋ค. ์ค๊ฐ ํํ์
ko.wikipedia.org
๐ ์ด๋ฏธ ์กด์ฌํ๋ ์ปดํ์ผ๋ฌ, GCC
๊ธฐ์กด์ GCC๋ผ๋ ์ปดํ์ผ๋ฌ๊ฐ ์ด๋ฏธ ์กด์ฌํ๊ณ ์์๋ค. ๊ทธ๋ฌ๋ ์ด GCC๋ ๋จ์ผ ๋ชจ๋๋ฆฌ์(๋ด๋ถ ์์๊ฐ ์์กด์ฑ์ด ๊ฐํ, ๊ตฌ์กฐ์ ์ธ ๊ฒฐํฉ์ด ๊ฐ๋ ฅํ) ์ปดํ์ผ๋ฌ๋ก ๊ตฌ์ฑ๋์ด ์์ด ํ์ฅ์ด ์ด๋ ต๋ค๋ ๋จ์ ์ด ์์๋ค.
GCC, the GNU Compiler Collection - GNU Project
GCC, the GNU Compiler Collection The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating sy
gcc.gnu.org
๐ LLVM์ ์ฅ์
ํ์ฅ (๋ชจ๋์ฑ)
LLVM์ ๊ฐ ์ปดํฌ๋ํธ๋ค์ ์ฌ์ฌ์ฉ์ฑ์ ์ค์์ํด์ ๋ชจ๋ํ๊ฐ ์ ๋์ด ์๋ค. ์ด๋ฅผ ํตํด GCC์ ํ์ฅ์ด ์ด๋ ต๋ค๋ ๋จ์ ์ ํด๊ฒฐํ ์ ์๋ค.
์ต์ ํ
- Intermediate Representation์ ์ฌ์ฉํ์ฌ ์ปดํ์ผ๋ฌ ๊ธฐ๋ฅ์ ์ํํ๊ธฐ์ ์ต์ ํ๊ฐ ์ฉ์ดํด์ง๋ค. LLVM ๊ธฐ๋ฐ์ ์ปดํ์ผ๋ฌ๋ ์๋ก์ด ์ธ์ด์ ์ง์์ด๋ ์ต์ ํ ๊ธฐ๋ฅ ์ถ๊ฐ๊ฐ ๋ ๊ฐ๋จํ๊ณ ์ ์ฐํ๋ค.
- LLVM ์ปดํ์ผ๋ฌ๋ ์ฝ๋ ์ต์ ํ ๋ฐ ์ปดํ์ผ ์๋ ๋ฉด์์ ์ผ๋ฐ์ ์ผ๋ก GCC๋ณด๋ค ๋น ๋ฅด๋ค.
The LLVM Compiler Infrastructure Project
The LLVM Compiler Infrastructure Project
LLVM Overview The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines. The name "LLVM" itself is not an acronym; it is the full name of the proj
llvm.org
โค๏ธ LLDB _ Low Level Debugger
- Xcode IDE์ ๋ด์ฅ๋์ด ์๋ Command-Line Debug ํ๊ฒฝ
์์ LLVM์์ ๋ชจ๋ํ ๋์ด ์๋ ์ปดํฌ๋ํธ๋ค์ ์ด์ฉํด ์งํ๋ ์ฃผ์ ์๋ธ ํ๋ก์ ํธ ์ค ํ๋๊ฐ ๋ฐ๋ก ์ด LLDB๋ผ๋ Debugger์ด๋ค. ๊ธฐ๊ณ์ด์ ๊ฐ๊น์ด ์์ญ๊น์ง ๋๋ฒ๊น ์ด ๊ฐ๋ฅํ๋ค๋ ์ฅ์ ์ด ์๋ค.
๐ Debuger
๋๋ฒ๊ฑฐ๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๋๋ฅผ ์์ ํ์ง ์๊ณ ๋ ๋ฐํ์ ์ ํ๋ก๊ทธ๋จ์ด ์ด๋ป๊ฒ ๋์ํ๋์ง ์ดํดํ ์ ์๊ธฐ์ ๋ถํ์ํ ๋น๋ ์๊ฐ์ ์ค์ผ ์ ์๋ค. ๋๋ฒ๊ฑฐ์๋ ์คํ ํ๋ฆ ์ ์ด์ ์ํ ์ ๊ทผ์ด๋ผ๋ ๋ ๊ฐ์ง ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ด ์๋ค. ์ฃผ๋ก ์ฝ๋์ ์ฌ๋ฌ ์์น์ Breakpoint๋ฅผ ์ค์ ํ์ฌ ํ๋ก๊ทธ๋จ ์คํ์ ์ ์ดํ๋ค. breakpoint์ ํ๋ก๊ทธ๋จ์ด ๋๋ฌํ ๋๋ง๋ค ๋๋ฒ๊ฑฐ๋ ํ๋ก๊ทธ๋จ ์คํ์ ์ผ์์ ์ผ๋ก ์ค์งํ๊ณ , ๋ค์ํ ๋ณ์์ ํ์ฌ ์ํ๋ฅผ ๊ฒ์ฌ ๋๋ ์์ ํ๊ณ , ๋ค์ statement๋ก ๋์ด๊ฐ๊ฑฐ๋ ๋ค์ด๊ฐ๊ฑฐ๋ ํน์ ์คํ์ ๊ณ์ํ๋ ๋ฑ์ ์์ ์ ์ํํ๋ค.
๐ Stepping
- Over
- ํ์ฌ Break ๊ฑธ๋ ค ์๋ ์ง์ ์์ ๋ฐ๋ก ๋ค์ Statement๋ก Step Over
- (lldb) next
- (lldb) n
- In
- ๋ค์ Statement๊ฐ Function Call์ธ ๊ฒฝ์ฐ Debugger๋ฅผ ํด๋น ํจ์ ๋ด๋ถ์ ์์นํ ์์ ์ง์ ์ผ๋ก ์ด๋
- (lldb) step
- (lldb) s
- Out
- ํ์ฌ ์งํ์ค์ธ function์ด return ๋ ๋๊น์ง ํ๋ก๊ทธ๋จ์ ์งํํ ํ Break
- (lldb) finish
๐ po
- description ์ถ๋ ฅ
- NSObject์ debugDescription ์ถ๋ ฅ
- ๋ณต์กํ ๋ด์ฉ์ description ๋ณด๊ธฐ ์ฝ๊ฒ ์ถ๋ ฅ
About LLDB and Debugging
About LLDB and Debugging Debugging refers to creating and using an analytical framework to isolate causal pathways and test hypotheses. The most important tool of debugging is the debugger, which helps you understand how your program behaves at runtime, wi
developer.apple.com
LLDB ์ ๋ณต - ์ผ๊ณฐ๋ท๋ท
po ๋ฅผ ์๊ณ ๊ณ์ ๊ฐ์? ๋ชฐ๋ผ๋ ์๊ด์์ต๋๋ค. LLDB Debugging ๋ฐฐ์ฐ๋ฌ ๊ฐ์๋ค! ?
yagom.net
'๐ iOS > ๐ถ ๊ถ๊ธ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] ARC_๊ฐ์ฒด ์๋ช , weak์ unowned ์ฐจ์ด (0) | 2024.03.21 |
---|---|
[NSCache&URLCache]์ ์ด๋ฏธ์ง ํ์ผ์ด URLCache์์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์๋ ๋์คํฌ์ ์ ์ฅ๋ ๊น? (0) | 2024.01.28 |
[UIKit]loadView์ view๋ ์ธ์ ํ ๋น๋ ๊น? (0) | 2024.01.27 |
[Swift]super.init()์ด ๋ฐ๋์ ํ์ํ๋ ๊ฒฝ์ฐ (0) | 2023.11.08 |