Debugging with JSwat

159 views
Skip to first unread message

Craig Andera

unread,
Oct 20, 2008, 2:53:56 PM10/20/08
to clo...@googlegroups.com
I'm a total Clojure beginner, not to mention a C# guy with little Java
experience, but as I suspect I'm not alone I'll go ahead and ask
what's probably a dumb question. :)

I'm writing some simple code, and I've hit the point where having a
debugger would be helpful. Once I convinced clojure-swank to launch
java with the right arguments, I was able to attach JSwat, to open my
.clj files, and to set breakpoints. But my breakpoints never trigger.

I've googled a bit, but haven't come across the (probably obvious)
answer to my problem. What am I missing?

I'm on Windows 2008, running clojure under clojure-swank from emacs.

[Later]

I wonder if this doesn't have something to do with the fact that I'm
doing everything via the REPL. Is it possible to break on code you've
evaluated via M-x slime-eval-buffer? I'm able to set breakpoints in
(e.g.) boot.clj.

Allen Rohner

unread,
Oct 21, 2008, 11:11:58 AM10/21/08
to Clojure
> I wonder if this doesn't have something to do with the fact that I'm
> doing everything via the REPL. Is it possible to break on code you've
> evaluated via M-x slime-eval-buffer? I'm able to set breakpoints in
> (e.g.) boot.clj.

I think it does. The compiler associates a file name line number with
each line in your file. The debugger uses those line numbers to set
breakpoints i.e. "set breakpoint on file foo.clj, line 15". Eval-ing
into the repl you don't get useful line numbers. Try using slime-load-
file.

Allen

Craig Andera

unread,
Oct 24, 2008, 9:23:56 AM10/24/08
to clo...@googlegroups.com
[Tried sending this before. Never appears to have shown up. Trying
again after mucking with my Google account some.]

No love with slime-load-file. When I get some time I'll try sticking
my code into a .jar and see if that gets me anywhere.

Or has anyone ever gotten this to work?

Bill Clementson

unread,
Oct 24, 2008, 10:46:35 AM10/24/08
to clo...@googlegroups.com
Hi Craig,

