1 /*
2 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.bugspot;
26
27 import java.io.PrintStream;
28 import java.net.*;
29 import java.rmi.*;
30 import sun.jvm.hotspot.*;
31 import sun.jvm.hotspot.debugger.*;
32 import sun.jvm.hotspot.debugger.dbx.*;
33 import sun.jvm.hotspot.debugger.proc.*;
34 import sun.jvm.hotspot.debugger.cdbg.*;
35 import sun.jvm.hotspot.debugger.win32.*;
36 import sun.jvm.hotspot.debugger.windbg.*;
37 import sun.jvm.hotspot.debugger.linux.*;
38 import sun.jvm.hotspot.debugger.sparc.*;
39 import sun.jvm.hotspot.debugger.remote.*;
40 import sun.jvm.hotspot.livejvm.*;
41 import sun.jvm.hotspot.memory.*;
42 import sun.jvm.hotspot.oops.*;
43 import sun.jvm.hotspot.runtime.*;
44 import sun.jvm.hotspot.types.*;
45 import sun.jvm.hotspot.utilities.*;
46
47 /** <P> This class wraps the basic functionality for connecting to the
48 * target process or debug server. It makes it simple to start up the
49 * debugging system. </P>
50 *
51 * <P> This agent (as compared to the HotSpotAgent) can connect to
52 * and interact with arbitrary processes. If the target process
53 * happens to be a HotSpot JVM, the Java debugging features of the
54 * Serviceability Agent are enabled. Further, if the Serviceability
55 * Agent's JVMDI module is loaded into the target VM, interaction
610 jvmdi = null;
611 }
612 } catch (Exception e) {
613 e.printStackTrace();
614 jvmdi = null;
615 }
616
617 return true;
618 }
619
620 //--------------------------------------------------------------------------------
621 // OS-specific debugger setup/connect routines
622 //
623
624 //
625 // Solaris
626 //
627
628 private void setupDebuggerSolaris() {
629 setupJVMLibNamesSolaris();
630 String prop = System.getProperty("sun.jvm.hotspot.debugger.useProcDebugger");
631 if (prop != null && !prop.equals("false")) {
632 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
633 debugger = dbg;
634 attachDebugger();
635
636 // Set up CPU-dependent stuff
637 if (cpu.equals("x86")) {
638 machDesc = new MachineDescriptionIntelX86();
639 } else if (cpu.equals("sparc")) {
640 int addressSize = dbg.getRemoteProcessAddressSize();
641 if (addressSize == -1) {
642 throw new DebuggerException("Error occurred while trying to determine the remote process's address size");
643 }
644
645 if (addressSize == 32) {
646 machDesc = new MachineDescriptionSPARC32Bit();
647 } else if (addressSize == 64) {
648 machDesc = new MachineDescriptionSPARC64Bit();
649 } else {
650 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
651 }
652 } else if (cpu.equals("amd64")) {
653 machDesc = new MachineDescriptionAMD64();
654 } else {
655 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
656 }
657
658 dbg.setMachineDescription(machDesc);
659 return;
660 } else {
661 String dbxPathName;
662 String dbxPathPrefix;
663 String dbxSvcAgentDSOPathName;
664 String dbxSvcAgentDSOPathPrefix;
665 String[] dbxSvcAgentDSOPathNames = null;
666
667 // use path names/prefixes specified on command
668 dbxPathName = System.getProperty("dbxPathName");
669 if (dbxPathName == null) {
670 dbxPathPrefix = System.getProperty("dbxPathPrefix");
671 if (dbxPathPrefix == null) {
672 dbxPathPrefix = defaultDbxPathPrefix;
673 }
674 dbxPathName = dbxPathPrefix + fileSep + os + fileSep + cpu + fileSep + "bin" + fileSep + "dbx";
675 }
676
677 dbxSvcAgentDSOPathName = System.getProperty("dbxSvcAgentDSOPathName");
678 if (dbxSvcAgentDSOPathName != null) {
679 dbxSvcAgentDSOPathNames = new String[] { dbxSvcAgentDSOPathName } ;
680 } else {
681 dbxSvcAgentDSOPathPrefix = System.getProperty("dbxSvcAgentDSOPathPrefix");
682 if (dbxSvcAgentDSOPathPrefix == null) {
683 dbxSvcAgentDSOPathPrefix = defaultDbxSvcAgentDSOPathPrefix;
684 }
685 if (cpu.equals("sparc")) {
686 dbxSvcAgentDSOPathNames = new String[] {
687 // FIXME: bad hack for SPARC v9. This is necessary because
688 // there are two dbx executables on SPARC, one for v8 and one
689 // for v9, and it isn't obvious how to tell the two apart
690 // using the dbx command line. See
691 // DbxDebuggerLocal.importDbxModule().
692 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + "v9" + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so",
693 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so",
694 };
695 } else {
696 dbxSvcAgentDSOPathNames = new String[] {
697 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" + fileSep + "libsvc_agent_dbx.so"
698 };
699 }
700 }
701 // Note we do not use a cache for the local debugger in server
702 // mode; it's taken care of on the client side
703 DbxDebuggerLocal dbg = new DbxDebuggerLocal(null, dbxPathName, dbxSvcAgentDSOPathNames, !isServer);
704 debugger = dbg;
705
706 attachDebugger();
707
708 // Set up CPU-dependent stuff
709 if (cpu.equals("x86")) {
710 machDesc = new MachineDescriptionIntelX86();
711 } else if (cpu.equals("sparc")) {
712 int addressSize = dbg.getRemoteProcessAddressSize();
713 if (addressSize == -1) {
714 throw new DebuggerException("Error occurred while trying to determine the remote process's address size. It's possible that the Serviceability Agent's dbx module failed to initialize. Examine the standard output and standard error streams from the dbx process for more information.");
715 }
716
717 if (addressSize == 32) {
718 machDesc = new MachineDescriptionSPARC32Bit();
719 } else if (addressSize == 64) {
720 machDesc = new MachineDescriptionSPARC64Bit();
721 } else {
722 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
723 }
724 }
725
726 dbg.setMachineDescription(machDesc);
727 }
728 }
729
730 private void connectRemoteDebugger() throws DebuggerException {
731 RemoteDebugger remote =
732 (RemoteDebugger) RMIHelper.lookup(debugServerID);
733 debugger = new RemoteDebuggerClient(remote);
734 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
735 os = debugger.getOS();
736 if (os.equals("solaris")) {
737 setupJVMLibNamesSolaris();
738 } else if (os.equals("win32")) {
739 setupJVMLibNamesWin32();
740 } else if (os.equals("linux")) {
741 setupJVMLibNamesLinux();
742 } else {
743 throw new RuntimeException("Unknown OS type");
744 }
745
746 cpu = debugger.getCPU();
747 }
748
749 private void setupJVMLibNamesSolaris() {
755 // Win32
756 //
757
758 private void setupDebuggerWin32() {
759 setupJVMLibNamesWin32();
760
761 if (cpu.equals("x86")) {
762 machDesc = new MachineDescriptionIntelX86();
763 } else if (cpu.equals("amd64")) {
764 machDesc = new MachineDescriptionAMD64();
765 } else if (cpu.equals("ia64")) {
766 machDesc = new MachineDescriptionIA64();
767 } else {
768 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
769 }
770
771 // Note we do not use a cache for the local debugger in server
772 // mode; it will be taken care of on the client side (once remote
773 // debugging is implemented).
774
775 if (System.getProperty("sun.jvm.hotspot.debugger.useWindbgDebugger") != null) {
776 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
777 } else {
778 debugger = new Win32DebuggerLocal(machDesc, !isServer);
779 }
780
781 attachDebugger();
782 }
783
784 private void setupJVMLibNamesWin32() {
785 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
786 saLibNames = new String[] { "sa.dll", "sa_g.dll" };
787 }
788
789 //
790 // Linux
791 //
792
793 private void setupDebuggerLinux() {
794 setupJVMLibNamesLinux();
795
796 if (cpu.equals("x86")) {
797 machDesc = new MachineDescriptionIntelX86();
798 } else if (cpu.equals("ia64")) {
799 machDesc = new MachineDescriptionIA64();
|
1 /*
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.bugspot;
26
27 import java.io.PrintStream;
28 import java.net.*;
29 import java.rmi.*;
30 import sun.jvm.hotspot.*;
31 import sun.jvm.hotspot.debugger.*;
32 import sun.jvm.hotspot.debugger.proc.*;
33 import sun.jvm.hotspot.debugger.cdbg.*;
34 import sun.jvm.hotspot.debugger.windbg.*;
35 import sun.jvm.hotspot.debugger.linux.*;
36 import sun.jvm.hotspot.debugger.sparc.*;
37 import sun.jvm.hotspot.debugger.remote.*;
38 import sun.jvm.hotspot.livejvm.*;
39 import sun.jvm.hotspot.memory.*;
40 import sun.jvm.hotspot.oops.*;
41 import sun.jvm.hotspot.runtime.*;
42 import sun.jvm.hotspot.types.*;
43 import sun.jvm.hotspot.utilities.*;
44
45 /** <P> This class wraps the basic functionality for connecting to the
46 * target process or debug server. It makes it simple to start up the
47 * debugging system. </P>
48 *
49 * <P> This agent (as compared to the HotSpotAgent) can connect to
50 * and interact with arbitrary processes. If the target process
51 * happens to be a HotSpot JVM, the Java debugging features of the
52 * Serviceability Agent are enabled. Further, if the Serviceability
53 * Agent's JVMDI module is loaded into the target VM, interaction
608 jvmdi = null;
609 }
610 } catch (Exception e) {
611 e.printStackTrace();
612 jvmdi = null;
613 }
614
615 return true;
616 }
617
618 //--------------------------------------------------------------------------------
619 // OS-specific debugger setup/connect routines
620 //
621
622 //
623 // Solaris
624 //
625
626 private void setupDebuggerSolaris() {
627 setupJVMLibNamesSolaris();
628 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
629 debugger = dbg;
630 attachDebugger();
631
632 // Set up CPU-dependent stuff
633 if (cpu.equals("x86")) {
634 machDesc = new MachineDescriptionIntelX86();
635 } else if (cpu.equals("sparc")) {
636 int addressSize = dbg.getRemoteProcessAddressSize();
637 if (addressSize == -1) {
638 throw new DebuggerException("Error occurred while trying to determine the remote process's address size");
639 }
640
641 if (addressSize == 32) {
642 machDesc = new MachineDescriptionSPARC32Bit();
643 } else if (addressSize == 64) {
644 machDesc = new MachineDescriptionSPARC64Bit();
645 } else {
646 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
647 }
648 } else if (cpu.equals("amd64")) {
649 machDesc = new MachineDescriptionAMD64();
650 } else {
651 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
652 }
653
654 dbg.setMachineDescription(machDesc);
655 }
656
657 private void connectRemoteDebugger() throws DebuggerException {
658 RemoteDebugger remote =
659 (RemoteDebugger) RMIHelper.lookup(debugServerID);
660 debugger = new RemoteDebuggerClient(remote);
661 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
662 os = debugger.getOS();
663 if (os.equals("solaris")) {
664 setupJVMLibNamesSolaris();
665 } else if (os.equals("win32")) {
666 setupJVMLibNamesWin32();
667 } else if (os.equals("linux")) {
668 setupJVMLibNamesLinux();
669 } else {
670 throw new RuntimeException("Unknown OS type");
671 }
672
673 cpu = debugger.getCPU();
674 }
675
676 private void setupJVMLibNamesSolaris() {
682 // Win32
683 //
684
685 private void setupDebuggerWin32() {
686 setupJVMLibNamesWin32();
687
688 if (cpu.equals("x86")) {
689 machDesc = new MachineDescriptionIntelX86();
690 } else if (cpu.equals("amd64")) {
691 machDesc = new MachineDescriptionAMD64();
692 } else if (cpu.equals("ia64")) {
693 machDesc = new MachineDescriptionIA64();
694 } else {
695 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
696 }
697
698 // Note we do not use a cache for the local debugger in server
699 // mode; it will be taken care of on the client side (once remote
700 // debugging is implemented).
701
702 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
703
704 attachDebugger();
705 }
706
707 private void setupJVMLibNamesWin32() {
708 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
709 saLibNames = new String[] { "sa.dll", "sa_g.dll" };
710 }
711
712 //
713 // Linux
714 //
715
716 private void setupDebuggerLinux() {
717 setupJVMLibNamesLinux();
718
719 if (cpu.equals("x86")) {
720 machDesc = new MachineDescriptionIntelX86();
721 } else if (cpu.equals("ia64")) {
722 machDesc = new MachineDescriptionIA64();
|