< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.c

Print this page


   1 /*
   2  * Copyright (c) 2002, 2018, 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 #include <jni.h>
  26 #include "libproc.h"

  27 
  28 #include <elf.h>
  29 #include <sys/types.h>
  30 #include <sys/stat.h>
  31 #include <fcntl.h>
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <limits.h>
  35 
  36 #if defined(x86_64) && !defined(amd64)
  37 #define amd64 1
  38 #endif
  39 
  40 #ifdef i386
  41 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
  42 #endif
  43 
  44 #ifdef amd64
  45 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
  46 #endif


 224   (JNIEnv *env, jobject this_obj, jstring altroot) {
 225   if (saaltroot != NULL) {
 226     free(saaltroot);
 227   }
 228   const char *path = (*env)->GetStringUTFChars(env, altroot, JNI_FALSE);
 229   /*
 230    * `saaltroot` is used for putenv().
 231    * So we need to keep this memory.
 232    */
 233   static const char *PREFIX = "SA_ALTROOT=";
 234   size_t len = strlen(PREFIX) + strlen(path) + 1;
 235   saaltroot = (char *)malloc(len);
 236   snprintf(saaltroot, len, "%s%s", PREFIX, path);
 237   putenv(saaltroot);
 238   (*env)->ReleaseStringUTFChars(env, altroot, path);
 239 }
 240 
 241 /*
 242  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 243  * Method:    attach0
 244  * Signature: (IZ)V
 245  */
 246 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__IZ
 247   (JNIEnv *env, jobject this_obj, jint jpid, jboolean is_in_container) {
 248 
 249   // For bitness checking, locate binary at /proc/jpid/exe
 250   char buf[PATH_MAX];
 251   snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
 252   verifyBitness(env, (char *) &buf);
 253   CHECK_EXCEPTION;
 254 
 255   char err_buf[200];
 256   struct ps_prochandle* ph;
 257   if ((ph = Pgrab(jpid, err_buf, sizeof(err_buf), is_in_container)) == NULL) {
 258     char msg[230];
 259     snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
 260     THROW_NEW_DEBUGGER_EXCEPTION(msg);
 261   }
 262   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
 263   fillThreadsAndLoadObjects(env, this_obj, ph);
 264 }
 265 
 266 /*
 267  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 268  * Method:    attach0
 269  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 270  */
 271 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
 272   (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
 273   const char *execName_cstr;
 274   const char *coreName_cstr;
 275   jboolean isCopy;
 276   struct ps_prochandle* ph;
 277 


   1 /*
   2  * Copyright (c) 2002, 2019, 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 #include <jni.h>
  26 #include "libproc.h"
  27 #include "proc_service.h"
  28 
  29 #include <elf.h>
  30 #include <sys/types.h>
  31 #include <sys/stat.h>
  32 #include <fcntl.h>
  33 #include <stdlib.h>
  34 #include <string.h>
  35 #include <limits.h>
  36 
  37 #if defined(x86_64) && !defined(amd64)
  38 #define amd64 1
  39 #endif
  40 
  41 #ifdef i386
  42 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
  43 #endif
  44 
  45 #ifdef amd64
  46 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
  47 #endif


 225   (JNIEnv *env, jobject this_obj, jstring altroot) {
 226   if (saaltroot != NULL) {
 227     free(saaltroot);
 228   }
 229   const char *path = (*env)->GetStringUTFChars(env, altroot, JNI_FALSE);
 230   /*
 231    * `saaltroot` is used for putenv().
 232    * So we need to keep this memory.
 233    */
 234   static const char *PREFIX = "SA_ALTROOT=";
 235   size_t len = strlen(PREFIX) + strlen(path) + 1;
 236   saaltroot = (char *)malloc(len);
 237   snprintf(saaltroot, len, "%s%s", PREFIX, path);
 238   putenv(saaltroot);
 239   (*env)->ReleaseStringUTFChars(env, altroot, path);
 240 }
 241 
 242 /*
 243  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 244  * Method:    attach0
 245  * Signature: (I)V
 246  */
 247 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
 248   (JNIEnv *env, jobject this_obj, jint jpid) {
 249 
 250   // For bitness checking, locate binary at /proc/jpid/exe
 251   char buf[PATH_MAX];
 252   snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
 253   verifyBitness(env, (char *) &buf);
 254   CHECK_EXCEPTION;
 255 
 256   char err_buf[200];
 257   struct ps_prochandle* ph;
 258   if ((ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) {
 259     char msg[230];
 260     snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
 261     THROW_NEW_DEBUGGER_EXCEPTION(msg);
 262   }
 263   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
 264   fillThreadsAndLoadObjects(env, this_obj, ph);
 265 }
 266 
 267 /*
 268  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
 269  * Method:    attach0
 270  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 271  */
 272 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
 273   (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
 274   const char *execName_cstr;
 275   const char *coreName_cstr;
 276   jboolean isCopy;
 277   struct ps_prochandle* ph;
 278 


< prev index next >