< prev index next >

src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m

Print this page


   1 /*
   2  * Copyright (c) 2002, 2016, 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  *


 672           continue;
 673           break;
 674         case ECHILD:
 675           print_error("attach: waitpid() failed. Child process pid (%d) does not exist \n", pid);
 676           break;
 677         case EINVAL:
 678           print_error("attach: waitpid() failed. Invalid options argument.\n");
 679           break;
 680         default:
 681           print_error("attach: waitpid() failed. Unexpected error %d\n",errno);
 682           break;
 683       }
 684       return false;
 685     }
 686   }
 687 }
 688 
 689 // attach to a process/thread specified by "pid"
 690 static bool ptrace_attach(pid_t pid) {
 691   int res;
 692   if ((res = ptrace(PT_ATTACH, pid, 0, 0)) < 0) {
 693     print_error("ptrace(PT_ATTACH, %d) failed with %d\n", pid, res);
 694     return false;
 695   } else {
 696     return ptrace_waitpid(pid);
 697   }
 698 }
 699 
 700 /*
 701  * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
 702  * Method:    attach0
 703  * Signature: (I)V
 704  */
 705 JNIEXPORT void JNICALL
 706 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(
 707   JNIEnv *env, jobject this_obj, jint jpid)
 708 {
 709   print_debug("attach0 called for jpid=%d\n", (int)jpid);
 710 
 711 JNF_COCOA_ENTER(env);
 712 
 713   kern_return_t result;


   1 /*
   2  * Copyright (c) 2002, 2017, 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  *


 672           continue;
 673           break;
 674         case ECHILD:
 675           print_error("attach: waitpid() failed. Child process pid (%d) does not exist \n", pid);
 676           break;
 677         case EINVAL:
 678           print_error("attach: waitpid() failed. Invalid options argument.\n");
 679           break;
 680         default:
 681           print_error("attach: waitpid() failed. Unexpected error %d\n",errno);
 682           break;
 683       }
 684       return false;
 685     }
 686   }
 687 }
 688 
 689 // attach to a process/thread specified by "pid"
 690 static bool ptrace_attach(pid_t pid) {
 691   int res;
 692   if ((res = ptrace(PT_ATTACHEXC, pid, 0, 0)) < 0) {
 693     print_error("ptrace(PT_ATTACHEXC, %d) failed with %d\n", pid, res);
 694     return false;
 695   } else {
 696     return ptrace_waitpid(pid);
 697   }
 698 }
 699 
 700 /*
 701  * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
 702  * Method:    attach0
 703  * Signature: (I)V
 704  */
 705 JNIEXPORT void JNICALL
 706 Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(
 707   JNIEnv *env, jobject this_obj, jint jpid)
 708 {
 709   print_debug("attach0 called for jpid=%d\n", (int)jpid);
 710 
 711 JNF_COCOA_ENTER(env);
 712 
 713   kern_return_t result;


< prev index next >