Beam files, module beam_lib and source code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

Robert Virding-4
Try:

> {ok, {_,[{_,{_,Forms}}]}} = beam_lib:chunks(YourBeamFile,[abstract_code]).
...
> lists:foreach(fun(F) -> io:put_chars(user,[erl_pp:form(F),"\n"]) end, Forms).

<Your erlang program will be written out>

To help the debugger the source code in abstract form can be included in
the beam file.  Unfortunately the default is to include it.  Giving
the option 'no_debug_info' causes the compiler to not include the code.

While it is very nice to have a debugger I don't think source should be
included as default.  Here is a little patch to compile.erl which
inverts this behaviour, the default is to NOT include the source and you
must give the option 'debug_info' to include source.

*** compile.erl~        Wed Jan 24 14:40:36 2001
--- compile.erl Wed Jan 24 15:05:16 2001
***************
*** 335,341 ****
       {iff,dexp,{listing,"expand"}},
       {iff,'E',{src_listing,"E"}},
       {iff,'abstr',{listing,"abstr"}},
!      {unless,no_debug_info,?pass(save_abstract_code)},
 
       %% Core Erlang passes.
       {pass,v3_core},
--- 335,341 ----
       {iff,dexp,{listing,"expand"}},
       {iff,'E',{src_listing,"E"}},
       {iff,'abstr',{listing,"abstr"}},
!      {iff,debug_info,?pass(save_abstract_code)},
 
       %% Core Erlang passes.
       {pass,v3_core},

Apply the patch to lib/compiler/src/compile.erl and remake.

        Robert




Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

Vance Shipley-2

Robert Virding writes:
}
} While it is very nice to have a debugger I don't think source should be
} included as default.

This is very suprising behaviour indeed.  As someone who bases
commercial products on Erlang/OTP I obviously immediately reversed
this behaviour in our build environment.

        -Vance


Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

Robert Virding-4
Adding the fix for compile.erl which I posted a few weeks back to change
the default behavior for debug_info in .beam files will not affect all
the libraries built when building the system.  However, if size is
important then replace bootstrap/lib/compiler-3.0.1/ebin/compile.beam
with a modified compile.beam.  Next time the release is built then all
the libraries will be stripped.  This saves about 40% of the size of
the system.

        Robert





Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

David Gould-2
On Thu, Feb 01, 2001 at 01:32:05PM +0100, Robert Virding wrote:
> Adding the fix for compile.erl which I posted a few weeks back to change
> the default behavior for debug_info in .beam files will not affect all
> the libraries built when building the system.  However, if size is
> important then replace bootstrap/lib/compiler-3.0.1/ebin/compile.beam
> with a modified compile.beam.  Next time the release is built then all
> the libraries will be stripped.  This saves about 40% of the size of
> the system.

Seems like it should be simple to write a tool to strip a beam file, maybe
even the basis of one was posted a while back. Or am I missing something?

-dg
 

--
David Gould                davidg               510 536 1443
If simplicity worked, the world would be overrun with insects.


Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

Robert Virding-4
David Gould <davidg> writes:

>On Thu, Feb 01, 2001 at 01:32:05PM +0100, Robert Virding wrote:
>> Adding the fix for compile.erl which I posted a few weeks back to change
>> the default behavior for debug_info in .beam files will not affect all
>> the libraries built when building the system.  However, if size is
>> important then replace bootstrap/lib/compiler-3.0.1/ebin/compile.beam
>> with a modified compile.beam.  Next time the release is built then all
>> the libraries will be stripped.  This saves about 40% of the size of
>> the system.
>
>Seems like it should be simple to write a tool to strip a beam file, maybe
>even the basis of one was posted a while back. Or am I missing something?

Yes, of course, it would be quite easy to write one.  My main point was
that I think the default should be to NOT include the debug info (which
is in fact the complete source code) and have the user add it when
needed.

The fix I sent out did this, and the second message just said how to
get this behaviour when building the system.

Now, maybe, even if you have the fix you would like to build the system
with all the debug info.  There should definitely
be a config flag for this, but the default should be off. IMAO

        Robert




Reply | Threaded
Open this post in threaded view
|

Beam files, module beam_lib and source code

David Gould-2
On Wed, Feb 14, 2001 at 11:59:53AM +0100, Robert Virding wrote:

> David Gould <davidg> writes:
> >On Thu, Feb 01, 2001 at 01:32:05PM +0100, Robert Virding wrote:
> >> Adding the fix for compile.erl which I posted a few weeks back to change
> >> the default behavior for debug_info in .beam files will not affect all
> >> the libraries built when building the system.  However, if size is
> >> important then replace bootstrap/lib/compiler-3.0.1/ebin/compile.beam
> >> with a modified compile.beam.  Next time the release is built then all
> >> the libraries will be stripped.  This saves about 40% of the size of
> >> the system.
> >
> >Seems like it should be simple to write a tool to strip a beam file, maybe
> >even the basis of one was posted a while back. Or am I missing something?
>
> Yes, of course, it would be quite easy to write one.  My main point was
> that I think the default should be to NOT include the debug info (which
> is in fact the complete source code) and have the user add it when
> needed.

Right. I didn't mean to dispute that the default should be off, I was just
thinking about stripping an existing build without rebuilding it....

-dg

--
David Gould                davidg               510 536 1443
If simplicity worked, the world would be overrun with insects.