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

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
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
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement