< prev index next >
src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -64,10 +64,16 @@
static jmethodID createClosestSymbol_ID = 0;
static jmethodID createLoadObject_ID = 0;
static jmethodID getThreadForThreadId_ID = 0;
static jmethodID listAdd_ID = 0;
+/*
+ * SA_ALTROOT environment variable.
+ * This memory holds env string for putenv(3).
+ */
+static char *saaltroot = NULL;
+
#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
@@ -209,25 +215,48 @@
}
/*
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
+ * Method: setSAAltRoot0
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_setSAAltRoot0
+ (JNIEnv *env, jobject this_obj, jstring altroot) {
+ if (saaltroot != NULL) {
+ free(saaltroot);
+ }
+ const char *path = (*env)->GetStringUTFChars(env, altroot, JNI_FALSE);
+ /*
+ * `saaltroot` is used for putenv().
+ * So we need to keep this memory.
+ */
+ static const char *PREFIX = "SA_ALTROOT=";
+ size_t len = strlen(PREFIX) + strlen(path) + 1;
+ saaltroot = (char *)malloc(len);
+ snprintf(saaltroot, len, "%s%s", PREFIX, path);
+ putenv(saaltroot);
+ (*env)->ReleaseStringUTFChars(env, altroot, path);
+}
+
+/*
+ * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
* Method: attach0
- * Signature: (I)V
+ * Signature: (IZ)V
*/
-JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I
- (JNIEnv *env, jobject this_obj, jint jpid) {
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__IZ
+ (JNIEnv *env, jobject this_obj, jint jpid, jboolean is_in_container) {
// For bitness checking, locate binary at /proc/jpid/exe
char buf[PATH_MAX];
snprintf((char *) &buf, PATH_MAX, "/proc/%d/exe", jpid);
verifyBitness(env, (char *) &buf);
CHECK_EXCEPTION;
char err_buf[200];
struct ps_prochandle* ph;
- if ( (ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) {
+ if ((ph = Pgrab(jpid, err_buf, sizeof(err_buf), is_in_container)) == NULL) {
char msg[230];
snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf);
THROW_NEW_DEBUGGER_EXCEPTION(msg);
}
(*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
@@ -274,10 +303,14 @@
(JNIEnv *env, jobject this_obj) {
struct ps_prochandle* ph = get_proc_handle(env, this_obj);
if (ph != NULL) {
Prelease(ph);
}
+ if (saaltroot != NULL) {
+ free(saaltroot);
+ saaltroot = NULL;
+ }
}
/*
* Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal
* Method: lookupByName0
< prev index next >