View Source int (debugger v5.4)

Interpreter Interface.

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 debugger.

The following can be done from the shell:

  • Specify the modules to be interpreted.
  • Specify breakpoints.
  • Monitor the current status of all processes executing code in interpreted modules, also processes at other Erlang nodes.

By attaching to 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 int.erl for available functions and dbg_wx_trace.erl for possible messages.

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.

Breakpoints

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.

A breakpoint has the following:

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

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

Summary

Functions

action_at_break(Module, Line, Action) -> ok

Equivalent to all_breaks/1

all_breaks(Module) -> [Break]

Gets and sets when and how to attach automatically to a process executing code in interpreted modules. false 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

break(Module, Line) -> ok | {error,break_exists}

break_in(Module, Name, Arity) -> ok | {error,function_not_found}

clear() -> ok

Equivalent to continue/3

continue(X,Y,Z) -> ok | {error,not_interpreted}

del_break_in(Module, Name, Arity) -> ok | {error,function_not_found}

delete_break(Module, Line) -> ok

disable_break(Module, Line) -> ok

enable_break(Module, Line) -> ok

file(Module) -> File | {error,not_loaded}

get_binding(Var, Bindings) -> {value,Value} | unbound

Equivalent to ni/1

interpretable(AbsModule) -> true | {error,Reason}

interpreted() -> [Module]

Equivalent to nn/1

ni(AbsModules) -> okni(AbsModule) -> {module,Module} | error

nn(AbsModule) -> ok

Equivalent to no_break/1

no_break(Module) -> ok

snapshot() -> [Snapshot]

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

test_at_break(Module, Line, Function) -> ok

Functions

Link to this function

action_at_break(Module, Line, Action)

View Source
-spec action_at_break(Module, Line, Action) -> ok
                   when Module :: module(), Line :: integer(), Action :: enable | disable | delete.

action_at_break(Module, Line, Action) -> ok

Sets the trigger action of the breakpoint at Line in Module to Action.

-spec all_breaks() -> [Break]
              when
                  Break :: {Point, Options},
                  Point :: {Module, Line},
                  Module :: module(),
                  Line :: integer(),
                  Options :: [Status | Trigger | null | Cond],
                  Status :: active | inactive,
                  Trigger :: enable | disable | delete,
                  Cond :: null | Function,
                  Function :: {Module, Name},
                  Name :: atom().

Equivalent to all_breaks/1

-spec all_breaks(Module) -> [Break]
              when
                  Break :: {Point, Options},
                  Point :: {Module, Line},
                  Module :: module(),
                  Line :: integer(),
                  Options :: [Status | Trigger | null | Cond],
                  Status :: active | inactive,
                  Trigger :: enable | disable | delete,
                  Cond :: null | Function,
                  Function :: {Module, Name},
                  Name :: atom().

all_breaks(Module) -> [Break]

Gets all breakpoints, or all breakpoints in Module.

-spec auto_attach() -> false | {Flags, Function}
               when
                   Flags :: [init | break | exit],
                   Function :: {Module, Name, Args},
                   Module :: module(),
                   Name :: atom(),
                   Args :: [term()].

Equivalent to auto_attach/2

-spec auto_attach(false) -> term().

Equivalent to auto_attach/2

Link to this function

auto_attach(Flags, Function)

View Source
-spec auto_attach(Flags, Function) -> term()
               when
                   Flags :: [init | break | exit],
                   Function :: {Module, Name, Args},
                   Module :: module(),
                   Name :: atom(),
                   Args :: [term()].

Gets and sets when and how to attach automatically to a process executing code in interpreted modules. false 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:

  • init - Attach when a process for the first time calls an interpreted function.
  • break - Attach whenever a process reaches a breakpoint.
  • exit - Attach when a process terminates.

When the specified event occurs, the function Function is called as:

spawn(Module, Name, [Pid | Args])

Pid is the pid of the process executing interpreted code.

