aboutsummaryrefslogtreecommitdiffstats
path: root/lib/debugger/doc/src/int.xml
blob: a0078714e692a71d495d53a7d273279d47c026a1 (plain) (blame)
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1998</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>int</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module since="">int</module>
  <modulesummary>Interpreter Interface.</modulesummary>
  <description>
    <p>The Erlang interpreter provides mechanisms for breakpoints and
      stepwise execution of code. It is primarily intended to be used by
      Debugger, see the User's Guide and
      <seealso marker="debugger"><c>debugger(3)</c></seealso>.</p>
    
    <p>The following can be done from the shell:</p>
    <list type="bulleted">
      <item>Specify the modules to be interpreted.</item>
      <item>Specify breakpoints.</item>
      <item>Monitor the current status of all processes executing code
	in interpreted modules, also processes at other Erlang nodes.
      </item>
    </list>

    <p>By <em>attaching to</em> a process executing interpreted code, it
      is possible to examine variable bindings and order stepwise
      execution. This is done by sending and receiving information
      to/from the process through a third process, called the meta
      process. You can implement your own attached process. See
      <c>int.erl</c> for available functions and <c>dbg_wx_trace.erl</c>
      for possible messages.</p>

    <p>The interpreter depends on the Kernel, STDLIB, and
      GS applications. This means that modules belonging to any of
      these applications are not allowed to be interpreted, as it could lead
      to a deadlock or emulator crash. This also applies to modules
      belonging to the Debugger application.</p>
  </description>

  <section>
    <marker id="int_breakpoints"/>
    <title>Breakpoints</title>

    <p>Breakpoints are specified on a line basis. When a process
      executing code in an interpreted module reaches a breakpoint, it
      stops. This means that a breakpoint must be set at an
      executable line, that is, a code line containing an executable
      expression.</p>

    <p>A breakpoint has the following:</p>
    <list type="bulleted">
      <item>A status, which is <em>active</em> or <em>inactive</em>. An
        inactive breakpoint is ignored.</item>
      <item>A trigger action. When a breakpoint is reached, the trigger
        action specifies if the breakpoint is to continue as active
        (<em>enable</em>), or to become inactive (<em>disable</em>), or
        to be removed (<em>delete</em>).</item>
      <item>Optionally an associated condition. A condition is a tuple
        <c>{Module,Name}</c>. When the breakpoint is reached,
        <c>Module:Name(Bindings)</c> is called. If it evaluates to
        <c>true</c>, execution stops. If it evaluates to <c>false</c>,
        the breakpoint is ignored. <c>Bindings</c> contains the current
        variable bindings. To retrieve the value for a specified variable,
        use <c>get_binding</c>.</item>
    </list>

    <p>By default, a breakpoint is active, has trigger action
      <c>enable</c>, and has no associated condition. For details
      about breakpoints, see the User's Guide.</p>
  </section>

  <funcs>
    <func>
      <name since="">i(AbsModule) -> {module,Module} | error</name>
      <name since="">i(AbsModules) -> ok</name>
      <name since="">ni(AbsModule) -> {module,Module} | error</name>
      <name since="">ni(AbsModules) -> ok</name>
      <fsummary>Interpret a module.</fsummary>
      <type>
	<v>AbsModules = [AbsModule]</v>
	<v>AbsModule = Module | File | [Module | File]</v>
	<v>&nbsp;Module = atom()</v>
	<v>&nbsp;File = string()</v>
      </type>
      <desc>
	<p>Interprets the specified module(s). <c>i/1</c> interprets
	  the module only at the current node. <c>ni/1</c> interprets
	  the module at all known nodes.</p>

	<p>A module can be specified by its module name (atom) or
	  filename.</p>

	<p>If specified by its module name, the object code
	  <c>Module.beam</c> is searched for in the current path.
	  The source code <c>Module.erl</c> is searched for first in
	  the same directory as the object code, then in an <c>src</c>
	  directory next to it.</p>

	<p>If specified by its filename, the filename can include a path
	  and the <c>.erl</c> extension can  be omitted. The object code
	  <c>Module.beam</c> is searched for first in the same directory
	  as the source code, then in an <c>ebin</c> directory next to
	  it, and then in the current path.</p>

	<note>
	  <p>The interpreter requires both the source code and the object
	    code. The object code <em>must</em> include debug
	    information, that is, only modules compiled with option
	    <c>debug_info</c> set can be interpreted.</p>
	</note>

	<p>The functions returns <c>{module,Module}</c> if the module
	  was interpreted, otherwise <c>error</c> is returned.</p>

	<p>The argument can also be a list of modules or filenames, in
	  which case the function tries to interpret each module as
	  specified earlier. The function then always returns <c>ok</c>,
	  but prints some information to <c>stdout</c> if a module
	  cannot be interpreted.</p>
      </desc>
    </func>
	
    <func>
      <name since="">n(AbsModule) -> ok</name>
      <name since="">nn(AbsModule) -> ok</name>
      <fsummary>Stop interpreting a module.</fsummary>
      <type>
	<v>AbsModule = Module | File | [Module | File]</v>
	<v>&nbsp;Module = atom()</v>
	<v>&nbsp;File = string()</v>
      </type>
      <desc>
	<p>Stops interpreting the specified module. <c>n/1</c> stops
	  interpreting the module only at the current node. <c>nn/1</c>
	  stops interpreting the module at all known nodes.</p>

	<p>As for <c>i/1</c> and <c>ni/1</c>, a module can be specified by
	  its module name or filename.</p>
      </desc>
    </func>

    <func>
      <name since="">interpreted() -> [Module]</name>
      <fsummary>Get all interpreted modules.</fsummary>
      <type>
	<v>Module = atom()</v>
      </type>
      <desc>
	<p>Returns a list with all interpreted modules.</p>
      </desc>
    </func>

    <func>
      <name since="">file(Module) -> File | {error,not_loaded}</name>
      <fsummary>Get the filename for an interpreted module.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>File = string()</v>
      </type>
      <desc>
	<p>Returns the source code filename <c>File</c> for an
	  interpreted module <c>Module</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">interpretable(AbsModule) -> true | {error,Reason}</name>
      <fsummary>Check if a module can be interpreted.</fsummary>
      <type>
	<v>AbsModule = Module | File</v>
	<v>&nbsp;Module = atom()</v>
	<v>&nbsp;File = string()</v>
	<v>Reason = no_src | no_beam | no_debug_info | badarg
	  | {app,App}</v>
	<v>&nbsp;App = atom()</v>
      </type>
      <desc>
	<p>Checks if a module can be interpreted. The module can be
	  specified by its module name <c>Module</c> or its source
	  filename <c>File</c>. If specified by a module name, the module
	  is searched for in the code path.</p>

	<p>The function returns <c>true</c> if all of the following
          apply:</p>
	<list type="bulleted">
          <item>Both source code and object code for the module is
            found.</item>
          <item>The module has been compiled with option <c>debug_info</c>
            set.</item>
          <item>The module does not belong to any of the applications
            Kernel, STDLIB, GS, or Debugger.</item>
	</list>

	<p>The function returns <c>{error,Reason}</c> if the module cannot
	  be interpreted. <c>Reason</c> can have the following values:</p>
	<taglist>
	  <tag><c>no_src</c></tag>
	  <item><p>No source code is found.
	    It is assumed that the source code and object code are located
	    either in the same directory, or in <c>src</c> and <c>ebin</c>
	    directories next to each other.</p></item>

	  <tag><c>no_beam</c></tag>
	  <item><p>No object code is found.
	    It is assumed that the source code and object code are located
	    either in the same directory, or in <c>src</c> and <c>ebin</c>
	    directories next to each other.</p></item>

	  <tag><c>no_debug_info</c></tag>
	  <item><p>The module has not been compiled with option
	    <c>debug_info</c> set.</p></item>

	  <tag><c>badarg</c></tag>
	  <item><p><c>AbsModule</c> is not found. This could be because
	    the specified file does not exist, or because
	    <c>code:which/1</c> does not return a BEAM filename,
	    which is the case not only for non-existing modules but also
	    for modules that are preloaded or cover-compiled.</p></item>

	  <tag><c>{app,App}</c></tag>
	  <item><p><c>App</c> is <c>kernel</c>, <c>stdlib</c>, <c>gs</c>,
	  or <c>debugger</c> if <c>AbsModule</c> belongs to one of these
	  applications.</p></item>
	</taglist>

	<p>Notice that the function can return <c>true</c> for a module
	  that in fact is not interpretable in the case where
	  the module is marked as sticky or resides in a directory
	  marked as sticky. The reason is that this is not discovered
	  until the interpreter tries to load the module.</p>
      </desc>
    </func>

    <func>
      <name since="">auto_attach() -> false | {Flags,Function}</name>
      <name since="">auto_attach(false)</name>
      <name since="">auto_attach(Flags, Function)</name>
      <fsummary>Get and set when and how to attach to a process.</fsummary>
      <type>
	<v>Flags = [init | break | exit]</v>
	<v>Function = {Module,Name,Args}</v>
	<v>&nbsp;Module = Name = atom()</v>
	<v>&nbsp;Args = [term()]</v>
      </type>
      <desc>
	<p>Gets and sets when and how to attach automatically to a
	  process executing code in interpreted modules. <c>false</c>
	  means never attach automatically, this is the default.
	  Otherwise automatic attach is defined by a list of flags and
	  a function. The following flags can be specified:</p>
	<list type="bulleted">
	  <item><c>init</c> - Attach when a process for the first
	    time calls an interpreted function.</item>
	  <item><c>break</c> - Attach whenever a process reaches a
	    breakpoint.</item>
	  <item><c>exit</c> - Attach when a process terminates.</item>
	</list>

	<p>When the specified event occurs, the function <c>Function</c>
	  is called as:</p>
	<pre>
