agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java

Print this page

        

*** 23,32 **** --- 23,34 ---- */ package sun.jvm.hotspot; import java.rmi.RemoteException; + import java.lang.reflect.Constructor; + import java.lang.reflect.InvocationTargetException; import sun.jvm.hotspot.debugger.Debugger; import sun.jvm.hotspot.debugger.DebuggerException; import sun.jvm.hotspot.debugger.JVMDebugger; import sun.jvm.hotspot.debugger.MachineDescription;
*** 61,71 **** private MachineDescription machDesc; private TypeDataBase db; private String os; private String cpu; - private String fileSep; // The system can work in several ways: // - Attaching to local process // - Attaching to local core file // - Connecting to remote debug server --- 63,72 ----
*** 153,162 **** --- 154,171 ---- startupMode = CORE_FILE_MODE; isServer = false; go(); } + /** This uses a JVMDebugger that is already attached to the core or process */ + public synchronized void attach(JVMDebugger d) + throws DebuggerException { + debugger = d; + isServer = false; + go(); + } + /** This attaches to a "debug server" on a remote machine; this remote server has already attached to a process or opened a core file and is waiting for RMI calls on the Debugger object to come in. */ public synchronized void attach(String remoteServerID)
*** 301,319 **** // // Local mode (client attaching to local process or setting up // server, but not client attaching to server) // try { os = PlatformInfo.getOS(); cpu = PlatformInfo.getCPU(); ! } ! catch (UnsupportedPlatformException e) { throw new DebuggerException(e); } - fileSep = System.getProperty("file.separator"); - if (os.equals("solaris")) { setupDebuggerSolaris(); } else if (os.equals("win32")) { setupDebuggerWin32(); } else if (os.equals("linux")) { --- 310,336 ---- // // Local mode (client attaching to local process or setting up // server, but not client attaching to server) // + // Handle existing or alternate JVMDebugger: + // these will set os, cpu independently of our PlatformInfo implementation. + String alternateDebugger = System.getProperty("sa.altDebugger"); + if (debugger != null) { + setupDebuggerExisting(); + + } else if (alternateDebugger != null) { + setupDebuggerAlternate(alternateDebugger); + + } else { + // Otherwise, os, cpu are those of our current platform: try { os = PlatformInfo.getOS(); cpu = PlatformInfo.getCPU(); ! } catch (UnsupportedPlatformException e) { throw new DebuggerException(e); } if (os.equals("solaris")) { setupDebuggerSolaris(); } else if (os.equals("win32")) { setupDebuggerWin32(); } else if (os.equals("linux")) {
*** 324,333 **** --- 341,351 ---- setupDebuggerDarwin(); } else { // Add support for more operating systems here throw new DebuggerException("Operating system " + os + " not yet supported"); } + } if (isServer) { RemoteDebuggerServer remote = null; try { remote = new RemoteDebuggerServer(debugger);
*** 421,430 **** --- 439,483 ---- //-------------------------------------------------------------------------------- // OS-specific debugger setup/connect routines // + // Use the existing JVMDebugger, as passed to our constructor. + // Retrieve os and cpu from that debugger, not the current platform. + private void setupDebuggerExisting() { + + os = debugger.getOS(); + cpu = debugger.getCPU(); + setupJVMLibNames(os); + machDesc = debugger.getMachineDescription(); + } + + // Given a classname, load an alternate implementation of JVMDebugger. + private void setupDebuggerAlternate(String alternateName) { + + try { + Class c = Class.forName(alternateName); + Constructor cons = c.getConstructor(); + debugger = (JVMDebugger) cons.newInstance(); + attachDebugger(); + setupDebuggerExisting(); + + } catch (ClassNotFoundException cnfe) { + throw new DebuggerException("Cannot find alternate SA Debugger: '" + alternateName + "'"); + } catch (NoSuchMethodException nsme) { + throw new DebuggerException("Alternate SA Debugger: '" + alternateName + "' has missing constructor."); + } catch (InstantiationException ie) { + throw new DebuggerException("Alternate SA Debugger: '" + alternateName + "' fails to initialise: ", ie); + } catch (IllegalAccessException iae) { + throw new DebuggerException("Alternate SA Debugger: '" + alternateName + "' fails to initialise: ", iae); + } catch (InvocationTargetException iae) { + throw new DebuggerException("Alternate SA Debugger: '" + alternateName + "' fails to initialise: ", iae); + } + + System.err.println("Loaded alternate HotSpot SA Debugger: " + alternateName); + } + // // Solaris // private void setupDebuggerSolaris() {
*** 464,473 **** --- 517,531 ---- RemoteDebugger remote = (RemoteDebugger) RMIHelper.lookup(debugServerID); debugger = new RemoteDebuggerClient(remote); machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription(); os = debugger.getOS(); + setupJVMLibNames(os); + cpu = debugger.getCPU(); + } + + private void setupJVMLibNames(String os) { if (os.equals("solaris")) { setupJVMLibNamesSolaris(); } else if (os.equals("win32")) { setupJVMLibNamesWin32(); } else if (os.equals("linux")) {
*** 477,488 **** } else if (os.equals("darwin")) { setupJVMLibNamesDarwin(); } else { throw new RuntimeException("Unknown OS type"); } - - cpu = debugger.getCPU(); } private void setupJVMLibNamesSolaris() { jvmLibNames = new String[] { "libjvm.so" }; } --- 535,544 ----