aboutsummaryrefslogblamecommitdiffstats
path: root/lib/debugger/doc/src/int.xml
blob: 31e9dfe923e268c575e9afbd2f85d0f9278f249b (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                       




                                     
                                        


                                                        










                                                                              









                         
                                                       

                                                                     


                                                                        
    


                                                         








                                                                        

                                                                  
                                                                        

                                


                                                                            
                                                                   
                                                


                
                                  



                                                                      

                                                                    

                     















                                                                          

                                                             

                                                                 







                                                           
                                              










                                                                     



                                                                 

                                                                    
                                                                      

                                   

                                                                        




                                                                        


                                                                         



                                                                     
                                                                  
 
                                                                      
                                                                   


                                                                        





                                      
                                                      









                                                                       

                                                                          




                                            
                                                       









                                                            
                                                                      




                              
                                                              





                                                                    
                                                                








                                                             

















































                                                                          
                                                                  

                                                                     






                                                            
                                                                           






                                            
                                                                  
                                                                     
                                                                
                                                                      


                                                                 
                                                      
                                                                  
                              
                                                                      


                                                                        
                           
             

                                       







                                                                     
                                                                      






                                                                      









                                                                           
                                                                       
                                                                
                                                                       




                                                                     




                                                                   
                                               










                                                                    
                                               




                              
                                                                      





                                               
                                                                        





                                                                     
                                                





                                                   
                                                                          





                                                                        
                                                





                                         
                                                  
            
                                                                            




                                                    
                                                      




                              
                                                                             




                                                   
                                                    




                              
                                                                           




                                                              
                                                                  












                                                                      
                                                                    








                                                                        

                                                                       




                                                                        
                                                       














                                                                
                                               












                                                              
                                                                         





                                                                         
                        














                                                                           


                                                                      
                               

                                                                     
               



                                                                
                                                    
                                                                        
                 
                                                            
                                                  
                                                            
                                                                       
                                                        
                                          
                                                                   







                                                                       
                        








                                                                        
                                                    




                                
                                                      






                                  
<?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>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>i(AbsModule) -> {module,Module} | error</name>
      <name>i(AbsModules) -> ok</name>
      <name>ni(AbsModule) -> {module,Module} | error</name>
      <name>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>n(AbsModule) -> ok</name>
      <name>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>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>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>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>auto_attach() -> false | {Flags,Function}</name>
      <name>auto_attach(false)</name>
      <name>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>stack_trace() -> Flag</name>
      <name>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>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>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>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>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>no_break() -> ok</name>
      <name>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>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>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>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>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>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>all_breaks() -> [Break]</name>
      <name>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>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>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>continue(Pid) -> ok | {error,not_interpreted}</name>
      <name>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>