<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- xref</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/tools-2.6.5.1.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Tools</strong><br><strong>Reference Manual</strong><br><small>Version 2.6.5.1</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Table of Contents</strong></small></p> <ul class="flipMenu"> <li id="no" title="cover " expanded="false">cover<ul> <li><a href="cover.html"> Top of manual page </a></li> <li title="start-0"><a href="cover.html#start-0">start/0</a></li> <li title="start-1"><a href="cover.html#start-1">start/1</a></li> <li title="compile-1"><a href="cover.html#compile-1">compile/1</a></li> <li title="compile-2"><a href="cover.html#compile-2">compile/2</a></li> <li title="compile_module-1"><a href="cover.html#compile_module-1">compile_module/1</a></li> <li title="compile_module-2"><a href="cover.html#compile_module-2">compile_module/2</a></li> <li title="compile_directory-0"><a href="cover.html#compile_directory-0">compile_directory/0</a></li> <li title="compile_directory-1"><a href="cover.html#compile_directory-1">compile_directory/1</a></li> <li title="compile_directory-2"><a href="cover.html#compile_directory-2">compile_directory/2</a></li> <li title="compile_beam-1"><a href="cover.html#compile_beam-1">compile_beam/1</a></li> <li title="compile_beam_directory-0"><a href="cover.html#compile_beam_directory-0">compile_beam_directory/0</a></li> <li title="compile_beam_directory-1"><a href="cover.html#compile_beam_directory-1">compile_beam_directory/1</a></li> <li title="analyse-1"><a href="cover.html#analyse-1">analyse/1</a></li> <li title="analyse-2"><a href="cover.html#analyse-2">analyse/2</a></li> <li title="analyse-2"><a href="cover.html#analyse-2">analyse/2</a></li> <li title="analyse-3"><a href="cover.html#analyse-3">analyse/3</a></li> <li title="analyse_to_file-1"><a href="cover.html#analyse_to_file-1">analyse_to_file/1</a></li> <li title="analyse_to_file-2"><a href="cover.html#analyse_to_file-2">analyse_to_file/2</a></li> <li title="analyse_to_file-2"><a href="cover.html#analyse_to_file-2">analyse_to_file/2</a></li> <li title="analyse_to_file-3"><a href="cover.html#analyse_to_file-3">analyse_to_file/3</a></li> <li title="modules-0"><a href="cover.html#modules-0">modules/0</a></li> <li title="imported_modules-0"><a href="cover.html#imported_modules-0">imported_modules/0</a></li> <li title="imported-0"><a href="cover.html#imported-0">imported/0</a></li> <li title="which_nodes-0"><a href="cover.html#which_nodes-0">which_nodes/0</a></li> <li title="is_compiled-1"><a href="cover.html#is_compiled-1">is_compiled/1</a></li> <li title="reset-1"><a href="cover.html#reset-1">reset/1</a></li> <li title="reset-0"><a href="cover.html#reset-0">reset/0</a></li> <li title="export-1"><a href="cover.html#export-1">export/1</a></li> <li title="export-2"><a href="cover.html#export-2">export/2</a></li> <li title="import-1"><a href="cover.html#import-1">import/1</a></li> <li title="stop-0"><a href="cover.html#stop-0">stop/0</a></li> <li title="stop-1"><a href="cover.html#stop-1">stop/1</a></li> </ul> </li> <li id="no" title="cprof " expanded="false">cprof<ul> <li><a href="cprof.html"> Top of manual page </a></li> <li title="analyse-0"><a href="cprof.html#analyse-0">analyse/0</a></li> <li title="analyse-1"><a href="cprof.html#analyse-1">analyse/1</a></li> <li title="analyse-1"><a href="cprof.html#analyse-1">analyse/1</a></li> <li title="analyse-2"><a href="cprof.html#analyse-2">analyse/2</a></li> <li title="pause-0"><a href="cprof.html#pause-0">pause/0</a></li> <li title="pause-1"><a href="cprof.html#pause-1">pause/1</a></li> <li title="pause-2"><a href="cprof.html#pause-2">pause/2</a></li> <li title="pause-3"><a href="cprof.html#pause-3">pause/3</a></li> <li title="restart-0"><a href="cprof.html#restart-0">restart/0</a></li> <li title="restart-1"><a href="cprof.html#restart-1">restart/1</a></li> <li title="restart-2"><a href="cprof.html#restart-2">restart/2</a></li> <li title="restart-3"><a href="cprof.html#restart-3">restart/3</a></li> <li title="start-0"><a href="cprof.html#start-0">start/0</a></li> <li title="start-1"><a href="cprof.html#start-1">start/1</a></li> <li title="start-2"><a href="cprof.html#start-2">start/2</a></li> <li title="start-3"><a href="cprof.html#start-3">start/3</a></li> <li title="stop-0"><a href="cprof.html#stop-0">stop/0</a></li> <li title="stop-1"><a href="cprof.html#stop-1">stop/1</a></li> <li title="stop-2"><a href="cprof.html#stop-2">stop/2</a></li> <li title="stop-3"><a href="cprof.html#stop-3">stop/3</a></li> </ul> </li> <li id="no" title="eprof " expanded="false">eprof<ul> <li><a href="eprof.html"> Top of manual page </a></li> <li title="start-0"><a href="eprof.html#start-0">start/0</a></li> <li title="start_profiling-1"><a href="eprof.html#start_profiling-1">start_profiling/1</a></li> <li title="profile-1"><a href="eprof.html#profile-1">profile/1</a></li> <li title="stop_profiling-0"><a href="eprof.html#stop_profiling-0">stop_profiling/0</a></li> <li title="profile-2"><a href="eprof.html#profile-2">profile/2</a></li> <li title="profile-4"><a href="eprof.html#profile-4">profile/4</a></li> <li title="analyse-0"><a href="eprof.html#analyse-0">analyse/0</a></li> <li title="total_analyse-0"><a href="eprof.html#total_analyse-0">total_analyse/0</a></li> <li title="log-1"><a href="eprof.html#log-1">log/1</a></li> <li title="stop-0"><a href="eprof.html#stop-0">stop/0</a></li> </ul> </li> <li title="erlang.el"><a href="erlang.el.html">erlang.el</a></li> <li id="no" title="fprof " expanded="false">fprof<ul> <li><a href="fprof.html"> Top of manual page </a></li> <li title="start-0"><a href="fprof.html#start-0">start/0</a></li> <li title="stop-0"><a href="fprof.html#stop-0">stop/0</a></li> <li title="stop-1"><a href="fprof.html#stop-1">stop/1</a></li> <li title="apply-2"><a href="fprof.html#apply-2">apply/2</a></li> <li title="apply-3"><a href="fprof.html#apply-3">apply/3</a></li> <li title="apply-3"><a href="fprof.html#apply-3">apply/3</a></li> <li title="apply-4"><a href="fprof.html#apply-4">apply/4</a></li> <li title="trace-2"><a href="fprof.html#trace-2">trace/2</a></li> <li title="trace-2"><a href="fprof.html#trace-2">trace/2</a></li> <li title="trace-2"><a href="fprof.html#trace-2">trace/2</a></li> <li title="trace-1"><a href="fprof.html#trace-1">trace/1</a></li> <li title="trace-1"><a href="fprof.html#trace-1">trace/1</a></li> <li title="trace-1"><a href="fprof.html#trace-1">trace/1</a></li> <li title="trace-1"><a href="fprof.html#trace-1">trace/1</a></li> <li title="profile-0"><a href="fprof.html#profile-0">profile/0</a></li> <li title="profile-2"><a href="fprof.html#profile-2">profile/2</a></li> <li title="profile-1"><a href="fprof.html#profile-1">profile/1</a></li> <li title="profile-1"><a href="fprof.html#profile-1">profile/1</a></li> <li title="profile-1"><a href="fprof.html#profile-1">profile/1</a></li> <li title="analyse-0"><a href="fprof.html#analyse-0">analyse/0</a></li> <li title="analyse-2"><a href="fprof.html#analyse-2">analyse/2</a></li> <li title="analyse-1"><a href="fprof.html#analyse-1">analyse/1</a></li> <li title="analyse-1"><a href="fprof.html#analyse-1">analyse/1</a></li> <li title="analyse-1"><a href="fprof.html#analyse-1">analyse/1</a></li> </ul> </li> <li id="no" title="instrument " expanded="false">instrument<ul> <li><a href="instrument.html"> Top of manual page </a></li> <li title="allocator_descr-2"><a href="instrument.html#allocator_descr-2">allocator_descr/2</a></li> <li title="block_header_size-1"><a href="instrument.html#block_header_size-1">block_header_size/1</a></li> <li title="class_descr-2"><a href="instrument.html#class_descr-2">class_descr/2</a></li> <li title="descr-1"><a href="instrument.html#descr-1">descr/1</a></li> <li title="holes-1"><a href="instrument.html#holes-1">holes/1</a></li> <li title="mem_limits-1"><a href="instrument.html#mem_limits-1">mem_limits/1</a></li> <li title="memory_data-0"><a href="instrument.html#memory_data-0">memory_data/0</a></li> <li title="memory_status-1"><a href="instrument.html#memory_status-1">memory_status/1</a></li> <li title="read_memory_data-1"><a href="instrument.html#read_memory_data-1">read_memory_data/1</a></li> <li title="read_memory_status-1"><a href="instrument.html#read_memory_status-1">read_memory_status/1</a></li> <li title="sort-1"><a href="instrument.html#sort-1">sort/1</a></li> <li title="store_memory_data-1"><a href="instrument.html#store_memory_data-1">store_memory_data/1</a></li> <li title="store_memory_status-1"><a href="instrument.html#store_memory_status-1">store_memory_status/1</a></li> <li title="sum_blocks-1"><a href="instrument.html#sum_blocks-1">sum_blocks/1</a></li> <li title="type_descr-2"><a href="instrument.html#type_descr-2">type_descr/2</a></li> <li title="type_no_range-1"><a href="instrument.html#type_no_range-1">type_no_range/1</a></li> </ul> </li> <li id="no" title="lcnt " expanded="false">lcnt<ul> <li><a href="lcnt.html"> Top of manual page </a></li> <li title="start-0"><a href="lcnt.html#start-0">start/0</a></li> <li title="stop-0"><a href="lcnt.html#stop-0">stop/0</a></li> <li title="collect-0"><a href="lcnt.html#collect-0">collect/0</a></li> <li title="collect-1"><a href="lcnt.html#collect-1">collect/1</a></li> <li title="clear-0"><a href="lcnt.html#clear-0">clear/0</a></li> <li title="clear-1"><a href="lcnt.html#clear-1">clear/1</a></li> <li title="conflicts-0"><a href="lcnt.html#conflicts-0">conflicts/0</a></li> <li title="conflicts-1"><a href="lcnt.html#conflicts-1">conflicts/1</a></li> <li title="locations-0"><a href="lcnt.html#locations-0">locations/0</a></li> <li title="locations-1"><a href="lcnt.html#locations-1">locations/1</a></li> <li title="inspect-1"><a href="lcnt.html#inspect-1">inspect/1</a></li> <li title="inspect-2"><a href="lcnt.html#inspect-2">inspect/2</a></li> <li title="information-0"><a href="lcnt.html#information-0">information/0</a></li> <li title="swap_pid_keys-0"><a href="lcnt.html#swap_pid_keys-0">swap_pid_keys/0</a></li> <li title="load-1"><a href="lcnt.html#load-1">load/1</a></li> <li title="save-1"><a href="lcnt.html#save-1">save/1</a></li> <li title="apply-1"><a href="lcnt.html#apply-1">apply/1</a></li> <li title="apply-2"><a href="lcnt.html#apply-2">apply/2</a></li> <li title="apply-3"><a href="lcnt.html#apply-3">apply/3</a></li> <li title="pid-2"><a href="lcnt.html#pid-2">pid/2</a></li> <li title="pid-3"><a href="lcnt.html#pid-3">pid/3</a></li> <li title="port-1"><a href="lcnt.html#port-1">port/1</a></li> <li title="port-2"><a href="lcnt.html#port-2">port/2</a></li> <li title="rt_collect-0"><a href="lcnt.html#rt_collect-0">rt_collect/0</a></li> <li title="rt_collect-1"><a href="lcnt.html#rt_collect-1">rt_collect/1</a></li> <li title="rt_clear-0"><a href="lcnt.html#rt_clear-0">rt_clear/0</a></li> <li title="rt_clear-1"><a href="lcnt.html#rt_clear-1">rt_clear/1</a></li> <li title="rt_opt-1"><a href="lcnt.html#rt_opt-1">rt_opt/1</a></li> <li title="rt_opt-2"><a href="lcnt.html#rt_opt-2">rt_opt/2</a></li> </ul> </li> <li id="no" title="make " expanded="false">make<ul> <li><a href="make.html"> Top of manual page </a></li> <li title="all-0"><a href="make.html#all-0">all/0</a></li> <li title="all-1"><a href="make.html#all-1">all/1</a></li> <li title="files-1"><a href="make.html#files-1">files/1</a></li> <li title="files-2"><a href="make.html#files-2">files/2</a></li> </ul> </li> <li id="no" title="tags " expanded="false">tags<ul> <li><a href="tags.html"> Top of manual page </a></li> <li title="file-1"><a href="tags.html#file-1">file/1</a></li> <li title="files-1"><a href="tags.html#files-1">files/1</a></li> <li title="dir-1"><a href="tags.html#dir-1">dir/1</a></li> <li title="dirs-1"><a href="tags.html#dirs-1">dirs/1</a></li> <li title="subdir-1"><a href="tags.html#subdir-1">subdir/1</a></li> <li title="subdirs-1"><a href="tags.html#subdirs-1">subdirs/1</a></li> <li title="root-1"><a href="tags.html#root-1">root/1</a></li> </ul> </li> <li id="loadscrollpos" title="xref " expanded="true">xref<ul> <li><a href="xref.html"> Top of manual page </a></li> <li title="add_application-2"><a href="xref.html#add_application-2">add_application/2</a></li> <li title="add_directory-2"><a href="xref.html#add_directory-2">add_directory/2</a></li> <li title="add_module-2"><a href="xref.html#add_module-2">add_module/2</a></li> <li title="add_release-2"><a href="xref.html#add_release-2">add_release/2</a></li> <li title="analyze-2"><a href="xref.html#analyze-2">analyze/2</a></li> <li title="d-1"><a href="xref.html#d-1">d/1</a></li> <li title="forget-1"><a href="xref.html#forget-1">forget/1</a></li> <li title="forget-2"><a href="xref.html#forget-2">forget/2</a></li> <li title="format_error-1"><a href="xref.html#format_error-1">format_error/1</a></li> <li title="get_default-1"><a href="xref.html#get_default-1">get_default/1</a></li> <li title="get_default-2"><a href="xref.html#get_default-2">get_default/2</a></li> <li title="get_library_path-1"><a href="xref.html#get_library_path-1">get_library_path/1</a></li> <li title="info-1"><a href="xref.html#info-1">info/1</a></li> <li title="info-2"><a href="xref.html#info-2">info/2</a></li> <li title="info-3"><a href="xref.html#info-3">info/3</a></li> <li title="m-1"><a href="xref.html#m-1">m/1</a></li> <li title="m-1"><a href="xref.html#m-1">m/1</a></li> <li title="q-2"><a href="xref.html#q-2">q/2</a></li> <li title="remove_application-2"><a href="xref.html#remove_application-2">remove_application/2</a></li> <li title="remove_module-2"><a href="xref.html#remove_module-2">remove_module/2</a></li> <li title="remove_release-2"><a href="xref.html#remove_release-2">remove_release/2</a></li> <li title="replace_application-3"><a href="xref.html#replace_application-3">replace_application/3</a></li> <li title="replace_module-3"><a href="xref.html#replace_module-3">replace_module/3</a></li> <li title="set_default-3"><a href="xref.html#set_default-3">set_default/3</a></li> <li title="set_default-2"><a href="xref.html#set_default-2">set_default/2</a></li> <li title="set_library_path-2"><a href="xref.html#set_library_path-2">set_library_path/2</a></li> <li title="start-1"><a href="xref.html#start-1">start/1</a></li> <li title="start-2"><a href="xref.html#start-2">start/2</a></li> <li title="stop-1"><a href="xref.html#stop-1">stop/1</a></li> <li title="update-1"><a href="xref.html#update-1">update/1</a></li> <li title="variables-1"><a href="xref.html#variables-1">variables/1</a></li> </ul> </li> </ul> </div></div> <div id="content"> <div class="innertube"> <!-- refpage --><center><h1>xref</h1></center> <h3>MODULE</h3> <div class="REFBODY">xref</div> <h3>MODULE SUMMARY</h3> <div class="REFBODY">A Cross Reference Tool for analyzing dependencies between functions, modules, applications and releases.</div> <h3>DESCRIPTION</h3> <div class="REFBODY"><p> <p>Xref is a cross reference tool that can be used for finding dependencies between functions, modules, applications and releases. </p> <p>Calls between functions are either <a name="local_call"></a> <strong>local calls</strong> like <span class="code">f()</span>, or <a name="external_call"></a> <strong>external calls</strong> like <span class="code">m:f()</span>. <a name="module_data"></a> <strong>Module data</strong>, which are extracted from BEAM files, include local functions, exported functions, local calls and external calls. By default, calls to built-in functions (BIF) are ignored, but if the option <span class="code">builtins</span>, accepted by some of this module's functions, is set to <span class="code">true</span>, calls to BIFs are included as well. It is the analyzing OTP version that decides what functions are BIFs. Functional objects are assumed to be called where they are created (and nowhere else). <a name="unresolved_call"></a> <strong>Unresolved calls</strong> are calls to <span class="code">apply</span> or <span class="code">spawn</span> with variable module, variable function, or variable arguments. Examples are <span class="code">M:F(a)</span>, <span class="code">apply(M, f, [a])</span>, and <span class="code">spawn(m, f(), Args)</span>. Unresolved calls are represented by calls where variable modules have been replaced with the atom <span class="code">'$M_EXPR'</span>, variable functions have been replaced with the atom <span class="code">'$F_EXPR'</span>, and variable number of arguments have been replaced with the number <span class="code">-1</span>. The above mentioned examples are represented by calls to <span class="code">'$M_EXPR':'$F_EXPR'/1</span>, <span class="code">'$M_EXPR':f/1</span>, and <span class="code">m:'$F_EXPR'/-1</span>. The unresolved calls are a subset of the external calls. </p> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p>Unresolved calls make module data incomplete, which implies that the results of analyses may be invalid.</p> </p></div> </div> <p><strong>Applications</strong> are collections of modules. The modules' BEAM files are located in the <span class="code">ebin</span> subdirectory of the application directory. The name of the application directory determines the name and version of the application. <strong>Releases</strong> are collections of applications located in the <span class="code">lib</span> subdirectory of the release directory. There is more to read about applications and releases in the Design Principles book. </p> <p> <a name="xref_server"></a> <strong>Xref servers</strong> are identified by names, supplied when creating new servers. Each Xref server holds a set of releases, a set of applications, and a set of modules with module data. Xref servers are independent of each other, and all analyses are evaluated in the context of one single Xref server (exceptions are the functions <span class="code">m/1</span> and <span class="code">d/1</span> which do not use servers at all). The <a name="mode"></a> <strong>mode</strong> of an Xref server determines what module data are extracted from BEAM files as modules are added to the server. Starting with R7, BEAM files compiled with the option <span class="code">debug_info</span> contain so called <a name="debug_info"></a> debug information, which is an abstract representation of the code. In <span class="code">functions</span> mode, which is the default mode, function calls and line numbers are extracted from debug information. In <span class="code">modules</span> mode, debug information is ignored if present, but dependencies between modules are extracted from other parts of the BEAM files. The <span class="code">modules</span> mode is significantly less time and space consuming than the <span class="code">functions</span> mode, but the analyses that can be done are limited. </p> <p>An <a name="analyzed_module"></a> <strong>analyzed module</strong> is a module that has been added to an Xref server together with its module data. A <a name="library_module"></a> <strong>library module</strong> is a module located in some directory mentioned in the <a name="library_path"></a> <strong>library path</strong>. A library module is said to be used if some of its exported functions are used by some analyzed module. An <a name="unknown_module"></a> <strong>unknown module</strong> is a module that is neither an analyzed module nor a library module, but whose exported functions are used by some analyzed module. An <a name="unknown_function"></a> <strong>unknown function</strong> is a used function that is neither local or exported by any analyzed module nor exported by any library module. An <a name="undefined_function"></a> <strong>undefined function</strong> is an externally used function that is not exported by any analyzed module or library module. With this notion, a local function can be an undefined function, namely if it is externally used from some module. All unknown functions are also undefined functions; there is a <span class="bold_code"><a href="xref_chapter.html#venn2">figure</a></span> in the User's Guide that illustrates this relationship. </p> <p>Starting with R9C, the module attribute tag <span class="code">deprecated</span> can be used to inform Xref about <a name="deprecated_function"></a> <strong>deprecated functions</strong> and optionally when functions are planned to be removed. A few examples show the idea: </p> <dl> <dt><strong>-deprecated({f,1}).</strong></dt> <dd>The exported function <span class="code">f/1</span> is deprecated. Nothing is said whether <span class="code">f/1</span> will be removed or not.</dd> <dt><strong>-deprecated({f,'_'}).</strong></dt> <dd>All exported functions <span class="code">f/0</span>, <span class="code">f/1</span> and so on are deprecated.</dd> <dt><strong>-deprecated(module).</strong></dt> <dd>All exported functions in the module are deprecated. Equivalent to <span class="code">-deprecated({'_','_'}).</span>.</dd> <dt><strong>-deprecated([{g,1,next_version}]).</strong></dt> <dd>The function <span class="code">g/1</span> is deprecated and will be removed in next version.</dd> <dt><strong>-deprecated([{g,2,next_major_release}]).</strong></dt> <dd>The function <span class="code">g/2</span> is deprecated and will be removed in next major release.</dd> <dt><strong>-deprecated([{g,3,eventually}]).</strong></dt> <dd>The function <span class="code">g/3</span> is deprecated and will eventually be removed.</dd> <dt><strong>-deprecated({'_','_',eventually}).</strong></dt> <dd>All exported functions in the module are deprecated and will eventually be removed.</dd> </dl> <p>Before any analysis can take place, module data must be <strong>set up</strong>. For instance, the cross reference and the unknown functions are computed when all module data are known. The functions that need complete data (<span class="code">analyze</span>, <span class="code">q</span>, <span class="code">variables</span>) take care of setting up data automatically. Module data need to be set up (again) after calls to any of the <span class="code">add</span>, <span class="code">replace</span>, <span class="code">remove</span>, <span class="code">set_library_path</span> or <span class="code">update</span> functions. </p> <p>The result of setting up module data is the <a name="call_graph"></a> <strong>Call Graph</strong>. A (directed) graph consists of a set of vertices and a set of (directed) edges. The edges represent <a name="call"></a> <strong>calls</strong> (From, To) between functions, modules, applications or releases. From is said to call To, and To is said to be used by From. The vertices of the Call Graph are the functions of all module data: local and exported functions of analyzed modules; used BIFs; used exported functions of library modules; and unknown functions. The functions <span class="code">module_info/0,1</span> added by the compiler are included among the exported functions, but only when called from some module. The edges are the function calls of all module data. A consequence of the edges being a set is that there is only one edge if a function is locally or externally used several times on one and the same line of code. </p> <p>The Call Graph is <a name="representation"></a> represented by Erlang terms (the sets are lists), which is suitable for many analyses. But for analyses that look at chains of calls, a list representation is much too slow. Instead the representation offered by the <span class="code">digraph</span> module is used. The translation of the list representation of the Call Graph - or a subgraph thereof - to the <span class="code">digraph</span> representation does not come for free, so the language used for expressing queries to be described below has a special operator for this task and a possibility to save the <span class="code">digraph</span> representation for subsequent analyses. </p> <p>In addition to the Call Graph there is a graph called the <a name="inter_call_graph"></a> <strong>Inter Call Graph</strong>. This is a graph of calls (From, To) such that there is a chain of calls from From to To in the Call Graph, and every From and To is an exported function or an unused local function. The vertices are the same as for the Call Graph. </p> <p>Calls between modules, applications and releases are also directed graphs. The <a name="type"></a> <strong>types</strong> of the vertices and edges of these graphs are (ranging from the most special to the most general): <span class="code">Fun</span> for functions; <span class="code">Mod</span> for modules; <span class="code">App</span> for applications; and <span class="code">Rel</span> for releases. The following paragraphs will describe the different constructs of the language used for selecting and analyzing parts of the graphs, beginning with the <a name="constants"></a> <strong>constants</strong>: </p> <ul> <li>Expression ::= Constants</li> <li>Constants ::= Consts | Consts <span class="code">:</span> Type | RegExpr</li> <li>Consts ::= Constant | <span class="code">[</span>Constant<span class="code">,</span> ...<span class="code">]</span> | <span class="code">{</span>Constant<span class="code">,</span> ...<span class="code">}</span> </li> <li>Constant ::= Call | Const</li> <li>Call ::= FunSpec <span class="code">-></span> FunSpec | <span class="code">{</span>MFA<span class="code">,</span> MFA<span class="code">}</span> | AtomConst <span class="code">-></span> AtomConst | <span class="code">{</span>AtomConst<span class="code">,</span> AtomConst<span class="code">}</span> </li> <li>Const ::= AtomConst | FunSpec | MFA</li> <li>AtomConst ::= Application | Module | Release</li> <li>FunSpec ::= Module <span class="code">:</span> Function <span class="code">/</span> Arity</li> <li>MFA ::= <span class="code">{</span>Module<span class="code">,</span> Function<span class="code">,</span> Arity<span class="code">}</span> </li> <li>RegExpr ::= RegString <span class="code">:</span> Type | RegFunc | RegFunc <span class="code">:</span> Type</li> <li>RegFunc ::= RegModule <span class="code">:</span> RegFunction <span class="code">/</span> RegArity</li> <li>RegModule ::= RegAtom</li> <li>RegFunction ::= RegAtom</li> <li>RegArity ::= RegString | Number | <span class="code">_</span> | <span class="code">-1</span> </li> <li>RegAtom ::= RegString | Atom | <span class="code">_</span> </li> <li>RegString ::= - a regular expression, as described in the <span class="code">regexp</span> module, enclosed in double quotes -</li> <li>Type ::= <span class="code">Fun</span> | <span class="code">Mod</span> | <span class="code">App</span> | <span class="code">Rel</span> </li> <li>Function ::= Atom</li> <li>Application ::= Atom</li> <li>Module ::= Atom</li> <li>Release ::= Atom</li> <li>Arity ::= Number | <span class="code">-1</span> </li> <li>Atom ::= - same as Erlang atoms -</li> <li>Number ::= - same as non-negative Erlang integers -</li> </ul> <p>Examples of constants are: <span class="code">kernel</span>, <span class="code">kernel->stdlib</span>, <span class="code">[kernel, sasl]</span>, <span class="code">[pg -> mnesia, {tv, mnesia}] : Mod</span>. It is an error if an instance of <span class="code">Const</span> does not match any vertex of any graph. If there are more than one vertex matching an untyped instance of <span class="code">AtomConst</span>, then the one of the most general type is chosen. A list of constants is interpreted as a set of constants, all of the same type. A tuple of constants constitute a chain of calls (which may, but does not have to, correspond to an actual chain of calls of some graph). Assigning a type to a list or tuple of <span class="code">Constant</span> is equivalent to assigning the type to each <span class="code">Constant</span>. </p> <p> <a name="regexp"></a> <strong>Regular expressions</strong> are used as a means to select some of the vertices of a graph. A <span class="code">RegExpr</span> consisting of a <span class="code">RegString</span> and a type - an example is <span class="code">"xref_.*" : Mod</span> - is interpreted as those modules (or applications or releases, depending on the type) that match the expression. Similarly, a <span class="code">RegFunc</span> is interpreted as those vertices of the Call Graph that match the expression. An example is <span class="code">"xref_.*":"add_.*"/"(2|3)"</span>, which matches all <span class="code">add</span> functions of arity two or three of any of the xref modules. Another example, one that matches all functions of arity 10 or more: <span class="code">_:_/"[1-9].+"</span>. Here <span class="code">_</span> is an abbreviation for <span class="code">".*"</span>, that is, the regular expression that matches anything. </p> <p>The syntax of <a name="variable"></a> <strong>variables</strong> is simple: </p> <ul> <li>Expression ::= Variable</li> <li>Variable ::= - same as Erlang variables -</li> </ul> <p>There are two kinds of variables: predefined variables and user variables. <a name="predefined_variable"></a> <strong>Predefined variables</strong> hold set up module data, and cannot be assigned to but only used in queries. <a name="user_variable"></a> <strong>User variables</strong> on the other hand can be assigned to, and are typically used for temporary results while evaluating a query, and for keeping results of queries for use in subsequent queries. The predefined variables are (variables marked with (*) are available in <span class="code">functions</span> mode only): </p> <dl> <dt><strong><span class="code">E</span></strong></dt> <dd>Call Graph Edges (*).</dd> <dt><strong><span class="code">V</span></strong></dt> <dd>Call Graph Vertices (*). </dd> <dt><strong><span class="code">M</span></strong></dt> <dd>Modules. All modules: analyzed modules, used library modules, and unknown modules.</dd> <dt><strong><span class="code">A</span></strong></dt> <dd>Applications.</dd> <dt><strong><span class="code">R</span></strong></dt> <dd>Releases. </dd> <dt><strong><span class="code">ME</span></strong></dt> <dd>Module Edges. All module calls.</dd> <dt><strong><span class="code">AE</span></strong></dt> <dd>Application Edges. All application calls. </dd> <dt><strong><span class="code">RE</span></strong></dt> <dd>Release Edges. All release calls. </dd> <dt><strong><span class="code">L</span></strong></dt> <dd>Local Functions (*). All local functions of analyzed modules.</dd> <dt><strong><span class="code">X</span></strong></dt> <dd>Exported Functions. All exported functions of analyzed modules and all used exported functions of library modules.</dd> <dt><strong><span class="code">F</span></strong></dt> <dd>Functions (*).</dd> <dt><strong><span class="code">B</span></strong></dt> <dd>Used BIFs. <span class="code">B</span> is empty if <span class="code">builtins</span> is <span class="code">false</span> for all analyzed modules.</dd> <dt><strong><span class="code">U</span></strong></dt> <dd>Unknown Functions.</dd> <dt><strong><span class="code">UU</span></strong></dt> <dd>Unused Functions (*). All local and exported functions of analyzed modules that have not been used. </dd> <dt><strong><span class="code">XU</span></strong></dt> <dd>Externally Used Functions. Functions of all modules - including local functions - that have been used in some external call.</dd> <dt><strong><span class="code">LU</span></strong></dt> <dd>Locally Used Functions (*). Functions of all modules that have been used in some local call. </dd> <dt><strong><span class="code">LC</span></strong></dt> <dd>Local Calls (*).</dd> <dt><strong><span class="code">XC</span></strong></dt> <dd>External Calls (*). </dd> <dt><strong><span class="code">AM</span></strong></dt> <dd>Analyzed Modules.</dd> <dt><strong><span class="code">UM</span></strong></dt> <dd>Unknown Modules.</dd> <dt><strong><span class="code">LM</span></strong></dt> <dd>Used Library Modules. </dd> <dt><strong><span class="code">UC</span></strong></dt> <dd>Unresolved Calls. Empty in <span class="code">modules</span> mode. </dd> <dt><strong><span class="code">EE</span></strong></dt> <dd>Inter Call Graph Edges (*). </dd> <dt><strong><span class="code">DF</span></strong></dt> <dd>Deprecated Functions. All deprecated exported functions and all used deprecated BIFs.</dd> <dt><strong><span class="code">DF_1</span></strong></dt> <dd>Deprecated Functions. All deprecated functions to be removed in next version.</dd> <dt><strong><span class="code">DF_2</span></strong></dt> <dd>Deprecated Functions. All deprecated functions to be removed in next version or next major release.</dd> <dt><strong><span class="code">DF_3</span></strong></dt> <dd>Deprecated Functions. All deprecated functions to be removed in next version, next major release, or later.</dd> </dl> <p>These are a few <a name="simple_facts"></a> facts about the predefined variables (the set operators <span class="code">+</span> (union) and <span class="code">-</span> (difference) as well as the cast operator <span class="code">(</span>Type<span class="code">)</span> are described below): </p> <ul> <li> <span class="code">F</span> is equal to <span class="code">L + X</span>.</li> <li> <span class="code">V</span> is equal to <span class="code">X + L + B + U</span>, where <span class="code">X</span>, <span class="code">L</span>, <span class="code">B</span> and <span class="code">U</span> are pairwise disjoint (that is, have no elements in common).</li> <li> <span class="code">UU</span> is equal to <span class="code">V - (XU + LU)</span>, where <span class="code">LU</span> and <span class="code">XU</span> may have elements in common. Put in another way:</li> <li> <span class="code">V</span> is equal to <span class="code">UU + XU + LU</span>.</li> <li> <span class="code">E</span> is equal to <span class="code">LC + XC</span>. Note that <span class="code">LC</span> and <span class="code">XC</span> may have elements in common, namely if some function is locally and externally used from one and the same function.</li> <li> <span class="code">U</span> is a subset of <span class="code">XU</span>.</li> <li> <span class="code">B</span> is a subset of <span class="code">XU</span>.</li> <li> <span class="code">LU</span> is equal to <span class="code">range LC</span>.</li> <li> <span class="code">XU</span> is equal to <span class="code">range XC</span>.</li> <li> <span class="code">LU</span> is a subset of <span class="code">F</span>.</li> <li> <span class="code">UU</span> is a subset of <span class="code">F</span>. </li> <li> <span class="code">range UC</span> is a subset of <span class="code">U</span>.</li> <li> <span class="code">M</span> is equal to <span class="code">AM + LM + UM</span>, where <span class="code">AM</span>, <span class="code">LM</span> and <span class="code">UM</span> are pairwise disjoint. </li> <li> <span class="code">ME</span> is equal to <span class="code">(Mod) E</span>.</li> <li> <span class="code">AE</span> is equal to <span class="code">(App) E</span>.</li> <li> <span class="code">RE</span> is equal to <span class="code">(Rel) E</span>.</li> <li> <span class="code">(Mod) V</span> is a subset of <span class="code">M</span>. Equality holds if all analyzed modules have some local, exported, or unknown function.</li> <li> <span class="code">(App) M</span> is a subset of <span class="code">A</span>. Equality holds if all applications have some module.</li> <li> <span class="code">(Rel) A</span> is a subset of <span class="code">R</span>. Equality holds if all releases have some application.</li> <li> <span class="code">DF_1</span> is a subset of <span class="code">DF_2</span>.</li> <li> <span class="code">DF_2</span> is a subset of <span class="code">DF_3</span>.</li> <li> <span class="code">DF_3</span> is a subset of <span class="code">DF</span>.</li> <li> <span class="code">DF</span> is a subset of <span class="code">X + B</span>.</li> </ul> <p>An important notion is that of <a name="conversion"></a> <strong>conversion</strong> of expressions. The syntax of a cast expression is: </p> <ul> <li>Expression ::= <span class="code">(</span> Type <span class="code">)</span> Expression</li> </ul> <p>The interpretation of the cast operator depends on the named type <span class="code">Type</span>, the type of <span class="code">Expression</span>, and the structure of the elements of the interpretation of <span class="code">Expression</span>. If the named type is equal to the expression type, no conversion is done. Otherwise, the conversion is done one step at a time; <span class="code">(Fun) (App) RE</span>, for instance, is equivalent to <span class="code">(Fun) (Mod) (App) RE</span>. Now assume that the interpretation of <span class="code">Expression</span> is a set of constants (functions, modules, applications or releases). If the named type is more general than the expression type, say <span class="code">Mod</span> and <span class="code">Fun</span> respectively, then the interpretation of the cast expression is the set of modules that have at least one of their functions mentioned in the interpretation of the expression. If the named type is more special than the expression type, say <span class="code">Fun</span> and <span class="code">Mod</span>, then the interpretation is the set of all the functions of the modules (in <span class="code">modules</span> mode, the conversion is partial since the local functions are not known). The conversions to and from applications and releases work analogously. For instance, <span class="code">(App) "xref_.*" : Mod</span> returns all applications containing at least one module such that <span class="code">xref_</span> is a prefix of the module name. </p> <p>Now assume that the interpretation of <span class="code">Expression</span> is a set of calls. If the named type is more general than the expression type, say <span class="code">Mod</span> and <span class="code">Fun</span> respectively, then the interpretation of the cast expression is the set of calls (M1, M2) such that the interpretation of the expression contains a call from some function of M1 to some function of M2. If the named type is more special than the expression type, say <span class="code">Fun</span> and <span class="code">Mod</span>, then the interpretation is the set of all function calls (F1, F2) such that the interpretation of the expression contains a call (M1, M2) and F1 is a function of M1 and F2 is a function of M2 (in <span class="code">modules</span> mode, there are no functions calls, so a cast to <span class="code">Fun</span> always yields an empty set). Again, the conversions to and from applications and releases work analogously. </p> <p>The interpretation of constants and variables are sets, and those sets can be used as the basis for forming new sets by the application of <a name="set_operator"></a> <strong>set operators</strong>. The syntax: </p> <ul> <li>Expression ::= Expression BinarySetOp Expression</li> <li>BinarySetOp ::= <span class="code">+</span> | <span class="code">*</span> | <span class="code">-</span> </li> </ul> <p><span class="code">+</span>, <span class="code">*</span> and <span class="code">-</span> are interpreted as union, intersection and difference respectively: the union of two sets contains the elements of both sets; the intersection of two sets contains the elements common to both sets; and the difference of two sets contains the elements of the first set that are not members of the second set. The elements of the two sets must be of the same structure; for instance, a function call cannot be combined with a function. But if a cast operator can make the elements compatible, then the more general elements are converted to the less general element type. For instance, <span class="code">M + F</span> is equivalent to <span class="code">(Fun) M + F</span>, and <span class="code">E - AE</span> is equivalent to <span class="code">E - (Fun) AE</span>. One more example: <span class="code">X * xref : Mod</span> is interpreted as the set of functions exported by the module <span class="code">xref</span>; <span class="code">xref : Mod</span> is converted to the more special type of <span class="code">X</span> (<span class="code">Fun</span>, that is) yielding all functions of <span class="code">xref</span>, and the intersection with <span class="code">X</span> (all functions exported by analyzed modules and library modules) is interpreted as those functions that are exported by some module <strong>and</strong> functions of <span class="code">xref</span>. </p> <p>There are also unary set operators: </p> <ul> <li>Expression ::= UnarySetOp Expression</li> <li>UnarySetOp ::= <span class="code">domain</span> | <span class="code">range</span> | <span class="code">strict</span> </li> </ul> <p>Recall that a call is a pair (From, To). <span class="code">domain</span> applied to a set of calls is interpreted as the set of all vertices From, and <span class="code">range</span> as the set of all vertices To. The interpretation of the <span class="code">strict</span> operator is the operand with all calls on the form (A, A) removed. </p> <p>The interpretation of the <a name="restriction"></a> <strong>restriction operators</strong> is a subset of the first operand, a set of calls. The second operand, a set of vertices, is converted to the type of the first operand. The syntax of the restriction operators: </p> <ul> <li>Expression ::= Expression RestrOp Expression</li> <li>RestrOp ::= <span class="code">|</span> </li> <li>RestrOp ::= <span class="code">||</span> </li> <li>RestrOp ::= <span class="code">|||</span> </li> </ul> <p>The interpretation in some detail for the three operators: </p> <dl> <dt><strong><span class="code">|</span></strong></dt> <dd>The subset of calls from any of the vertices.</dd> <dt><strong><span class="code">||</span></strong></dt> <dd>The subset of calls to any of the vertices.</dd> <dt><strong><span class="code">|||</span></strong></dt> <dd>The subset of calls to and from any of the vertices. For all sets of calls <span class="code">CS</span> and all sets of vertices <span class="code">VS</span>, <span class="code">CS ||| VS </span> is equivalent to <span class="code">CS | VS * CS || VS</span>.</dd> </dl> <p> <a name="graph_analyses"></a> Two functions (modules, applications, releases) belong to the same strongly connected component if they call each other (in)directly. The interpretation of the <span class="code">components</span> operator is the set of strongly connected components of a set of calls. The <span class="code">condensation</span> of a set of calls is a new set of calls between the strongly connected components such that there is an edge between two components if there is some constant of the first component that calls some constant of the second component. </p> <p>The interpretation of the <span class="code">of</span> operator is a chain of calls of the second operand (a set of calls) that passes throw all of the vertices of the first operand (a tuple of constants), in the given order. The second operand is converted to the type of the first operand. For instance, the <span class="code">of</span> operator can be used for finding out whether a function calls another function indirectly, and the chain of calls demonstrates how. The syntax of the graph analyzing operators: </p> <ul> <li>Expression ::= Expression GraphOp Expression</li> <li>GraphOp ::= <span class="code">components</span> | <span class="code">condensation</span> | <span class="code">of</span> </li> </ul> <p>As was mentioned before, the graph analyses operate on the <span class="code">digraph</span> representation of graphs. By default, the <span class="code">digraph</span> representation is created when needed (and deleted when no longer used), but it can also be created explicitly by use of the <span class="code">closure</span> operator: </p> <ul> <li>Expression ::= ClosureOp Expression</li> <li>ClosureOp ::= <span class="code">closure</span> </li> </ul> <p>The interpretation of the <span class="code">closure</span> operator is the transitive closure of the operand. </p> <p>The restriction operators are defined for closures as well; <span class="code">closure E | xref : Mod</span> is interpreted as the direct or indirect function calls from the <span class="code">xref</span> module, while the interpretation of <span class="code">E | xref : Mod</span> is the set of direct calls from <span class="code">xref</span>. If some graph is to be used in several graph analyses, it saves time to assign the <span class="code">digraph</span> representation of the graph to a user variable, and then make sure that every graph analysis operates on that variable instead of the list representation of the graph. </p> <p>The lines where functions are defined (more precisely: where the first clause begins) and the lines where functions are used are available in <span class="code">functions</span> mode. The line numbers refer to the files where the functions are defined. This holds also for files included with the <span class="code">-include</span> and <span class="code">-include_lib</span> directives, which may result in functions defined apparently in the same line. The <strong>line operators</strong> are used for assigning line numbers to functions and for assigning sets of line numbers to function calls. The syntax is similar to the one of the cast operator: </p> <ul> <li>Expression ::= <span class="code">(</span> LineOp<span class="code">)</span> Expression</li> <li>Expression ::= <span class="code">(</span> XLineOp<span class="code">)</span> Expression</li> <li>LineOp ::= <span class="code">Lin</span> | <span class="code">ELin</span> | <span class="code">LLin</span> | <span class="code">XLin</span> </li> <li>XLineOp ::= <span class="code">XXL</span> </li> </ul> <p>The interpretation of the <span class="code">Lin</span> operator applied to a set of functions assigns to each function the line number where the function is defined. Unknown functions and functions of library modules are assigned the number 0. </p> <p>The interpretation of some LineOp operator applied to a set of function calls assigns to each call the set of line numbers where the first function calls the second function. Not all calls are assigned line numbers by all operators: </p> <ul> <li>the <span class="code">Lin</span> operator is defined for Call Graph Edges;</li> <li>the <span class="code">LLin</span> operator is defined for Local Calls.</li> <li>the <span class="code">XLin</span> operator is defined for External Calls.</li> <li>the <span class="code">ELin</span> operator is defined for Inter Call Graph Edges.</li> </ul> <p>The <span class="code">Lin</span> (<span class="code">LLin</span>, <span class="code">XLin</span>) operator assigns the lines where calls (local calls, external calls) are made. The <span class="code">ELin</span> operator assigns to each call (From, To), for which it is defined, every line L such that there is a chain of calls from From to To beginning with a call on line L. </p> <p>The <span class="code">XXL</span> operator is defined for the interpretation of any of the LineOp operators applied to a set of function calls. The result is that of replacing the function call with a line numbered function call, that is, each of the two functions of the call is replaced by a pair of the function and the line where the function is defined. The effect of the <span class="code">XXL</span> operator can be undone by the LineOp operators. For instance, <span class="code">(Lin) (XXL) (Lin) E</span> is equivalent to <span class="code">(Lin) E</span>. </p> <p>The <span class="code">+</span>, <span class="code">-</span>, <span class="code">*</span> and <span class="code">#</span> operators are defined for line number expressions, provided the operands are compatible. The LineOp operators are also defined for modules, applications, and releases; the operand is implicitly converted to functions. Similarly, the cast operator is defined for the interpretation of the LineOp operators. </p> <p>The interpretation of the <a name="count"></a> <strong>counting operator</strong> is the number of elements of a set. The operator is undefined for closures. The <span class="code">+</span>, <span class="code">-</span> and <span class="code">*</span> operators are interpreted as the obvious arithmetical operators when applied to numbers. The syntax of the counting operator: </p> <ul> <li>Expression ::= CountOp Expression</li> <li>CountOp ::= <span class="code">#</span> </li> </ul> <p>All binary operators are left associative; for instance, <span class="code">A | B || C</span> is equivalent to <span class="code">(A | B) || C</span>. The following is a list of all operators, in increasing order of <a name="precedence"></a> <strong>precedence</strong>: </p> <ul> <li> <span class="code">+</span>, <span class="code">-</span> </li> <li><span class="code">*</span></li> <li><span class="code">#</span></li> <li> <span class="code">|</span>, <span class="code">||</span>, <span class="code">|||</span> </li> <li><span class="code">of</span></li> <li> <span class="code">(</span>Type<span class="code">)</span> </li> <li> <span class="code">closure</span>, <span class="code">components</span>, <span class="code">condensation</span>, <span class="code">domain</span>, <span class="code">range</span>, <span class="code">strict</span> </li> </ul> <p>Parentheses are used for grouping, either to make an expression more readable or to override the default precedence of operators: </p> <ul> <li>Expression ::= <span class="code">(</span> Expression <span class="code">)</span> </li> </ul> <p>A <a name="query"></a> <strong>query</strong> is a non-empty sequence of statements. A statement is either an assignment of a user variable or an expression. The value of an assignment is the value of the right hand side expression. It makes no sense to put a plain expression anywhere else but last in queries. The syntax of queries is summarized by these productions: </p> <ul> <li>Query ::= Statement<span class="code">,</span> ...</li> <li>Statement ::= Assignment | Expression</li> <li>Assignment ::= Variable <span class="code">:=</span> Expression | Variable <span class="code">=</span> Expression</li> </ul> <p>A variable cannot be assigned a new value unless first removed. Variables assigned to by the <span class="code">=</span> operator are removed at the end of the query, while variables assigned to by the <span class="code">:=</span> operator can only be removed by calls to <span class="code">forget</span>. There are no user variables when module data need to be set up again; if any of the functions that make it necessary to set up module data again is called, all user variables are forgotten. </p> <p><strong>Types</strong></p> <div class="example"><pre> application() = atom() arity() = int() | -1 bool() = true | false call() = {atom(), atom()} | funcall() constant() = mfa() | module() | application() | release() directory() = string() file() = string() funcall() = {mfa(), mfa()} function() = atom() int() = integer() >= 0 library() = atom() library_path() = path() | code_path mfa() = {module(), function(), arity()} mode() = functions | modules module() = atom() release() = atom() string_position() = int() | at_end variable() = atom() xref() = atom() | pid() </pre></div> </p></div> <h3>EXPORTS</h3> <p><a name="add_application-2"><span class="bold_code">add_application(Xref, Directory [, Options]) -> {ok, application()} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Directory = directory()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {builtins, bool()} | {name, application()} | {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {application_clash, {application(), directory(), directory()}} | {file_error, file(), error()} | {invalid_filename, term()} | {invalid_options, term()} | - see also add_directory -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Adds an application, the modules of the application and <span class="bold_code"><a href="#module_data">module data</a></span> of the modules to an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The modules will be members of the application. The default is to use the base name of the directory with the version removed as application name, but this can be overridden by the <span class="code">name</span> option. Returns the name of the application. </p> <p>If the given directory has a subdirectory named <span class="code">ebin</span>, modules (BEAM files) are searched for in that directory, otherwise modules are searched for in the given directory. </p> <p>If the <span class="bold_code"><a href="#mode">mode</a></span> of the Xref server is <span class="code">functions</span>, BEAM files that contain no <span class="bold_code"><a href="#debug_info">debug information</a></span> are ignored. </p> </p></div> <p><a name="add_directory-2"><span class="bold_code">add_directory(Xref, Directory [, Options]) -> {ok, Modules} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Directory = directory()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Modules = [module()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {builtins, bool()} | {recurse, bool()} | {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {file_error, file(), error()} | {invalid_filename, term()} | {invalid_options, term()} | {unrecognized_file, file()} | - error from beam_lib:chunks/2 -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Adds the modules found in the given directory and the <span class="bold_code"><a href="#module_data">modules' data</a></span> to an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The default is not to examine subdirectories, but if the option <span class="code">recurse</span> has the value <span class="code">true</span>, modules are searched for in subdirectories on all levels as well as in the given directory. Returns a sorted list of the names of the added modules. </p> <p>The modules added will not be members of any applications. </p> <p>If the <span class="bold_code"><a href="#mode">mode</a></span> of the Xref server is <span class="code">functions</span>, BEAM files that contain no <span class="bold_code"><a href="#debug_info">debug information</a></span> are ignored. </p> </p></div> <p><a name="add_module-2"><span class="bold_code">add_module(Xref, File [, Options]) -> {ok, module()} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">File = file()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {builtins, bool()} | {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {file_error, file(), error()} | {invalid_filename, term()} | {invalid_options, term()} | {module_clash, {module(), file(), file()}} | {no_debug_info, file()} | - error from beam_lib:chunks/2 -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Adds a module and its <span class="bold_code"><a href="#module_data">module data</a></span> to an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The module will not be member of any application. Returns the name of the module. </p> <p>If the <span class="bold_code"><a href="#mode">mode</a></span> of the Xref server is <span class="code">functions</span>, and the BEAM file contains no <span class="bold_code"><a href="#debug_info">debug information</a></span>, the error message <span class="code">no_debug_info</span> is returned. </p> </p></div> <p><a name="add_release-2"><span class="bold_code">add_release(Xref, Directory [, Options]) -> {ok, release()} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Directory = directory()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {builtins, bool()} | {name, release()} | {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {application_clash, {application(), directory(), directory()}} | {file_error, file(), error()} | {invalid_filename, term()} | {invalid_options, term()} | {release_clash, {release(), directory(), directory()}} | - see also add_directory -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Adds a release, the applications of the release, the modules of the applications, and <span class="bold_code"><a href="#module_data">module data</a></span> of the modules to an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The applications will be members of the release, and the modules will be members of the applications. The default is to use the base name of the directory as release name, but this can be overridden by the <span class="code">name</span> option. Returns the name of the release. </p> <p>If the given directory has a subdirectory named <span class="code">lib</span>, the directories in that directory are assumed to be application directories, otherwise all subdirectories of the given directory are assumed to be application directories. If there are several versions of some application, the one with the highest version is chosen. </p> <p>If the <span class="bold_code"><a href="#mode">mode</a></span> of the Xref server is <span class="code">functions</span>, BEAM files that contain no <span class="bold_code"><a href="#debug_info">debug information</a></span> are ignored. </p> </p></div> <p><a name="analyze-2"><span class="bold_code">analyze(Xref, Analysis [, Options]) -> {ok, Answer} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Analysis = undefined_function_calls | undefined_functions | locals_not_used | exports_not_used | deprecated_function_calls | {deprecated_function_calls, DeprFlag} | deprecated_functions | {deprecated_functions, DeprFlag} | {call, FuncSpec} | {use, FuncSpec} | {module_call, ModSpec} | {module_use, ModSpec} | {application_call, AppSpec} | {application_use, AppSpec} | {release_call, RelSpec} | {release_use, RelSpec}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Answer = [term()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">AppSpec = application() | [application()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">DeprFlag = next_version | next_major_release | eventually</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">FuncSpec = mfa() | [mfa()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ModSpec = module() | [module()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {verbose, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">RelSpec = release() | [release()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()} | {parse_error, string_position(), term()} | {unavailable_analysis, term()} | {unknown_analysis, term()} | {unknown_constant, string()} | {unknown_variable, variable()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p> <a name="analyze"></a> Evaluates a predefined analysis. Returns a sorted list without duplicates of <span class="code">call()</span> or <span class="code">constant()</span>, depending on the chosen analysis. The predefined analyses, which operate on all <span class="bold_code"><a href="#analyzed_module">analyzed modules</a></span>, are (analyses marked with (*) are available in <span class="code">functions</span><span class="bold_code"><a href="#mode">mode</a></span> only):</p> <dl> <dt><strong><span class="code">undefined_function_calls</span>(*)</strong></dt> <dd>Returns a list of calls to <span class="bold_code"><a href="#undefined_function">undefined functions</a></span>.</dd> <dt><strong><span class="code">undefined_functions</span></strong></dt> <dd>Returns a list of <span class="bold_code"><a href="#undefined_function">undefined functions</a></span>. </dd> <dt><strong><span class="code">locals_not_used</span>(*)</strong></dt> <dd>Returns a list of local functions that have not been locally used.</dd> <dt><strong><span class="code">exports_not_used</span></strong></dt> <dd>Returns a list of exported functions that have not been externally used.</dd> <dt><strong><span class="code">deprecated_function_calls</span>(*)</strong></dt> <dd>Returns a list of external calls to <span class="bold_code"><a href="#deprecated_function">deprecated functions</a></span>.</dd> <dt><strong><span class="code">{deprecated_function_calls, DeprFlag}</span>(*)</strong></dt> <dd>Returns a list of external calls to deprecated functions. If <span class="code">DeprFlag</span> is equal to <span class="code">next_version</span>, calls to functions to be removed in next version are returned. If <span class="code">DeprFlag</span> is equal to <span class="code">next_major_release</span>, calls to functions to be removed in next major release are returned as well as calls to functions to be removed in next version. Finally, if <span class="code">DeprFlag</span> is equal to <span class="code">eventually</span>, all calls to functions to be removed are returned, including calls to functions to be removed in next version or next major release.</dd> <dt><strong><span class="code">deprecated_functions</span></strong></dt> <dd>Returns a list of externally used deprecated functions.</dd> <dt><strong><span class="code">{deprecated_functions, DeprFlag}</span></strong></dt> <dd>Returns a list of externally used deprecated functions. If <span class="code">DeprFlag</span> is equal to <span class="code">next_version</span>, functions to be removed in next version are returned. If <span class="code">DeprFlag</span> is equal to <span class="code">next_major_release</span>, functions to be removed in next major release are returned as well as functions to be removed in next version. Finally, if <span class="code">DeprFlag</span> is equal to <span class="code">eventually</span>, all functions to be removed are returned, including functions to be removed in next version or next major release.</dd> <dt><strong><span class="code">{call, FuncSpec}</span>(*)</strong></dt> <dd>Returns a list of functions called by some of the given functions.</dd> <dt><strong><span class="code">{use, FuncSpec}</span>(*)</strong></dt> <dd>Returns a list of functions that use some of the given functions.</dd> <dt><strong><span class="code">{module_call, ModSpec}</span></strong></dt> <dd>Returns a list of modules called by some of the given modules.</dd> <dt><strong><span class="code">{module_use, ModSpec}</span></strong></dt> <dd>Returns a list of modules that use some of the given modules.</dd> <dt><strong><span class="code">{application_call, AppSpec}</span></strong></dt> <dd>Returns a list of applications called by some of the given applications.</dd> <dt><strong><span class="code">{application_use, AppSpec}</span></strong></dt> <dd>Returns a list of applications that use some of the given applications.</dd> <dt><strong><span class="code">{release_call, RelSpec}</span></strong></dt> <dd>Returns a list of releases called by some of the given releases.</dd> <dt><strong><span class="code">{release_use, RelSpec}</span></strong></dt> <dd>Returns a list of releases that use some of the given releases.</dd> </dl> </p></div> <p><a name="d-1"><span class="bold_code">d(Directory) -> [DebugInfoResult] | [NoDebugInfoResult] | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Directory = directory()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">DebugInfoResult = {deprecated, [funcall()]} | {undefined, [funcall()]} | {unused, [mfa()]}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">NoDebugInfoResult = {deprecated, [mfa()]} | {undefined, [mfa()]}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {file_error, file(), error()} | {invalid_filename, term()} | {unrecognized_file, file()} | - error from beam_lib:chunks/2 -</span><br> </div> </div> <div class="REFBODY"><p> <p>The modules found in the given directory are checked for calls to <span class="bold_code"><a href="#deprecated_function">deprecated functions</a></span>, calls to <span class="bold_code"><a href="#undefined_function">undefined functions</a></span>, and for unused local functions. The code path is used as <span class="bold_code"><a href="#library_path">library path</a></span>. </p> <p>If some of the found BEAM files contain <span class="bold_code"><a href="#debug_info">debug information</a></span>, then those modules are checked and a list of tuples is returned. The first element of each tuple is one of: </p> <ul> <li> <span class="code">deprecated</span>, the second element is a sorted list of calls to deprecated functions;</li> <li> <span class="code">undefined</span>, the second element is a sorted list of calls to undefined functions;</li> <li> <span class="code">unused</span>, the second element is a sorted list of unused local functions.</li> </ul> <p>If no BEAM file contains debug information, then a list of tuples is returned. The first element of each tuple is one of: </p> <ul> <li> <span class="code">deprecated</span>, the second element is a sorted list of externally used deprecated functions;</li> <li> <span class="code">undefined</span>, the second element is a sorted list of undefined functions.</li> </ul> </p></div> <p><a name="forget-1"><span class="bold_code">forget(Xref) -> ok</span></a><br><a name="forget-2"><span class="bold_code">forget(Xref, Variables) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {not_user_variable, term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Variables = [variable()] | variable()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p><span class="code">forget/1</span> and <span class="code">forget/2</span> remove all or some of the <span class="bold_code"><a href="#user_variable">user variables</a></span> of an <span class="bold_code"><a href="#xref_server">xref server</a></span>.</p> </p></div> <p><a name="format_error-1"><span class="bold_code">format_error(Error) -> Chars</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Chars = [char() | Chars]</span><br> </div> </div> <div class="REFBODY"><p> <p>Given the error returned by any function of this module, the function <span class="code">format_error</span> returns a descriptive string of the error in English. For file errors, the function <span class="code">format_error/1</span> in the <span class="code">file</span> module is called.</p> </p></div> <p><a name="get_default-1"><span class="bold_code">get_default(Xref) -> [{Option, Value}]</span></a><br><a name="get_default-2"><span class="bold_code">get_default(Xref, Option) -> {ok, Value} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = builtins | recurse | verbose | warnings</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Value = bool()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Returns the default values of one or more options.</p> </p></div> <p><a name="get_library_path-1"><span class="bold_code">get_library_path(Xref) -> {ok, LibraryPath}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">LibraryPath = library_path()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Returns the <span class="bold_code"><a href="#library_path">library path</a></span>.</p> </p></div> <p><a name="info-1"><span class="bold_code">info(Xref) -> [Info]</span></a><br><a name="info-2"><span class="bold_code">info(Xref, Category) -> [{Item, [Info]}]</span></a><br><a name="info-3"><span class="bold_code">info(Xref, Category, Items) -> [{Item, [Info]}]</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Application = [] | [application()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Category = modules | applications | releases | libraries</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Info = {application, Application} | {builtins, bool()} | {directory, directory()} | {library_path, library_path()} | {mode, mode()} | {no_analyzed_modules, int()} | {no_applications, int()} | {no_calls, {NoResolved, NoUnresolved}} | {no_function_calls, {NoLocal, NoResolvedExternal, NoUnresolved}} | {no_functions, {NoLocal, NoExternal}} | {no_inter_function_calls, int()} | {no_releases, int()} | {release, Release} | {version, Version}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Item = module() | application() | release() | library()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Items = Item | [Item]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">NoLocal = NoExternal = NoResolvedExternal, NoResolved = NoUnresolved = int()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Release = [] | [release()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Version = [int()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>The <span class="code">info</span> functions return information as a list of pairs {Tag, term()} in some order about the state and the <span class="bold_code"><a href="#module_data">module data</a></span> of an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. </p> <p><span class="code">info/1</span> returns information with the following tags (tags marked with (*) are available in <span class="code">functions</span> mode only):</p> <ul> <li> <span class="code">library_path</span>, the <span class="bold_code"><a href="#library_path">library path</a></span>;</li> <li> <span class="code">mode</span>, the <span class="bold_code"><a href="#mode">mode</a></span>;</li> <li> <span class="code">no_releases</span>, number of releases;</li> <li> <span class="code">no_applications</span>, total number of applications (of all releases);</li> <li> <span class="code">no_analyzed_modules</span>, total number of <span class="bold_code"><a href="#analyzed_module">analyzed modules</a></span>;</li> <li> <span class="code">no_calls</span> (*), total number of calls (in all modules), regarding instances of one function call in different lines as separate calls;</li> <li> <span class="code">no_function_calls</span> (*), total number of <span class="bold_code"><a href="#local_call">local calls</a></span>, resolved <span class="bold_code"><a href="#external_call">external calls</a></span> and <span class="bold_code"><a href="#unresolved_call">unresolved calls</a></span>;</li> <li> <span class="code">no_functions</span> (*), total number of local and exported functions;</li> <li> <span class="code">no_inter_function_calls</span> (*), total number of calls of the <span class="bold_code"><a href="#inter_call_graph">Inter Call Graph</a></span>.</li> </ul> <p><span class="code">info/2</span> and <span class="code">info/3</span> return information about all or some of the analyzed modules, applications, releases or library modules of an Xref server. The following information is returned for every analyzed module:</p> <ul> <li> <span class="code">application</span>, an empty list if the module does not belong to any application, otherwise a list of the application name;</li> <li> <span class="code">builtins</span>, whether calls to BIFs are included in the module's data;</li> <li> <span class="code">directory</span>, the directory where the module's BEAM file is located;</li> <li> <span class="code">no_calls</span> (*), number of calls, regarding instances of one function call in different lines as separate calls;</li> <li> <span class="code">no_function_calls</span> (*), number of local calls, resolved external calls and unresolved calls;</li> <li> <span class="code">no_functions</span> (*), number of local and exported functions;</li> <li> <span class="code">no_inter_function_calls</span> (*), number of calls of the Inter Call Graph;</li> </ul> <p>The following information is returned for every application:</p> <ul> <li> <span class="code">directory</span>, the directory where the modules' BEAM files are located;</li> <li> <span class="code">no_analyzed_modules</span>, number of analyzed modules;</li> <li> <span class="code">no_calls</span> (*), number of calls of the application's modules, regarding instances of one function call in different lines as separate calls;</li> <li> <span class="code">no_function_calls</span> (*), number of local calls, resolved external calls and unresolved calls of the application's modules;</li> <li> <span class="code">no_functions</span> (*), number of local and exported functions of the application's modules;</li> <li> <span class="code">no_inter_function_calls</span> (*), number of calls of the Inter Call Graph of the application's modules;</li> <li> <span class="code">release</span>, an empty list if the application does not belong to any release, otherwise a list of the release name;</li> <li> <span class="code">version</span>, the application's version as a list of numbers. For instance, the directory "kernel-2.6" results in the application name <span class="code">kernel</span> and the application version [2,6]; "kernel" yields the name <span class="code">kernel</span> and the version [].</li> </ul> <p>The following information is returned for every release:</p> <ul> <li> <span class="code">directory</span>, the release directory;</li> <li> <span class="code">no_analyzed_modules</span>, number of analyzed modules;</li> <li> <span class="code">no_applications</span>, number of applications;</li> <li> <span class="code">no_calls</span> (*), number of calls of the release's modules, regarding instances of one function call in different lines as separate calls;</li> <li> <span class="code">no_function_calls</span> (*), number of local calls, resolved external calls and unresolved calls of the release's modules;</li> <li> <span class="code">no_functions</span> (*), number of local and exported functions of the release's modules;</li> <li> <span class="code">no_inter_function_calls</span> (*), number of calls of the Inter Call Graph of the release's modules.</li> </ul> <p>The following information is returned for every library module:</p> <ul> <li> <span class="code">directory</span>, the directory where the <span class="bold_code"><a href="#library_module">library module's</a></span> BEAM file is located.</li> </ul> <p>For every number of calls, functions etc. returned by the <span class="code">no_</span> tags, there is a query returning the same number. Listed below are examples of such queries. Some of the queries return the sum of a two or more of the <span class="code">no_</span> tags numbers. <span class="code">mod</span> (<span class="code">app</span>, <span class="code">rel</span>) refers to any module (application, release). </p> <ul> <li> <p><span class="code">no_analyzed_modules</span></p> <ul> <li> <span class="code">"# AM"</span> (info/1)</li> <li> <span class="code">"# (Mod) app:App"</span> (application)</li> <li> <span class="code">"# (Mod) rel:Rel"</span> (release)</li> </ul> </li> <li> <p><span class="code">no_applications</span></p> <ul> <li> <span class="code">"# A"</span> (info/1)</li> </ul> </li> <li> <p><span class="code">no_calls</span>. The sum of the number of resolved and unresolved calls:</p> <ul> <li> <span class="code">"# (XLin) E + # (LLin) E"</span> (info/1)</li> <li> <span class="code">"T = E | mod:Mod, # (LLin) T + # (XLin) T"</span> (module)</li> <li> <span class="code">"T = E | app:App, # (LLin) T + # (XLin) T"</span> (application)</li> <li> <span class="code">"T = E | rel:Rel, # (LLin) T + # (XLin) T"</span> (release)</li> </ul> </li> <li> <p><span class="code">no_functions</span>. Functions in library modules and the functions <span class="code">module_info/0,1</span> are not counted by <span class="code">info</span>. Assuming that <span class="code">"Extra := _:module_info/\"(0|1)\" + LM"</span> has been evaluated, the sum of the number of local and exported functions are:</p> <ul> <li> <span class="code">"# (F - Extra)"</span> (info/1)</li> <li> <span class="code">"# (F * mod:Mod - Extra)"</span> (module)</li> <li> <span class="code">"# (F * app:App - Extra)"</span> (application)</li> <li> <span class="code">"# (F * rel:Rel - Extra)"</span> (release)</li> </ul> </li> <li> <p><span class="code">no_function_calls</span>. The sum of the number of local calls, resolved external calls and unresolved calls:</p> <ul> <li> <span class="code">"# LC + # XC"</span> (info/1)</li> <li> <span class="code">"# LC | mod:Mod + # XC | mod:Mod"</span> (module)</li> <li> <span class="code">"# LC | app:App + # XC | app:App"</span> (application)</li> <li> <span class="code">"# LC | rel:Rel + # XC | mod:Rel"</span> (release)</li> </ul> </li> <li> <p><span class="code">no_inter_function_calls</span></p> <ul> <li> <span class="code">"# EE"</span> (info/1)</li> <li> <span class="code">"# EE | mod:Mod"</span> (module)</li> <li> <span class="code">"# EE | app:App"</span> (application)</li> <li> <span class="code">"# EE | rel:Rel"</span> (release)</li> </ul> </li> <li> <p><span class="code">no_releases</span></p> <ul> <li> <span class="code">"# R"</span> (info/1)</li> </ul> </li> </ul> </p></div> <p><a name="m-1"><span class="bold_code">m(Module) -> [DebugInfoResult] | [NoDebugInfoResult] | Error</span></a><br><a name="m-1"><span class="bold_code">m(File) -> [DebugInfoResult] | [NoDebugInfoResult] | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">DebugInfoResult = {deprecated, [funcall()]} | {undefined, [funcall()]} | {unused, [mfa()]}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">File = file()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Module = module()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">NoDebugInfoResult = {deprecated, [mfa()]} | {undefined, [mfa()]}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {file_error, file(), error()} | {interpreted, module()} | {invalid_filename, term()} | {cover_compiled, module()} | {no_such_module, module()} | - error from beam_lib:chunks/2 -</span><br> </div> </div> <div class="REFBODY"><p> <p>The given BEAM file (with or without the <span class="code">.beam</span> extension) or the file found by calling <span class="code">code:which(Module)</span> is checked for calls to <span class="bold_code"><a href="#deprecated_function">deprecated functions</a></span>, calls to <span class="bold_code"><a href="#undefined_function">undefined functions</a></span>, and for unused local functions. The code path is used as <span class="bold_code"><a href="#library_path">library path</a></span>. </p> <p>If the BEAM file contains <span class="bold_code"><a href="#debug_info">debug information</a></span>, then a list of tuples is returned. The first element of each tuple is one of: </p> <ul> <li> <span class="code">deprecated</span>, the second element is a sorted list of calls to deprecated functions;</li> <li> <span class="code">undefined</span>, the second element is a sorted list of calls to undefined functions;</li> <li> <span class="code">unused</span>, the second element is a sorted list of unused local functions.</li> </ul> <p>If the BEAM file does not contain debug information, then a list of tuples is returned. The first element of each tuple is one of: </p> <ul> <li> <span class="code">deprecated</span>, the second element is a sorted list of externally used deprecated functions;</li> <li> <span class="code">undefined</span>, the second element is a sorted list of undefined functions.</li> </ul> </p></div> <p><a name="q-2"><span class="bold_code">q(Xref, Query [, Options]) -> {ok, Answer} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Answer = false | [constant()] | [Call] | [Component] | int() | [DefineAt] | [CallAt] | [AllLines]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Call = call() | ComponentCall</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ComponentCall = {Component, Component}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Component = [constant()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">DefineAt = {mfa(), LineNumber}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">CallAt = {funcall(), LineNumbers}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">AllLines = {{DefineAt, DefineAt}, LineNumbers}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">LineNumbers = [LineNumber]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">LineNumber = int()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {verbose, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Query = string() | atom()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()} | {parse_error, string_position(), term()} | {type_error, string()} | {type_mismatch, string(), string()} | {unknown_analysis, term()} | {unknown_constant, string()} | {unknown_variable, variable()} | {variable_reassigned, string()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Evaluates a <span class="bold_code"><a href="#query">query</a></span> in the context of an <span class="bold_code"><a href="#xref_server">Xref server</a></span>, and returns the value of the last statement. The syntax of the value depends on the expression: </p> <ul> <li>A set of calls is represented by a sorted list without duplicates of <span class="code">call()</span>.</li> <li>A set of constants is represented by a sorted list without duplicates of <span class="code">constant()</span>.</li> <li>A set of strongly connected components is a sorted list without duplicates of <span class="code">Component</span>.</li> <li>A set of calls between strongly connected components is a sorted list without duplicates of <span class="code">ComponentCall</span>.</li> <li>A chain of calls is represented by a list of <span class="code">constant()</span>. The list contains the From vertex of every call and the To vertex of the last call.</li> <li>The <span class="code">of</span> operator returns <span class="code">false</span> if no chain of calls between the given constants can be found.</li> <li>The value of the <span class="code">closure</span> operator (the <span class="code">digraph</span> representation) is represented by the atom <span class="code">'closure()'</span>.</li> <li>A set of line numbered functions is represented by a sorted list without duplicates of <span class="code">DefineAt</span>.</li> <li>A set of line numbered function calls is represented by a sorted list without duplicates of <span class="code">CallAt</span>.</li> <li>A set of line numbered functions and function calls is represented by a sorted list without duplicates of <span class="code">AllLines</span>.</li> </ul> <p>For both <span class="code">CallAt</span> and <span class="code">AllLines</span> it holds that for no list element is <span class="code">LineNumbers</span> an empty list; such elements have been removed. The constants of <span class="code">component</span> and the integers of <span class="code">LineNumbers</span> are sorted and without duplicates. </p> </p></div> <p><a name="remove_application-2"><span class="bold_code">remove_application(Xref, Applications) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Applications = application() | [application()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {no_such_application, application()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Removes applications and their modules and <span class="bold_code"><a href="#module_data">module data</a></span> from an <span class="bold_code"><a href="#xref_server">Xref server</a></span>.</p> </p></div> <p><a name="remove_module-2"><span class="bold_code">remove_module(Xref, Modules) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Modules = module() | [module()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {no_such_module, module()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Removes <span class="bold_code"><a href="#analyzed_module">analyzed modules</a></span> and <span class="bold_code"><a href="#module_data">module data</a></span> from an <span class="bold_code"><a href="#xref_server">Xref server</a></span>.</p> </p></div> <p><a name="remove_release-2"><span class="bold_code">remove_release(Xref, Releases) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {no_such_release, release()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Releases = release() | [release()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Removes releases and their applications, modules and <span class="bold_code"><a href="#module_data">module data</a></span> from an <span class="bold_code"><a href="#xref_server">Xref server</a></span>.</p> </p></div> <p><a name="replace_application-3"><span class="bold_code">replace_application(Xref, Application, Directory [, Options]) -> {ok, application()} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Application = application()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Directory = directory()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {builtins, bool()} | {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {no_such_application, application()} | - see also add_application -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Replaces the modules of an application with other modules read from an application directory. Release membership of the application is retained. Note that the name of the application is kept; the name of the given directory is not used. </p> </p></div> <p><a name="replace_module-3"><span class="bold_code">replace_module(Xref, Module, File [, Options]) -> {ok, module()} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">File = file()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Module = module()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ReadModule = module()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {module_mismatch, module(), ReadModule} | {no_such_module, module()} | - see also add_module -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Replaces <span class="bold_code"><a href="#module_data">module data</a></span> of an <span class="bold_code"><a href="#analyzed_module">analyzed module</a></span> with data read from a BEAM file. Application membership of the module is retained, and so is the value of the <span class="code">builtins</span> option of the module. An error is returned if the name of the read module differs from the given module. </p> <p>The <span class="code">update</span> function is an alternative for updating module data of recompiled modules.</p> </p></div> <p><a name="set_default-3"><span class="bold_code">set_default(Xref, Option, Value) -> {ok, OldValue} | Error</span></a><br><a name="set_default-2"><span class="bold_code">set_default(Xref, OptionValues) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">OptionValues = [OptionValue] | OptionValue</span><br> </div> <div class="REFTYPES"> <span class="bold_code">OptionValue = {Option, Value}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = builtins | recurse | verbose | warnings</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Value = bool()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Sets the default value of one or more options. The options that can be set this way are:</p> <ul> <li> <span class="code">builtins</span>, with initial default value <span class="code">false</span>;</li> <li> <span class="code">recurse</span>, with initial default value <span class="code">false</span>;</li> <li> <span class="code">verbose</span>, with initial default value <span class="code">false</span>;</li> <li> <span class="code">warnings</span>, with initial default value <span class="code">true</span>.</li> </ul> <p>The initial default values are set when creating an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. </p> </p></div> <p><a name="set_library_path-2"><span class="bold_code">set_library_path(Xref, LibraryPath [, Options]) -> ok | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">LibraryPath = library_path()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {verbose, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()} | {invalid_path, term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Sets the <span class="bold_code"><a href="#library_path">library path</a></span>. If the given path is a list of directories, the set of <span class="bold_code"><a href="#library_module">library modules</a></span> is determined by choosing the first module encountered while traversing the directories in the given order, for those modules that occur in more than one directory. By default, the library path is an empty list. </p> <p>The library path <a name="code_path"></a> <span class="code">code_path</span> is used by the functions <span class="code">m/1</span> and <span class="code">d/1</span>, but can also be set explicitly. Note however that the code path will be traversed once for each used <span class="bold_code"><a href="#library_module">library module</a></span> while setting up module data. On the other hand, if there are only a few modules that are used by not analyzed, using <span class="code">code_path</span> may be faster than setting the library path to <span class="code">code:get_path()</span>. </p> <p>If the library path is set to <span class="code">code_path</span>, the set of library modules is not determined, and the <span class="code">info</span> functions will return empty lists of library modules.</p> </p></div> <p><a name="start-1"><span class="bold_code">start(NameOrOptions) -> Return</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Name = atom()()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">XrefOrOptions = Xref | Options</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {xref_mode, mode()} | term()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Return = {ok, pid()} | {error, {already_started, pid()}}</span><br> </div> </div> <div class="REFBODY"><p> <p>Creates an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The process may optionally be given a name. The default <span class="bold_code"><a href="#mode">mode</a></span> is <span class="code">functions</span>. Options that are not recognized by Xref are passed on to <span class="code">gen_server:start/4</span>.</p> </p></div> <p><a name="start-2"><span class="bold_code">start(Name, Options) -> Return</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Name = atom()()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {xref_mode, mode()} | term()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Return = {ok, pid()} | {error, {already_started, pid()}}</span><br> </div> </div> <div class="REFBODY"><p> <p>Creates an <span class="bold_code"><a href="#xref_server">Xref server</a></span> with a given name. The default <span class="bold_code"><a href="#mode">mode</a></span> is <span class="code">functions</span>. Options that are not recognized by Xref are passed on to <span class="code">gen_server:start/4</span>.</p> </p></div> <p><a name="stop-1"><span class="bold_code">stop(Xref)</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Stops an <span class="bold_code"><a href="#xref_server">Xref server</a></span>.</p> </p></div> <p><a name="update-1"><span class="bold_code">update(Xref [, Options]) -> {ok, Modules} | Error</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Error = {error, module(), Reason}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Modules = [module()]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = {verbose, bool()} | {warnings, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()} | {module_mismatch, module(), ReadModule} | - see also add_module -</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Replaces the <span class="bold_code"><a href="#module_data">module data</a></span> of all <span class="bold_code"><a href="#analyzed_module">analyzed modules</a></span> the BEAM files of which have been modified since last read by an <span class="code">add</span> function or <span class="code">update</span>. Application membership of the modules is retained, and so is the value of the <span class="code">builtins</span> option. Returns a sorted list of the names of the replaced modules.</p> </p></div> <p><a name="variables-1"><span class="bold_code">variables(Xref [, Options]) -> {ok, [VariableInfo]}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Options = [Option] | Option</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Option = predefined | user | {verbose, bool()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = {invalid_options, term()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">VariableInfo = {predefined, [variable()]} | {user, [variable()]}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Xref = xref()</span><br> </div> </div> <div class="REFBODY"><p> <p>Returns a sorted lists of the names of the variables of an <span class="bold_code"><a href="#xref_server">Xref server</a></span>. The default is to return the <span class="bold_code"><a href="#user_variable">user variables</a></span> only.</p> </p></div> <h3><a name="id2291707">See Also</a></h3> <div class="REFBODY"> <p>beam_lib(3), digraph(3), digraph_utils(3), regexp(3), <span class="bold_code"><a href="xref_chapter.html">TOOLS User's Guide</a></span></p> </div> </div> <div class="footer"> <hr> <p>Copyright © 1997-2010 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>