Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335896

Summary: Support SA Core Attaching Connectors
Product: [Eclipse Project] JDT Reporter: Michael Rennie <Michael_Rennie>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: curtis.windatt.public, daniel_megert, darin.eclipse, knut.wannheden, markus.kell.r, remy.suen
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: 4.3 candidate

Description Michael Rennie CLA 2011-01-31 15:18:29 EST
Java SE 1.6 has support for remote debugging via ProcessAttach.

We should provide a remote debug launching connector for this.

The details are here: http://download.oracle.com/javase/6/docs/technotes/guides/jpda/enhancements.html
Comment 1 Michael Rennie CLA 2011-07-07 10:29:53 EDT
I should mention here that there are may other kinds of launching connectors that we also do not support (but could). 

More information is here: http://download.oracle.com/javase/6/docs/technotes/guides/jpda/conninv.html#Connectors

The SA core attaching connector sounds interesting...
Comment 2 Michael Rennie CLA 2011-09-26 12:15:43 EDT
Getting the connection information is all included in the API for Process attach - which includes an API for getting all VMs (and their process ids) that can be attached to.

Here is a simple snippet that enumerates all of the VMs running that can be attached to and dumps out their properties:

import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

class AttachTest {
    public static void main(String args[]) {
    	List<VirtualMachineDescriptor> vms = VirtualMachine.list();
    	try {
    		for(int i = 0; i < vms.size(); i++) {
	    		VirtualMachine vm = VirtualMachine.attach(vms.get(i));
	    		if(vm != null) {
	    			Properties props = vm.getAgentProperties();
	    			printProps("Attached VM '"+vm.id()+"' agent properties:\n", props);
	    			props = vm.getSystemProperties();
	    			printProps("Attached VM '"+vm.id()+"' system properties:\n", props);
	    		}
    		}
    	}
    	catch(Exception e) {
    		e.printStackTrace();
    	}
    }
    
    static void printProps(String desc, Properties props) {
    	System.out.println(desc);
    	Entry<Object, Object> entry = null;
		for(Iterator<Entry<Object, Object>> it = props.entrySet().iterator(); it.hasNext();) {
			entry = it.next();
			System.out.print("\t[key: "+entry.getKey());
			System.out.println("][value: "+entry.getValue()+"]");
		}
    }
}

Once we are connected to the virtual machine we can insert our own Java agent. The biggest problem is that so far I have not found a way to begin a debug session (using JDI / JDWP).
Comment 3 Michael Rennie CLA 2012-03-05 15:57:07 EST
After spending quite a bit more time investigating the other launching connectors, the only ones of much interest are the two connectors:

1. SA Core Attaching Connector
2. SA Core Debug Server Attaching Connector

some more information about these connectors can be found: http://www.oracle.com/technetwork/java/javase/tooldescr-136044.html#gbmnc

I pushed a new branch with my test code:

http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?h=mrennie/bug335896&id=535d7b50cddb871270ead6a06a4abde56afe9a35

that has the hooks for those two launching connectors. I found them to be very cool, such that you can have a read-only view of a core dump on either a local or remote machine *and* allows you to attach to a hung process (local or remote, given the process id). The problem with these two connectors (and the reason I am deferring any more work on this) is that they rely on RMI for communication. This prevents us from using our current JDI impl's for VirtualMachine, etc, because those are coded to rely on socket communication. Therefore the effort to support either of these (very cool) connectors is very large.