I found beam_lib
in stdlib and tried the following.
I want to see the bytecode of function main
. There’s a chunk code
, how to disassembly it? I can’t find related functions in beam_lib
.
% foo.erl
-module(foo).
-record(person, {name, age}).
main()->
Person=#person{name=yama, age=17},
name=Person#person.name.
$ erl
> begin c("foo.erl"), beam_lib:info(foo) end.
[{file,"foo.beam"},
{module,foo},
{chunks,[{"AtU8",20,43},
{"Code",72,56},
{"StrT",136,0},
{"ImpT",144,28},
{"ExpT",180,28},
{"Meta",216,45},
{"LocT",272,4},
{"Attr",284,39},
{"CInf",332,80},
{"Dbgi",420,46},
{"Line",476,20},
{"Type",504,10}]}]
> beam_lib:chunks(foo, ["Code"]).
{ok,{foo,[{"Code",
<<0,0,0,16,0,0,0,0,0,0,0,171,0,0,0,5,0,0,0,2,1,16,...>>}]}}