1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>beam_lib</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>beam_lib</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
beam_lib</UL>
<H3>MODULE SUMMARY</H3>
<UL>
An interface to the BEAM file format</UL>
<H3>DESCRIPTION</H3>
<UL>
<P><CODE>beam_lib</CODE> provides an interface to files
created by the BEAM compiler ("BEAM files"). The format used,
a variant of "EA IFF 1985" Standard for Interchange Format Files,
divides data into chunks.
<P>Chunk data can be returned as binaries or as compound terms.
Compound terms are returned when chunks are referenced by names
(atoms) rather than identifiers (strings). The names recognized
and the corresponding identifiers are <CODE>abstract_code</CODE>
("Abst"), <CODE>attributes</CODE> ("Attr"), <CODE>exports</CODE> ("ExpT"),
<CODE>labeled_exports</CODE> ("ExpT"), <CODE>imports</CODE> ("ImpT"),
<CODE>locals</CODE> ("LocT"), <CODE>labeled_locals</CODE> ("LocT"), and
<CODE>atoms</CODE> ("Atom").
<P>The syntax of the compound term (<CODE>ChunkData</CODE>) is as follows:
<P><UL>
<LI><CODE>ChunkData = {ChunkId, binary()}
| {abstract_code, AbstractCode}
| {attributes, [{Attribute, [AttributeValue]}]}
| {exports, [{Function, Arity}]}
| {labeled_exports, [{Function, Arity, Label}]}
| {imports, [{Module, Function, Arity}]}
| {locals, [{Function, Arity}]}]}
| {labeled_locals, [{Function, Arity, Label}]}]}
| {atoms, [{integer(), atom()}]}</CODE>
<BR>
</LI><BR>
<LI><CODE>ChunkRef = ChunkId | ChunkName</CODE>
<BR>
</LI><BR>
<LI><CODE>ChunkName = abstract_code | attributes | exports
| imports | locals</CODE>
<BR>
</LI><BR>
<LI><CODE>ChunkId = string()</CODE>
<BR>
</LI><BR>
<LI><CODE>AbstractCode = {AbstVersion, forms()}
| no_abstract_code</CODE>
<BR>
</LI><BR>
<LI><CODE>AbstVersion = atom()</CODE>
<BR>
</LI><BR>
<LI><CODE>Attribute = atom()</CODE>
<BR>
</LI><BR>
<LI><CODE>AttributeValue = term()</CODE>
<BR>
</LI><BR>
<LI><CODE>Module = Function = atom()</CODE>
<BR>
</LI><BR>
<LI><CODE>Arity = integer() >= 0</CODE>
<BR>
</LI><BR>
<LI><CODE>Label = integer() >= 0</CODE>
<BR>
</LI><BR>
</UL>
<P>The list of attributes is sorted on <CODE>Attribute</CODE>, and
each attribute name occurs once in the list. The attribute
values occur in the same order as on the file. The lists of
functions are also sorted. It is not checked that the forms
conform to the abstract format indicated by <CODE>AbstVersion</CODE>.
<P><CODE>no_abstract_code</CODE> means that the "Abst" chunk is present,
but empty.
<P>Each of the functions described below accept either
a filename or a binary containing a beam module.
</UL>
<H3>EXPORTS</H3>
<P><A NAME="chunks%2"><STRONG><CODE>chunks(FileNameOrBinary, [ChunkRef]) ->
{ok, {Module, [ChunkData]}} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>FileNameOrBinary = string() | atom() | binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = {unknown_chunk, FileName, atom()}
| - see info/1 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>chunks/2</CODE> function reads chunk data for selected
chunks. The order of the returned list of chunk data is determined
by the order of the list of chunks references; if each
chunk data were replaced by the tag, the result would be the
given list.
</UL>
<P><A NAME="version%1"><STRONG><CODE>version(FileNameOrBinary) ->
{ok, {Module, Version}} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>FileNameOrBinary = string() | atom() | binary()</CODE></STRONG><BR>
<STRONG><CODE>Version = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see chunks/2 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>version/1</CODE> function returns the module version(s)
found in a BEAM file.
</UL>
<P><A NAME="info%1"><STRONG><CODE>info(FileNameOrBinary) ->
[SourceRef, {module, Module}, {chunks, [ChunkInfo]}]
| {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>FileName = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>FileNameOrBinary = FileName | binary()</CODE></STRONG><BR>
<STRONG><CODE>SourceRef = {file, FileName} | {binary, binary()}</CODE></STRONG><BR>
<STRONG><CODE>ChunkInfo = {ChunkId, StartPosition, Size}</CODE></STRONG><BR>
<STRONG><CODE>StartPosition = integer() > 0</CODE></STRONG><BR>
<STRONG><CODE>Size = integer() >= 0</CODE></STRONG><BR>
<STRONG><CODE>Reason = {chunk_too_big, FileName, ChunkId, ChunkSize, FileSize}
| {invalid_beam_file, FileName, FilePosition}
| {invalid_chunk, FileName, ChunkId}
| {missing_chunk, FileName, ChunkId}
| {not_a_beam_file, FileName}
| {file_error, FileName, FileError}
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>info/1</CODE> function extracts some information about
a BEAM file: the file name, the module name, and
for each chunk the identifier as well as the position and size
in bytes of the chunk data.
</UL>
<P><A NAME="cmp%2"><STRONG><CODE>cmp(FileNameOrBinary, FileNameOrBinary) ->
ok | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>FileName = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>FileNameOrBinary = FileName | binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = {modules_different, Module, Module}
| {chunks_different, ChunkId}
| - see info/1 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>cmp/2</CODE> function compares the contents of two BEAM
files. If the module names are the same, and the chunks with
the identifiers "Code", "ExpT", "ImpT", "StrT", and "Atom"
have the same contents in both files, <CODE>ok</CODE> is
returned. Otherwise an error message is returned.
</UL>
<P><A NAME="cmp_dirs%2"><STRONG><CODE>cmp_dirs(Directory1, Directory2) ->
{Only1, Only2, Different} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Directory1 = Directory2 = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Different = [{FileName1, FileName2}]</CODE></STRONG><BR>
<STRONG><CODE>Only1 = Only2 = [FileName]</CODE></STRONG><BR>
<STRONG><CODE>FileName = FileName1 = FileName2 = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see info/1 -</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>cmp_dirs/2</CODE> function compares the BEAM files in
two directories. Only files with extension ".beam" are
compared. BEAM files that exist in directory
<CODE>Directory1</CODE> (<CODE>Directory2</CODE>) only are returned in
<CODE>Only1</CODE> (<CODE>Only2</CODE>). BEAM files that exist on both
directories but are considered different by <CODE>cmp/2</CODE> are
returned as pairs {<CODE>FileName1</CODE>, <CODE>FileName2</CODE>} where
<CODE>FileName1</CODE> (<CODE>FileName2</CODE>) exists in directory
<CODE>Directory1</CODE> (<CODE>Directory2</CODE>).
</UL>
<P><A NAME="diff_dirs%2"><STRONG><CODE>diff_dirs(Directory1, Directory2) ->
ok | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Directory1 = Directory2 = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see info/1 -</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>diff_dirs/2</CODE> function compares the BEAM files in
two directories the way <CODE>cmp_dirs/2</CODE> does, but names of
files that exist in only one directory or are different are
presented on standard output.
</UL>
<P><A NAME="strip%1"><STRONG><CODE>strip(FileNameOrBinary) ->
{ok, {Module, FileNameOrBinary}} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>FileName = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>FileNameOrBinary = FileName | binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see info/1 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>strip/1</CODE> function removes all chunks from a BEAM
file except those needed by the loader. In particular, the
abstract code is removed. The module name found in the file
and the file name, possibly with the ".beam" extension
added, are returned.
</UL>
<P><A NAME="strip_files%1"><STRONG><CODE>strip_files(Files) ->
{ok, [{Module, FileNameOrBinary]}} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Files = [FileNameOrBinary]</CODE></STRONG><BR>
<STRONG><CODE>FileName = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>FileNameOrBinary = FileName | binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see info/1 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>strip_files/1</CODE> function removes all chunks except
those needed by the loader from BEAM files. In particular,
the abstract code is removed. The returned list contains one
element for each given file name, ordered as the given
list. The list element is a pair of the module name found in
the file and the file name, the latter possibly with the
".beam" extension added.
</UL>
<P><A NAME="strip_release%1"><STRONG><CODE>strip_release(Directory) ->
{ok, [{Module, FileName]}} | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Directory = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>FileName = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = - see info/1 -
</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>The <CODE>strip_release/1</CODE> function removes all chunks
except those needed by the loader from the BEAM files of a
release. <CODE>Directory</CODE> should be the installation root
directory. For example, the current OTP release can be
stripped with the call
<CODE>beam_lib:strip_release(code:root_dir())</CODE>. The returned
list contains module names and file names of stripped files.
</UL>
<P><A NAME="format_error%1"><STRONG><CODE>format_error(Error) -> character_list()</CODE></STRONG></A><BR>
<UL>
<P>Given the error returned by any function in this module,
the function <CODE>format_error</CODE> returns a descriptive string
of the error in English. For file errors, the function
<CODE>format_error/1</CODE> in the <CODE>file</CODE> module is called.
</UL>
<H3>AUTHORS</H3>
<UL>
Hans Bolinder - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright © 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>
|