Debugging with IEx

Learn various methods of debugging in Elixir.

We’d expect that a relatively new language would come with a fairly minimal set of tools. After all, the development team will be having fun playing with the language. Not so with Elixir. Tooling was important from the start, and the core team has spent a lot of time providing a world-class environment in which to develop code.

In this short chapter, we’ll look at some aspects of this. This chapter is not the full list. We’ve already seen the ExDoc tool, which creates beautiful documentation for our code. Later, when we look at OTP applications, we’ll experiment with the Elixir release manager, a tool for managing releases while our application continues to run. For now, let’s look at testing, code exploration, and server-monitoring tools.

We already know that IEx is the go-to utility to play with Elixir code. It also has a secret second life as a debugger. It isn’t fancy, but it lets us get into a running program and examine the environment.

Implementation

We enter the debugger when the running Elixir code hits a breakpoint. There are two ways of creating a breakpoint. One works by adding calls into the code we want to debug. The other is initiated from inside IEx. We’ll look at both using the following buggy code:

Get hands-on with 1400+ tech skills courses.