[erlang-questions] Help with erl_parse / epp

Brian Candler B.Candler@REDACTED
Fri Dec 11 10:57:43 CET 2009


On Thu, Dec 10, 2009 at 08:52:21AM -0800, Jacob Vorreuter wrote:
> You can check out my EUC presentation if you're interested in this kind of
> stuff: http://jacobvorreuter.com/hacking-erlang-at-euc-2009

This is very helpful, thank you. I also discovered erl_pp - it's cool to be
able to take your "dingbats" language and turn it back into erlang source :-)

I have one more question if you don't mind.

In the documentation of the abstract form, it says that if a module is
compiled with debug_info, the abstract form is available as a "chunk" named
abstract_code. Is it possible to get at this at runtime, after a module has
been loaded?

I found beam_lib:chunks, but I have only been able to get it to work with
the beam *file* rather than the loaded module.

7> l(rfe_cmd).
{module,rfe_cmd}
8> beam_lib:chunks(rfe_cmd, [abstract_code]).
{error,beam_lib,{file_error,"rfe_cmd.beam",enoent}}
9> beam_lib:version(rfe_cmd).
{error,beam_lib,{file_error,"rfe_cmd.beam",enoent}}

Clearly, it's trying to read from the beam file, As it happens, the beam
file is under ebin/, which is in my -pa(th). It works if I give the full
filename:

10> beam_lib:chunks("ebin/rfe_cmd.beam", [abstract_code]).

But is it possible to get this chunk from the from the loaded module, or is
it too late by that stage?

BTW, I am running R13B01 as packaged by Ubuntu Karmic.

Thanks,

Brian.


More information about the erlang-questions mailing list