robisonsantos / evm

Erlang Version Manager
116 stars 27 forks source link

Compile with +debug_info #21

Closed michelboaventura closed 7 years ago

michelboaventura commented 7 years ago

Hi,

I'm trying to use dialyzer with erlang 19.2 which was installed by evm, but I'm getting this error:

dialyzer --build_plt --apps erts kernel stdlib
dialyzer: Could not get abstract code for file: /home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam (please recompile it with +debug_info)

How do I tell evm to compile erlang with debug info? Thanks

robisonsantos commented 7 years ago

I'm trying to find the best way to solve your issue, but could not repro it locally.

robison@ghost:/tmp|⇒ dialyzer --build_plt --apps erts kernel stdlib
  Compiling some key modules to native code... done in 0m14.04s
  Creating PLT /home/robison/.dialyzer_plt ...
Unknown functions:
  compile:file/2
  compile:forms/2
  compile:noenv_forms/2
  compile:output_generated/1
  crypto:block_decrypt/4
  crypto:start/0
Unknown types:
  compile:option/0
 done in 0m20.07s
done (passed successfully)

Are you running evm on mac or linux?

robisonsantos commented 7 years ago

What happens if you run dialyzer --build_plt --apps erts kernel stdlib syntax_tools

michelboaventura commented 7 years ago

I'm running on Gentoo/Linux.

dialyzer --build_plt --apps erts kernel stdlib syntax_tools

dialyzer: Could not get abstract code for file: /home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam (please recompile it with +debug_info)

I'm trying evm because the erlang version installed using emerge (gentoo's package manager) gives the same error.

robisonsantos commented 7 years ago

I'll see what I can do to fix this.

On Sun, Jan 15, 2017 at 12:03 PM, Michel Boaventura < notifications@github.com> wrote:

I'm running on Gentoo/Linux.

dialyzer --build_plt --apps erts kernel stdlib syntax_tools

dialyzer: Could not get abstract code for file: /home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam (please recompile it with +debug_info)

I'm trying evm because the erlang version installed using emerge (gentoo's package manager) gives the same error.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robisonsantos/evm/issues/21#issuecomment-272719694, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHvLflfI5A70XFdMLWKBfhyMQ2CPhAfks5rSnurgaJpZM4Lj7n9 .

-- Robison W R Santos

robisonsantos commented 7 years ago

In my linux mint and mac erlang modules are compiled with debug_info by default.

Could you confirm the output of the following command:

cd /home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin
erl -noinput -eval 'io:format("~s\n", [case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of  {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";  _ -> "no" end])' -s init stop -- erlang.beam

I'll have to run an image of Gentoo to verify my fix there.

michelboaventura commented 7 years ago

Hi Robison, thanks for the help.

Your commando just prints 'yes' on my terminal.

robisonsantos commented 7 years ago

Hmm.. that means the module was compiled with debug_info.

See this:

robison@ghost:/tmp|⇒ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- test_mod.beam
no

robison@ghost:/tmp|⇒ erlc +debug_info test_mod.erl        
test_mod.erl:3: Warning: function main/0 is unused

robison@ghost:/tmp|⇒ erl -noinput -eval 'io:format("~s\n",
[case beam_lib:chunks(hd(init:get_plain_arguments()), ["Abst"]) of
    {ok,{_,[{"Abst",A}]}} when byte_size(A) /= 0 -> "yes";
    _ -> "no" end])' -s init stop -- test_mod.beam
yes
michelboaventura commented 7 years ago

I'm playing with it and found out which dialyzer function is thinking I don't have debug.

https://github.com/erlang/otp/blob/568e6b5faebf85fb35119858fcb4824f46a4266c/lib/dialyzer/src/dialyzer_plt.erl#L478

If I manually run dialyzer_utils:get_abstract_code_from_beam I get an error:

1> dialyzer_utils:get_abstract_code_from_beam("/home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam").
error
robisonsantos commented 7 years ago

I'm installing a Gentoo image to test it here. If I can reproduce, then I might be able to find a solution.

I need to read about dialyzer_utils:get_abstract_code_from_beam to know in which situation it would return error.

On Sun, Jan 15, 2017 at 2:02 PM, Michel Boaventura <notifications@github.com

wrote:

I'm playing with it and found out which dialyzer function is thinking I don't have debug.

https://github.com/erlang/otp/blob/568e6b5faebf85fb35119858fcb482 4f46a4266c/lib/dialyzer/src/dialyzer_plt.erl#L478

If I manually run dialyzer_utils:get_abstract_code_from_beam I get an error:

1> dialyzer_utils:get_abstract_code_from_beam("/home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam").error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robisonsantos/evm/issues/21#issuecomment-272727437, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHvLTqQyj-dMF7SWmPkowfW4YTWDddkks5rSpdwgaJpZM4Lj7n9 .

-- Robison W R Santos

michelboaventura commented 7 years ago

Thanks!

Going further it seems the error is being caused by beam_lib:chunks

1> beam_lib:chunks("/home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam", [abstract_code]).
{error,beam_lib,                                                                                                                                                                               
       {invalid_chunk,"/home/michel/.evm/erlang_versions/otp_src_19.2/lib/erlang/lib/erts-8.2/ebin/erlang.beam",                                                                               
                      "Abst"}}
robisonsantos commented 7 years ago

I installed erlang 19.2 in a Gentoo image and was still not able to reproduce. Did you pass any parameter to evm install when installing this version in your distro ?

robisonsantos commented 7 years ago

I can try building an evm version for you to force building with debug, but without a place to verify, you'll have to test it for me.

michelboaventura commented 7 years ago

I've cleaned everything related with erlang and the problem persists. I'm compiling now 18.3 do see if this still happens. You can tell me what to do to try to force debug and I will try here. I've looked at the options from the configure script but couldn't find anything.

robisonsantos commented 7 years ago

Ok,

Lets try a few things:

Edit your $HOME/.evm/scripts/evm Look for evm_install and add the following after the line that says: echo "Compiling and installing $1"

    echo ">>>>>>> DEBUG"
    cd erts/emulator
    ERL_TOP=$UNTAR_DIR make FLAVOR=plain
    export ERLC_OPTS="-Werror +debug_info"
    cd -
    echo ">>>>>>> END DEBUG"

load the script again: source $HOME/.evm/scripts/evm Uninstall and install the erlang again: evm uninstall 19.2 && evm install 19.2 -y

If that still does not work, change the FLAVOR=plain with TYPE=debug and try again. Let me know if that fix the issue.

michelboaventura commented 7 years ago

@robisonsantos, none of the options worked. I've also downloaded the source from erlang and tried to compile by hand. It yields the same problem, so I think something may be wrong with my Gentoo which has nothing to do with evm. I will play with the source during the week and update you of any changes. Thank you for the help!

michelboaventura commented 7 years ago

@robisonsantos, this issue was deeper than we thought. After the help of erlang mailing lists we figure out the problem has to do with newer zlib's versions which became more strict on error checking and therefore "created" a bug on erlang's code (which where wrong). You can see the details here: http://erlang.org/pipermail/erlang-questions/2017-January/091452.html

I'm closing this issue, since it has nothing to do with evm. Thank you for the help.

darthdeus commented 7 years ago

This might be a silly question, but how do I tell if my local install is actually missing the +debug_info flag, or if it's a bug due to zlib?

Never mind my above comment, I downgraded zlib to an older version and everything is working out wonderfully.