src/jdk.hotspot.agent/solaris/native/libsaproc/saproc.cpp
changeset 58173 6a30ad1cfeec
parent 51477 e77d7687c831
child 59070 22ee476cc664
equal deleted inserted replaced
58149:00aebe177a71 58173:6a30ad1cfeec
     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.
   690   int gcode;
   690   int gcode;
   691   const char* cmdLine_cstr = env->GetStringUTFChars(cmdLine, &isCopy);
   691   const char* cmdLine_cstr = env->GetStringUTFChars(cmdLine, &isCopy);
   692   char errMsg[ERR_MSG_SIZE];
   692   char errMsg[ERR_MSG_SIZE];
   693   td_err_e te;
   693   td_err_e te;
   694   CHECK_EXCEPTION;
   694   CHECK_EXCEPTION;
       
   695   if (cmdLine_cstr == NULL) {
       
   696     return;
       
   697   }
   695 
   698 
   696   // some older versions of libproc.so crash when trying to attach 32 bit
   699   // some older versions of libproc.so crash when trying to attach 32 bit
   697   // debugger to 64 bit core file. check and throw error.
   700   // debugger to 64 bit core file. check and throw error.
   698 #ifndef _LP64
   701 #ifndef _LP64
   699   atoi(cmdLine_cstr);
   702   errno = 0;
       
   703   strtol(cmdLine_cstr, NULL, 10);
   700   if (errno) {
   704   if (errno) {
   701      // core file
   705      // core file
   702      int core_fd;
   706      int core_fd;
   703      if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) {
   707      if ((core_fd = open64(cmdLine_cstr, O_RDONLY)) >= 0) {
   704         Elf32_Ehdr e32;
   708         Elf32_Ehdr e32;
   705         if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) &&
   709         if (pread64(core_fd, &e32, sizeof (e32), 0) == sizeof (e32) &&
   706             memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 &&
   710             memcmp(&e32.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0 &&
   707             e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) {
   711             e32.e_type == ET_CORE && e32.e_ident[EI_CLASS] == ELFCLASS64) {
   708               close(core_fd);
   712               close(core_fd);
       
   713               env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
   709               THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger");
   714               THROW_NEW_DEBUGGER_EXCEPTION("debuggee is 64 bit, use java -d64 for debugger");
   710         }
   715         }
   711         close(core_fd);
   716         close(core_fd);
   712      }
   717      }
   713      // all other conditions are handled by libproc.so.
   718      // all other conditions are handled by libproc.so.
   716 
   721 
   717   // connect to process/core
   722   // connect to process/core
   718   ps_prochandle_t* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode, NULL);
   723   ps_prochandle_t* ph = proc_arg_grab(cmdLine_cstr, (isProcess? PR_ARG_PIDS : PR_ARG_CORES), PGRAB_FORCE, &gcode, NULL);
   719 
   724 
   720   env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
   725   env->ReleaseStringUTFChars(cmdLine, cmdLine_cstr);
       
   726 
   721   if (! ph) {
   727   if (! ph) {
   722      if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) {
   728      if (gcode > 0 && gcode < sizeof(proc_arg_grab_errmsgs)/sizeof(const char*)) {
   723         snprintf(errMsg, ERR_MSG_SIZE, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]);
   729         snprintf(errMsg, ERR_MSG_SIZE, "Attach failed : %s", proc_arg_grab_errmsgs[gcode]);
   724         THROW_NEW_DEBUGGER_EXCEPTION(errMsg);
   730         THROW_NEW_DEBUGGER_EXCEPTION(errMsg);
   725     } else {
   731     } else {