Debugging a SourceChecker in IDE

1 view
Skip to first unread message

Ales Plsek

unread,
Oct 21, 2009, 11:52:50 AM10/21/09
to Type annotations (JSR 308) discussions
Hi all,

We are developing our own set of checkers based on the SourceChecker
from the framework.

I was wondering, is there any way how to configure an IDE (Eclipse,
Maia, etc.) to launch a debugging mode to see what is our
SourceChecker doing?

Is there anyone who configured his IDE in this way? Could you provide
an excerpt of your IDE configuration file?
Any hints which source directories to include in the buildpath and
where to find the main method to supply the parameters?

Thank you for any help,
Ales


P.S. I apologize for multiple posts.

Guenther Noack

unread,
Oct 21, 2009, 4:59:44 PM10/21/09
to jsr308-...@googlegroups.com
Hi!

Did you already try the steps I gave you in the Checker Framework
discussion list?

-Guenther

Ales Plsek

unread,
Oct 21, 2009, 5:15:06 PM10/21/09
to Type annotations (JSR 308) discussions
Hello Gunter,

I was reading your post. I will definitely try your approach, however,
I am not sure if it really does what we need.
Please, let me ask you, with the configuration of your project, are
you able to run any "Debug Configuration" in Eclipse? I though that
for this a complete source code is needed.
It seems to me that the problem here is that JSR308 implementation
needs "com.sun.tools.javac.*" packages which I can not find in the
distribution.

Well, I am just guessing, a straightforward approach could be to
include the whole source code of JSR308 in a project and afterwards
have a Debug configuration starting by calling
"com.sun.tools.javac.Main.main" where you could supply all input
parameters... (your checker, the .java files to be checked, etc.).

Best,
Ales

Mahmood Ali

unread,
Oct 21, 2009, 5:47:55 PM10/21/09
to jsr308-...@googlegroups.com
Greetings,

Here is my setup in Eclipse:

Projects:
Depends on your needs, whether you want to use binary releases or
source all the way, you need to have the following projects checked out:
- checkers (in checker-framework repo): The Checker Framework
repository
- jsr308-langtools or jsr308-langtools.basic (from jsr308-langtools
repositories): The compiler
- javaparser (in checker-framework repo): The java parser used to
parse stub files.

Workspace Settings:
Please set JDK6 as your default Java library. If you are using a Mac,
I recommend using soylatte JDK6 rather than Apple JDK6.

Project Setup (in order of complexity) - details of Java Build Path
- javaparser:
source: javaparser/src
output: javaparser/bin

- jsr308-langtools:
source: jsr308-langtools/src/share/classes
output: jsr308-langtools/build <-- Not perfect but oh well

- checkers:
source: checkers/src, checkers/tests/src
projects: jsr308-langtools, javaparser
libraries: checkers/lib/asmx.jar, checkers/tests/junit.jar
Order and Export: jsr308-langtools needs to be checked and higher
than 'JRE System Library [JVM 1.6]'

Running and Debugging Configuration:
Project: checkers
Main class: com.sun.tools.javac.Main
Program arguments: [whatever you want to pass to the compiler]
Classpath:
Add jsr308-langtools project to 'Bootstrap Entries' above 'JRE
System Library [JVM 1.6]'

Violla, and now your system should work almost flawlessly. I don't
think that you need to setup any any symbolic links, as has been
recommended elsewhere.

You may face a couple of issues when switching back and forth between
using Ant and Eclipse (especially related to the compiler). I usually
just do a Refresh/Clean Build, but you can just change the binary
output for the jsr308-langtools instead. Similarly, running the
checker tests is a bit tricky, and I will try to document it further
in the manual instead.

Please confirm whether or not these configurations are working for you!

Regards,
- Mahmood

Ales Plsek

unread,
Oct 21, 2009, 11:39:26 PM10/21/09
to Type annotations (JSR 308) discussions
Hello Mahmood!

Thank you very much for this excellent post!
I am following your approach, however, I have encountered several
minor problems:

