duckworthd
duckworthd

Reputation: 15217

Interactively execute code while debugging in Scala

Is there a method for inserting code into a Scala application while debugging? For example, could I have something like this,

var c = 1.0
0.until(10).foreach{ i =>
   if (i == 5) {
      startDebuggingMagicHere()
   }
}

where I could then inspect and interact with c, i, and any other variable in scope via methods and assignment.

Upvotes: 1

Views: 1150

Answers (1)

Ant Kutschera
Ant Kutschera

Reputation: 6588

In the Scala-IDE plugin for Eclipse, debugging is supported. Set a breakpoint in the Scala code and you will be able to do limited things. Current support is not as good as that for Java. I believe it is planned to improve by the Summer.

What you can do is:

  1. use the "variables" view to see the current values of variables and modify values,
  2. tell the debugger to "drop to frame" so that it starts the current method call again, using the original values from the stack,
  3. modify code and save the file which causes the debugger to insert the new code and drop to frame, i.e. restart the method call (this does not always work - depending how much you change the code you may need to restart the app, e.g. if you change the class definition)

What you can't do is:

  1. inspect variables from the editor,
  2. write code in the "display" view and execute it. Both of these work with Java, but not Scala.

Upvotes: 3

Related Questions