src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.c
changeset 53379 e47074d2d8cc
parent 51203 220c9188db4f
child 55069 6e0786d8451b
equal deleted inserted replaced
53378:52abdb8a48b2 53379:e47074d2d8cc
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include <jni.h>
    25 #include <jni.h>
    26 #include "libproc.h"
    26 #include "libproc.h"
       
    27 #include "proc_service.h"
    27 
    28 
    28 #include <elf.h>
    29 #include <elf.h>
    29 #include <sys/types.h>
    30 #include <sys/types.h>
    30 #include <sys/stat.h>
    31 #include <sys/stat.h>
    31 #include <fcntl.h>
    32 #include <fcntl.h>
   239 }
   240 }
   240 
   241 
   241 /*
   242 /*
   242  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
   243  * Class:     sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
   243  * Method:    attach0
   244  * Method:    attach0
   244  * Signature: (IZ)V
   245  * Signature: (I)V
   245  */
   246  */
   246 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__IZ
   247 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
   247   (JNIEnv *env, jobject this_obj, jint jpid, jboolean is_in_container) {
   248   (JNIEnv *env, jobject this_obj, jint jpid) {
   248 
   249 
   249   // For bitness checking, locate binary at /proc/jpid/exe
   250   // For bitness checking, locate binary at /proc/jpid/exe
   250   char buf[PATH_MAX];
   251   char buf[PATH_MAX];
   251   snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
   252   snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
   252   verifyBitness(env, (char *) &buf);
   253   verifyBitness(env, (char *) &buf);
   253   CHECK_EXCEPTION;
   254   CHECK_EXCEPTION;
   254 
   255 
   255   char err_buf[200];
   256   char err_buf[200];
   256   struct ps_prochandle* ph;
   257   struct ps_prochandle* ph;
   257   if ((ph = Pgrab(jpid, err_buf, sizeof(err_buf), is_in_container)) == NULL) {
   258   if ((ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) {
   258     char msg[230];
   259     char msg[230];
   259     snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
   260     snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
   260     THROW_NEW_DEBUGGER_EXCEPTION(msg);
   261     THROW_NEW_DEBUGGER_EXCEPTION(msg);
   261   }
   262   }
   262   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
   263   (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);