1

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.

duckworthd
  • 14,679
  • 16
  • 53
  • 68
  • Take a look at this answer: http://stackoverflow.com/a/2161749/576766 – tenshi Jan 18 '12 at 21:27
  • possible duplicate of [Drop into interpreter during arbitrary scala code location](http://stackoverflow.com/questions/2160355/drop-into-interpreter-during-arbitrary-scala-code-location) – Daniel C. Sobral Jan 18 '12 at 22:16
  • I'm aware of the other topic, but it doesn't seem to work as of Scala 2.9, particularly if I use `sbt`. – duckworthd Feb 07 '12 at 05:32

1 Answers1

3

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.
Ant Kutschera
  • 6,257
  • 4
  • 29
  • 40
  • I've been using IntelliJ IDEA. If support in Eclipse is good enough, perhaps I should migrate? – duckworthd Feb 07 '12 at 05:32
  • I don't know the IntelliJ plugin for scala, but the Eclipse one is backed by Typesafe and is currently under active development, if that helps... – Ant Kutschera Feb 08 '12 at 20:24