Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to Pry for Crystal?

Tags:

crystal-lang

I am very new in crystal language. I would like to know if a debugger like Ruby's Pry exists in Crystal?

It means that you can put in code something like 'binding.pry' at program stop execution at this line and let you control of variables.

like image 321
Voldemar Duletskiy Avatar asked Feb 18 '16 20:02

Voldemar Duletskiy


People also ask

What is IRB pry?

Pry is like IRB on steroids Both IRB and Pry use REPL commands: Read, Evaluate, Print, and Loop. But Pry allows you to go further when debugging. For example, Pry gives you color-coded syntax, which helps when you're trying to figure out what will happen when code is executed.

How does binding pry work?

So when you place the line binding. pry in your code, that line will get interpreted at runtime (as your program is executed). When the interpreter hits that line, your program will actually freeze and your terminal will turn into a REPL that exists right in the middle of your program, wherever you added the binding.


1 Answers

Although very incomplete, there is support for LLDB.

You may add debugger anywhere in your code to initiate a breakpoint for LLDB to stop at. You should (must?) build a binary with the -d or --debug flag, then run it using LLDB:

$ crystal build -d foo.cr
$ lldb ./foo
(lldb) run

See https://groups.google.com/forum/m/#!topic/crystal-lang/gRf-yDNdZ-Y for a more detailed example.

like image 76
Julien Portalier Avatar answered Oct 12 '22 02:10

Julien Portalier