This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Dropping into Interpreter for Interactive Debugging

1 reply
duckworthd
Joined: 2011-09-04,
User offline. Last seen 1 year 7 weeks ago.

Hi all,

I've been trying to find a way to drop into the interpreter
programmatically to interactively debug my code. My code will be
running through SBT, and so far I have been unable to find a working
solution. Posted is my example SBT build.sbt,

// Project settings
scalaVersion := "2.9.1"

// copy retrieved dependencies to ./lib_managed
retrieveManaged := true

// libraries
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % "2.9.1",
"org.scala-lang" % "jline" % "2.9.1"
)

// Compiler options
scalacOptions ++= Seq(
"-unchecked",
"-deprecation"
)

And my actual Main.scala program,

import scala.tools.nsc.interpreter.ILoop._

object Main extends App {

case class C(a: Int, b: Double, c: String) {
def throwAFit(): Unit = {
println("But I don't wanna!!!")
}
}

// main
override def main(args: Array[String]): Unit = {

val c = C(1, 2.0, "davis")

0.until(10).foreach {
i =>
println("i = " + i)
breakIf(i == 5)
}
}
}

Currently, I get the following (expected) error,

Failed to initialize compiler: object scala not found.
** Note that as of 2.8 scala does not assume use of the java
classpath.
** For the old behavior pass -usejavacp to scala, or if using a
Settings
** object programatically, settings.usejavacp.value = true.

However, including "-usejavacp" in scalacOptions in my build.sbt file
fails to fix the issue. Furthermore, compiling my code directly with
scalac and executing it results in the same issue found with "scala -
i" here: https://issues.scala-lang.org/browse/SI-4945

Can anyone help me get an interactive debugger running? Thanks!

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Dropping into Interpreter for Interactive Debugging
On Wed, Jan 18, 2012 at 9:52 PM, Daniel Duckworth <duckworthd@gmail.com> wrote:
Hi all,

I've been trying to find a way to drop into the interpreter
programmatically to interactively debug my code.  My code will be
running through SBT, and so far I have been unable to find a working
solution.

Hi Daniel,
See "embeddedDefaults" in the FAQ: https://github.com/harrah/xsbt/wiki/FAQ
-jason

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland