1 /*
2 * Copyright (c) 2000, 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;
26
27 import java.io.PrintStream;
28 import java.net.*;
29 import java.rmi.*;
30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.debugger.dbx.*;
32 import sun.jvm.hotspot.debugger.proc.*;
33 import sun.jvm.hotspot.debugger.remote.*;
34 import sun.jvm.hotspot.debugger.win32.*;
35 import sun.jvm.hotspot.debugger.windbg.*;
36 import sun.jvm.hotspot.debugger.linux.*;
37 import sun.jvm.hotspot.memory.*;
38 import sun.jvm.hotspot.oops.*;
39 import sun.jvm.hotspot.runtime.*;
40 import sun.jvm.hotspot.types.*;
41 import sun.jvm.hotspot.utilities.*;
42
43 /** <P> This class wraps much of the basic functionality and is the
44 * highest-level factory for VM data structures. It makes it simple
45 * to start up the debugging system. </P>
46 *
47 * <P> FIXME: need to add a way to configure the paths to dbx and the
48 * DSO from the outside. However, this should work for now for
49 * internal use. </P>
50 *
51 * <P> FIXME: especially with the addition of remote debugging, this
52 * has turned into a mess; needs rethinking. </P>
53 */
54
419 try {
420 VM.initialize(db, debugger);
421 } catch (DebuggerException e) {
422 throw (e);
423 } catch (Exception e) {
424 throw new DebuggerException(e);
425 }
426 }
427 }
428
429 //--------------------------------------------------------------------------------
430 // OS-specific debugger setup/connect routines
431 //
432
433 //
434 // Solaris
435 //
436
437 private void setupDebuggerSolaris() {
438 setupJVMLibNamesSolaris();
439 if(System.getProperty("sun.jvm.hotspot.debugger.useProcDebugger") != null) {
440 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
441 debugger = dbg;
442 attachDebugger();
443
444 // Set up CPU-dependent stuff
445 if (cpu.equals("x86")) {
446 machDesc = new MachineDescriptionIntelX86();
447 } else if (cpu.equals("sparc")) {
448 int addressSize = dbg.getRemoteProcessAddressSize();
449 if (addressSize == -1) {
450 throw new DebuggerException("Error occurred while trying to determine the remote process's " +
451 "address size");
452 }
453
454 if (addressSize == 32) {
455 machDesc = new MachineDescriptionSPARC32Bit();
456 } else if (addressSize == 64) {
457 machDesc = new MachineDescriptionSPARC64Bit();
458 } else {
459 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
460 }
461 } else if (cpu.equals("amd64")) {
462 machDesc = new MachineDescriptionAMD64();
463 } else {
464 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
465 }
466
467 dbg.setMachineDescription(machDesc);
468 return;
469
470 } else {
471 String dbxPathName;
472 String dbxPathPrefix;
473 String dbxSvcAgentDSOPathName;
474 String dbxSvcAgentDSOPathPrefix;
475 String[] dbxSvcAgentDSOPathNames = null;
476
477 // use path names/prefixes specified on command
478 dbxPathName = System.getProperty("dbxPathName");
479 if (dbxPathName == null) {
480 dbxPathPrefix = System.getProperty("dbxPathPrefix");
481 if (dbxPathPrefix == null) {
482 dbxPathPrefix = defaultDbxPathPrefix;
483 }
484 dbxPathName = dbxPathPrefix + fileSep + os + fileSep + cpu + fileSep + "bin" + fileSep + "dbx";
485 }
486
487 dbxSvcAgentDSOPathName = System.getProperty("dbxSvcAgentDSOPathName");
488 if (dbxSvcAgentDSOPathName != null) {
489 dbxSvcAgentDSOPathNames = new String[] { dbxSvcAgentDSOPathName } ;
490 } else {
491 dbxSvcAgentDSOPathPrefix = System.getProperty("dbxSvcAgentDSOPathPrefix");
492 if (dbxSvcAgentDSOPathPrefix == null) {
493 dbxSvcAgentDSOPathPrefix = defaultDbxSvcAgentDSOPathPrefix;
494 }
495 if (cpu.equals("sparc")) {
496 dbxSvcAgentDSOPathNames = new String[] {
497 // FIXME: bad hack for SPARC v9. This is necessary because
498 // there are two dbx executables on SPARC, one for v8 and one
499 // for v9, and it isn't obvious how to tell the two apart
500 // using the dbx command line. See
501 // DbxDebuggerLocal.importDbxModule().
502 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + "v9" + fileSep + "lib" +
503 fileSep + "libsvc_agent_dbx.so",
504 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" +
505 fileSep + "libsvc_agent_dbx.so",
506 };
507 } else {
508 dbxSvcAgentDSOPathNames = new String[] {
509 dbxSvcAgentDSOPathPrefix + fileSep + os + fileSep + cpu + fileSep + "lib" +
510 fileSep + "libsvc_agent_dbx.so"
511 };
512 }
513 }
514
515 // Note we do not use a cache for the local debugger in server
516 // mode; it's taken care of on the client side
517 DbxDebuggerLocal dbg = new DbxDebuggerLocal(null, dbxPathName, dbxSvcAgentDSOPathNames, !isServer);
518 debugger = dbg;
519
520 attachDebugger();
521
522 // Set up CPU-dependent stuff
523 if (cpu.equals("x86")) {
524 machDesc = new MachineDescriptionIntelX86();
525 } else if (cpu.equals("sparc")) {
526 int addressSize = dbg.getRemoteProcessAddressSize();
527 if (addressSize == -1) {
528 throw new DebuggerException("Error occurred while trying to determine the remote process's " +
529 "address size. It's possible that the Serviceability Agent's dbx module failed to " +
530 "initialize. Examine the standard output and standard error streams from the dbx " +
531 "process for more information.");
532 }
533
534 if (addressSize == 32) {
535 machDesc = new MachineDescriptionSPARC32Bit();
536 } else if (addressSize == 64) {
537 machDesc = new MachineDescriptionSPARC64Bit();
538 } else {
539 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
540 }
541 }
542
543 dbg.setMachineDescription(machDesc);
544
545 }
546 }
547
548 private void connectRemoteDebugger() throws DebuggerException {
549 RemoteDebugger remote =
550 (RemoteDebugger) RMIHelper.lookup(debugServerID);
551 debugger = new RemoteDebuggerClient(remote);
552 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
553 os = debugger.getOS();
554 if (os.equals("solaris")) {
555 setupJVMLibNamesSolaris();
556 } else if (os.equals("win32")) {
557 setupJVMLibNamesWin32();
558 } else if (os.equals("linux")) {
559 setupJVMLibNamesLinux();
560 } else {
561 throw new RuntimeException("Unknown OS type");
562 }
563
564 cpu = debugger.getCPU();
565 }
566
567 private void setupJVMLibNamesSolaris() {
572 // Win32
573 //
574
575 private void setupDebuggerWin32() {
576 setupJVMLibNamesWin32();
577
578 if (cpu.equals("x86")) {
579 machDesc = new MachineDescriptionIntelX86();
580 } else if (cpu.equals("amd64")) {
581 machDesc = new MachineDescriptionAMD64();
582 } else if (cpu.equals("ia64")) {
583 machDesc = new MachineDescriptionIA64();
584 } else {
585 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
586 }
587
588 // Note we do not use a cache for the local debugger in server
589 // mode; it will be taken care of on the client side (once remote
590 // debugging is implemented).
591
592 if (System.getProperty("sun.jvm.hotspot.debugger.useWindbgDebugger") != null) {
593 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
594 } else {
595 debugger = new Win32DebuggerLocal(machDesc, !isServer);
596 }
597
598 attachDebugger();
599
600 // FIXME: add support for server mode
601 }
602
603 private void setupJVMLibNamesWin32() {
604 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
605 }
606
607 //
608 // Linux
609 //
610
611 private void setupDebuggerLinux() {
612 setupJVMLibNamesLinux();
613
614 if (cpu.equals("x86")) {
615 machDesc = new MachineDescriptionIntelX86();
616 } else if (cpu.equals("ia64")) {
|
1 /*
2 * Copyright (c) 2000, 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;
26
27 import java.io.PrintStream;
28 import java.net.*;
29 import java.rmi.*;
30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.debugger.proc.*;
32 import sun.jvm.hotspot.debugger.remote.*;
33 import sun.jvm.hotspot.debugger.windbg.*;
34 import sun.jvm.hotspot.debugger.linux.*;
35 import sun.jvm.hotspot.memory.*;
36 import sun.jvm.hotspot.oops.*;
37 import sun.jvm.hotspot.runtime.*;
38 import sun.jvm.hotspot.types.*;
39 import sun.jvm.hotspot.utilities.*;
40
41 /** <P> This class wraps much of the basic functionality and is the
42 * highest-level factory for VM data structures. It makes it simple
43 * to start up the debugging system. </P>
44 *
45 * <P> FIXME: need to add a way to configure the paths to dbx and the
46 * DSO from the outside. However, this should work for now for
47 * internal use. </P>
48 *
49 * <P> FIXME: especially with the addition of remote debugging, this
50 * has turned into a mess; needs rethinking. </P>
51 */
52
417 try {
418 VM.initialize(db, debugger);
419 } catch (DebuggerException e) {
420 throw (e);
421 } catch (Exception e) {
422 throw new DebuggerException(e);
423 }
424 }
425 }
426
427 //--------------------------------------------------------------------------------
428 // OS-specific debugger setup/connect routines
429 //
430
431 //
432 // Solaris
433 //
434
435 private void setupDebuggerSolaris() {
436 setupJVMLibNamesSolaris();
437 ProcDebuggerLocal dbg = new ProcDebuggerLocal(null, true);
438 debugger = dbg;
439 attachDebugger();
440
441 // Set up CPU-dependent stuff
442 if (cpu.equals("x86")) {
443 machDesc = new MachineDescriptionIntelX86();
444 } else if (cpu.equals("sparc")) {
445 int addressSize = dbg.getRemoteProcessAddressSize();
446 if (addressSize == -1) {
447 throw new DebuggerException("Error occurred while trying to determine the remote process's " +
448 "address size");
449 }
450
451 if (addressSize == 32) {
452 machDesc = new MachineDescriptionSPARC32Bit();
453 } else if (addressSize == 64) {
454 machDesc = new MachineDescriptionSPARC64Bit();
455 } else {
456 throw new DebuggerException("Address size " + addressSize + " is not supported on SPARC");
457 }
458 } else if (cpu.equals("amd64")) {
459 machDesc = new MachineDescriptionAMD64();
460 } else {
461 throw new DebuggerException("Solaris only supported on sparc/sparcv9/x86/amd64");
462 }
463
464 dbg.setMachineDescription(machDesc);
465 return;
466 }
467
468 private void connectRemoteDebugger() throws DebuggerException {
469 RemoteDebugger remote =
470 (RemoteDebugger) RMIHelper.lookup(debugServerID);
471 debugger = new RemoteDebuggerClient(remote);
472 machDesc = ((RemoteDebuggerClient) debugger).getMachineDescription();
473 os = debugger.getOS();
474 if (os.equals("solaris")) {
475 setupJVMLibNamesSolaris();
476 } else if (os.equals("win32")) {
477 setupJVMLibNamesWin32();
478 } else if (os.equals("linux")) {
479 setupJVMLibNamesLinux();
480 } else {
481 throw new RuntimeException("Unknown OS type");
482 }
483
484 cpu = debugger.getCPU();
485 }
486
487 private void setupJVMLibNamesSolaris() {
492 // Win32
493 //
494
495 private void setupDebuggerWin32() {
496 setupJVMLibNamesWin32();
497
498 if (cpu.equals("x86")) {
499 machDesc = new MachineDescriptionIntelX86();
500 } else if (cpu.equals("amd64")) {
501 machDesc = new MachineDescriptionAMD64();
502 } else if (cpu.equals("ia64")) {
503 machDesc = new MachineDescriptionIA64();
504 } else {
505 throw new DebuggerException("Win32 supported under x86, amd64 and ia64 only");
506 }
507
508 // Note we do not use a cache for the local debugger in server
509 // mode; it will be taken care of on the client side (once remote
510 // debugging is implemented).
511
512 debugger = new WindbgDebuggerLocal(machDesc, !isServer);
513
514 attachDebugger();
515
516 // FIXME: add support for server mode
517 }
518
519 private void setupJVMLibNamesWin32() {
520 jvmLibNames = new String[] { "jvm.dll", "jvm_g.dll" };
521 }
522
523 //
524 // Linux
525 //
526
527 private void setupDebuggerLinux() {
528 setupJVMLibNamesLinux();
529
530 if (cpu.equals("x86")) {
531 machDesc = new MachineDescriptionIntelX86();
532 } else if (cpu.equals("ia64")) {
|