Breakpoints in anonymous/partial functions

I'm having trouble setting breakpoints inside partial functions. For example,

  x match {
    Some(n) =>
      println( n )
    None =>
      println( "None" )

I get a red X if I attempt to put a breakpoint on anything inside the match's braces. When I debug the program, none of the breakpoints are tripped.

Additionally, sometimes I have anonymous functions that I'd like to trigger breakpoints. For example, in Lift:

  "foo" -> {"/blah", () => println("foo") }

I'd like to drop into the debugger when the link button is clicked, not when the link function is generated on the way out of the snippet.

Are these things achievable?


not yet, afaik :(
you can solve some problems by adding linebreaks, extracting the logic into local methods and so on, but the ultimate solution has yet to be invented


Scala Debug info is built on the standards for Java debuggers, which only offers resolution down to a per-line basis. I've heard some interesting proposals to offer a finer resolution within the boundaries of this format, but for now you'll need to live with hitting the same breakpoint more often than you desire.

Perhaps another possibility is to use the a conditional breakpoint, where the condition performs Thread.getStackTrace and only stops if it's at the inner function. The tricky part would be to make this usable.



Here's what I've ended up with:

object Debugger {
  def break = {
    (() => ())()       /// no-op - put your breakpoint here

  def break[A](x : A) : A = {

object Test {
  def main(args : Array[String]) = {
    val xs = (1 to 10).toList

    println( => Debugger.break(println(x))))

So if you want to put a breakpoint in an expression, wrap a value in Debugger.break(x). It will trigger a breakpoint and then return its argument unmodified. This way, you can wrap any value in Debugger.break to get into the debugger. The frame directly above the breakpoint will have the values you're looking to inspect.


Please sign in to leave a comment.