int(3)

πŸ“¦
version 29.0.6 Β· 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu stonking

πŸ‘‘ int(3) β€” the NAME section, bestie

It's an Erlang Module Definition page, and the module is int, aka the Interpreter Interface. Yes that's its government name. Slay.


✨ DESCRIPTION ✨

The Erlang interpreter is the whole reason we can do breakpoints and stepwise execution of code, fr fr. It's mainly meant to be driven by Debugger β€” go peek at the User's Guide for Debugger and the module debugger if you want the lore. πŸ¦‹

So here's the cute lil list of things you can do straight from the shell:

  • Specify the modules to be interpreted. πŸ’…
  • Specify breakpoints. πŸŽ€
  • Monitor the current status of all processes executing code in interpreted modules β€” and yes, that includes processes hanging out on other Erlang nodes. πŸ‘€

By attaching to a process that's executing interpreted code, you can examine variable bindings and order stepwise execution. The way this works is you send/receive info to/from the process through a third process, called the meta process. You can absolutely implement your own attached process, no gatekeeping. See int.erl for the available functions and dbg_wx_trace.erl for the possible messages. 🫢

Important caveat, do not skip this one: the interpreter depends on the Kernel, STDLIB, and WX applications. That means modules belonging to any of those applications are not allowed to be interpreted, since it could lead to a deadlock or an emulator crash. πŸ’€ This applies to modules in the Debugger application too. Not a vibe. Don't do it.

πŸŽ€ Breakpoints πŸŽ€

Breakpoints are specified on a line basis. When a process executing code in an interpreted module reaches a breakpoint, it stops. Periodt. Which means a breakpoint has to be set at an executable line β€” like, a code line containing an executable expression. Setting it on vibes alone won't work, sorry. πŸ™ˆ

A breakpoint has the following:

  • status, which is either active or inactive. An inactive breakpoint is just ignored, it's giving background character.
  • trigger action. When a breakpoint is reached, the trigger action says whether the breakpoint stays active (enable), becomes inactive (disable), or gets yeeted entirely (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/2. πŸ”₯

By default, a breakpoint is active, has trigger action enable, and has no associated condition. Iconic defaults, honestly. For the full details about breakpoints, see Breakpoints and Break Dialog Windows in the User's Guide for Debugger. ✨


πŸ”₯ FUNCTIONS πŸ”₯

action_at_break(Module, Line, Action) -> ok

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

Sets the trigger action of the breakpoint at Line in Module to Action. That's it, that's the whole job. πŸ’…


all_breaks() -> [Break]

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().

Gets all the breakpoints. Every single one. πŸ‘‘


all_breaks(Module) -> [Break]

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().

Gets all the breakpoints in module Module. Scoped, focused, main character energy. πŸ¦‹


auto_attach() -> false | {Flags, Function}

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

Gets how to attach automatically to a process executing code in interpreted modules.

See auto_attach/2 for the meaning of the possible values in Flags. ✨


auto_attach(false) -> term()

Disables auto attach. That's the whole synopsis. Short and sweet. πŸ’…


auto_attach(Flags, Function) -> term()

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

Sets when and how to attach automatically to a process executing code in interpreted modules. 🫢

By default, when the interpreter is started, automatic attach is disabled.

If Flags is an empty list, automatic attach is disabled. (Same energy, just said twice.)

Otherwise Flags should be a list containing at least one of these flags:

  • 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. πŸŽ€


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

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

Creates a breakpoint at Line in Module. πŸ’–


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

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

Creates a breakpoint at the first line of every clause of function Module:Name/Arity. All of them. No crumbs. πŸ”₯


clear() -> ok.

Clears information about processes executing interpreted code by removing all information about terminated processes. Spring cleaning, but for pids. 🧹✨


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

Resumes process execution for Pid. Go forth, bestie. πŸ¦‹


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

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

Resumes process execution for pid(X, Y, Z). Same energy, you're just spelling out the pid by hand. πŸ’…


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

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

Deletes the breakpoints at the first line of every clause of function Module:Name/Arity. The break_in/3 reversal arc, honestly. 😭


delete_break(Module, Line) -> ok

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

Deletes the breakpoint at Line in Module. Gone. Not coming back. πŸ’€


disable_break(Module, Line) -> ok

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

Makes the breakpoint at Line in Module inactive. It's still there, it's just not participating. πŸ™ˆ


enable_break(Module, Line) -> ok

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

Makes the breakpoint at Line in Module active. Back on her bullshit, respectfully. πŸ‘‘


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

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

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


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

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

Retrieves the binding of Var from Bindings. πŸ”

This function is intended to be used by the conditional function of a breakpoint. iykyk. πŸ’…


i(AbsModules | AbsModule) -> Result

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

Interprets the specified module(s) on the local node. 🏠✨

A module can be specified by its module name (an atom) or by 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 can be interpreted. No debug_info, no interpretation. Periodt. πŸ’€

The function 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. In that case the function then always returns ok, but it prints some information to stdout if a module cannot be interpreted. πŸ™ˆ


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

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().

Checks if a module can be interpreted. The vibe check, essentially. πŸ’…

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, WX, or Debugger. πŸš«πŸ‘‘

okay so if the module can't be interpreted, the function returns {error,Reason} β€” and Reason can be one of these, bestie:

  • 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: the function can return true for a module that is not interpretable 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. πŸ’…

✨ interpreted() -> [Module] ✨

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

Returns a list with all interpreted modules. Obsessed. 🫢

✨ n(AbsModule) -> ok ✨

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

Stops interpreting the specified module on the local node.

Similar to i/1 and ni/1, a module can be specified by its module name or filename. 🌸

✨ ni(AbsModules | AbsModule) -> Result ✨

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

Interprets the specified module(s) on 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 can be interpreted. πŸ”₯

The function 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. πŸ’–

✨ nn(AbsModule) -> ok ✨

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

Stops interpreting the specified module on all known nodes.

Similar to i/1 and ni/1, a module can be specified by its module name or filename. 🌈

✨ no_break() -> ok. ✨

       no_break() -> ok.

Deletes all breakpoints. πŸŽ€

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

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

Deletes all breakpoints in Module. 🧚

✨ snapshot() -> [Snapshot] ✨

       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().

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 is {}. 😴
  • running β€” The process is running. Info is {}. πŸƒ
  • waiting β€” The process is waiting at a receive. Info is {}. ⏳
  • break β€” Process execution is stopped, normally at a breakpoint. Info is {Module,Line}. πŸ›‘
  • exit β€” The process is terminated. Info is ExitReason. πŸ’€
  • no_conn β€” The connection is down to the node where the process is running. Info is {}. πŸ“‘

✨ stack_trace() -> Flag ✨

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

Gets how to save call frames in the stack.

See stack_trace/1 for the meaning of Flag. ⭐

✨ stack_trace(Flag) -> term() ✨

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

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. πŸ™ˆ

✨ test_at_break(Module, Line, Function) -> ok ✨

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

Sets the conditional test of the breakpoint at Line in Module to Function.

Function Function must fulfill the requirements specified in section Breakpoints. πŸŽ€


source/version: Ericsson AB, debugger 7.0; page: int(3). date: not in this footer, but the vibe is immaculate. mwah πŸ’‹

πŸ“¦ where this page comes from