Thu, 30 Aug 2012 11:20:01 -0400
7154641: Servicability agent should work on platforms other than x86, sparc
Summary: Added capability to load support classes for other cpus
Reviewed-by: coleenp, bobv, sla
Contributed-by: Bill Pittore <bill.pittore@oracle.com>
duke@435 | 1 | /* |
bpittore@4028 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #ifndef _LIBPROC_H_ |
duke@435 | 26 | #define _LIBPROC_H_ |
duke@435 | 27 | |
bpittore@4028 | 28 | #include <jni.h> |
duke@435 | 29 | #include <unistd.h> |
duke@435 | 30 | #include <stdint.h> |
duke@435 | 31 | #include "proc_service.h" |
duke@435 | 32 | |
bpittore@4028 | 33 | #if defined(arm) || defined(ppc) |
bpittore@4028 | 34 | #include "libproc_md.h" |
bpittore@4028 | 35 | #endif |
bpittore@4028 | 36 | |
duke@435 | 37 | #if defined(sparc) || defined(sparcv9) |
duke@435 | 38 | /* |
duke@435 | 39 | If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64 |
duke@435 | 40 | otherwise it should be from /usr/include/asm-sparc |
duke@435 | 41 | These two files define pt_regs structure differently |
duke@435 | 42 | */ |
duke@435 | 43 | #ifdef _LP64 |
duke@435 | 44 | #include "asm-sparc64/ptrace.h" |
duke@435 | 45 | #else |
duke@435 | 46 | #include "asm-sparc/ptrace.h" |
duke@435 | 47 | #endif |
duke@435 | 48 | |
duke@435 | 49 | #endif //sparc or sparcv9 |
duke@435 | 50 | |
duke@435 | 51 | /************************************************************************************ |
duke@435 | 52 | |
duke@435 | 53 | 0. This is very minimal subset of Solaris libproc just enough for current application. |
duke@435 | 54 | Please note that the bulk of the functionality is from proc_service interface. This |
duke@435 | 55 | adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core |
duke@435 | 56 | file by this interface. |
duke@435 | 57 | |
duke@435 | 58 | 1. pthread_id unique in both NPTL & LinuxThreads. We store this in |
duke@435 | 59 | OSThread::_pthread_id in JVM code. |
duke@435 | 60 | |
duke@435 | 61 | 2. All threads see the same pid when they call getpid() under NPTL. |
duke@435 | 62 | Threads receive different pid under LinuxThreads. We used to save the result of |
duke@435 | 63 | ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id |
duke@435 | 64 | was lost under NPTL. Now, we store the result of ::gettid() call in |
duke@435 | 65 | OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is |
duke@435 | 66 | unique again. We therefore use OSThread::_thread_id as unique identifier. |
duke@435 | 67 | |
duke@435 | 68 | 3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id |
duke@435 | 69 | to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores |
duke@435 | 70 | lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But |
duke@435 | 71 | unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id |
duke@435 | 72 | only for processes. For core dumps, we don't use libthread_db at all (like gdb). |
duke@435 | 73 | |
duke@435 | 74 | 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for |
duke@435 | 75 | ptrace call, we refer to lwp_id of the thread. |
duke@435 | 76 | |
duke@435 | 77 | 5. for core file, we parse ELF files and read data from them. For processes we use |
duke@435 | 78 | combination of ptrace and /proc calls. |
duke@435 | 79 | |
duke@435 | 80 | *************************************************************************************/ |
duke@435 | 81 | |
duke@435 | 82 | #ifdef ia64 |
duke@435 | 83 | struct user_regs_struct { |
duke@435 | 84 | /* copied from user.h which doesn't define this in a struct */ |
duke@435 | 85 | |
duke@435 | 86 | #define IA64_REG_COUNT (EF_SIZE/8+32) /* integer and fp regs */ |
duke@435 | 87 | unsigned long regs[IA64_REG_COUNT]; /* integer and fp regs */ |
duke@435 | 88 | }; |
duke@435 | 89 | #endif |
duke@435 | 90 | |
duke@435 | 91 | #if defined(sparc) || defined(sparcv9) |
duke@435 | 92 | #define user_regs_struct pt_regs |
duke@435 | 93 | #endif |
duke@435 | 94 | |
duke@435 | 95 | // This C bool type must be int for compatibility with Linux calls and |
duke@435 | 96 | // it would be a mistake to equivalence it to C++ bool on many platforms |
duke@435 | 97 | |
duke@435 | 98 | typedef int bool; |
duke@435 | 99 | #define true 1 |
duke@435 | 100 | #define false 0 |
duke@435 | 101 | |
duke@435 | 102 | struct ps_prochandle; |
duke@435 | 103 | |
duke@435 | 104 | // attach to a process |
duke@435 | 105 | struct ps_prochandle* Pgrab(pid_t pid); |
duke@435 | 106 | |
duke@435 | 107 | // attach to a core dump |
duke@435 | 108 | struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile); |
duke@435 | 109 | |
duke@435 | 110 | // release a process or core |
duke@435 | 111 | void Prelease(struct ps_prochandle* ph); |
duke@435 | 112 | |
duke@435 | 113 | // functions not directly available in Solaris libproc |
duke@435 | 114 | |
duke@435 | 115 | // initialize libproc (call this only once per app) |
duke@435 | 116 | // pass true to make library verbose |
duke@435 | 117 | bool init_libproc(bool verbose); |
duke@435 | 118 | |
duke@435 | 119 | // get number of threads |
duke@435 | 120 | int get_num_threads(struct ps_prochandle* ph); |
duke@435 | 121 | |
duke@435 | 122 | // get lwp_id of n'th thread |
duke@435 | 123 | lwpid_t get_lwp_id(struct ps_prochandle* ph, int index); |
duke@435 | 124 | |
duke@435 | 125 | // get regs for a given lwp |
duke@435 | 126 | bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs); |
duke@435 | 127 | |
duke@435 | 128 | // get number of shared objects |
duke@435 | 129 | int get_num_libs(struct ps_prochandle* ph); |
duke@435 | 130 | |
duke@435 | 131 | // get name of n'th lib |
duke@435 | 132 | const char* get_lib_name(struct ps_prochandle* ph, int index); |
duke@435 | 133 | |
duke@435 | 134 | // get base of lib |
duke@435 | 135 | uintptr_t get_lib_base(struct ps_prochandle* ph, int index); |
duke@435 | 136 | |
duke@435 | 137 | // returns true if given library is found in lib list |
duke@435 | 138 | bool find_lib(struct ps_prochandle* ph, const char *lib_name); |
duke@435 | 139 | |
duke@435 | 140 | // symbol lookup |
duke@435 | 141 | uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name, |
duke@435 | 142 | const char* sym_name); |
duke@435 | 143 | |
duke@435 | 144 | // address->nearest symbol lookup. return NULL for no symbol |
duke@435 | 145 | const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset); |
duke@435 | 146 | |
bpittore@4028 | 147 | struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj); |
bpittore@4028 | 148 | |
bpittore@4028 | 149 | void throw_new_debugger_exception(JNIEnv* env, const char* errMsg); |
bpittore@4028 | 150 | |
duke@435 | 151 | #endif //__LIBPROC_H_ |