< prev index next >

agent/src/os/solaris/proc/saproc.cpp

Print this page


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


 738 #ifndef _LP64
 739   atoi(cmdLine_cstr);
 740   if (errno) {
 741      // core file
 742      int core_fd;
 743      if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) {
 744         Elf32_Ehdr e32;
 745         if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) &&
 746             memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 &&
 747             e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) {
 748               close(core_fd);
 749               THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger");
 750         }
 751         close(core_fd);
 752      }
 753      // all other conditions are handled by libproc.so.
 754   }
 755 #endif
 756 
 757   // connect to process/core
 758   struct ps_prochandle* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode);

 759   env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
 760   if (! ph) {
 761      if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) {
 762         char errMsg[ERR_MSG_SIZE];
 763         sprintf(errMsg, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]);
 764         THROW_NEW_DEBUGGER_EXCEPTION(errMsg);
 765     } else {
 766         if (_libsaproc_debug && gcode == G_STRANGE) {
 767            perror("libsaproc DEBUG: ");
 768         }
 769         if (isProcess) {
 770            THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to process!");
 771         } else {
 772            THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to core file!");
 773         }
 774      }
 775   }
 776 
 777   // even though libproc.so supports 64 bit debugger and 32 bit debuggee, we don't
 778   // support such cross-bit-debugging. check for that combination and throw error.


1216      env->ReleaseStringUTFChars(objectName, objectName_cstr);
1217    }
1218    env->ReleaseStringUTFChars(symbolName, symbolName_cstr);
1219    return (jlong) (uintptr_t) symbol_addr;
1220 }
1221 
1222 /*
1223  * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
1224  * Method:      lookupByAddress0
1225  * Signature:   (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
1226  * Description: lookup symbol name for a given address
1227  */
1228 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByAddress0
1229    (JNIEnv *env, jobject this_obj, jlong address) {
1230    jlong p_ps_prochandle;
1231    p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
1232 
1233    char nameBuf[SYMBOL_BUF_SIZE + 1];
1234    GElf_Sym sym;
1235    int res = Plookup_by_addr((struct ps_prochandle*) p_ps_prochandle, (uintptr_t) address,
1236                                  nameBuf, sizeof(nameBuf), &sym);

1237    if (res != 0) { // failed
1238       return 0;
1239    }
1240 
1241    jstring resSym = env->NewStringUTF(nameBuf);
1242    CHECK_EXCEPTION_(0);
1243 
1244    return env->CallObjectMethod(this_obj, createClosestSymbol_ID, resSym, (address - sym.st_value));
1245 }
1246 
1247 /*
1248  * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
1249  * Method:    demangle0
1250  * Signature: (Ljava/lang/String;)Ljava/lang/String;
1251  */
1252 JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_demangle0
1253   (JNIEnv *env, jobject this_object, jstring name) {
1254   jboolean isCopy;
1255   const char* ptr = env->GetStringUTFChars(name, &isCopy);
1256   char  buf[2*SYMBOL_BUF_SIZE + 1];


   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  *


 738 #ifndef _LP64
 739   atoi(cmdLine_cstr);
 740   if (errno) {
 741      // core file
 742      int core_fd;
 743      if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) {
 744         Elf32_Ehdr e32;
 745         if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) &&
 746             memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 &&
 747             e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) {
 748               close(core_fd);
 749               THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger");
 750         }
 751         close(core_fd);
 752      }
 753      // all other conditions are handled by libproc.so.
 754   }
 755 #endif
 756 
 757   // connect to process/core
 758   ps_prochandle_t* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode, NULL);
 759 
 760   env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
 761   if (! ph) {
 762      if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) {
 763         char errMsg[ERR_MSG_SIZE];
 764         sprintf(errMsg, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]);
 765         THROW_NEW_DEBUGGER_EXCEPTION(errMsg);
 766     } else {
 767         if (_libsaproc_debug && gcode == G_STRANGE) {
 768            perror("libsaproc DEBUG: ");
 769         }
 770         if (isProcess) {
 771            THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to process!");
 772         } else {
 773            THROW_NEW_DEBUGGER_EXCEPTION("Not able to attach to core file!");
 774         }
 775      }
 776   }
 777 
 778   // even though libproc.so supports 64 bit debugger and 32 bit debuggee, we don't
 779   // support such cross-bit-debugging. check for that combination and throw error.


1217      env->ReleaseStringUTFChars(objectName, objectName_cstr);
1218    }
1219    env->ReleaseStringUTFChars(symbolName, symbolName_cstr);
1220    return (jlong) (uintptr_t) symbol_addr;
1221 }
1222 
1223 /*
1224  * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
1225  * Method:      lookupByAddress0
1226  * Signature:   (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
1227  * Description: lookup symbol name for a given address
1228  */
1229 JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_lookupByAddress0
1230    (JNIEnv *env, jobject this_obj, jlong address) {
1231    jlong p_ps_prochandle;
1232    p_ps_prochandle = env->GetLongField(this_obj, p_ps_prochandle_ID);
1233 
1234    char nameBuf[SYMBOL_BUF_SIZE + 1];
1235    GElf_Sym sym;
1236    int res = Plookup_by_addr((struct ps_prochandle*) p_ps_prochandle, (uintptr_t) address,
1237                              nameBuf, sizeof(nameBuf), &sym, NULL);
1238 
1239    if (res != 0) { // failed
1240       return 0;
1241    }
1242 
1243    jstring resSym = env->NewStringUTF(nameBuf);
1244    CHECK_EXCEPTION_(0);
1245 
1246    return env->CallObjectMethod(this_obj, createClosestSymbol_ID, resSym, (address - sym.st_value));
1247 }
1248 
1249 /*
1250  * Class:     sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
1251  * Method:    demangle0
1252  * Signature: (Ljava/lang/String;)Ljava/lang/String;
1253  */
1254 JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_demangle0
1255   (JNIEnv *env, jobject this_object, jstring name) {
1256   jboolean isCopy;
1257   const char* ptr = env->GetStringUTFChars(name, &isCopy);
1258   char  buf[2*SYMBOL_BUF_SIZE + 1];


< prev index next >