Created
August 29, 2012 15:20
-
-
Save y-yoshinoya/3514248 to your computer and use it in GitHub Desktop.
jdi connection sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
) | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-Xrunjdwp:transport=dt_socket,address=8009,server=y,suspend=n