For the jsr308-langtools
- there is a compilation error in
com.sun.tools.javac.jvm.ClassReader.java
- the class Version (line 849): "The class Version is
ambiguous."

For the checkers project (I am checkout-ing the "checker-framework/
checkers" directory):
- class checkers.nullness.NullnessUtils
- method castNonNull() - on line 66, gives a lot of errors

The rest compiles very well!
Probably I am doing something wrong... but, please, could you verify
this?

Thank you very much in advance.

Regards,
Ales

Guenther Noack

unread,
Oct 22, 2009, 4:57:20 AM10/22/09
to jsr308-...@googlegroups.com
Hi!

In my configuration, I'm able to debug (using the Eclipse debugger) the
existing checkers with source code. I had to attach the
jsr308-langtools/dist/lib/src.zip to one of my JARs for that. As far as
I remember, there's an Ant target in jsr308-langtools to build it.

I'm also able to run the tests inside the Eclipse JUnit runner
directly. To do that, I had to create a run configuration to run JUnit
tests. In its configuration dialog, on the "arguments" tab, I added
"-Xbootclasspath/p:${workspace_loc:checkers}/langtools-dist/lib/javac.jar"
as VM argument. I also had to play a bit with the JAR file import order,
where I ended up with this:

<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests/src"/>
<classpathentry kind="lib" path="checkers.jar" sourcepath="src"/>
<classpathentry kind="lib" path="lib/asmx.jar"/>
<classpathentry kind="lib" path="lib/javaparser.jar"/>
<classpathentry kind="lib" path="tests/junit.jar"/>
<classpathentry kind="lib" path="langtools-dist/lib/doclets.jar" sourcepath="langtools-dist/lib/src.zip"/>
<classpathentry kind="lib" path="langtools-dist/lib/javadoc.jar"/>
<classpathentry kind="lib" path="langtools-dist/lib/javac.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>

(This is equivalent to how the JAR imports appear for me in "Project
Properties->Java Build Path->Order and Export".)

Note that langtools-dist is a symlink to jsr308-langtools/dist in my
project. I did this to avoid having hard-coded JAR-file references
checked into my SVN repositories. I know it's a hack, it's just one way
to do it. :-> Creating jsr308-langtools as a project in eclipse and
referencing the JARs across Eclipse project boundaries should work just
as fine.

Best regards,
Guenther

On Wed, Oct 21, 2009 at 02:15:06PM -0700, Ales Plsek wrote:
>
> Hello Gunter,
>
> I was reading your post. I will definitely try your approach, however,
> I am not sure if it really does what we need.
> Please, let me ask you, with the configuration of your project, are
> you able to run any "Debug Configuration" in Eclipse? I though that
> for this a complete source code is needed.
> It seems to me that the problem here is that JSR308 implementation
> needs "com.sun.tools.javac.*" packages which I can not find in the
> distribution.
>
> Well, I am just guessing, a straightforward approach could be to
> include the whole source code of JSR308 in a project and afterwards
> have a Debug configuration starting by calling
> "com.sun.tools.javac.Main.main" where you could supply all input
> parameters... (your checker, the .java files to be checked, etc.).
>
> Best,
> Ales
>

Ales Plsek

unread,
Oct 22, 2009, 4:26:47 PM10/22/09
to Type annotations (JSR 308) discussions
Hello Mahmood again,

So we have resolved all the compilation errors.

Solution for the jsr308-langtools project
- add import com.sun.tools.javac.jvm.ClassFile.Version;

For the checkers project :
- comment out all the @Nonnull annotations since they are not
supported by JKD6

Finally, the program's arguments are:
-processor checkers.SCJChecker -cp ./build/scj ./scj-tests/scjAllowed/
SCJAllowedTest.java

Where in /build/scj is the our SCJChecker compilation, the ./scj-
tests/ is the source directory for classes that we verify.

Thanks a lot one more time!

Regards,
Ales
Reply all
Reply to author
Forward
0 new messages