Skip to content

Instantly share code, notes, and snippets.

@y-yoshinoya
Created August 29, 2012 15:20
Show Gist options
  • Save y-yoshinoya/3514248 to your computer and use it in GitHub Desktop.
Save y-yoshinoya/3514248 to your computer and use it in GitHub Desktop.
jdi connection sample
import sbt._
import Keys._
object MyBuild extends Build {
lazy val root = Project("root", file("."),
settings = Project.defaultSettings ++ Seq(
version := "0.1",
scalaVersion := "2.9.2",
libraryDependencies ++= Nil,
unmanagedJars in Compile <+= (javaHome) map { javaHome =>
Attributed.blank(javaHome.getOrElse(file(System.getProperty("java.home"))) / "lib" / "tools.jar")
}
)
)
}
import com.sun.jdi._
import com.sun.jdi.connect._
import com.sun.jdi.connect.Connector._
import scala.collection.JavaConversions._
object Debugger extends App {
val vm = connect("localhost", 8009).get
val threads = vm.allThreads
println(threads)
def connect(host: String, port: Int): Option[VirtualMachine] = {
val vmm = Bootstrap.virtualMachineManager
vmm.attachingConnectors.find(_.name == "com.sun.jdi.SocketAttach").map { attachingConnector =>
val arg = attachingConnector.defaultArguments
arg.get("port").asInstanceOf[IntegerArgument].setValue(port)
arg.get("hostname").setValue(host)
attachingConnector.attach(arg)
}
}
}
@y-yoshinoya
Copy link
Author

-Xrunjdwp:transport=dt_socket,address=8009,server=y,suspend=n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment