I read a thread on the valgrind list about tracking bogus close
calls, and I immediately thought that this would be a good job for frysk.
So, I gave it a try. It was absurdly easy to write…
First, frysk has included ftrace
in its tree for a while — this is a very simple frysk-based analog to strace
. I started by taking the ftrace sources and finding the spot where a system call is printed. Since ftrace.java is all of 200 lines of code, this took about 20 seconds.
Then I changed this code to look for a call to close
(another 20 seconds) and in particular a failing call (slightly longer than 20 seconds, due to a frysk oddity — more objective observers would probably note that I hadn’t read the sources…).
Well, that’s it. Unfortunately it still doesn’t work — it turns out that libunwind still can’t properly make stack traces of other processes. I understand this is under development.
That’s disappointing of course. But today, contra both my mood of late and my general disposition, I’m more inclined to focus on the positive. It is very cool that this sort of hacking is so easy to do. In the future I think it will be even simpler: not only will the various bugs be sorted out, but you’ll be able to write little scripts to drive the frysk libraries — using jython, or groovy, or kawa, or whatever suits your fancy.
This ties into a couple of things I think are interesting.
One is that, in Java, most programs double as libraries as a consequence of the design of the language and runtime. No special care is needed to make this work; for very badly written programs you can simply load them via a new class loader and let them operate in their own universe. This in turn makes it much simpler to treat existing java programs as part of a toolbox that you can assemble as you like.
And, frysk is (or for the more cautious, will be) a very useful part of this toolbox — useful in a “java-y” way, in a “script-y” way, and with various front ends, useful in a “unix-y” way, I think. Essentially it enables us to write non-trivial ad hoc debugging and tracing scripts.
Be the first to leave a comment. Don’t be shy.