I was able to get JSwat to work with Clojure (see my blog post from
yesterday: http://bc.tech.coop/blog/081023.html)

Are you doing all of the following:

1. Specify the appropriate debug options when you start Clojure (see
step #4 in my blog post)
2. Load the Clojure source file you want to debug (you can't debug
definitions created in the repl)
3. Start JSwat and use the "Session/Attach..." menu option to attach
to the correct host/port (in my case, "localhost" and "8888" since I'm
debugging a local Java instance and I specified port "8888" when I
started Java)
4. In JSwat, open the same Clojure source file you loaded in step #2
and add a breakpoint (you can just click on the source line#) - note
that you can only add breakpoints to lines in a defn, not lines in a
defmacro definition
5. In the Clojure repl evaluate a form that will call the function
that has your breakpoint.
6. In JSwat, you should see that the breakpoint has been hit and
program execution is paused

--
Bill Clementson

Craig Andera

unread,
Oct 24, 2008, 10:55:41 AM10/24/08
to clo...@googlegroups.com
> Are you doing all of the following:
>
> 1. Specify the appropriate debug options when you start Clojure (see
> step #4 in my blog post)

Yep. Here's the full command line:

c:\WINDOWS\system32\java.exe -Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n -cp
"C:/bin/clojure/clojure/svn/clojure.jar;c:/data/.clojure/*"
clojure.lang.Repl

> 2. Load the Clojure source file you want to debug (you can't debug
> definitions created in the repl)

Did so from the SLIME REPL via (load-file "/path/to/my/source.clj")

> 3. Start JSwat and use the "Session/Attach..." menu option to attach
> to the correct host/port (in my case, "localhost" and "8888" since I'm
> debugging a local Java instance and I specified port "8888" when I
> started Java)

Yep. Localhost and 50525 for me this time (got port from the message
spewed into *inferior-lisp*).

> 4. In JSwat, open the same Clojure source file you loaded in step #2
> and add a breakpoint (you can just click on the source line#) - note
> that you can only add breakpoints to lines in a defn, not lines in a
> defmacro definition

Yep.

> 5. In the Clojure repl evaluate a form that will call the function
> that has your breakpoint.

Yep.

> 6. In JSwat, you should see that the breakpoint has been hit and
> program execution is paused

Nope. :p

Fortunately I've since solved the problem I originally wanted the
debugger for (yay REPL), but it still would be nice to get this to
work...

I'm puzzled by my ability to successfully hit breakpoints in boot.clj.
That seems to imply I'm doing something partially right.

Bill Clementson

unread,
Oct 24, 2008, 11:03:17 AM10/24/08
to clo...@googlegroups.com
Hi Craig,

On Fri, Oct 24, 2008 at 7:55 AM, Craig Andera <craig....@gmail.com> wrote:
>
>> Are you doing all of the following:
>>
>> 1. Specify the appropriate debug options when you start Clojure (see
>> step #4 in my blog post)
>
> Yep. Here's the full command line:
>
> c:\WINDOWS\system32\java.exe -Xdebug
> -Xrunjdwp:transport=dt_socket,server=y,suspend=n -cp
> "C:/bin/clojure/clojure/svn/clojure.jar;c:/data/.clojure/*"
> clojure.lang.Repl

No, that's not enough. You didn't specify the port that you want to
connect to JSwat on. add "address=8888" (or something similar) to this
to specify which port you want to use. In my blog example, I'm using
"8888":
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888

>> 2. Load the Clojure source file you want to debug (you can't debug
>> definitions created in the repl)
>
> Did so from the SLIME REPL via (load-file "/path/to/my/source.clj")
>
>> 3. Start JSwat and use the "Session/Attach..." menu option to attach
>> to the correct host/port (in my case, "localhost" and "8888" since I'm
>> debugging a local Java instance and I specified port "8888" when I
>> started Java)
>
> Yep. Localhost and 50525 for me this time (got port from the message
> spewed into *inferior-lisp*).

Port "50525" is the port that SLIME/SWANK is using to establish the
communications between your running Clojure instance and the emacs
lisp code. You can't use this same port for JSwat.

>> 4. In JSwat, open the same Clojure source file you loaded in step #2
>> and add a breakpoint (you can just click on the source line#) - note
>> that you can only add breakpoints to lines in a defn, not lines in a
>> defmacro definition
>
> Yep.
>
>> 5. In the Clojure repl evaluate a form that will call the function
>> that has your breakpoint.
>
> Yep.
>
>> 6. In JSwat, you should see that the breakpoint has been hit and
>> program execution is paused
>
> Nope. :p
>
> Fortunately I've since solved the problem I originally wanted the
> debugger for (yay REPL), but it still would be nice to get this to
> work...

If you do the above, it should work for you.

> I'm puzzled by my ability to successfully hit breakpoints in boot.clj.
> That seems to imply I'm doing something partially right.

--
Bill Clementson

Craig Andera

unread,
Oct 24, 2008, 11:16:40 AM10/24/08
to clo...@googlegroups.com
> No, that's not enough. You didn't specify the port that you want to
> connect to JSwat on. add "address=8888" (or something similar) to this
> to specify which port you want to use. In my blog example, I'm using
> "8888":
> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888

> Port "50525" is the port that SLIME/SWANK is using to establish the


> communications between your running Clojure instance and the emacs
> lisp code. You can't use this same port for JSwat.

Actually, there are two port-related messages in *inferior-lisp*: one
talks about the port that SLIME is using to talk to SWANK, and I used
the other one. So it appears that a port is chosen for you if you
don't specify one. And as I said, I'm able to attach JSwat and set
(and, more importantly, trigger) breakpoints in boot.clj. So I don't
think anything was wrong with how I was connecting JSwat.

That said, I went head and did as you suggested (it's a PITA to look
up the port every time as I had been doing), but still no luck.

> If you do the above, it should work for you.

If only that were true. :)

It's very likely/nearly certain I'm still doing something wrong - I
appreciate the help.

Bill Clementson

unread,
Oct 24, 2008, 1:09:44 PM10/24/08
to clo...@googlegroups.com

I'm grasping at straws here, but:

1. Presumably, you're running a compatible version of JSwat (the
latest version doesn't work with Java 1.5)
2. Presumably, you've tried setting breakpoints on multiple lines in
your source file (for some reason, you can't always set a breakpoint
on a clojure line - I haven't figured out why, maybe something to do
with whether the statement is defined with defn or not).
3. Presumably, you've tried debugging different source files (in case
there's some peculiar problem with the specific source file you're
attempting to debug)

It might help if you create a small clojure program, and note down all
the steps that you go through. Then, I can replicate what you're doing
and see if I get a different result.

- Bill

Craig Andera

unread,
Oct 24, 2008, 1:31:56 PM10/24/08
to clo...@googlegroups.com
>> It's very likely/nearly certain I'm still doing something wrong - I
>> appreciate the help.

Indeed it was me: everything started working as soon as I made sure my
.clj files were in CLASSPATH the way require describes they should be.
I'm sure it doesn't help that I'm a Java n00b in addition to being a
Clojure neophyte.

As a bonus, require works now, too. Lesson learned: putting your files
anywhere else is asking for trouble.

Thanks, Bill - it's always inspiring when someone else makes an effort
- keeps me from ignoring the problem for too long! (Been a fan of your
blog for quite a while now, BTW.) Hat tip to Allen as well.

Bill Clementson

unread,
Oct 24, 2008, 1:42:35 PM10/24/08
to clo...@googlegroups.com

Great - glad to hear that you got it working!

- Bill

Craig Andera

unread,
Oct 29, 2008, 4:20:32 PM10/29/08
to clo...@googlegroups.com
As a follow-on to this, it turns out that debugging works *only* when
I pull the files in via require; neither slime-load-file nor
slime-eval-buffer nor load-file result in breakpoints getting hit.

On Fri, Oct 24, 2008 at 1:27 PM, Craig Andera <can...@wangdera.com> wrote:
>>> It's very likely/nearly certain I'm still doing something wrong - I
>>> appreciate the help.
>

Reply all
Reply to author
Forward
0 new messages