1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
33
<modulesummary>Interpreter Interface</modulesummary>
35
<p>The Erlang interpreter provides mechanisms for breakpoints and
36
stepwise execution of code. It is mainly intended to be used by
37
the <em>Debugger</em>, see Debugger User's Guide and
38
<c>debugger(3)</c>.</p>
40
<p>From the shell, it is possible to:</p>
42
<item>Specify which modules should be interpreted.</item>
43
<item>Specify breakpoints.</item>
44
<item>Monitor the current status of all processes executing code
45
in interpreted modules, also processes at other Erlang nodes.
49
<p>By <em>attaching to</em> a process executing interpreted code, it
50
is possible to examine variable bindings and order stepwise
51
execution. This is done by sending and receiving information
52
to/from the process via a third process, called the meta process.
53
It is possible to implement your own attached process. See
54
<c>int.erl</c> for available functions and <c>dbg_ui_trace.erl</c>
55
for possible messages.</p>
57
<p>The interpreter depends on the Kernel, STDLIB and GS
58
applications, which means modules belonging to any of these
59
applications are not allowed to be interpreted as it could lead
60
to a deadlock or emulator crash. This also applies to modules
61
belonging to the Debugger application itself.</p>
65
<title>Breakpoints</title>
67
<p>Breakpoints are specified on a line basis. When a process
68
executing code in an interpreted module reaches a breakpoint, it
69
will stop. This means that that a breakpoint must be set at an
70
executable line, that is, a line of code containing an executable
73
<p>A breakpoint have a status, a trigger action and may have a
74
condition associated with it. The status is either <em>active</em>
75
or <em>inactive</em>. An inactive breakpoint is ignored. When a
76
breakpoint is reached, the trigger action specifies if
77
the breakpoint should continue to be active (<em>enable</em>), if
78
it should become inactive (<em>disable</em>), or if it should be
79
removed (<em>delete</em>). A condition is a tuple
80
<c>{Module,Name}</c>. When the breakpoint is reached,
81
<c>Module:Name(Bindings)</c> is called. If this evaluates to
82
<c>true</c>, execution will stop. If this evaluates to
83
<c>false</c>, the breakpoint is ignored. <c>Bindings</c> contains
84
the current variable bindings, use <c>get_binding</c> to retrieve
85
the value for a given variable.</p>
87
<p>By default, a breakpoint is active, has trigger action
88
<c>enable</c> and has no condition associated with it. For more
89
detailed information about breakpoints, refer to Debugger User's
95
<name>i(AbsModule) -> {module,Module} | error</name>
96
<name>i(AbsModules) -> ok</name>
97
<name>ni(AbsModule) -> {module,Module} | error</name>
98
<name>ni(AbsModules) -> ok</name>
99
<fsummary>Interpret a module</fsummary>
101
<v>AbsModules = [AbsModule]</v>
102
<v>AbsModule = Module | File | [Module | File]</v>
103
<v> Module = atom()</v>
104
<v> File = string()</v>
107
<p>Interprets the specified module(s). <c>i/1</c> interprets
108
the module only at the current node. <c>ni/1</c> interprets
109
the module at all known nodes.</p>
111
<p>A module may be given by its module name (atom) or by its
112
file name. If given by its module name, the object code
113
<c>Module.beam</c> is searched for in the current path.
114
The source code <c>Module.erl</c> is searched for first in
115
the same directory as the object code, then in a <c>src</c>
116
directory next to it.</p>
118
<p>If given by its file name, the file name may include a path
119
and the <c>.erl</c> extension may be omitted. The object code
120
<c>Module.beam</c> is searched for first in the same directory
121
as the source code, then in an <c>ebin</c> directory next to
122
it, and then in the current path.</p>
125
<p>The interpreter needs both the source code and the object
126
code, and the object code <em>must</em> include debug
127
information. That is, only modules compiled with the option
128
<c>debug_info</c> set can be interpreted.</p>
131
<p>The functions returns <c>{module,Module}</c> if the module
132
was interpreted, or <c>error</c> if it was not.</p>
134
<p>The argument may also be a list of modules/file names, in
135
which case the function tries to interpret each module as
136
specified above. The function then always returns <c>ok</c>,
137
but prints some information to stdout if a module could not be
143
<name>n(AbsModule) -> ok</name>
144
<name>nn(AbsModule) -> ok</name>
145
<fsummary>Stop interpreting a module</fsummary>
147
<v>AbsModule = Module | File | [Module | File]</v>
148
<v> Module = atom()</v>
149
<v> File = string()</v>
152
<p>Stops interpreting the specified module. <c>n/1</c> stops
153
interpreting the module only at the current node. <c>nn/1</c>
154
stops interpreting the module at all known nodes.</p>
156
<p>As for <c>i/1</c> and <c>ni/1</c>, a module may be given by
157
either its module name or its file name.</p>
162
<name>interpreted() -> [Module]</name>
163
<fsummary>Get all interpreted modules</fsummary>
165
<v>Module = atom()</v>
168
<p>Returns a list with all interpreted modules.</p>
173
<name>file(Module) -> File | {error,not_loaded}</name>
174
<fsummary>Get the file name for an interpreted module</fsummary>
176
<v>Module = atom()</v>
177
<v>File = string()</v>
180
<p>Returns the source code file name <c>File</c> for an
181
interpreted module <c>Module</c>.</p>
186
<name>interpretable(AbsModule) -> true | {error,Reason}</name>
187
<fsummary>Check if a module is possible to interpret</fsummary>
189
<v>AbsModule = Module | File</v>
190
<v> Module = atom()</v>
191
<v> File = string()</v>
192
<v>Reason = no_src | no_beam | no_debug_info | badarg
194
<v> App = atom()</v>
197
<p>Checks if a module is possible to interpret. The module can
198
be given by its module name <c>Module</c> or its source file
199
name <c>File</c>. If given by a module name, the module is
200
searched for in the code path.</p>
202
<p>The function returns <c>true</c> if both source code and
203
object code for the module is found, the module has been
204
compiled with the option <c>debug_info</c> set and does not
205
belong to any of the applications Kernel, STDLIB, GS or
208
<p>The function returns <c>{error,Reason}</c> if the module for
209
some reason is not possible to interpret.</p>
211
<p><c>Reason</c> is <c>no_src</c> if no source code is found or
212
<c>no_beam</c> if no object code is found. It is assumed that
213
the source- and object code are located either in the same
214
directory, or in <c>src</c> and <c>ebin</c> directories next
217
<p><c>Reason</c> is <c>no_debug_info</c> if the module has not
218
been compiled with the option <c>debug_info</c> set.</p>
220
<p><c>Reason</c> is <c>badarg</c> if <c>AbsModule</c> is not
221
found. This could be because the specified file does not
222
exist, or because <c>code:which/1</c> does not return a
223
beam file name, which is the case not only for non-existing
224
modules but also for modules which are preloaded or cover
227
<p><c>Reason</c> is <c>{app,App}</c> where <c>App</c> is
228
<c>kernel</c>, <c>stdlib</c>, <c>gs</c> or <c>debugger</c> if
229
<c>AbsModule</c> belongs to one of these applications.</p>
231
<p>Note that the function can return <c>true</c> for a module
232
which in fact is not interpretable in the case where
233
the module is marked as sticky or resides in a directory
234
marked as sticky, as this is not discovered until
235
the interpreter actually tries to load the module.</p>
240
<name>auto_attach() -> false | {Flags,Function}</name>
241
<name>auto_attach(false)</name>
242
<name>auto_attach(Flags, Function)</name>
243
<fsummary>Get/set when and how to attach to a process</fsummary>
245
<v>Flags = [init | break | exit]</v>
246
<v>Function = {Module,Name,Args}</v>
247
<v> Module = Name = atom()</v>
248
<v> Args = [term()]</v>
251
<p>Gets and sets when and how to automatically attach to a
252
process executing code in interpreted modules. <c>false</c>
253
means never automatically attach, this is the default.
254
Otherwise automatic attach is defined by a list of flags and
255
a function. The following flags may be specified:</p>
257
<item><c>init</c> - attach when a process for the very first
258
time calls an interpreted function.</item>
259
<item><c>break</c> - attach whenever a process reaches a
261
<item><c>exit</c> - attach when a process terminates.</item>
264
<p>When the specified event occurs, the function <c>Function</c>
265
will be called as:</p>
267
spawn(Module, Name, [Pid | Args])
269
<p><c>Pid</c> is the pid of the process executing interpreted
275
<name>stack_trace() -> Flag</name>
276
<name>stack_trace(Flag)</name>
277
<fsummary>Get/set if and how to save call frames</fsummary>
279
<v>Flag = all | no_tail | false</v>
282
<p>Gets and sets how to save call frames in the stack. Saving
283
call frames makes it possible to inspect the call chain of a
284
process, and is also used to emulate the stack trace if an
285
error (an exception of class error) occurs.</p>
287
<item><c>all</c> - save information about all current calls,
288
that is, function calls that have not yet returned a value.
289
This is the default.</item>
290
<item><c>no_tail</c> - save information about current calls,
291
but discard previous information when a tail recursive call
292
is made. This option consumes less memory and may be
293
necessary to use for processes with long lifetimes and many
294
tail recursive calls.</item>
295
<item><c>false</c> - do not save any information about current
302
<name>break(Module, Line) -> ok | {error,break_exists}</name>
303
<fsummary>Create a breakpoint</fsummary>
305
<v>Module = atom()</v>
309
<p>Creates a breakpoint at <c>Line</c> in <c>Module</c>.</p>
314
<name>delete_break(Module, Line) -> ok</name>
315
<fsummary>Delete a breakpoint</fsummary>
317
<v>Module = atom()</v>
321
<p>Deletes the breakpoint located at <c>Line</c> in
327
<name>break_in(Module, Name, Arity) -> ok
328
| {error,function_not_found}</name>
329
<fsummary>Create breakpoints in the specified function</fsummary>
331
<v>Module = Name = atom()</v>
335
<p>Creates a breakpoint at the first line of every clause of
336
the <c>Module:Name/Arity</c> function.</p>
341
<name>del_break_in(Module, Name, Arity) -> ok
342
| {error,function_not_found}</name>
343
<fsummary>Delete breakpoints from the specified function
346
<v>Module = Name = atom()</v>
350
<p>Deletes the breakpoints at the first line of every clause of
351
the <c>Module:Name/Arity</c> function.
357
<name>no_break() -> ok</name>
358
<name>no_break(Module) -> ok</name>
359
<fsummary>Delete all breakpoints</fsummary>
361
<p>Deletes all breakpoints, or all breakpoints in <c>Module</c>.
367
<name>disable_break(Module, Line) -> ok</name>
368
<fsummary>Make a breakpoint inactive</fsummary>
370
<v>Module = atom()</v>
374
<p>Makes the breakpoint at <c>Line</c> in <c>Module</c>
380
<name>enable_break(Module, Line) -> ok</name>
381
<fsummary>Make a breakpoint active</fsummary>
383
<v>Module = atom()</v>
387
<p>Makes the breakpoint at <c>Line</c> in <c>Module</c> active.
393
<name>action_at_break(Module, Line, Action) -> ok</name>
394
<fsummary>Set the trigger action of a breakpoint</fsummary>
396
<v>Module = atom()</v>
398
<v>Action = enable | disable | delete</v>
401
<p>Sets the trigger action of the breakpoint at <c>Line</c> in
402
<c>Module</c> to <c>Action</c>.</p>
407
<name>test_at_break(Module, Line, Function) -> ok</name>
408
<fsummary>Set the conditional test of a breakpoint</fsummary>
410
<v>Module = atom()</v>
412
<v>Function = {Module,Name}</v>
413
<v> Name = atom()</v>
416
<p>Sets the conditional test of the breakpoint at <c>Line</c> in
417
<c>Module</c> to <c>Function</c>. The function must
418
fulfill the requirements specified in the section
419
<em>Breakpoints</em> above.</p>
424
<name>get_binding(Var, Bindings) -> {value,Value} | unbound</name>
425
<fsummary>Retrieve a variable binding</fsummary>
428
<v>Bindings = term()</v>
429
<v>Value = term()</v>
432
<p>Retrieves the binding of <c>Var</c>. This function is
433
intended to be used by the conditional function of a
439
<name>all_breaks() -> [Break]</name>
440
<name>all_breaks(Module) -> [Break]</name>
441
<fsummary>Get all breakpoints</fsummary>
443
<v>Break = {Point,Options}</v>
444
<v> Point = {Module,Line}</v>
445
<v> Module = atom()</v>
446
<v> Line = int()</v>
447
<v> Options = [Status,Trigger,null,Cond|]</v>
448
<v> Status = active | inactive</v>
449
<v> Trigger = enable | disable | delete</v>
450
<v> Cond = null | Function</v>
451
<v> Function = {Module,Name}</v>
452
<v> Name = atom()</v>
455
<p>Gets all breakpoints, or all breakpoints in <c>Module</c>.
461
<name>snapshot() -> [Snapshot]</name>
462
<fsummary>Get information about all processes excuting interpreted
465
<v>Snapshot = {Pid, Function, Status, Info}</v>
466
<v> Pid = pid()</v>
467
<v> Function = {Module,Name,Args}</v>
468
<v> Module = Name = atom()</v>
469
<v> Args = [term()]</v>
470
<v> Status = idle | running | waiting | break | exit
472
<v> Info = {} | {Module,Line} | ExitReason</v>
473
<v> Line = int()</v>
474
<v> ExitReason = term()</v>
477
<p>Gets information about all processes executing interpreted code.
480
<item><c>Pid</c> - process identifier.</item>
481
<item><c>Function</c> - first interpreted function called by
483
<item><c>Status</c> - current status of the process.</item>
484
<item><c>Info</c> - additional information.</item>
486
<p><c>Status</c> is one of:</p>
488
<item><c>idle</c> - the process is no longer executing
489
interpreted code. <c>Info={}</c>.</item>
490
<item><c>running</c> - the process is running. <c>Info={}</c>.
492
<item><c>waiting</c> - the process is waiting at a
493
<c>receive</c>. <c>Info={}</c>.</item>
494
<item><c>break</c> - process execution has been stopped,
495
normally at a breakpoint. <c>Info={Module,Line}</c>.</item>
496
<item><c>exit</c> - the process has terminated.
497
<c>Info=ExitReason</c>.</item>
498
<item><c>no_conn</c> - the connection is down to the node
499
where the process is running. <c>Info={}</c>.</item>
505
<name>clear() -> ok</name>
506
<fsummary>Clear information about processes executing interpreted
509
<p>Clears information about processes executing interpreted code
510
by removing all information about terminated processes.</p>
515
<name>continue(Pid) -> ok | {error,not_interpreted}</name>
516
<name>continue(X,Y,Z) -> ok | {error,not_interpreted}</name>
517
<fsummary>Resume process execution</fsummary>
520
<v>X = Y = Z = int()</v>
523
<p>Resume process execution for <c>Pid</c>, or for
524
<c>c:pid(X,Y,Z)</c>.</p>