3

I am trying to set a breakpoint in a Scala Macro implementation using the Eclipse IDE and failing

Firstly: Scala Macros Rock! Up to now I have preferred Clojure to Scala, but with macros I'm no longer sure

I'm trying to create a macro that will return the toString of a function and the function itself. When that works I'm going to make a new function with a sensible toString. Ah happy days.

But I need to be able to debug the macros. I use Eclipse (20110615-0604), with Scala (2.10.1). I downloaded the scala-compiler-2.10.1.jar and the code from http://www.warski.org/blog/2012/12/starting-with-scala-macros-a-short-tutorial/ now works. I've written a couple of simple macros as well. The macros are in an eclipse project "ScalaMacro" and the code that uses them is in a separate project "HelloScalaMacro"

I'd now like to debug them

Following the instructions at http://docs.scala-lang.org/overviews/macros/overview.html I have created a runtime configuration with scala.tools.nsc.Main as the entry point. I've added -cp HelloScala.scala, and when I run the configuration it actually seems to compile the code (if I put errors in, it reports the errors correctly).

Unfortunately the instructions imply that a breakpoint in the macro implementation should cause Eclipse to pause. It doesn't.

I've done the usual: google search for Eclipse/Scala macro/Debug/Breakpoint, read all the stackoverflow questions in the scala-macro tag, and played around a lot with every eclipse setting I can find.

So if any of you out there know how to set breakpoints, could you let me know how: is it an eclipse version / scala version / ... issue?

4

2 回答 2

2

Nadavwr(就在下面)给出的说明很有帮助,我将它们推荐给其他人。

对我来说,关键的解决方案是意识到涉及到两个项目,一个是定义宏的项目,另一个是使用宏的项目。相当愚蠢的是,我试图调试定义宏的项目

所以文档中给出的说明是正确的,我只需要确保我在正确的项目中运行它们:当然很明显。

为了其他人的利益,我发现使用命令行 scalac 来获得正确的命令行非常有帮助:更快地编辑它,并控制我所在的目录,然后在 eclipse

对于考虑使用 Scala 宏的人来说,要意识到的另一件事是直接运行 scalac 的错误消息比 eclipse 的错误消息要好得多。

于 2013-05-06T12:39:27.120 回答
2

I haven't tried this myself, and in principle it is as likely (or more likely) to fail as what you've already tried, but if successful it could be more convenient to you.

To try this you should have Scala-IDE along with the source feature installed. Make sure you are working off of an Eclipse installation that is either "Eclipse Classic", "Eclipse for RCP Developers", or a similar concoction you came up with on your own.

You will also want to install the Equinox Weaving Launcher plugin, that will allow you to create an "Eclipse Application with Equinox Weaving" launchers.

Now:

  1. Create a new workspace
  2. Create a Scala project
  3. Plant your macro code in that project
  4. Add a break point in the macro source

Getting ready to debug:

  1. Create a new "Eclipse Application with Equinox Weaving" debug launch configuration. Give a name more elegant than "New_configuration".

    • under "location", point it towards a new different workspace directory
    • under the "configuration" tab, provide something like "-Xmx1536m"
    • By default, all plugins available to your running Eclipse instance should be available to the instance you are about to launch. Eclipse may need some cajoling in order to include a non-plugin project in the classpath -- if this doesn't work, that's the first thing I'd try to look at.
  2. You will now want to launch the debug configuration.

    • Depending on your Scala-IDE version, you may encounter a "Multiple launchers available -- Select one..." warning. I'd go for "Equinox Weaving enabled Eclipse Application Launcher".

Once inside the Eclipse instance being debugged:

  1. Create the project you want to use the macro
  2. Make sure to add a dependency on the binary output
  3. Add a small usage example of your macro to the project in the workspace being debugged.
  4. Cross your fingers
  5. Build

In theory, the launching Eclipse instance will now pause the instance being debugged on your break point.

于 2013-05-06T12:07:59.537 回答