This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: swank-kawa.scm


On Mon, Apr 22, 2013 at 2:29 AM, Helmut Eller <eller.helmut@gmail.com> wrote:
> On Sun, Apr 21 2013, Chuah Teong Leong wrote:
>
>> Hi Helmut Eller,
>>
>> I've been looking into kawa support within emacs. So far I have slime,
>> scheme-complete, paredit set up. I came across this code you wrote.
>>
>> I have 2 problems that I'm hoping you could help me with.
>>
>> 1) Compilation
>> I'm working on windows and I'm not exactly sure if I got the
>> compilation process correct. I ran kawa with -cp to tools.jar and
>> kawa.jar and did (compile "swank-kawa.scm" "swank-kawa") from the
>> repl. There wasn't any error message and it produced a swank-kawa.zip
>> within slime\contrib. I'm wondering if it should have been renamed to
>> a jar and included it in the classpath. I haven't done anything yet
>> and assume that is how it should be.
>
> Initially I would recommend not to compile the file. You can load the
> source file with (require ".../swank-kawa.scm").  Try this from the Kawa
> REPL outside of Emacs in a normal shell to minimize confusion.
>
> If you really want to know how to compile, here are some hints:
>
> I think that compile-file is obsolete in Kawa or at least Per Bothner
> considers it bad practice. If you use compile-file you should use the
> load function instead of require: (load "..swank-kawa.zip").
>
> The recommended way to compile is from the shell with something like
> "kawa -C swank-kawa.scm".  Add classpath stuff and other flags as
> needed.  This produces .class files like javac does.  These .class files
> can then be put in a jar file with the normal jar tool, just like normal
> java classes.  To load such a jar, the jar file needs to be in the
> classpath and you need to use (import (swank-kawa)) inside Kawa.
>
>>
>> 2) Usage
>> at the end of the instruction you said
>> "Start everything with  M-- M-x slime kawa"
>>
>> I couldn't quite figure how to do that.
>> I did M-x slime and got this
>>
>> (begin (require "G:/emacs-24.2/lisp/slime/contrib/swank-kawa.scm")
>> (start-swank "c:/Users/****/AppData/Local/Temp/slime.13604"))
>> Listening for transport dt_socket at address: 49420
>> #|kawa:1|# Thread[swank,5,main]
>> #|kawa:2|# connection: Socket[addr=/127.0.0.1,port=49424,localport=49423]
>> listener: Thread[swank-listener,5,main] 28560412 chan@df11d5 #<environment r0>
>> attaching: $PPID 20
>> attaching2: com.sun.jdi.ProcessAttach (defaults: pid=, timeout=)
>> {pid=pid=$PPID, timeout=timeout=20}
>> java.util.ServiceConfigurationError:
>> com.sun.tools.attach.spi.AttachProvider: Provider
>> sun.tools.attach.WindowsAttachProvider could not be instantiated:
>> java.lang.UnsatisfiedLinkError: no attach in java.library.path
>> closing socket: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=49423]
>> exception in thread Thread[swank,5,main]: java.lang.Error: mcase failed tmp
>> (chan@cc7ed2
>>  (error "java.io.IOException: no providers installed" "IOException"
>>   ("com.sun.tools.jdi.ProcessAttachingConnector.attach(ProcessAttachingConnector.java:104)"
>>    "swank$Mnkawa.attach(swank-kawa.scm:1777)"
>>    "swank$Mnkawa.vmAttach(swank-kawa.scm:1758)"
>
>
> OK, it seems that your setup is mostly correct but it runs in to a
> problem in my code.  The function getpid in swank-kawa.scm is supposed
> to return the process id of the current process; to my knowledge there's
> no portable way to do that in Java.  The code simply assumes that we run
> on Linux and uses a Linux specific trick to figure out the pid (that's
> where the $PPID comes from in the debug output).  I don't know what the
> best trick is on Windows. Maybe steal something from the Clojure people:
> https://github.com/pallet/ritz/blob/develop/repl-utils/src/ritz/repl_utils/sys.clj
>
> On Linux
> ((java.lang.management.ManagementFactory:getRuntimeMXBean):getName)
> seems to return something useful. but (java.lang.System:getProperty
> "pid") doesn't.
>
> Anyway, if you want to explore this further then I would recommend that
> you start swank in Kawa REPL outside of Emacs like so:
>
>   #|kawa:1|# (require "/home/helmut/lisp/slime/contrib/swank-kawa.scm")
>   #|kawa:2|# (create-swank-server 4005)
>   Listening on port: 4005
>
> Then you can use M-x slime-connect in Emacs to proceed and the Kawa side
> should print something like:
>
>   connection: Socket[addr=/127.0.0.1,port=52781,localport=4005]
>   listener: Thread[swank-listener,5,main] 11515472 chan@1ea71d4
>   #<environment main>
>   attaching: 3763 20
>   attaching2: com.sun.jdi.ProcessAttach (defaults: pid=, timeout=)
>   {pid=pid=3763, timeout=timeout=20}
>
> Helmut

Ok I did as you said but it crashed with the same error message.
You're right the missing $PPID is a problem on windows.
I went in a wrote another getpid function in its place with the
assumption that this approach works on windows
http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id

As you mentioned there are two approaches but both approaches gave the
same error.
Running swank outside emacs did not work. I'm guessing because we're
running two different jvm with two different pid.
So I did M-- M-x slime RET kawa instead.

(begin (require
"G:/HOME/.emacs.d/extra-lisp/slime/contrib/swank-kawa.scm")
(start-swank "c:/Users/Alan/AppData/Local/Temp/slime.6100"))
Listening for transport dt_socket at address: 58664
#|kawa:1|# Thread[swank,5,main]
#|kawa:2|# connection: Socket[addr=/127.0.0.1,port=58672,localport=58671]
listener: Thread[swank-listener,5,main] 7253171 chan@44a3c0 #<environment r0>
found 7904
PID 7904@Alan-PC
7904
attaching: 7904 20
attaching2: com.sun.jdi.ProcessAttach (defaults: pid=, timeout=)
{pid=pid=7904, timeout=timeout=20}
java.util.ServiceConfigurationError:
com.sun.tools.attach.spi.AttachProvider: Provider
sun.tools.attach.WindowsAttachProvider could not be instantiated:
java.lang.UnsatisfiedLinkError: no attach in java.library.path
closing socket: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=58671]
exception in thread Thread[swank,5,main]: java.lang.Error: mcase failed tmp
(chan@139d980
 (error "java.io.IOException: no providers installed" "IOException"
  ("com.sun.tools.jdi.ProcessAttachingConnector.attach(ProcessAttachingConnector.java:104)"
   "swank$Mnkawa.attach(swank-kawa.scm:1778)"
   "swank$Mnkawa.vmAttach(swank-kawa.scm:1759)"
   "swank$Mnkawa.vmMonitor(swank-kawa.scm:1294)"

seems like the pid is getting passed in now, however I still get the
same error message.

not sure what this is trying to say
java.util.ServiceConfigurationError:
com.sun.tools.attach.spi.AttachProvider: Provider
sun.tools.attach.WindowsAttachProvider could not be instantiated:
java.lang.UnsatisfiedLinkError: no attach in java.library.path


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]