spawn(Module, Name, [Pid | Args])</pre>

	<p><c>Pid</c> is the pid of the process executing interpreted
	  code.</p>
      </desc>
    </func>

    <func>
      <name since="">stack_trace() -> Flag</name>
      <name since="">stack_trace(Flag)</name>
      <fsummary>Get and set if and how to save call frames.</fsummary>
      <type>
	<v>Flag = all | no_tail | false</v>
      </type>
      <desc>
	<p>Gets and sets how to save call frames in the stack. Saving
	  call frames makes it possible to inspect the call chain of a
	  process, and is also used to emulate the stack trace if an
	  error (an exception of class error) occurs. The following
	  flags can be specified:</p>
	<taglist>
	  <tag><c>all</c></tag>
	  <item><p>Save information about all current calls,
	    that is, function calls that have not yet returned a value.</p>
	  </item>

	  <tag><c>no_tail</c></tag>
	  <item><p>Save information about current calls,
	    but discard previous information when a tail recursive call
	    is made. This option consumes less memory and can be
	    necessary to use for processes with long lifetimes and many
	    tail recursive calls. This is the default.</p></item>

	  <tag><c>false</c></tag>
	  <item><p>Save no information about currentcalls.</p></item>
	</taglist>
      </desc>
    </func>

    <func>
      <name since="">break(Module, Line) -> ok | {error,break_exists}</name>
      <fsummary>Create a breakpoint.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
      </type>
      <desc>
	<p>Creates a breakpoint at <c>Line</c> in <c>Module</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">delete_break(Module, Line) -> ok</name>
      <fsummary>Delete a breakpoint.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
      </type>
      <desc>
	<p>Deletes the breakpoint at <c>Line</c> in <c>Module</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">break_in(Module, Name, Arity) -> ok
	| {error,function_not_found}</name>
      <fsummary>Create breakpoints in the specified function.</fsummary>
      <type>
	<v>Module = Name = atom()</v>
	<v>Arity = int()</v>
      </type>
      <desc>
	<p>Creates a breakpoint at the first line of every clause of 
	  function <c>Module:Name/Arity</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">del_break_in(Module, Name, Arity) -> ok
	| {error,function_not_found}</name>
      <fsummary>Delete breakpoints from the specified function.</fsummary>
      <type>
	<v>Module = Name = atom()</v>
	<v>Arity = int()</v>
      </type>
      <desc>
	<p>Deletes the breakpoints at the first line of every clause of 
	  function <c>Module:Name/Arity</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">no_break() -> ok</name>
      <name since="">no_break(Module) -> ok</name>
      <fsummary>Delete all breakpoints.</fsummary>
      <desc>
	<p>Deletes all breakpoints, or all breakpoints in <c>Module</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">disable_break(Module, Line) -> ok</name>
      <fsummary>Make a breakpoint inactive.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
      </type>
      <desc>
	<p>Makes the breakpoint at <c>Line</c> in <c>Module</c> inactive.</p>
      </desc>
    </func>

    <func>
      <name since="">enable_break(Module, Line) -> ok</name>
      <fsummary>Make a breakpoint active.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
      </type>
      <desc>
	<p>Makes the breakpoint at <c>Line</c> in <c>Module</c> active.</p>
      </desc>
    </func>

    <func>
      <name since="">action_at_break(Module, Line, Action) -> ok</name>
      <fsummary>Set the trigger action of a breakpoint.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
	<v>Action = enable | disable | delete</v>
      </type>
      <desc>
	<p>Sets the trigger action of the breakpoint at <c>Line</c> in
	  <c>Module</c> to <c>Action</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">test_at_break(Module, Line, Function) -> ok</name>
      <fsummary>Set the conditional test of a breakpoint.</fsummary>
      <type>
	<v>Module = atom()</v>
	<v>Line = int()</v>
	<v>Function = {Module,Name}</v>
	<v>&nbsp;Name = atom()</v>
      </type>
      <desc>
	<p>Sets the conditional test of the breakpoint at <c>Line</c> in
	  <c>Module</c> to <c>Function</c>. The function must
	  fulfill the requirements specified in section
          <seealso marker="#int_breakpoints">Breakpoints</seealso>.</p>
      </desc>
    </func>

    <func>
      <name since="">get_binding(Var, Bindings) -> {value,Value} | unbound</name>
      <fsummary>Retrieve a variable binding.</fsummary>
      <type>
	<v>Var = atom()</v>
	<v>Bindings = term()</v>
	<v>Value = term()</v>
      </type>
      <desc>
	<p>Retrieves the binding of <c>Var</c>. This function is
	  intended to be used by the conditional function of a
	  breakpoint.</p>
      </desc>
    </func>

    <func>
      <name since="">all_breaks() -> [Break]</name>
      <name since="">all_breaks(Module) -> [Break]</name>
      <fsummary>Get all breakpoints.</fsummary>
      <type>
	<v>Break = {Point,Options}</v>
	<v>&nbsp;Point = {Module,Line}</v>
	<v>&nbsp;&nbsp;Module = atom()</v>
	<v>&nbsp;&nbsp;Line = int()</v>
	<v>&nbsp;Options = [Status,Trigger,null,Cond|]</v>
	<v>&nbsp;&nbsp;Status = active | inactive</v>
	<v>&nbsp;&nbsp;Trigger = enable | disable | delete</v>
	<v>&nbsp;&nbsp;Cond = null | Function</v>
	<v>&nbsp;&nbsp;&nbsp;Function = {Module,Name}</v>
	<v>&nbsp;&nbsp;&nbsp;&nbsp;Name = atom()</v>
      </type>
      <desc>
	<p>Gets all breakpoints, or all breakpoints in <c>Module</c>.</p>
      </desc>
    </func>

    <func>
      <name since="">snapshot() -> [Snapshot]</name>
      <fsummary>Get information about all processes executing interpreted
	code.</fsummary>
      <type>
	<v>Snapshot = {Pid, Function, Status, Info}</v>
	<v>&nbsp;Pid = pid()</v>
	<v>&nbsp;Function = {Module,Name,Args}</v>
	<v>&nbsp;&nbsp;Module = Name = atom()</v>
	<v>&nbsp;&nbsp;Args = [term()]</v>
	<v>&nbsp;Status = idle | running | waiting | break | exit
	  | no_conn</v>
	<v>&nbsp;Info = {} | {Module,Line} | ExitReason</v>
	<v>&nbsp;&nbsp;Line = int()</v>
	<v>&nbsp;&nbsp;ExitReason = term()</v>
      </type>
      <desc>
	<p>Gets information about all processes executing interpreted code.
	</p>
	<list type="bulleted">
	  <item><c>Pid</c> - Process identifier.</item>
	  <item><c>Function</c> - First interpreted function called by
	    the process.</item>
	  <item><c>Status</c> - Current status of the process.</item>
	  <item><c>Info</c> - More information.</item>
	</list>

	<p><c>Status</c> is one of the following:</p>
	<list type="bulleted">
	  <item><c>idle</c> - The process is no longer executing
	    interpreted code. <c>Info={}</c>.</item>
	  <item><c>running</c> - The process is running. <c>Info={}</c>.
	  </item>
	  <item><c>waiting</c> - The process is waiting at a
	    <c>receive</c>. <c>Info={}</c>.</item>
	  <item><c>break</c> - Process execution is stopped,
	    normally at a breakpoint. <c>Info={Module,Line}</c>.</item>
	  <item><c>exit</c> - The process is terminated.
	    <c>Info=ExitReason</c>.</item>
	  <item><c>no_conn</c> - The connection is down to the node
	    where the process is running. <c>Info={}</c>.</item>
	</list>
      </desc>
    </func>

    <func>
      <name since="">clear() -> ok</name>
      <fsummary>Clear information about processes executing interpreted
	code.</fsummary>
      <desc>
	<p>Clears information about processes executing interpreted code
	  by removing all information about terminated processes.</p>
      </desc>
    </func>

    <func>
      <name since="">continue(Pid) -> ok | {error,not_interpreted}</name>
      <name since="">continue(X,Y,Z) -> ok | {error,not_interpreted}</name>
      <fsummary>Resume process execution.</fsummary>
      <type>
	<v>Pid = pid()</v>
	<v>X = Y = Z = int()</v>
      </type>
      <desc>
	<p>Resumes process execution for <c>Pid</c> or
	  <c>c:pid(X,Y,Z)</c>.</p>
      </desc>
    </func>
  </funcs>
</erlref>