d2๋ฅผ ํธ์ถํ๊ณ d2๋ฅผ ๋ณ๊ฒฝํ๋ d1 ํจ์ ์์ d2 ํจ์๋ฅผ ์ ์ํ๋ฉด d1์ d2์ ๋ํ ์ด์ ์ ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๋๋ ์ด๊ฒ์ด ๋ชจ๋ ๋ฏธ๋ฆฌ ์ปดํ์ผ ๋์๊ธฐ ๋๋ฌธ์ด๋ผ๊ณ ์๊ฐํ์ง๋ง ์๋ง๋ ์ด๊ฒ์ ๋ํ ๊ฒฝ๊ณ ๊ฐ ์์ด์ผํ ๊น์? ์๋๋ฉด ์ด์ ์ ์๋ฅผ longjmp๋ก ์ ์ ์๋ก ๋ฐ๊ฟ ์ ์์ต๋๊น?
(ํญ์ ์ ์ฒด ๋ถํ๋ฅผ ์ํํ์ง๋ ์๊ธฐ ๋๋ฌธ์ REPL์ ๊ฐ์ฅ ์ค์ํฉ๋๋ค)
julia> function d2()
a
end
julia> function d()
d2()
end
julia> d()
in d: a not defined
julia> function d2()
b=2
end
julia> d()
in d: a not defined
julia> d2
Methods for generic function d2
d2() at prompt:2
julia> function d()
d2()
end
julia> d()
2
ํจ์๊ฐ ์ ์ ๋ ๋ d2()
๋ํ ์ฝ๋๊ฐ ์์ฑ๋์ด d()
๋ฉ์๋๊ฐ ์ด๋ ํด๊ฒฐ๋๊ธฐ ๋๋ฌธ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์์ ์ธ๊ธํ๋ฏ์ด d2()
๋ ์๋ ์์๋๋ก ์๋ํ๋๋ก ์ ์ ๋๋๋ก ์ฌ์ ์ ํ ์ ์์ต๋๋ค. ์ด์์ ์ผ๋ก๋ d()
์ ์์กดํ๋ ๋ชจ๋ ํญ๋ชฉ์ด ์ด์ ๊ฐ์ด ๋ณ๊ฒฝ ๋ ๋ ์๋์ผ๋ก ๋ค์ ์ ์ํ์ง๋ง์ด๋ฅผ ํ์ฉํ๋ ๋ฉํ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค. ์ด ๋์์ ๋ํ ๊ฒฝ๊ณ ๋ฅผ ๋งค๋ด์ผ์ ๋ฃ์ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ฌ์ ํ ๊ทธ๊ฒ์ ๊ณ ์น๋ ๊ฒ์ด ๋ ์ข์ง๋ง, ์กฐ๊ธ ๊น๋ค๋ก์ด ์ผ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค :-/
์๋ฌด๋ ์ด๊ฒ์ ๋์น ์ฑ์ง ๋ชปํ๊ธฐ๋ฅผ ๋ฐ๋์ง๋ง ๊ทธ๊ฒ์ ํ์ค์ ์ด์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค :)
๊ทธ๊ฒ๋ณด๋ค ๋ ์ฌ๋ฏธ ์์ต๋๋ค. ์คํ๋ ๋๊น์ง ํด๊ฒฐ๋์ง ์๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ์์ ์ค์ธ JIT๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
julia> function f2()
a
end
julia> function f1()
f2()
end
julia> function f2()
2
end
julia> f1()
2
๊ทธ๋ฌ๋ ๋๋ ์ด๊ฒ์ด REPL์์ ์์์น ๋ชปํ ๊ฒฐ๊ณผ๋ฅผ ์ด๋ํ ์ ์๋ค๋ ๊ฒ์ ๋๋ ค์ํฉ๋๋ค. ๋น๋ก ๋ด๊ฐ ๊ทธ๊ฒ์ ์ฒ๋ฆฌํ๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ ์ค์ ๋ก๋ ๋ชจ๋ฅด์ง๋ง. ๊ทน์ ์ธ ๋ฐฉ์์ ์ฐจ์ด๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด ์ค๋ฅ๋ฅผ ์ฌ์ฉํ์ง๋ง ๋ด๋ถ ๋ฐฉ์ ์์ด๋ ์์๋ฅผ ๋ณ๊ฒฝํ๋ ํจ๊ณผ๋ฅผ ๋ณด๋ ค๊ณ ํ ๋๋ ๋ฐ์ํ ์ ์์ต๋๋ค!
๋ฉ์๋๊ฐ ๋ณ๊ฒฝ ๋ ๋ ์ ๋ฐ์ดํธํด์ผ ํ ์์๋ ๋ ๊ฐ์ง ์ ํ์ ์์น๊ฐ ์์ต๋๋ค.
์ ์๋ ํจ์ ๋ณธ๋ฌธ์ ๋ณ๊ฒฝํ์ฌ ์ ๋ฐ์ดํธ ํ ์ ์์ต๋๋ค. ์ ์๋ฆฌ์์ ๋ณ๊ฒฝํ๊ฑฐ๋ ํธ์ถ ์ฌ์ดํธ๋ฅผ ์ ๊ทน์ ์ผ๋ก ์ ๋ฐ์ดํธํ์ฌ ์ ์์น๋ฅผ ํธ์ถํ๊ฑฐ๋ ์ด์ ํจ์ ๋ณธ๋ฌธ์ ์ ๋ฒ์ ์ผ๋ก ์ ํํ๋ ์คํ ์ผ๋ก ๋์ฒด ํ ์ ์์ต๋๋ค. , ์ ํ์ ์ผ๋ก ํธ์ถ ์ฌ์ดํธ๋ฅผ ํจ์นํฉ๋๋ค. ์ธ๋ผ์ธ์ ๊ฒฝ์ฐ ํจ์๋ฅผ ์ธ๋ผ์ธ ํ ํธ์ถ์๋ฅผ ์ถ์ ํ๊ณ ๋ค์ JITํด์ผํฉ๋๋ค.
์ค์ ๋ก ์ฐ๋ฆฌ๊ฐ ํ ์์๋ ์ผ์ ์ฝ๋๋ฅผ ๋ฒ๋ฆฌ๋ ๊ฒ์
๋๋ค. ์๋ํ๋ฉด ๋ฉ์๋๊ฐ ํธ์ถํ๋ ํจ์๊ฐ ์ธ๋ผ์ธ๋์ง ์์๋๋ผ๋ ๋ฉ์๋๊ฐ ๋ณ๊ฒฝ๋๋ฉด ๋ณ๊ฒฝ ๋ ์์๋ ์ ํ ๋์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด๊ฒ์ ๋๋ถ๋ถ ๋ํ ํ ์ผ์ด์ค๋ฅผ์ํ ๊ฒ์ด๋ฏ๋ก ์ฝ๋๋ฅผ ๋ค์ ์ปดํ์ผํ๋ ๊ฒ์ ํฐ ๋ฌธ์ ๊ฐ ์๋๋๋ค.
47 ๋ฒ ๋ฌธ์ ์ ๋์ผํ ์์
์ด ํ์ํฉ๋๋ค.
Bummer. ์, ์ํฅ์๋ฐ๋ ๊ฒ์ ์ฃผ๋ก repl์ด๊ธฐ ๋๋ฌธ์ ์ณ์ ์ผ์ ์ฒ์ฒํํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๋ฐํ์์ ์ด๊ฒ์ ๊ฑฐ์ ์์๋์ง ์์์ผํฉ๋๋ค. ์ ๋๊ตฐ๊ฐ๊ฐ ๋ฌด์ธ๊ฐ๋ฅผ ์ ์ํ ๋ค์ ๋ํ์์ ์ ์ธํ๊ณ ๋ค์ ์ ์ํ ๊น์? ์๋ฃจ์ ์ด ๊ฒฐ๊ตญ ๋ง์ ์ค๋ฒ ํค๋๋ฅผ ์ ๋ฐํ๋ ๊ฒฝ์ฐ ์ ํ ์ฌํญ์ด๋ฉฐ ์๋์ผ๋ก repl์์ ์ํ๋์ด์ผํฉ๋๊น?
์ด๊ฒ์ด ํ์ฌ ์ ์๋์ด ์์ง ์๋ค๋ ๊ฒ์ ๋ฌธ์ํํด์ผํฉ๋๋ค.
๊ธฐ์ ์ ์ผ๋ก ์ด๊ฒ์ ๋ฒ๊ทธ๊ฐ ์๋๋ผ ์ ์๋์ง ์์ ๋์์ ๋๋ค. ๋ฉ์๋๋ฅผ ์ฌ์ ์ํ๋ฉด ๊ฒฐ๊ณผ ๋์์ด ์ ์๋์ง ์์ต๋๋ค. ๋ฐ๋ผ์ Julia๋ ํ์ฌํ๋ ์ผ์ ํฌํจํ์ฌ ์ํ๋๋๋ก ํ ์ ์์ต๋๋ค. ๋ฉ์๋ ์ฌ์ ์์ ์ ์ ์ ๋ ๋์์ ์ ๊ณตํ๋ ๊ฒ์ ๋ฒ๊ทธ ์์ ์ด ์๋๋ผ ๊ธฐ๋ฅ์ ๋๋ค. ๋ํ ์ ์๋์ง ์์ ๋์์์ ์ ์ ์ ๋ ๋์์ ์ ๊ณตํ๋ ๊ฒ์ด ์ฃผ์ ๋ณ๊ฒฝ ์ฌํญ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด v1.0 ๋ฌธ์ ๋ผ๊ณ ํ์ ํ์ง ์์ต๋๋ค. ์ด๊ฒ์ ์ ํจํ v1.0 ์ฝ๋๋ฅผ ์์์ํค์ง ์๊ณ v1.1์์ ๊ตฌํ ๋ ์ ์์ต๋๋ค.
Apple์ LLVM / LLDB ์ง์์ Greg Clayton์ ํฌํจ ๋ ๊ธฐํธ ์ ๋ณด (๊ธฐํธ ๊ฐ์ ธ ์ค๊ธฐ)์์ ๋ฐ์ด๋๋ฆฌ์ ์ข ์์ฑ์ ๊ฒฐ์ ํ๋ ๋ฐ ํ์ํ ์ ๋ณด๋ฅผ ๋์ถํ๋ ๋ฐฉ๋ฒ (lldb ๋ผ์ด๋ธ๋ฌ๋ฆฌ, llvm์ ํ์ ํ๋ก์ ํธ ์ฌ์ฉ)์ ๋ฌธ์ํํ๊ธฐ์ ์ถฉ๋ถํ ์น์ ํ์ต๋๋ค. ๋ฐ์ด๋๋ฆฌ๋ก ๋ด ๋ณด๋ธ ์ฌ๋ณผ (์ ์ฒด ์ข ์์ฑ ๊ทธ๋ํ๋ฅผ ๊ตฌ์ฑํ๋ ๋ฐ ํ์ํจ)๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค.
2012 ๋ 3 ์ 31 ์ผ ์คํ 11:02์ Jason E. Aten์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
LLDB ์ ํธ๊ฐ ์ฌ๋ฌ๋ถ,
lldb ๋ผ์ด๋ธ๋ฌ๋ฆฌ / ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ์ด์ ๋ ๊ฐ์ ๊ธฐํธ ๋ชฉ๋ก์ ๋ฐํํ๋ OSX์์ ์คํ์ค์ธ ํน์ ์ฝ๋๋ฅผ ๋์ฒด ํ ์ ์๋์ง ๊ถ๊ธํฉ๋๋ค. (dyldinfo -lazy_bind -exports
); ์ฆ, ๋ฐ์ด๋๋ฆฌ ๊ณต์ ๊ฐ์ฒด ๋๋ ๋ฒ๋ค์์ ๊ฐ์ ธ์ค๊ณ ๋ด ๋ณด๋ธ ์ฌ๋ณผ์ ๋์ดํด์ผํฉ๋๋ค. ๋ด ํฌ๋ง์ lldb ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ OSX์์ Linux์ ๋์ผํ ํด๋ผ์ด์ธํธ ์ฝ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค๋ ๊ฒ์ด ์์ต๋๋ค. (๋ฆฌ๋ ์ค ๋ฒ์ ์ ์ฝ๋๋ ํ์ฌ libbfd์ libdld๋ฅผ ์ฌ์ฉํ์ฌ ๋์ผํ ์์ ์ ์ํํ์ง๋ง ๋์ค์๋ ๊ฑฐ์ ์ฌ๋ / ์ ์ง ๊ด๋ฆฌ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์ต๋๋ค.)
lldb๊ฐ ์๋ํ๋ ค๋ฉด ๋์ผํ ์ ๋ณด (๊ฐ์ ธ์จ ์ฌ๋ณผ ๋ชฉ๋ก ๋ฐ Mach-O ํ์ผ์ ๋ํ ๋ด ๋ณด๋ธ ์ฌ๋ณผ ๋ชฉ๋ก)๊ฐ ํ์ํ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ฏ๋ก include / lldb /๋ฅผ ์ดํด๋ณด๊ณ ์์ง๋ง ์ด๋ค API๋ฅผ ์ฌ์ฉํ ์ง ๋ช ํํ์ง ์์ต๋๋ค. lldb์ ์์ ์ฝ๋์ ๋ํ ๋ชจ๋ ์ ์ / ํฌ์ธํฐ๋ฅผ ํ์ํฉ๋๋ค!
๊ฐ์ฌํฉ๋๋ค.
์ ์ด์จdyldinfo๊ฐ ๋ฌด์์ํ๋์ง ๋ช ํํ์ง ์์ ๊ฒฝ์ฐ ๋ค์ ์๊ฐ ์์ต๋๋ค. (ํ์ง๋ง ๊ธฐํธ ์ด๋ฆ ๋ง ํ์ํ๋ฉฐ ์ฃผ์ ๋ ์ธ๊ทธ๋จผํธ ๋๋ ์น์ ์ ํ์ํ์ง ์์ต๋๋ค.)
$ ํ์ผ / tmp / sample_bundle
/ tmp / sample_bundle : Mach-O 64 ๋นํธ ๋ฒ๋ค x86_64$ dyldinfo -lazy_bind -export / tmp / sample_bundle
์ง์ฐ ๋ฐ์ธ๋ฉ ์ ๋ณด (dyld ์ ๋ณด์ lazy_bind ๋ถ๋ถ์์) :
์ธ๊ทธ๋จผํธ ์น์ ์ฃผ์ ์ธ๋ฑ์ค dylib ๊ธฐํธ
__DATA __la_symbol_ptr 0x00001030 0x0000 ํ๋ซ ๋ค์ ์คํ์ด์ค __mm_pop_chunk
__DATA __la_symbol_ptr 0x00001038 0x0015 ํ๋ซ ๋ค์ ์คํ์ด์ค _dh_define
์ ๋ณด ๋ด๋ณด๋ด๊ธฐ (trie์์) :
0x000008A0 _C_ipair
0x00000920 _init_ipair
0x00000BC0 _C_iprot
0x00000C40 _C_ipi2
0x00000CC0 _C_ipi1
0x00001040 _K_ipair_R43808f40
0x00001160 _K_ipi1_R5cb4475d
0x00001260 _K_ipi2_R5cb4475d
0x00001360 _K_iprot_Rfc8fe739
0x00001460 _majver_ipair
0x00001464 _minver_ipair
2012 ๋ 4 ์ 2 ์ผ ์์์ผ ์คํ 3:13์ Greg Clayton [email protected] ์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
Yes you can do this with LLDB. If you load a binary and dump its symbol table, you will see the information you want. For symbols that are lazily bound, you can look for "Trampoline" symbols:
cd lldb/test/lang/objc/foundation
make
lldb a.out
(lldb) target modules dump symtab a.out
Symtab, file = .../lldb/test/lang/objc/foundation/a.out, num_symbols = 54:
Debug symbol
|Synthetic symbol
||Externally Visible
|||
Index UserID DSX Type File Address/Value Load Address Size Flags Name
------- ------ --- ------------ ------------------ ------------------ ------------------ ---------- ----------------------------------
[ 0] 0 D SourceFile 0x0000000000000000 Sibling -> [ 15] 0x00640000 /Volumes/work/gclayton/Documents/src/lldb/test/lang/objc/foundation/main.m
[ 1] 2 D ObjectFile 0x000000004f79f1ca 0x0000000000000000 0x00660001 /Volumes/work/gclayton/Documents/src/lldb/test/lang/objc/foundation/main.o
[ 2] 4 D Code 0x00000001000010f0 0x00000000000000c0 0x000e0000 -[MyString initWithNSString:]
[ 3] 8 D Code 0x00000001000011b0 0x0000000000000090 0x000e0000 -[MyString dealloc]
[ 4] 12 D Code 0x0000000100001240 0x00000000000000a0 0x000e0000 -[MyString description]
[ 5] 16 D Code 0x00000001000012e0 0x0000000000000020 0x000e0000 -[MyString descriptionPauses]
[ 6] 20 D Code 0x0000000100001300 0x0000000000000030 0x000e0000 -[MyString setDescriptionPauses:]
[ 7] 24 D Code 0x0000000100001330 0x0000000000000030 0x000e0000 -[MyString str_property]
[ 8] 28 D Code 0x0000000100001360 0x0000000000000050 0x000e0000 -[MyString setStr_property:]
[ 9] 32 D Code 0x00000001000013b0 0x0000000000000040 0x000f0000 Test_Selector
[ 10] 36 D Code 0x00000001000013f0 0x0000000000000130 0x000f0000 Test_NSString
[ 11] 40 D Code 0x0000000100001520 0x0000000000000120 0x000f0000 Test_MyString
[ 12] 44 D Code 0x0000000100001640 0x00000000000001b0 0x000f0000 Test_NSArray
[ 13] 48 D Code 0x00000001000017f0 0x00000000000000e1 0x000f0000 main
[ 14] 56 D X Data 0x0000000100002680 0x0000000000000000 0x00200000 my_global_str
[ 15] 58 D SourceFile 0x0000000000000000 Sibling -> [ 19] 0x00640000 /Volumes/work/gclayton/Documents/src/lldb/test/lang/objc/foundation/my-base.m
[ 16] 60 D ObjectFile 0x000000004f79f1ca 0x0000000000000000 0x00660001 /Volumes/work/gclayton/Documents/src/lldb/test/lang/objc/foundation/my-base.o
[ 17] 62 D Code 0x00000001000018e0 0x0000000000000020 0x000e0000 -[MyBase propertyMovesThings]
[ 18] 66 D Code 0x0000000100001900 0x000000000000001f 0x000e0000 -[MyBase setPropertyMovesThings:]
[ 19] 82 Data 0x0000000100002000 0x0000000000000460 0x000e0000 pvars
[ 20] 83 ObjCIVar 0x0000000100002518 0x0000000000000148 0x001e0000 MyBase.propertyMovesThings
[ 21] 84 X Data 0x0000000100002660 0x0000000000000008 0x000f0000 NXArgc
[ 22] 85 X Data 0x0000000100002668 0x0000000000000008 0x000f0000 NXArgv
[ 23] 86 X ObjCClass 0x00000001000024d8 0x0000000000000028 0x000f0000 MyBase
[ 24] 87 X ObjCClass 0x0000000100002460 0x0000000000000028 0x000f0000 MyString
[ 25] 88 X ObjCIVar 0x0000000100002510 0x0000000000000008 0x000f0000 MyString._desc_pauses
[ 26] 89 X ObjCIVar 0x0000000100002508 0x0000000000000008 0x000f0000 MyString.date
[ 27] 90 X ObjCIVar 0x0000000100002500 0x0000000000000008 0x000f0000 MyString.str
[ 28] 91 X ObjCMetaClass 0x00000001000024b0 0x0000000000000028 0x000f0000 MyBase
[ 29] 92 X ObjCMetaClass 0x0000000100002488 0x0000000000000028 0x000f0000 MyString
[ 30] 97 X Data 0x0000000100002678 0x0000000000000008 0x000f0000 __progname
[ 31] 98 X Data 0x0000000100000000 0x00000000000010b0 0x000f0010 _mh_execute_header
[ 32] 99 X Data 0x0000000100002670 0x0000000000000008 0x000f0000 environ
[ 33] 101 X Data 0x0000000100002680 0x0000000000000000 0x000f0000 my_global_str
[ 34] 102 X Code 0x00000001000010b0 0x0000000000000040 0x000f0000 start
[ 35] 103 Trampoline 0x0000000100001938 0x0000000000000006 0x00010200 NSLog
[ 36] 104 X Undefined 0x0000000000000000 0x0000000000000000 0x00010400 OBJC_CLASS_$_NSArray
[ 37] 105 X Undefined 0x0000000000000000 0x0000000000000000 0x00010200 OBJC_CLASS_$_NSAutoreleasePool
[ 38] 106 X Undefined 0x0000000000000000 0x0000000000000000 0x00010400 OBJC_CLASS_$_NSDate
[ 39] 107 X Undefined 0x0000000000000000 0x0000000000000000 0x00010400 OBJC_CLASS_$_NSObject
[ 40] 108 X Undefined 0x0000000000000000 0x0000000000000000 0x00010200 OBJC_CLASS_$_NSString
[ 41] 109 X Undefined 0x0000000000000000 0x0000000000000000 0x00010400 OBJC_METACLASS_$_NSObject
[ 42] 110 X Undefined 0x0000000000000000 0x0000000000000000 0x00010400 __CFConstantStringClassReference
[ 43] 111 X Undefined 0x0000000000000000 0x0000000000000000 0x00010100 _objc_empty_cache
[ 44] 112 X Undefined 0x0000000000000000 0x0000000000000000 0x00010100 _objc_empty_vtable
[ 45] 113 Trampoline 0x000000010000193e 0x0000000000000006 0x00010300 exit
[ 46] 114 Trampoline 0x0000000100001920 0x0000000000000006 0x00010100 objc_getProperty
[ 47] 115 Trampoline 0x0000000100001926 0x0000000000000006 0x00010100 objc_msgSend
[ 48] 116 Trampoline 0x000000010000192c 0x0000000000000006 0x00010100 objc_msgSendSuper2
[ 49] 117 X Undefined 0x0000000000000000 0x0000000000000000 0x00010100 objc_msgSend_fixup
[ 50] 118 Trampoline 0x0000000100001932 0x0000000000000006 0x00010100 objc_setProperty
[ 51] 119 Trampoline 0x0000000100001944 0x0000000000000006 0x00010300 printf
[ 52] 120 Trampoline 0x000000010000194a 0x0000000000000006 0x00010300 usleep
[ 53] 121 X Undefined 0x0000000000000000 0x0000000000000000 0x00010300 dyld_stub_binder
(lldb)
All lazily bound symbols will have type Trampoline:
[ 45] 113 Trampoline 0x000000010000193e 0x0000000000000006 0x00010300 exit
[ 46] 114 Trampoline 0x0000000100001920 0x0000000000000006 0x00010100 objc_getProperty
[ 47] 115 Trampoline 0x0000000100001926 0x0000000000000006 0x00010100 objc_msgSend
[ 48] 116 Trampoline 0x000000010000192c 0x0000000000000006 0x00010100 objc_msgSendSuper2
[ 50] 118 Trampoline 0x0000000100001932 0x0000000000000006 0x00010100 objc_setProperty
[ 51] 119 Trampoline 0x0000000100001944 0x0000000000000006 0x00010300 printf
[ 52] 120 Trampoline 0x000000010000194a 0x0000000000000006 0x00010300 usleep
The other symbols that are exernal are marked with an "X" (which is a boolean flag on each symbol).
The symbols can be accessed via the SBModule:
size_t
SBModule::GetNumSymbols ();
lldb::SBSymbol
SBModule::GetSymbolAtIndex (size_t idx);
And then you can get the symbol type from each SBSymbol:
SymbolType
SBSymbol::GetType ();
I just added the ability to see if a symbol is externally visible:
% svn commit
Sending include/lldb/API/SBSymbol.h
Sending scripts/Python/interface/SBSymbol.i
Sending source/API/SBSymbol.cpp
Transmitting file data ...
Committed revision 153893.
bool
SBSymbol::IsExternal();
So your flow should be:
SBDebugger::Initialize();
SBDebugger debugger(SBDebugger::Create());
SBTarget target (debugger.CreateTarget (const char *filename,
const char *target_triple,
const char *platform_name,
bool add_dependent_modules,
lldb::SBError& error));
SBFileSpec exe_file_spec (filename);
SBModule exe_module (target.FindModule(exe_file_spec));
if (exe_module.IsValid()
{
const size_t num_symbols = exe_module. GetNumSymbols();
for (size_t i=0; i<num_symbols; ++i)
{
SBSymbol symbol (exe_module. GetSymbolAtIndex(i));
if (symbol.IsExternal())
{
}
if (symbol.GetType() == lldb::eSymbolTypeTrampoline)
{
}
}
}
> _______________________________________________
> lldb-dev mailing list
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
2012 ๋ 4 ์ 2 ์ผ ์์์ผ ์คํ 4:05์ Greg Clayton [email protected] ์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
A quick clarification on the args to CreateTarget:
"filename" is just a full path to the local object file you want to observer. "target_triple" is your <arch>-<vendor>-<os>, or something like "x86_64-apple-darwin" or "i386-pc-linux" and can be NULL if the file is only a single architecture. "platform_name" can be NULL. "add_dependent_modules" should be false, since you are only interested in seeing the one object file itself, an SBError instance should be created and passed in.
๊ฐ๋ฐ์ ๋ชฉ๋ก ํ ๋ก : https://groups.google.com/forum/?fromgroups=#!topic/julia -dev / snnGKJul4vg.
์ด๊ฒ์ ๋๋๋๋ก ์ค๋๋ ์ค๋ ๋๋ฅผ ์ค๋นํ๊ณ ์์ง๋ง ์ฝ๋ ์๋ ๋ฒค์น๋งํน ์ฝ๋ ๋ก์ด ๋ฌธ์ ์ ๊ฐ์ฅ์๋ฆฌ๋ฅผ ์ ํนํ๊ณ ์์์ ๊นจ๋ฌ์์ต๋๋ค. listTests()
๋ฐ runTests()
๋ ๊ฐ์ ํจ์๊ฐ ํฌํจ ๋ Core.include()
ํ์ผ์ ๋ฐ๋ณตํด์ ์ฌ์ฉํ์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ listTests()
๋ฐ runTests()
๋ฅผ ํธ์ถํ์ฌ ์ ๋ฒค์น ๋งํฌ ํ์ผ์๋ก๋ ํ ๋๋ง๋ค ์ฌ์ ์ ํ ๋ค์ ํธ์ถํฉ๋๋ค. 2 ๋จ๊ณ ํจ์๋ฅผ ์ฌ์ ์ํ์ง ์๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ์ ๋์ด๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ์ง๋ง ์ด์ ๊ฐ์ ๊ฒ์ ์ฌ์ ์ํ๋ ๊ฒ์ ๋์ผํ "API"๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ ํ์ผ์๋ก๋ํ๋ ๋ฐ ๋์ ๋ฐฉ๋ฒ์
๋๊น?
๋ชจ๋์ ๋ฐ๋ณต์ ์ผ๋ก ํฌํจํ๋ ๊ฒ์ด ๋ ๋์ ์๋ ์์ง๋ง ๊ฐ๋ฐ์ ๋ชฉ๋ก์์๋ ์ ๊ธฐ ๋ ์ต๋ช ๋ชจ๋ ๋ฌธ์ ์ ์ถฉ๋ํ๋ค๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ์๋ ๊ด์ฐฎ์ ์ ์์ง๋ง ๋์ผํ ๋ชจ๋์ ์ฌ๋ฌ ๋ฒ ์ ์ํ๊ณ ๋ฐ์ํ๋ ๊ฒฝ๊ณ ๋ฅผ ๋ฌด์ํ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
์๋ง๋ ์ค๋๋ ์ค๋ ๋์ด์ง๋ง ๊ทธ ์ด๋ ๋๋ณด ๋ค ๊ด๋ จ์ด ์์ต๋๋ค.
๋ ๋ค๋ฅธ ์ ๊ทผ ๋ฐฉ์์ evalfile
๋ฅผ ์ฌ์ฉํ๊ณ ํ์ผ์ ํจ์ ํํ์ "๋ฐํ"ํ๋ ๊ฒ์
๋๋ค. ์ต๋ช
๋ชจ๋ ๋ฌธ์ ๋ ๋ฌด์์
๋๊น?
๋๋ ์ด๊ฒ์ ์ธ๊ธํ๊ณ ์์๋ค : https://github.com/JuliaLang/julia/issues/3661.
๋๊ตฌ๋ ์ง ๊ตฌํ ์ ๋ต์ ๋ํ ์ถ๊ฐ ์๊ฐ์ด ์์ต๋๊น? ๋๋ (์ต์ ํ๋์ง ์์ AST๋ฅผ ๊ธฐ๋ฐ์ผ๋ก) ์๋ก์ด ๋ฉ์๋๊ฐ ์์ฑ ๋ ๋๋ง๋ค ์ ๋ฐ์ดํธ๋๋ ๋ฐ์ ๋ ํธ์ถ ๊ทธ๋ํ๋ฅผ ์ ์งํ๋ ๊ฐ๋จํ ์ฒด๊ณ๋ฅผ ์ฝ๋ฉํ๋ ค๊ณ ์๊ฐํ๊ณ ์์์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ ๋ฉ์๋๊ฐ ์ฌ์ ์ ๋ ๋ ํด๋น ๊ทธ๋ํ๋ฅผ ์ดํด๋ณด๊ณ ์ฌ์ ์ ๋ ๊ฐ ํจ์์ ํ์ ํญ๋ชฉ์ ์ปดํ์ผ ๋ ๋ฒ์ ์ ์ ๊ฑฐํฉ๋๋ค.
๊ทธ๊ฒ์ ์๋ํ ๋งํ ํฉ๋ฆฌ์ ์ธ ์ ๊ทผ ๋ฐฉ์์ ๋๋ค. ๊ทธ๋ ๊ฒ ํ ์์์ด ์๋ค๋ฉด, ๊ณ์ํด์ ๋ฌด์จ ์ผ์ด ์ผ์ด๋๋์ง ๋ด ์๋ค!
์์ ์์ _execution_์ด ํธ์ถ์์ ์ฌ ์ปดํ์ผ์ ํธ๋ฆฌ๊ฑฐํ๋ฉด ์ด๋ป๊ฒ๋ฉ๋๊น?
๋๋์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ด REPL์ ์ฌ์ฉ์ ๊ฒฝํ์ ๋์ด์๋ ํฅ๋ฏธ๋ก์ด ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค๋ ๊ฒ์ ๋ค๋ฆ๊ฒ ๊นจ๋ฌ์ ๊ธฐ ๋๋ฌธ์ ๋ฌป์ต๋๋ค. ๋ฉํ ํ๋ก๊ทธ๋๋ฐ ๋ฌธ์ ์ ๋ํ ๊ถ๊ทน์ ์ธ ๋๋ต, ์ฆ ํจ์จ์ ์ธ "๋จ๊ณ์ "๊ธฐ๋ฅ์ ์์ฑ ํ ์์๊ฒ ํด์ค ์ ์์ต๋๋ค. ๋ชจ๋ฅด๋ ์ฌ๋๋ค์์ํ ๋ฐฐ๊ฒฝ : ์ผ๋ถ ๊ธฐ๋ฅ์ ํ์ฌ ๋ฉํ ํ๋ก๊ทธ๋๋ฐ์ ์ํด ๊ตฌํ๋๋ฉฐ, ํนํ ์๊ณ ๋ฆฌ์ฆ์ ์ผ๋ถ ์ธก๋ฉด์ด ์ฌ์ํ์ง ์์ ๋ฐฉ์์ผ๋ก ์ ๋ ฅ ์ ํ์ ์์กดํ๋ ๊ธฐ๋ฅ ---- ํ์ค ์๋ ์ซ์๊ฐ ํจ์ ๋ณธ๋ฌธ์ ๋ฃจํ ์๋ ๋ฐฐ์ด์ ์ฐจ์๊ณผ ๊ฐ์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์๋ฅผ ๋ค์ด ์ฐจ์ 1๊ณผ 2์ ๋ํด ๋ช ์ ์ ์ผ๋ก ํจ์๋ฅผ ์ ์ํ ๋ค์ ๋ค์๊ณผ ๊ฐ์ ๋ํผ๋ฅผ ๊ฐ๋ ๊ฒ์ ๋๋ค.
_method_cache = Dict()
function myfunction(A::AbstractArray)
N = ndims(A)
if !haskey(_method_cache, N)
func = eval(<an expression that generates the function definition for N dimensions>)
_method_cache[N] = func
else
func = _method_cache[N]
end
return func(A)
end
๋ฐ๋ผ์ ์ฒ์ myfunction
๊ฐ 4 ์ฐจ์ ๋ฐฐ์ด์ ๋ํด ์คํ๋๋ฉด ๋จผ์ 4 ์ฐจ์์ ํน์ ํ ๋ฒ์ ์ ์ ์ํ๊ณ _method_cache
์ ์ถ๊ฐ ํ ๋ค์ ์
๋ ฅ์์ ์ ํจ์๋ฅผ ํ๊ฐํฉ๋๋ค. 4 ์ฐจ์ ๋ฐฐ์ด๋ก myfunction
์ ๋ํ ํฅํ ํธ์ถ์ ์ฌ์ ์์ ์ ์๋ฅผ ๊ฒ์ํ๊ณ ํ๊ฐํฉ๋๋ค. _method_cache
๋ Julia ์์ ์ ๋ด๋ถ ๋ฉ์๋ ํ
์ด๋ธ๊ณผ ๋ณํํ์ฌ์ด ํน์ ํจ์์๋ง ์ฌ์ฉ๋๋ ์ผ์ข
์ "๊ทธ๋ฆผ์ ๋ฉ์๋ ํ
์ด๋ธ"์
๋๋ค. (๋น๊ณต๊ฐ๋ก ์ ์งํ๊ธฐ ์ํด ์ผ๋ฐ์ ์ผ๋ก let
์บก์ํ๋ฉ๋๋ค.)
์ด ์์ ์ ์ ๊ทผ ๋ฐฉ์์ ์คํํ๋ ๋ฐ ์๊ฐ์ด ๊ฑธ๋ฆฌ๋ ํจ์ ๋ณธ๋ฌธ์ ์ ์๋ํ์ง๋ง ์ฌ์ ์กฐํ์ ํ์ํ ๊ฒ๋ณด๋ค ์งง์ ์๊ฐ์ ์คํ๋๋ ํจ์์๋ ์ ํฉํ์ง ์์ผ๋ฉฐ ํนํ ์ํ๋ ํจ์์๋ ์ ํฉํ์ง ์์ต๋๋ค. ์ธ๋ผ์ธ ํ ์ ์์ต๋๋ค.
์ด๋ฅผ ์ํํ๋ ๋ ์ข์ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
function myfunction(A::AbstractArray)
bodyexpr = <an expression for the body of the function specific for N dimensions>
f = <strong i="17">@eval</strong> begin
function myfunction(A::$(typeof(A)))
$bodyexpr
end
end
return f(A)
end
์ฌ๊ธฐ์ myfunction
myfunction
๋ฅผ ์คํํ๋ฉด ์ด๋ฌํ ํน์ ์
๋ ฅ ์ ํ์ ๋ํด
ํ์ฌ ์ด๊ฒ์ ํ ๊ฐ์ง ์ค์ํ ์ด์ ๋๋ฌธ์ ์๋ํ์ง ์์ต๋๋ค. ๋ฐฉ๊ธ myfunction
๋ผ๊ณ ๋ถ๋ฅด๋ ๊ฒ์ ์ด๋ฏธ ์ปดํ์ผ๋์์ผ๋ฏ๋ก ์๋ก์ด ์ ์์ ๋ํด ์์ง ๋ชปํฉ๋๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก์ด ํน์ ํธ์ถ์๋ ํญ์ myfunction
์ฌ์ฉํ์ฌ eval
myfunction
์ ์๋ก์ด ๋ฒ์ ์ ์์ฑํฉ๋๋ค.
๋ฐ๋ผ์ ํธ๋ฆญ์ ํธ์ถ์๋ฅผ ๋ค์ ์ปดํ์ผํ๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ์ด๊ฒ์ด ์คํ ์ค์ผ ๋ _ ๋ฐ์ํด์ผํฉ๋๋ค _. ๋ฌด์จ ์ผ์ด ์ผ์ด๋ ๊น์?
# 5395๋ ์ฐธ์กฐํ์ญ์์ค.
์ค์ ๋ก ๋ฉ์๋ ์ฌ์ ์๋ฅผ ํฌํจํ์ง ์์ง๋ง ์ ์ฌํ ์ฒ๋ฆฌ๊ฐ ํ์ํ ์ถ์ ์ ํ๊ณผ ๊ด๋ จ๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์คํ ์ฌ๊ธฐ๋ค:
abstract A
immutable B <: A; end
immutable C <: A; end
g(x::Vector{A}) = f(x[1])
f(::B) = 1
g(A[B()])
f(::C) = 0.5
g(A[C()])
๋ง์ง๋ง ์ค์ 4602678819172646912
์
๋๋ค. f(::A)
๋ํ ์ ํ ์ถ๋ก ์ด ๋ ์ด์ ์ ํจํ์ง ์๊ธฐ ๋๋ฌธ์ g
๋ํ ์ฝ๋๋ฅผ ๋ฒ๋ ค์ผํฉ๋๋ค.
๋ค, ์์ฃผ ๋ถ๋ช ํฉ๋๋ค. ๊ต์ฒด ๋ฐฉ๋ฒ์ ํน๋ณํ ๊ฒฝ์ฐ ์ผ๋ฟ์ ๋๋ค. ๊ทธ๋ฌ๋ ํญ์ ์๋ก์ด ๋ฉ์๋ ์ ์๊ฐ ํฌํจ๋ฉ๋๋ค.
ํ์ฌ ์ํฉ์ ์ ์ง ๋ชจํธ ํ ์ ์์ต๋๋ค.
f() = x()
x() = 1
println(f())
x() = 2
println(f())
์ค๋ค
1
๋์
g() = y()
precompile(g, ())
y() = 1
println(g())
y() = 2
println(g())
์ค๋ค
2
๋์ค์ ๊ฒฝ์ฐ๋ ํธ์ถ์ ์ฌ ์ปดํ์ผ์ ์๋ฎฌ๋ ์ดํธํ๊ธฐ์ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ์ฉํ ์์๋ ๊ฒ ๊ฐ์ต๋๋ค (์ค์ ๋ก ์ฌ ์ปดํ์ผ์ด ์๋์ ์๊ณ ์์ต๋๋ค).
์ด๋ฆฌ์์ ๋ง์ ํ ๊ฒ ๊ฐ์ ๋๋์ด ๋ค์ง๋ง,์ด ๋ฌธ์ ๋ ํ ๋จ๊ณ์ ๊ฐ์ ์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก ํด๊ฒฐํ ์ ์์๊น์? ํจ์ ์ฃผ์๋ฅผ ํ๋ ์ฝ๋ฉํ๋ ๋์ ๊ณ ์ ๋ ์์น์์ ์ฐพ์์ ํธ์ถํ์ญ์์ค. ์ด๊ฒ์ C ++ ๋๋ Java ๊ฐ์ ๊ธฐ๋ฅ๊ณผ ์ ์ฌํ ์ฑ๋ฅ์ ๊ฐ์ง ์์ต๋๊น? ๊ทธ๋ฐ ๋ค์ ์ ์ ๋๋ ๋์ ์ฃผ์๋ฅผ ๊ฐ๋๋ก ํจ์์ ์ฃผ์์ ๋ฌ ์ ์์ผ๋ฉฐ ์ ์ ์ฃผ์๋ก ํจ์๋ฅผ ์ฌ์ ์ํ๋ ค๊ณ ํ๋ฉด ๊ฒฝ๊ณ / ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ธฐ๋ณธ ๊ธฐ๋ฅ ๋์์ ์ค์ ํ๋ ์ค์์น๊ฐ์์ ์๋ ์์ต๋๋ค. ๋๋ ์ธ์ด์ ์ต์ํ์ง ์๊ณ ์ฝ๋๋ฒ ์ด์ค์ ์์ ํ ์ต์ํ์ง ์์ง๋ง ์ด๊ฒ์ด ๊ฐ๋ฅํ๊ฒ ๋ค๋ฆฌ๋ฉด ์ฝ์ ์ค ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
@ omer4d ๊ทธ ์์ด๋์ด์ ํ ๊ฐ์ง ๋ฌธ์ ๋ Julia๊ฐ ๋ง์ ์์ ํจ์๋ฅผ ์ธ๋ผ์ธํ๊ธฐ ๋๋ฌธ์ ํน์ ํจ์์ ๋ํ ๋ชจ๋ "์ข ์ ํญ๋ชฉ"์ ์ฐพ๋ ๋ฐฉ๋ฒ์ด ํ์ํ๋ค๋ ๊ฒ์ ๋๋ค.
C ++์ฒ๋ผ ์ ์ ์ฃผ์๋ก๋ง ์ธ๋ผ์ธ ํ ์ ์์ต๋๋ค. ์ด๊ฒ์ ๋ถํธ์ ์ผ๊ธฐํด์๋ ์๋ฉ๋๋ค.
๊ธฐ๋ณธ ๋์์ ๋ชจ๋ ๊ธฐ๋ฅ์ ์ ์ ์ฃผ์๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๋ํ ํ ๊ฐ๋ฐ์ ๊ด์ฌ์ด์๋ ์ฌ๋๋ค์ ์ ํ ์ํฅ์๋ฐ์ง ์์ต๋๋ค.
์ฑ๋ฅ์ ๊ด์ฌ์ด ์์ง๋ง ๋ํ ํ ๊ฐ๋ฐ์ ์ํ๋ ์ฌ๋๋ค์ ์ค์์น๋ฅผ ์ฌ์ฉํ์ฌ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ธฐ๋ฅ ์ฃผ์๋ฅผ ๋์ ์ผ๋ก ๋ง๋ค ์ ์์ต๋๋ค.
์ํธ ์์ฉ๊ณผ ์ฑ๋ฅ์ ๋ชจ๋ ์ํ๋ ์ฌ๋๋ค์ ๊ด๋ จ ํจ์์ ์ฃผ์์ ๋ฌ ์ ์๋๋ฐ, ์ด๋ ๋ง์ ์์
์ด ์๋์ด์ผํฉ๋๋ค. ์ธ๋ผ์ธ์ ๋ง์ด ํธ์ถ๋๋ ์งง์ ์ ์์ค ํจ์์๋ง ๊ด๋ จ์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค.
์๋ง๋ ๊ธฐ๋ณธ ๋์์ ๋ชจ๋๋ณ๋ก ์ค์ ํ ์๋ ์์ต๋๋ค.
์ ๊ทผ์ด ๋ถ๊ฐ๋ฅํ ๋ฐ์๋ ๋ช ๊ฐ์ง ์ด์ ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋จผ์ ,
์ฃผ์์ ์ ๋ง ๊ท์ฐฎ์ ์ผ์
๋๋ค. ํนํ ํดํน์ด ํ์ํ ๋
์ด์ ๊ฐ์ ๊ตฌํ ์ธ๋ถ ์ฌํญ์ ๋ํด. ์ฃผ์์ ์ฌ์ฉํ์ฌ 2๋ฅผ ํด๊ฒฐํ๋ ๊ฒฝ์ฐ
๋๋ 3 ๊ฐ์ง ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด ํฌ๊ฒ ์์ด๊ธฐ ์์ํฉ๋๋ค. ๋์งธ,
ํจ์์ ์ ํฉํ ์ฃผ์์ ์ ํํ๋ ์ข์ ๋ฐฉ๋ฒ์
๋๋ค. ์๋ค
์ธ๋ผ์ธ์ ์ํ๋์ง ์ฌ๋ถ์
๋ํ์์ผ๋ก ๊ฐ๋ฐํฉ๋๋ค. ์
์งธ, ๋ค๋ฅธ ๊ธฐ๋ฅ์ ์ ํ ๊ณต์
๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ผ๋ฏ๋ก ๋จ์ง ํธ์ถ ์ฌ์ดํธ๊ฐ ์๋๋๋ค. ์ฌ์ค ์ฐ๋ฆฌ๋ ํ์ฌ
์ฐ๋ฆฌ๊ฐ ๋ง๋ค ์์๋ ๊ฒ๋ณด๋ค ๋ ์ ์ ์ ํ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
์ด ๋ฌธ์ ์ ์ง๋ฉดํ์ฌ ์์ ํฉ๋๋ค.
๊ธ์์, ์์ญ ๊ฐ์ ํ์ ์ด ํค์๋์ ๋ฐ๋ณต์ ์ธ ์๋ ์ฌ ์ปดํ์ผ์ ์ฌ์ฉํ์ฌ ๋๋ถ๋ถ์ ์์ ์ ์ธ์ด๋ก ์ํํ๋ ์ฌ๋์ผ๋ก์, ๋๋๋ก ํจ์๋ฅผ ํ๋ ๊ฐ ํ์ ํ๊ณ ๋ช์ฃผ๊ธฐ์ ๋ํ ํ ๊ฐ๋ฐ ํ์ ์ฌ ์ปดํ์ผํด์ผํ๋ ๊ฒ์ ๊ทธ๋ ๊ฒ ๋์๊ฒ ๋ค๋ฆฌ์ง๋ ์์ต๋๋ค. . ๊ทธ๋๋ ์ธ ๋ฒ์งธ ์์ ์ ๋ค๋ฃฐ ์๋ ์์ผ๋ ๋ฌผ๋ฌ๋๊ฒ ์ต๋๋ค. ์ฌ ์ปดํ์ผ์ ์์ ๋ ํจ์์ ํธ์ถ ํธ๋ฆฌ์ ๋ฃจํธ์ ๊ฒ์์ด๋ ์ ๋๋ฉ์ด์ ๋ฃจํ๊ฐ ํฌํจ๋์ด ์์ผ๋ฉด ์ข ๋ฃํ๊ณ ๋ค์ ์์ํด์ผํ๋ค๋ ๊ฒ์ ์๋ฏธํ๊ธฐ ๋๋ฌธ์ ๊ทธ๋ฌํ ์๋ฃจ์ ์ด ์คํ ๊ฐ๋ฅํ์ง ์๋ค๋ ๊ฒ์ ๋ถํํ ์ผ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. = (
@JeffBezanson ์ ์ด๋ ์ฒ์์๋ ์ฌ์ด ๊ฒฝ์ฐ์ ๊ฐ์ฅ ๊ด์ฌ์ด์์ ๊ฒ์
๋๋ค. eval
ํตํด ์ก์ธ์คํ๋ ๊ฒ (์ : REPL ํ๋กฌํํธ์์ ์
๋ ฅ)๊ณผ๋ ๋ฌ๋ฆฌ ์คํ์ค์ธ ์ฝ๋๊ฐ ์
๋ฐ์ดํธ๋๋๋งํผ ์ ๊ฒฝ ์ฐ์ง ์์ต๋๋ค. ๊ฒฐ๊ตญ ์ฌ์ ์ ํ ๋ ํธ์ถ๋๋ display
์ ์ฌ๋ฐ๋ฅธ ๋ฒ์ ์ ๊ฐ์ ธ ์ค๋ ๊ฒ๋ ์ค์ํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ ๋ ์ด๊ฒ์ด ์ฐ๋ฆฌ๊ฐ ์ ์ง์ ์ปดํ์ผ์ํ๋ ๋ฐ ๋น ๋ฅด๊ฒ ๊ฐ๊น์ ์ง ๊ฒ์ด๋ผ๊ณ ๋ฏฟ์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ์๊ธฐ ์ํด ์กฐ๊ธ ๋๋์ต๋๋ค. ์ฒ๋ฆฌํ๊ธฐ ์ฝ๋ค๊ณ ์๊ฐํด์๊ฐ ์๋๋ผ ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ด ์์๋๋ก ์๋ํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
julia> f(a, b) = a + b
f (generic function with 1 method)
julia> g(args...) = f(args...)
g (generic function with 1 method)
julia> g(1, 2)
3
julia> f(a::Int, b::Int) = a - b
f (generic function with 2 methods)
julia> g(1, 2)
-1
ํธ์ง : ์ค์ ๋ก ์ด๊ฒ์ Vararg ์ ๋ ฅ์ ๋ํ ํน๋ณํ ๊ฒฝ์ฐ์ฒ๋ผ ๋ณด์ ๋๋ค ..... ์ด๊ฒ์ vararg ํจ์๊ฐ ํธ์ถ ๋ ๋๋ง๋ค ์ฌ ์ปดํ์ผ๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๊น? ์๋๋ฉด ํ์ํ ๋๋ง ์ฌ ์ปดํ์ผ ํ ๋งํผ ๋๋ํฉ๋๊น? ๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ ๊ธฐ๋ฅ์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌ ํ ์ โโ์์ต๋๊น?
julia> f(a, b) = a + b
f (generic function with 1 method)
julia> g(a, b) = f(a, b)
g (generic function with 1 method)
julia> g(1, 2)
3
julia> f(a::Int, b::Int) = a - b
f (generic function with 2 methods)
julia> g(1, 2)
3
์ค์ ๋ก ํจ์๋ ์ฌ๋ฐ๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ์ง๋ง @code_typed
๋ ์๋ชป๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค .....
julia> f(a, b) = a + b
f (generic function with 1 method)
julia> g(args...) = f(args...)
g (generic function with 1 method)
julia> g(1, 2)
3
julia> <strong i="7">@code_typed</strong> g(1, 2)
1-element Array{Any,1}:
:($(Expr(:lambda, Any[:(args::(top(apply_type))(Vararg,Any)::Any::Any)], Any[Any[],Any[Any[:args,(Int64,Int64),0]],Any[]], :(begin # none, line 1:
return (top(box))(Int64,(top(add_int))((top(tupleref))(args::(Int64,Int64),1)::Int64,(top(tupleref))(args::(Int64,Int64),2)::Int64))
end::Int64))))
julia> f(a::Int, b::Int) = a - b
f (generic function with 2 methods)
julia> g(1, 2)
-1
julia> <strong i="8">@code_typed</strong> g(1, 2)
1-element Array{Any,1}:
:($(Expr(:lambda, Any[:(args::(top(apply_type))(Vararg,Any)::Any::Any)], Any[Any[],Any[Any[:args,(Int64,Int64),0]],Any[]], :(begin # none, line 1:
return (top(box))(Int64,(top(add_int))((top(tupleref))(args::(Int64,Int64),1)::Int64,(top(tupleref))(args::(Int64,Int64),2)::Int64))
end::Int64))))
๊ณผ
julia> f(a, b) = a + b
f (generic function with 1 method)
julia> g(args...) = f(args...)
g (generic function with 1 method)
julia> g(1, 2)
3
julia> f(a::Int, b::Int) = a - b
f (generic function with 2 methods)
julia> g(1, 2)
-1
julia> <strong i="12">@code_typed</strong> g(1, 2)
1-element Array{Any,1}:
:($(Expr(:lambda, Any[:(args::(top(apply_type))(Vararg,Any)::Any::Any)], Any[Any[],Any[Any[:args,(Int64,Int64),0]],Any[]], :(begin # none, line 1:
return (top(box))(Int64,(top(sub_int))((top(tupleref))(args::(Int64,Int64),1)::Int64,(top(tupleref))(args::(Int64,Int64),2)::Int64))
end::Int64))))
์ด๋ค ๊ฒ์ด ํ ๋น ๋ ๋๋ง๋ค ๋ณ๊ฒฝ๋๋ ์ซ์๋ก ํจ์์ ๋ฉ์๋ (๋๋ ํจ์ ์ ํ / ๊ฐ์ฒด ์์ฒด ๋ง)๋ฅผ ์์ธํํ์ฌ ์ปดํ์ผ ๋ (ํธ์ถ์) ํจ์๋ก ์ ์ฅ๋ ์ซ์ (์ฆ, ์๋ก์ด ๊ตฌ์กฐ ์ฌ์ฉ) ์ฌ๋ถ๋ฅผ ํ์ธํ ์์๊ฒ๋ฉ๋๋ค. ํจ์,์ด ์ซ์๋ฅผ ํ๋๋ก ์ ์ฅํ๋ ๋ฑ) ์ฌ์ ํ ์ธ๋ผ์ธ ๋ (ํธ์ถ ๋) ํจ์์์ "ํ์ฌ"์ธ ๊ฒ๊ณผ ์ผ์นํฉ๋๊น?
(๋ฌผ๋ก ํฐ ์ฑ๋ฅ ์ ํ์์ด)
๊ทธ๋ฆฌ๊ณ ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ ์ ๋ฒ์ ์ ์ปดํ์ผํ๊ฑฐ๋ ๋ช
์ ์ ํธ์ถ๋ก ์๋ฃํ๋ ๊ฒ์ ๊ณ ๋ คํ์ญ์์ค.
์ด๋ ์ฑ๋ฅ์ ๋ฏธ์น๋ ์ํฅ์ ๋ฐํ์์ผ๋ก ์ด๋์ํฌ ์ ์์ผ๋ฉฐ (๋ชจ๋ ๊ณณ์์) ๋ฐ๋์งํ์ง ์์ต๋๋ค. ํ์ํ ๊ฒ์ ์ข ์์ฑ์ ์น์ ์ถ์ ํ๊ณ ๋ฉ์๋๊ฐ ๋ถ๋ถ์ ์ผ๋ก ์ฌ์ ์ ๋ ๋ ์ํฅ์๋ฐ์ ์์๋ ๋ชจ๋ ๊ฒ์ ๋ค์ ์ปดํ์ผํ๋ ๊ฒ์ ๋๋ค. ๊ทธ๊ฒ์ ์๋ง๋ ๊ฐ๋ฅํ ๊ฒ์ ๋๋ค. ๊ทธ๊ฒ์ ๋จ์ง _ ๊ฑฐ๋ํ _ ๊ณ ํต ์ผ๋ฟ์ ๋๋ค.
์ด ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ์ฑ ์ด ๋งคํฌ๋ก๋ก ์ฝ๊ฒ ์ผ๋ฐํ๋๋์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง, ๊ทธ๋ ๋ค๋ฉด ๊ทธ๊ฒ์ด ์์ผ๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
๋ฐ๋ผ์ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์ด๋ํ์ฌ ํจ์๋ฅผ ์ธ๋ผ์ธ ํ ๋ชจ๋ ๋ฉ์๋๋ฅผ ์ ์ฅํ๊ณ ๋ณ๊ฒฝ์ ๋ค์ ์ปดํ์ผํด์ผํฉ๋๋ค. (๋ฌผ๋ก ํ์ฌ ์คํ ํ์ธ ๋ฑ)
์ฌ๊ธฐ์ ์ด๋ ค์ด ๋ฌธ์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๋ฌธ์ ์ ๋ํ ํด๊ฒฐ์ฑ
์์ ์์
ํ๋ ๋์ ์ฃผ์ด์ง ํจ์๊ฐ ์์ ๋ฐฉ๋ฒ ์ค ํ๋์์ ์ฌ์ฉ ๋ ๊ฒฝ์ฐ (๋ฐ ๊ฒฝ์ฐ์๋ง) ์ค์ ๋ ๋ชจ๋ ํจ์์ ํ๋๊ทธ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๊ณ ์ข์ ์๊ฐ์ธ์ง ๊ถ๊ธํฉ๋๋ค. inlining ๋ฑ) ์ธ๋ผ์ธ ๋ฉ์๋๊ฐ ์ฌ์ ์๋์๋ค๋ ๊ฒฝ๊ณ ๋ฅผ ์์ฑํ๊ธฐ ์ํด. (๋ชจํธํ ๊ฒฝ๊ณ ์๋ ๋ฐฉ์๊ณผ ์ ์ฌ)
ํ๋๊ทธ๋ฅผ ์ ์ฅํ๋ ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์๋ค๋ฉด ์ค๋ฆฌ์ 0.5์ ์๋ก์ด ๋ฉ์๋ / ํจ์ ๊ตฌ์กฐ๋ฅผ ๋ค์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด์ repl์์ ์ด๊ฒ์ ์น๋ ๊ฒ์ด ํจ์ฌ ๋ ์ฌ์์ก์ผ๋ฉฐ์ด ๋์์ ๋งต์ ๋ํด ๋ฌธ์ํ๋์ด์ผํฉ๋๊น?
julia> function f(x)
1
end
f (generic function with 1 method)
julia> map(f, 1:10)
10-element Array{Int64,1}:
1
1
1
1
1
1
1
1
1
1
julia> function f(x)
2
end
WARNING: Method definition f(Any) in module Main at REPL[9]:2 overwritten at REPL[11]:2.
f (generic function with 1 method)
julia> map(f, 1:10)
10-element Array{Int64,1}:
1
1
1
1
1
1
1
1
1
1
๊ทธ๊ฒ์ ์ฌ์ ํ โโ๋ฐ๋๋ผ # 265์ ๋๋ค. v0.6-dev์์ ๊ณง ์์ ๋ ๊ฒ์ด๋ผ๋ ์ ์ ๊ฐ์ฌ ํ ๊ฒ์ ๋๋ค. :)
@vtjnash ๋ฐํ์ ์ฑ๋ฅ์ด๋ ๋ฉ๋ชจ๋ฆฌ
์ฝ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ (140MB-> 170MB)๊ฐ ํ์ํ์ง๋ง ์ฑ๋ฅ (์ปดํ์ผ ๋๋ ๋ฐํ์)์ ํฐ ์ํฅ์์ฃผ์ง ์์์ผํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ ๋ ์์ง ๋ง์ ์ต์ ํ๋ฅผ ์๋ํ์ง ์์์ต๋๋ค.
์ง๊ธ๊น์ง์ ๋ฐ๋ชจ๋ ์ฌ๋ฏธ ์์ต๋๋ค.
julia> f() = 1
f (generic function with 1 method)
julia> function g(x)
<strong i="7">@eval</strong> f() = $x # this is the correct way to write `global f() = x` (which should be a syntax error, but isn't currently)
return @eval(f)() # use `eval` to hide the value from optimization / inlining, but the call is not inside eval
end
g (generic function with 1 method)
julia> g(2)
WARNING: Method definition f() in module Main at REPL[1]:1 overwritten at REPL[2]:2.
1
julia> g(3)
WARNING: Method definition f() in module Main at REPL[2]:2 overwritten at REPL[2]:2.
2
julia> g(4)
WARNING: Method definition f() in module Main at REPL[2]:2 overwritten at REPL[2]:2.
3
g
์ปดํ์ผ ์์์ f
์ฌ์ ์ ์คํ ์์๋ก ์ธํด 2, 3, 4๊ฐ ๋ฐํ๋์ง ์๋ ์ด์ ๋ ๋ฌด์์
๋๊น?
๋์ถฉ ๋ง์ต๋๋ค. ์ด ์์๊ฐํ๋ ๋ง์ ๋ ์ ํํ ๊ทธ๋์ ์ฃผ ์ธ์ด๋ ์ปดํ์ผ์ ์ ์ํ์ง ์๋ฏธํ๋ g
์ ์ฌ์ ์ํ๋ ์๊ฐ ๋ ํด์ f
์ธํฐํ๋ฆฌํฐ์ ํ์๋๊ธฐ
์ข์์, ์ฌ๊ธฐ์ +
ํ๋ฆฌ๋ฏธํฐ๋ธ๋ฅผ ์ฌ์ ์ํ๋ ๋ ๋ค๋ฅธ ์ฌ๋ฏธ์๋ ๋ฐ๋ชจ๊ฐ ์์ต๋๋ค.
julia> add_ctr = UInt(0)
0x0000000000000000
julia> Base.:+(a::Int, b::Int) = (global add_ctr += 1; Core.Intrinsics.add_int(a, b))
julia> add_ctr
0x0000000000000016
julia> last = 0;
julia> println(Int(add_ctr - last)); last = add_ctr;
287
julia> println(Int(add_ctr - last)); last = add_ctr;
17
์์์์
๋๋ค. +
์ด Base์์ ์ ํ ์ฌ์ฉ๋์ง ์๋๋ค๊ณ ์๊ฐํ๋ฏ๋ก ์ฌ ์ปดํ์ผ ํ ๊ฒ์ด ์์ต๋๋ค. REPL์ด ๋ํ๋๊ธฐ ์ ์ ์ต์ํ 100 ๋ฒ ํธ์ถ๋์ด์ผํ๋ค๋ ๊ฒ์ ์๊ณ ์๋ svd
์ ๊ฐ์ ์ค์ ํจ์๋ฅผ ์ฌ์ ์ํ์ญ์์ค. ๊ทธ๋ฌ๋ฉด ์ฐ๋ฆฌ๋ ๊ฐ๋ ํ ๊ฒ์
๋๋ค.
ํ๋กํ์ผ ๋ง / ์ถ์ ์ ์ํด ์ฝ๋๋ฅผ ์ค์๊ฐ์ผ๋ก ๋ค์ ๊ณ์ธก ํ ์์๋ ๊ธฐํ๊ฐ ๋ ์๊ฐ๊ณ ์์ต๋๋ค.
๊ณผ์ฐ. Ctrl-D; julia<Enter>
์ํ์ค๊ฐ ๊ฑฐ์ ๋ณ ์๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ์์ ์ ํค๋ณด๋๋ฅผ ๊ตฌ์
ํ๋ ค๊ณ ํ์ต๋๋ค. ๊ทธ๋ด ํ์๊ฐ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฆด๋ฆฌ์ค ๋
ธํธ๋ฅผ ์์ฑํ๋ ๊ฒ์ ๋ค์ ๋นํ์ค์ ์ผ ์ ์์ง๋ง, ์ดํด๋ ์ด์ collect
-ing a Generator
๋ํ ๊ตฌ๋ฌธ์ด๋ผ๋ ์ ์ ์ ์ํด์ผํฉ๋๋ค. 0.4์์?- @which
๋ ์๋ํ์ง ์์ต๋๋ค)? ์์ vchuravy์ ๋น์ทํ์ด ์์ ๋ ๊ฐ ํจ์๊ฐ ์ด์ 0.5์ ์ ํ์ด๋ผ๋ ์ ์ ๊ณ ๋ คํ๋๋ผ๋ ์ฝ๊ฐ์ ๋ฌธ์ ์
๋๋ค.
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0-rc3+0 (2016-08-22 23:43 UTC)
_/ |\__'_|_|_|\__'_| |
|__/ | x86_64-linux-gnu
julia> f(x) = 1
f (generic function with 1 method)
julia> [f(x) for x in 1:5]
5-element Array{Int64,1}:
1
1
1
1
1
julia> f(x) = 2
WARNING: Method definition f(Any) in module Main at REPL[1]:1 overwritten at REPL[3]:1.
f (generic function with 1 method)
julia> [f(x) for x in 1:5]
5-element Array{Int64,1}:
1
1
1
1
1
julia> <strong i="9">@which</strong> [f(x) for x in 1:5]
collect(itr::Base.Generator) at array.jl:295
๊ทธ๋ ์ง ์์ต๋๊น?
์์ # 265์ ์ ์ฉ
์ด๊ฒ ์ ๋ง ์์ ๋์๋์ ๐ฒ
์ด ์๋ฃจ์ ์ ์ฌ์ ํ โโ0.5.x๋ก ๋ฐฑ ํฌํธ ๋ ๊ณํ์ ๋๊น?
์๋.
@ rapus95 , ์ด๊ฒ์ ๋งค์ฐ ์นจ๋ต์ ์ธ ๋ณ๊ฒฝ์ด๋ฉฐ ์๋ชป๋๋ฉด ๋ง์ ์ฌ์ฉ์์ ์ค๋ฆฌ์๋ฅผ ๋ถ์์ ํ๊ฒ ๋ง๋ค ์ ์์ต๋๋ค. ๋ฆด๋ฆฌ์ค์ ์์ ์ ๋ง์คํฐ๋ฅผ ๋ฐ๋ฅด๋ ๊ฒ๋ณด๋ค ๋ ๋ง์ ์์ ์ฑ์ ์ ๊ณตํ๋ ๊ฒ์ด๋ฏ๋ก 0.6์ ํฌํจํ๋ ๊ฒ์ด ํจ์ฌ ์ข์ต๋๋ค. (0.6 ๋ฆด๋ฆฌ์ค ์ด์ ์ ์ํ๋ ๊ฒฝ์ฐ ์ธ์ ๋ ์ง master๋ฅผ ํ๋ก์ฐ ํ ์ ์์ต๋๋ค.)
์ด ๋ฌธ์ ์ ๋ํ ์ง์ ์ ๋ณด๊ฒ๋์ด ์ ๋ง ๊ธฐ์ฉ๋๋ค! ์ด๋ ๊ฒํ๋ฉด ์ปดํ์ผ๋ฌ๊ฐ https://groups.google.com/forum/#!topic/julia -users / OBs0fmNmjCU์ ์ค๋ช ๋ ์ฌ๋ก๋ฅผ ์ต์ ํ ํ ์ ์๋ค๋ฉด ๋๋ผ ์ธ ๊ฒ์ ๋๋ค.
์. ์ ๋ง ๋ฉ์ง ์๊ฐ์ ๋๋ค!
์๋ ํ์ธ์!
์ด ์์ ์ฌํญ์ 0.5 ์๋ฆฌ์ฆ๋ก ๋ฐฑ ํฌํธ ํ ๊ฐ๋ฅ์ฑ์ด ์์ต๋๊น? ์๋๋ฉด 0.6์ด ๋ ๋๋ง ์๋ํฉ๋๊น?
์ด๋ ์ฃผ์ ๋ณ๊ฒฝ ์ฌํญ์ด๋ฉฐ 0.6์์๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ด ์ผ๋ง๋ ๋ฉ์ง ์ง ๊ณผ์ฅํ๊ธฐ ์ด๋ ต์ต๋๋ค. ์ค๋๋ ์ต๊ด์ ์ฌํ๊ฒ ์ฃฝ๊ธฐ ๋๋ฌธ์ ๋๋๋ก ์ค๋ฆฌ์๋ฅผ ๋ถํ์ํ๊ฒ ๋ค์ ์์ํ๊ฑฐ๋ ์ฌ ๊ตฌ์ถํ์ง๋ง, ๊ธฐ์ตํ๋ฉด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ์์ด ์์ ํ ๊ฒ์ ์ฒด์ธ์ ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์. ์ ๋ง ๋ฉ์ง ์๊ฐ์ ๋๋ค!