1 Dialyzer

1.1 Introduction

Scope

Dialyzer is a static analysis tool that identifies software discrepancies, such as definite type errors, code that has become dead or unreachable because of programming error, and unnecessary tests, in single Erlang modules or entire (sets of) applications.

Dialyzer can be called from the command line, from Erlang, and from a GUI.

Prerequisites

It is assumed that the reader is familiar with the Erlang programming language.

1.2 The Persistent Lookup Table

Dialyzer stores the result of an analysis in a Persistent Lookup Table (PLT). The PLT can then be used as a starting point for later analyses. It is recommended to build a PLT with the Erlang/OTP applications that you are using, but also to include your own applications that you are using frequently.

The PLT is built using option --build_plt to Dialyzer. The following command builds the recommended minimal PLT for Erlang/OTP:

dialyzer --build_plt --apps erts kernel stdlib mnesia

Dialyzer looks if there is an environment variable called DIALYZER_PLT and places the PLT at this location. If no such variable is set, Dialyzer places the PLT at $HOME/.dialyzer_plt. The placement can also be specified using the options --plt or --output_plt.

Information can be added to an existing PLT using option --add_to_plt. If you also want to include the Erlang compiler in the PLT and place it in a new PLT, then use the following command:

dialyzer --add_to_plt --apps compiler --output_plt my.plt

Then you can add your favorite application my_app to the new PLT:

dialyzer --add_to_plt --plt my.plt -r my_app/ebin

But you realize that it is unnecessary to have the Erlang compiler in this one:

dialyzer --remove_from_plt --plt my.plt --apps compiler

Later, when you have fixed a bug in your application my_app, you want to update the PLT so that it becomes fresh the next time you run Dialyzer. In this case, run the following command:

dialyzer --check_plt --plt my.plt

Dialyzer then reanalyzes the changed files and the files that depend on these files. Notice that this consistency check is performed automatically the next time you run Dialyzer with this PLT. Option --check_plt is only for doing so without doing any other analysis.

To get information about a PLT, use the following option:

dialyzer --plt_info

To specify which PLT, use option --plt.

To get the output printed to a file, use option --output_file.

Notice that when manipulating the PLT, no warnings are emitted. To turn on warnings during (re)analysis of the PLT, use option --get_warnings.

1.3 Using Dialyzer from the Command Line

Dialyzer has a command-line version for automated use. See dialyzer(3).

1.4 Using Dialyzer from Erlang

Dialyzer can also be used directly from Erlang. See dialyzer(3).

1.5 Using Dialyzer from the GUI

Choosing the Applications or Modules

The File window displays a listing of the current directory. Click your way to the directories/modules you want to add or type the correct path in the entry.

Mark the directories/modules you want to analyze for discrepancies and click Add. You can either add the .beam and .erl files directly, or add directories that contain these kind of files. Notice that you are only allowed to add the type of files that can be analyzed in the current mode of operation (see below), and that you cannot mix .beam and .erl files.

Analysis Modes

Dialyzer has two analysis modes: "Byte Code" and "Source Code". They are controlled by the buttons in the top-middle part of the main window, under Analysis Options.

Controlling the Discrepancies Reported by Dialyzer

Under the Warnings pull-down menu, there are buttons that control which discrepancies are reported to the user in the Warnings window. By clicking these buttons, you can enable/disable a whole class of warnings. Information about the classes of warnings is found on the "Warnings" item under the Help menu (in the rightmost top corner).

If modules are compiled with inlining, spurious warnings can be emitted. In the Options menu you can choose to ignore inline-compiled modules when analyzing byte code. When starting from source code, this is not a problem because inlining is explicitly turned off by Dialyzer. The option causes Dialyzer to suppress all warnings from inline-compiled modules, as there is currently no way for Dialyzer to find what parts of the code have been produced by inlining.

Running the Analysis

Once you have chosen the modules or directories you want to analyze, click the Run button to start the analysis. If you for some reason want to stop the analysis while it is running, click the Stop button.

The information from the analysis is displayed in the Log window and the Warnings window.

Include Directories and Macro Definitions

When analyzing from source, you might have to supply Dialyzer with a list of include directories and macro definitions (as you can do with the erlc flags -I and -D). This can be done either by starting Dialyzer with these flags from the command line as in:

dialyzer -I my_includes -DDEBUG -Dvsn=42 -I one_more_dir

or by adding these explicitly using submenu Manage Macro Definitions or Manage Include Directories in the Options menu.

Saving the Information on the Log and Warnings Windows

The File menu includes options to save the contents of the Log window and the Warnings window. Simply choose the options and enter the file to save the contents in.

There are also buttons to clear the contents of each window.

Inspecting the Inferred Types of the Analyzed Functions

Dialyzer stores the information of the analyzed functions in a Persistent Lookup Table (PLT), see section The Persistent Lookup Table.

After an analysis, you can inspect this information. In the PLT menu you can choose to either search the PLT or inspect the contents of the whole PLT. The information is presented in EDoc format.

1.6 Feedback and Bug Reports

We very much welcome user feedback - even wishlists! If you notice anything weird, especially if Dialyzer reports any discrepancy that is a false positive, please send an error report describing the symptoms and how to reproduce them.

© 2010–2021 Ericsson AB
Licensed under the Apache License, Version 2.0.