nonware

nonware

Unable to hit breakpoints in VS Code using ElixirLS - How does one debug in VS Code?

Hello! An Elixir neophyte here. I’d like to debug my code using VS Code. I saw in the ReadMe for ElixirLS you can sink breakpoints for one’s code and step through it, as one might with an IDE (or other language even in VS Code).

The code I am learning with I’ve compiled by running iex -S mix and I am invoking MyModule.my_function(someArg) but the breakpoint i placed in VS Code on some line in my_function is never hit. I do see that there is an open issue where one can’t debug in an iex -S mix session. So that brings me to my question: How do I hit this break point? Is there some setup in VS Code or something to pass to mix to enable debugging so I can hit the breakpoint in VS Code?

Thanks a bunch!

Most Liked

mindok

mindok

Hi @nonware, this isn’t answering your question directly I know, but I tend to use an IO.inspect (or friends) either side of a function call as my primary debugging tool. Elixir is a functional language and by and large you put data into a function and get transformed data out with no side effects so I find this style of debugging quite effective for me personally. In addition, code recompile and reload in a running system is generally very quick and just works in Phoenix, so moving a few IO.inspects around while the system is running is no trouble. I coded a lot of .Net in the past and made heavy use of the Visual Studio debugging tools, which were excellent, but I honestly haven’t found the same need for that style of debugging (yet) in Elixir. In over 2 years I haven’t even taken the time to try and set them up.

I’d be keen to hear informed responses though - it’s probably about time I learned about it!

WFransen

WFransen

I’m personally a huge fan of IEx.pry.

There’s a great article on debugging, not necessarily with VsCode, but maybe this can be helpful. http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/

Best of luck!

harmon25

harmon25

I am with @mindok on this one.
In a mutable language where variables can be changed under your nose, breakpoints are more useful in my opinion.

If you have such a big elixir/erlang function that you cannot keep track of the values of variables - and a breakpoint is the best(?) way to verify the value/state is what you expect; I think you may want to consider breaking that function up, so it is easier to comprehend.

Tools like :observer are also quite useful for real time debugging - as a breakpoint in the IDE does little to assist in understanding the rest of the state of the runtime at that point in time. This is a result of erlangs actor model, and concurrency characteristics - that traditional imperative languages do not use.

Also the built in :debugger module that opens a window will struggle in certain environments, like VScode + WSL, as there is not a xdisplay for the window. Not sure if this is what the elixir-ls breakpoint stuff relies on, but if developing in an environment that does not have native GUI capabilities, the functionality might not work.

Am also interested to hear compelling use cases for using breakpoints in the beam, as I might be missing something!

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement