agent/src/os/solaris/proc/saproc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File sadis Sdiff agent/src/os/solaris/proc

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

Print this page




   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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 #include "salibproc.h"
  26 #include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h"

  27 #include <thread_db.h>
  28 #include <strings.h>
  29 #include <limits.h>
  30 #include <demangle.h>
  31 #include <stdarg.h>
  32 #include <stdlib.h>
  33 #include <errno.h>
  34 
  35 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
  36 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
  37 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; }
  38 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;}
  39 
  40 #define SYMBOL_BUF_SIZE  256
  41 #define ERR_MSG_SIZE     (PATH_MAX + 256)
  42 
  43 // debug mode
  44 static int _libsaproc_debug = 0;
  45 
  46 static void print_debug(const char* format,...) {


1280   createSenderFrame_ID = env->GetMethodID(clazz,
1281                             "createSenderFrame", "(Lsun/jvm/hotspot/debugger/proc/ProcCFrame;JJ)Lsun/jvm/hotspot/debugger/proc/ProcCFrame;");
1282   CHECK_EXCEPTION;
1283 
1284   createLoadObject_ID = env->GetMethodID(clazz,
1285                             "createLoadObject", "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
1286   CHECK_EXCEPTION;
1287 
1288   createClosestSymbol_ID = env->GetMethodID(clazz,
1289                             "createClosestSymbol", "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
1290   CHECK_EXCEPTION;
1291 
1292   listAdd_ID = env->GetMethodID(env->FindClass("java/util/List"), "add", "(Ljava/lang/Object;)Z");
1293   CHECK_EXCEPTION;
1294 
1295   // part of the class sharing workaround
1296   classes_jsa_fd_ID = env->GetFieldID(clazz, "classes_jsa_fd", "I");
1297   CHECK_EXCEPTION;
1298   p_file_map_header_ID = env->GetFieldID(clazz, "p_file_map_header", "J");
1299   CHECK_EXCEPTION;




























































































































1300 }


   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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 #include "salibproc.h"
  26 #include "sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h"
  27 #include "sun_jvm_hotspot_asm_Disassembler.h"
  28 #include <thread_db.h>
  29 #include <strings.h>
  30 #include <limits.h>
  31 #include <demangle.h>
  32 #include <stdarg.h>
  33 #include <stdlib.h>
  34 #include <errno.h>
  35 
  36 #define CHECK_EXCEPTION_(value) if(env->ExceptionOccurred()) { return value; }
  37 #define CHECK_EXCEPTION if(env->ExceptionOccurred()) { return;}
  38 #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throwNewDebuggerException(env, str); return value; }
  39 #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throwNewDebuggerException(env, str); return;}
  40 
  41 #define SYMBOL_BUF_SIZE  256
  42 #define ERR_MSG_SIZE     (PATH_MAX + 256)
  43 
  44 // debug mode
  45 static int _libsaproc_debug = 0;
  46 
  47 static void print_debug(const char* format,...) {


1281   createSenderFrame_ID = env->GetMethodID(clazz,
1282                             "createSenderFrame", "(Lsun/jvm/hotspot/debugger/proc/ProcCFrame;JJ)Lsun/jvm/hotspot/debugger/proc/ProcCFrame;");
1283   CHECK_EXCEPTION;
1284 
1285   createLoadObject_ID = env->GetMethodID(clazz,
1286                             "createLoadObject", "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
1287   CHECK_EXCEPTION;
1288 
1289   createClosestSymbol_ID = env->GetMethodID(clazz,
1290                             "createClosestSymbol", "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
1291   CHECK_EXCEPTION;
1292 
1293   listAdd_ID = env->GetMethodID(env->FindClass("java/util/List"), "add", "(Ljava/lang/Object;)Z");
1294   CHECK_EXCEPTION;
1295 
1296   // part of the class sharing workaround
1297   classes_jsa_fd_ID = env->GetFieldID(clazz, "classes_jsa_fd", "I");
1298   CHECK_EXCEPTION;
1299   p_file_map_header_ID = env->GetFieldID(clazz, "p_file_map_header", "J");
1300   CHECK_EXCEPTION;
1301 }
1302 
1303 
1304 /*
1305  * Class:     sun_jvm_hotspot_asm_Disassembler
1306  * Method:    load_library
1307  * Signature: (Ljava/lang/String;)L
1308  */
1309 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIEnv * env,
1310                                                                            jclass disclass,
1311                                                                            jstring libname_s) {
1312   jboolean isCopy;
1313   const char * libname = env->GetStringUTFChars(libname_s, &isCopy);
1314   char buffer[PATH_MAX+1];
1315   snprintf(buffer, PATH_MAX, "%s.so", libname);
1316   void* hsdis_handle = dlopen(buffer, RTLD_LAZY | RTLD_GLOBAL);
1317   if (hsdis_handle != NULL) {
1318     return (jlong)dlsym(hsdis_handle, "decode_instructions_virtual");
1319   }
1320   return 0;
1321 }
1322 
1323 struct decode_env {
1324   JNIEnv* env;
1325   jobject dis;
1326   jobject visitor;
1327   jmethodID handle_event;
1328   jmethodID raw_print;
1329   char buffer[4096];
1330 };
1331 
1332 typedef void* (*decode_func)(void* start_va,
1333                              void* start, void* end,
1334                              void* (*event_callback)(void*, const char*, void*),
1335                              void* event_stream,
1336                              int (*printf_callback)(void*, const char*, ...),
1337                              void* printf_stream,
1338                              const char* options);
1339 
1340 static void* event_to_env(void* env_pv, const char* event, void* arg) {
1341   decode_env* denv = (decode_env*)env_pv;
1342   JNIEnv* env = denv->env;
1343   jstring event_string = env->NewStringUTF(event);
1344   jlong result = env->CallLongMethod(denv->dis, denv->handle_event, denv->visitor, event_string, (jlong) arg);
1345   jthrowable exception = env->ExceptionOccurred();
1346   if (exception) {
1347     env->ExceptionClear();
1348     result = 0;
1349   }
1350   return (void*)result;
1351 }
1352 
1353 static int printf_to_env(void* env_pv, const char* format, ...) {
1354   decode_env* denv = (decode_env*)env_pv;
1355   JNIEnv* env = denv->env;
1356   size_t flen = strlen(format);
1357   const char* raw = NULL;
1358   if (flen == 0)  return 0;
1359   if (flen < 2 ||
1360       strchr(format, '%') == NULL) {
1361     raw = format;
1362   } else if (format[0] == '%' && format[1] == '%' &&
1363              strchr(format+2, '%') == NULL) {
1364     // happens a lot on machines with names like %foo
1365     flen--;
1366     raw = format+1;
1367   }
1368   if (raw != NULL) {
1369     jstring output = env->NewStringUTF(raw);
1370     env->CallVoidMethod(denv->dis, denv->raw_print, denv->visitor, output);
1371     jthrowable exception = env->ExceptionOccurred();
1372     if (exception) {
1373       env->ExceptionClear();
1374     }
1375     return (int) flen;
1376   }
1377   va_list ap;
1378   va_start(ap, format);
1379   int cnt = vsnprintf(denv->buffer, sizeof(denv->buffer), format, ap);
1380   va_end(ap);
1381 
1382   jstring output = env->NewStringUTF(denv->buffer);
1383   env->CallVoidMethod(denv->dis, denv->raw_print, denv->visitor, output);
1384   jthrowable exception = env->ExceptionOccurred();
1385   if (exception) {
1386     env->ExceptionClear();
1387   }
1388   return cnt;
1389 }
1390 
1391 
1392 /*
1393  * Class:     sun_jvm_hotspot_asm_Disassembler
1394  * Method:    decode
1395  * Signature: (Lsun/jvm/hotspot/asm/InstructionVisitor;J[BLjava/lang/String;J)V
1396  */
1397 JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env,
1398                                                                     jobject dis,
1399                                                                     jobject visitor,
1400                                                                     jlong startPc,
1401                                                                     jbyteArray code,
1402                                                                     jstring options_s,
1403                                                                     jlong decode_instructions_virtual) {
1404   jboolean isCopy;
1405   jbyte* start = env->GetByteArrayElements(code, &isCopy);
1406   jbyte* end = start + env->GetArrayLength(code);
1407   const char * options = env->GetStringUTFChars(options_s, &isCopy);
1408 
1409   decode_env denv;
1410   denv.env = env;
1411   denv.dis = dis;
1412   denv.visitor = visitor;
1413   jclass disclass = env->GetObjectClass(dis);
1414   denv.handle_event = env->GetMethodID(disclass, "handle_event", "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;J)J");
1415   CHECK_EXCEPTION;
1416 
1417   denv.raw_print = env->GetMethodID(disclass, "raw_print", "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;)V");
1418   CHECK_EXCEPTION;
1419 
1420   
1421   (*(decode_func)decode_instructions_virtual)((void*)startPc, start, end,
1422                                               &event_to_env,  (void*) &denv,
1423                                               &printf_to_env, (void*) &denv,
1424                                               options);
1425 }
agent/src/os/solaris/proc/saproc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File