Skip to content

Three Modes of Debugger

Yun Lin edited this page Mar 8, 2017 · 1 revision

Microbat uses JPDA to collect the runtime information of a program to be debugged (target VM). JPDA supports three modes for the debugger to connect with the target VM: launch, attach, and listen. More details can be referred in http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/

#Launch Mode Existing Microbat supports only launch mode, in which the debugger launches the target VM. In this mode, the debugger starts with the target VM.

#Attach Mode For this mode, the target VM is started first. We can regard the target VM as a "server". It is running the program while listening for some debugger to connect (attach) to it. Once connected, the debugger can send request to "server" (i.e., target VM) to retrieve runtime information.

I have done some implementation for support this mode. An example for debugging an eclipse plugin looks like the following: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:53338 -Dosgi.requiredJavaVersion=1.7 -Xms256m -Xmx18196m -Declipse.pde.launch=true -Dfile.encoding=Cp1252 -classpath D:\linyun\software\eclipse-java-mars-clean\eclipse\plugins\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar org.eclipse.equinox.launcher.Main -launcher D:\linyun\software\eclipse-java-mars-clean\eclipse\eclipse.exe -name Eclipse -showsplash 600 -product org.eclipse.sdk.ide -data D:\linyun\workspace\runtime-microbat-ziyuan/../runtime-learntest -configuration file:D:/linyun/workspace/runtime-microbat-ziyuan/.metadata/.plugins/org.eclipse.pde.core/learntest/ -dev file:D:/linyun/workspace/runtime-microbat-ziyuan/.metadata/.plugins/org.eclipse.pde.core/learntest/dev.properties -os win32 -ws win32 -arch x86_64 -nl en_US -consoleLog

#Listen Mode For this mode, we regard the debugger as a "server" now and the target VM is a "client". Usually, we start the debugger and it start listening for a target VM to connect to it for a while. In this while, the target VM is started to connect to the debugger. In this mode, a debugger can listen to multiple target VMs. In other word, a debugger can collect the information from many target VMs.

I have done some implementation for support this mode. An example for debugging an eclipse plugin looks like the following: java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:53339 -Dosgi.requiredJavaVersion=1.7 -Xms256m -Xmx18196m -Declipse.pde.launch=true -Dfile.encoding=Cp1252 -classpath D:\linyun\software\eclipse-java-mars-clean\eclipse\plugins\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar org.eclipse.equinox.launcher.Main -launcher D:\linyun\software\eclipse-java-mars-clean\eclipse\eclipse.exe -name Eclipse -showsplash 600 -product org.eclipse.sdk.ide -data D:\linyun\workspace\runtime-microbat-ziyuan/../runtime-learntest -configuration file:D:/linyun/workspace/runtime-microbat-ziyuan/.metadata/.plugins/org.eclipse.pde.core/learntest/ -dev file:D:/linyun/workspace/runtime-microbat-ziyuan/.metadata/.plugins/org.eclipse.pde.core/learntest/dev.properties -os win32 -ws win32 -arch x86_64 -nl en_US -consoleLog