File: beam_lib.html

package info (click to toggle)
erlang-doc-html 1%3A8.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 18,028 kB
  • ctags: 7,419
  • sloc: perl: 1,841; ansic: 323; erlang: 155
file content (293 lines) | stat: -rw-r--r-- 11,143 bytes parent folder | download
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 (&#34;BEAM files&#34;). The format used,
a variant of &#34;EA IFF 1985&#34; 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>
(&#34;Abst&#34;), <CODE>attributes</CODE> (&#34;Attr&#34;), <CODE>exports</CODE> (&#34;ExpT&#34;),
<CODE>labeled_exports</CODE> (&#34;ExpT&#34;), <CODE>imports</CODE> (&#34;ImpT&#34;),
<CODE>locals</CODE> (&#34;LocT&#34;), <CODE>labeled_locals</CODE> (&#34;LocT&#34;), and
<CODE>atoms</CODE> (&#34;Atom&#34;).

<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() &#62;= 0</CODE>
         <BR>
</LI><BR>
<LI><CODE>Label = integer() &#62;= 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 &#34;Abst&#34; 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]) -&#62; 
{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()}
         | -&#160;see info/1&#160;-
        </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) -&#62; 
{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 = -&#160;see chunks/2&#160;-
</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) -&#62; 
[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() &#62; 0</CODE></STRONG><BR>
<STRONG><CODE>Size = integer() &#62;= 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) -&#62; 
         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}
         | -&#160;see info/1&#160;-
        </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 &#34;Code&#34;, &#34;ExpT&#34;, &#34;ImpT&#34;, &#34;StrT&#34;, and &#34;Atom&#34;
         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) -&#62; 
{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 = -&#160;see info/1&#160;-</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 &#34;.beam&#34; 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) -&#62; 
ok | {error, Module, Reason}
</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Directory1 = Directory2 = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason = -&#160;see info/1&#160;-</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) -&#62; 
{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 = -&#160;see info/1&#160;-
        </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 &#34;.beam&#34; extension
         added, are returned.
</UL>
<P><A NAME="strip_files%1"><STRONG><CODE>strip_files(Files) -&#62; 
{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 = -&#160;see info/1&#160;-
        </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
         &#34;.beam&#34; extension added.
</UL>
<P><A NAME="strip_release%1"><STRONG><CODE>strip_release(Directory) -&#62; 
{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 = -&#160;see info/1&#160;-
        </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) -&#62; 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 &copy; 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>