#StackBounty: #erlang #elixir Pretty-print Elixir source code from Dbgi chunk

Bounty: 500

If I have a beam file compiled from Erlang code with debug_info, printing the corresponding source code is fairly easy:

{ok, {_, [{debug_info, {debug_info_v1, erl_abstract_code, AbstractCode}}]}} =
    beam_lib:chunks("my_module.beam", [debug_info]).
{ok, Forms} = erl_abstract_code:debug_info(erlang_v1, module_name, AbstractCode, []).
io:format("~s~n", [erl_prettypr:format(erl_syntax:form_list(Forms))]).

But what about Elixir? I can do the first two steps like this:

{ok, {_, [{debug_info, {debug_info_v1, elixir_erl, AbstractCode}}]}} = 
    beam_lib:chunks("Elixir.MyModule.beam", [debug_info]).
{ok, Forms} = elixir_erl:debug_info(elixir_v1, module_name, AbstractCode).

This gives a map of this form:

#{attributes => ...,
  compile_opts => [],
  definitions => ...,
  deprecated => [],
  file => <<"my_module.ex">>,
  line => 95,
  module => 'Elixir.MyModule',
  unreachable => []}

How do I print that as human-readable Elixir code?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.