Debugging the Scala Compiler

203 views
Skip to first unread message

Tongfei Chen

unread,
Jul 17, 2016, 1:15:34 AM7/17/16
to scala-user
I'm trying to debug the Scala compiler.

Running the class scala.tools.nsc.Main as the main entry class results in the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: scala.reflect.internal.util.ScalaClassLoader$class.create(Lscala/reflect/internal/util/ScalaClassLoader;Ljava/lang/String;Lscala/Function1;Lscala/collection/Seq;Lscala/reflect/ClassTag;)Ljava/lang/Object;
at scala.tools.nsc.Global$$anon$5.create(Global.scala:1575)
at scala.tools.nsc.Global$.scala$tools$nsc$Global$$reporter(Global.scala:1576)
at scala.tools.nsc.Global$.apply(Global.scala:1571)
at scala.tools.nsc.MainClass.newCompiler(Main.scala:20)
at scala.tools.nsc.Driver.process(Driver.scala:47)
at scala.tools.nsc.Driver.main(Driver.scala:68)
at scala.tools.nsc.Main.main(Main.scala)

How should I run the nsc compiler?

Adriaan Moors

unread,
Jul 18, 2016, 5:18:31 PM7/18/16
to Tongfei Chen, scala-user
I recommend remote debugging. 

On the command line, do `export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8002"` and run the compiler as normal, then start a remote debugging  session to port 8002.

(If you're using sbt to build & run the compiler, that would be

> set javaOptions in compiler := List("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8003")

> scalac .... )

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tongfei Chen

unread,
Jul 18, 2016, 10:51:22 PM7/18/16
to scala-user, cton...@gmail.com
Thanks Adriaan. I wonder if it is possible to debug in IntelliJ IDEA, since I can set breakpoints, see the call stack, watch the vars, etc.

Adriaan Moors

unread,
Jul 18, 2016, 11:00:13 PM7/18/16
to Tongfei Chen, scala-user
Yes, I use IntelliJ with the setup I described above, using the "Remote" debugging configuration.

We've only recently switched over to the sbt build, so the docs are a bit out of date.
Use the "intellij" command in sbt to generate an intellij project (importing from sbt does not work).

Tongfei Chen

unread,
Jul 18, 2016, 11:53:56 PM7/18/16
to scala-user, cton...@gmail.com
Am I supposed to first launch the compiler using "scalac *.scala" and then run the remote debugging configuration in IDEA?

som-snytt

unread,
Jul 19, 2016, 6:13:36 PM7/19/16
to scala-user

Maybe you're not including the scala-reflect.jar on the class path?
Reply all
Reply to author
Forward
0 new messages