-spec break(Module, Line) -> ok | {error, break_exists} when Module :: module(), Line :: integer().

break(Module, Line) -> ok | {error,break_exists}

Creates a breakpoint at Line in Module.

Link to this function

break_in(Module, Name, Arity)

View Source
-spec break_in(Module, Name, Arity) -> ok | {error, function_not_found}
            when Module :: module(), Name :: atom(), Arity :: integer().

break_in(Module, Name, Arity) -> ok | {error,function_not_found}

Creates a breakpoint at the first line of every clause of function Module:Name/Arity.

-spec clear() -> ok.

clear() -> ok

Clears information about processes executing interpreted code by removing all information about terminated processes.

-spec continue(Pid :: pid()) -> ok | {error, not_interpreted}.

Equivalent to continue/3

-spec continue(X, Y, Z) -> ok | {error, not_interpreted}
            when X :: integer(), Y :: integer(), Z :: integer().

continue(X,Y,Z) -> ok | {error,not_interpreted}

Resumes process execution for Pid or c:pid(X,Y,Z).

Link to this function

del_break_in(Module, Name, Arity)

View Source
-spec del_break_in(Module, Name, Arity) -> ok | {error, function_not_found}
                when Module :: module(), Name :: atom(), Arity :: integer().

del_break_in(Module, Name, Arity) -> ok | {error,function_not_found}

Deletes the breakpoints at the first line of every clause of function Module:Name/Arity.

Link to this function

delete_break(Module, Line)

View Source
-spec delete_break(Module, Line) -> ok when Module :: module(), Line :: integer().

delete_break(Module, Line) -> ok

Deletes the breakpoint at Line in Module.

Link to this function

disable_break(Module, Line)

View Source
-spec disable_break(Module, Line) -> ok when Module :: module(), Line :: integer().

disable_break(Module, Line) -> ok

Makes the breakpoint at Line in Module inactive.

Link to this function

enable_break(Module, Line)

View Source
-spec enable_break(Module, Line) -> ok when Module :: module(), Line :: integer().

enable_break(Module, Line) -> ok

Makes the breakpoint at Line in Module active.

-spec file(Module) -> File | {error, not_loaded} when Module :: module(), File :: file:filename_all().

file(Module) -> File | {error,not_loaded}

Returns the source code filename File for an interpreted module Module.

Link to this function

get_binding(Var, Bindings)

View Source
-spec get_binding(Var, Bindings) -> {value, Value} | unbound
               when Var :: atom(), Bindings :: term(), Value :: term().

get_binding(Var, Bindings) -> {value,Value} | unbound

Retrieves the binding of Var. This function is intended to be used by the conditional function of a breakpoint.

-spec i(AbsModules) -> ok
     when
         AbsModules :: [AbsModule],
         AbsModule :: Module | File,
         Module :: module(),
         File :: file:name_all();
 (AbsModule) -> {module, Module} | error
     when AbsModule :: Module | File, Module :: module(), File :: file:name_all().

Equivalent to ni/1

Link to this function

interpretable(AbsModule)

View Source
-spec interpretable(AbsModule) -> true | {error, Reason}
                 when
                     AbsModule :: Module | File,
                     Module :: module(),
                     File :: file:name_all(),
                     Reason :: no_src | no_beam | no_debug_info | badarg | {app, App},
                     App :: atom().

interpretable(AbsModule) -> true | {error,Reason}

Checks if a module can be interpreted. The module can be specified by its module name Module or its source filename File. If specified by a module name, the module is searched for in the code path.

The function returns true if all of the following apply:

  • Both source code and object code for the module is found.
  • The module has been compiled with option debug_info set.
  • The module does not belong to any of the applications Kernel, STDLIB, GS, or Debugger.

The function returns {error,Reason} if the module cannot be interpreted. Reason can have the following values:

  • no_src - No source code is found. It is assumed that the source code and object code are located either in the same directory, or in src and ebin directories next to each other.

  • no_beam - No object code is found. It is assumed that the source code and object code are located either in the same directory, or in src and ebin directories next to each other.

  • no_debug_info - The module has not been compiled with option debug_info set.

  • badarg - AbsModule is not found. This could be because the specified file does not exist, or because code:which/1 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.

  • {app,App} - App is kernel, stdlib, gs, or debugger if AbsModule belongs to one of these applications.

Notice that the function can return true 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.

-spec interpreted() -> [Module] when Module :: module().

interpreted() -> [Module]

Returns a list with all interpreted modules.

-spec n(AbsModule) -> ok
     when
         AbsModule :: Module | File | [Module | File], Module :: module(), File :: file:name_all().

Equivalent to nn/1

-spec ni(AbsModules) -> ok
      when
          AbsModules :: [AbsModule],
          AbsModule :: Module | File,
          Module :: module(),
          File :: file:name_all();
  (AbsModule) -> {module, Module} | error
      when AbsModule :: Module | File, Module :: module(), File :: file:name_all().

ni(AbsModules) -> okni(AbsModule) -> {module,Module} | error

Interprets the specified module(s). i/1 interprets the module only at the current node. ni/1 interprets the module at all known nodes.

A module can be specified by its module name (atom) or filename.

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

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

Note

The interpreter requires both the source code and the object code. The object code must include debug information, that is, only modules compiled with option debug_info set can be interpreted.

The functions returns {module,Module} if the module was interpreted, otherwise error is returned.

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 ok, but prints some information to stdout if a module cannot be interpreted.

-spec nn(AbsModule) -> ok
      when
          AbsModule :: Module | File | [Module | File],
          Module :: module(),
          File :: file:name_all().

nn(AbsModule) -> ok

Stops interpreting the specified module. n/1 stops interpreting the module only at the current node. nn/1 stops interpreting the module at all known nodes.

As for i/1 and ni/1, a module can be specified by its module name or filename.

-spec no_break() -> ok.

Equivalent to no_break/1

-spec no_break(Module :: term()) -> ok.

no_break(Module) -> ok

Deletes all breakpoints, or all breakpoints in Module.

-spec snapshot() -> [Snapshot]
            when
                Snapshot :: {Pid, Function, Status, Info},
                Pid :: pid(),
                Function :: {Module, Name, Args},
                Module :: module(),
                Name :: atom(),
                Args :: [term()],
                Status :: idle | running | waiting | break | exit | no_conn,
                Info :: {} | {Module, Line} | ExitReason,
                Line :: integer(),
                ExitReason :: term().

snapshot() -> [Snapshot]

Gets information about all processes executing interpreted code.

  • Pid - Process identifier.
  • Function - First interpreted function called by the process.
  • Status - Current status of the process.
  • Info - More information.

Status is one of the following:

  • idle - The process is no longer executing interpreted code. Info={}.
  • running - The process is running. Info={}.
  • waiting - The process is waiting at a receive. Info={}.
  • break - Process execution is stopped, normally at a breakpoint. Info={Module,Line}.
  • exit - The process is terminated. Info=ExitReason.
  • no_conn - The connection is down to the node where the process is running. Info={}.
-spec stack_trace() -> Flag when Flag :: all | no_tail | false.

Equivalent to stack_trace/1

-spec stack_trace(Flag) -> term() when Flag :: all | no_tail | false.

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:

  • all - Save information about all current calls, that is, function calls that have not yet returned a value.

  • no_tail - 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.

  • false - Save no information about current calls.

Link to this function

test_at_break(Module, Line, Function)

View Source
-spec test_at_break(Module, Line, Function) -> ok
                 when
                     Module :: module(),
                     Line :: integer(),
                     Function :: {Module, Name},
                     Name :: atom().

test_at_break(Module, Line, Function) -> ok

Sets the conditional test of the breakpoint at Line in Module to Function. The function must fulfill the requirements specified in section Breakpoints.