Beam file format questions.

Happi <>
Mon Aug 26 18:04:33 CEST 2002


The exported functions you can get by:
> test:module_info(exports).
[{test,0},{this_is_a_test,1},{module_info,0},{module_info,1}]

If you want more info from the beam file you might want to look into
beam_disasm:

> beam_disasm:file(test).
{beam_file,[{exports,[{module_info,1,8},
                      {module_info,0,6},
                      {this_is_a_test,1,4},
                      {test,0,2}]},
            {imports,[]},
            {code,[[{label,1},
                    {func_info,[{atom,test},{atom,test},0]},
                    {label,2},
                    {test_heap,4,0},
                    {put_tuple,3,{x,0}},
                    {put,{atom,ok}},
                    {put,{atom,this_is_a_test}},
                    {put,{atom,google}},
                    return],
                   [{label,3},
                    {func_info,[{atom,test},{atom,this_is_a_test},1]},
                    {label,4},
                    {move,{atom,ok},{x,0}},
                    return],
                   [{label,5},
                    {func_info,[{atom,test},{atom,module_info},0]},
                    {label,6},
                    {move,nil,{x,0}},
                    return],
                   [{label,7},
                    {func_info,[{atom,test},{atom,module_info},1]},
                    {label,8},
                    {move,nil,{x,0}},
                    return]]},
            {atoms,[{1,test},
                    {2,ok},
                    {3,this_is_a_test},
                    {4,google},
                    {5,module_info}]},
            {local_funs,[]},
            {strings,[]},
            {attributes,[{vsn,[27859361916344551882987425212895222028]}]},
            {comp_info,[{options,[v3,nowarn_shadow_vars,warn_unused_vars]},
                        {version,"2002.08.14"},
                        {time,{2002,8,26,15,54,54}}]}]}


or if you have a hipe system and whant to see the beam code prettyprinted:

> hipe:c(test,[pp_beam,no_load]).
  label 1:
    {func_info,[{atom,test},{atom,test},0]}
  label 2:
    {test_heap,4,0}
    {put_tuple,3,{x,0}}
    {put,{atom,ok}}
    {put,{atom,this_is_a_test}}
    {put,{atom,google}}
    return

  label 3:
    {func_info,[{atom,test},{atom,this_is_a_test},1]}
  label 4:
    {move,{atom,ok},{x,0}}
    return

  label 5:
    {func_info,[{atom,test},{atom,module_info},0]}
  label 6:
    {move,nil,{x,0}}
    return

  label 7:
    {func_info,[{atom,test},{atom,module_info},1]}
  label 8:
    {move,nil,{x,0}}
    return

Good luck,
Erik Stenman

--------------------------------------
I'm Happi, you should be happy.
Praeterea censeo "0xCA" scribere Erlang posse.


----- Original Message -----
From: "Eric Merritt" <>
To: <>
Sent: Monday, August 26, 2002 5:46 PM
Subject: Beam file format questions.


> Hello all,
>
>  I am attempting to parse the beam files generated by
> the erlang 8-2 compiler. My purpose here is to extract
> a list of exported functions from the beam file. It is
> proving a bit interesting, overall. I looked at the
> information provided by Mr. Gustavsson here ->
>
> http://www.ericsson.com/cslab/~bjorn/beam_file_format.html
>
>  I figured it should be pretty easy to parse, but I
> ran into some difficulties.
>
> First, the 'Atom' and 'Code' chunks seem to have an
> extra two null bytes padded onto the end of thier
> chunks (beyond the length specified in the chunk
> header). The other chunks seem to obey the format
> specified in the above document. It could very well be
> that I am just a bit off in the head and missing
> something. Hopefully, one of you will confirm.
>
> Second, the 'ExpT' chunks doesn't seem too useful to
> me at all. I am exporting two functions in my test
> code, so accoring to the spec there  should be a total
> of 24 bytes (12 bytes per exported function '3*4') of
> information after the chunk header, in mine there are
> 52 bytes. I hope one of you with a little more insight
> and experience can explain where I am screwing up.
> Following is some code I am using to generate the beam
> file I am testing with, it doesn't do anything at all
> really except produce a beam file.
>
> -----------------------------------------------------
>
> -module(test).
>
> -export([test/0, this_is_a_test/1]).
>
> test() ->
> {ok, this_is_a_test, 'google'}.
>
> this_is_a_test(Ok) ->
> ok.
>
> -----------------------------------------------------
>
> Thanks,
> Eric
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
>





More information about the erlang-questions mailing list