agent/src/os/linux/libproc.h

Wed, 14 Jan 2009 19:45:01 -0800

author
swamyv
date
Wed, 14 Jan 2009 19:45:01 -0800
changeset 964
8db2b3e46c38
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6786948: SA on core file fails on solaris-amd64 if vm started with -XX:+StartAttachListener
Reviewed-by: jjh, dcubed

duke@435 1 /*
duke@435 2 * Copyright 2003-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any 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
duke@435 28 #include <unistd.h>
duke@435 29 #include <stdint.h>
duke@435 30 #include "proc_service.h"
duke@435 31
duke@435 32 #if defined(sparc) || defined(sparcv9)
duke@435 33 /*
duke@435 34 If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64
duke@435 35 otherwise it should be from /usr/include/asm-sparc
duke@435 36 These two files define pt_regs structure differently
duke@435 37 */
duke@435 38 #ifdef _LP64
duke@435 39 #include "asm-sparc64/ptrace.h"
duke@435 40 #else
duke@435 41 #include "asm-sparc/ptrace.h"
duke@435 42 #endif
duke@435 43
duke@435 44 #endif //sparc or sparcv9
duke@435 45
duke@435 46 /************************************************************************************
duke@435 47
duke@435 48 0. This is very minimal subset of Solaris libproc just enough for current application.
duke@435 49 Please note that the bulk of the functionality is from proc_service interface. This
duke@435 50 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
duke@435 51 file by this interface.
duke@435 52
duke@435 53 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
duke@435 54 OSThread::_pthread_id in JVM code.
duke@435 55
duke@435 56 2. All threads see the same pid when they call getpid() under NPTL.
duke@435 57 Threads receive different pid under LinuxThreads. We used to save the result of
duke@435 58 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
duke@435 59 was lost under NPTL. Now, we store the result of ::gettid() call in
duke@435 60 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
duke@435 61 unique again. We therefore use OSThread::_thread_id as unique identifier.
duke@435 62
duke@435 63 3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
duke@435 64 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
duke@435 65 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
duke@435 66 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
duke@435 67 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
duke@435 68
duke@435 69 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
duke@435 70 ptrace call, we refer to lwp_id of the thread.
duke@435 71
duke@435 72 5. for core file, we parse ELF files and read data from them. For processes we use
duke@435 73 combination of ptrace and /proc calls.
duke@435 74
duke@435 75 *************************************************************************************/
duke@435 76
duke@435 77 #ifdef ia64
duke@435 78 struct user_regs_struct {
duke@435 79 /* copied from user.h which doesn't define this in a struct */
duke@435 80
duke@435 81 #define IA64_REG_COUNT (EF_SIZE/8+32) /* integer and fp regs */
duke@435 82 unsigned long regs[IA64_REG_COUNT]; /* integer and fp regs */
duke@435 83 };
duke@435 84 #endif
duke@435 85
duke@435 86 #if defined(sparc) || defined(sparcv9)
duke@435 87 #define user_regs_struct pt_regs
duke@435 88 #endif
duke@435 89
duke@435 90 // This C bool type must be int for compatibility with Linux calls and
duke@435 91 // it would be a mistake to equivalence it to C++ bool on many platforms
duke@435 92
duke@435 93 typedef int bool;
duke@435 94 #define true 1
duke@435 95 #define false 0
duke@435 96
duke@435 97 struct ps_prochandle;
duke@435 98
duke@435 99 // attach to a process
duke@435 100 struct ps_prochandle* Pgrab(pid_t pid);
duke@435 101
duke@435 102 // attach to a core dump
duke@435 103 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
duke@435 104
duke@435 105 // release a process or core
duke@435 106 void Prelease(struct ps_prochandle* ph);
duke@435 107
duke@435 108 // functions not directly available in Solaris libproc
duke@435 109
duke@435 110 // initialize libproc (call this only once per app)
duke@435 111 // pass true to make library verbose
duke@435 112 bool init_libproc(bool verbose);
duke@435 113
duke@435 114 // get number of threads
duke@435 115 int get_num_threads(struct ps_prochandle* ph);
duke@435 116
duke@435 117 // get lwp_id of n'th thread
duke@435 118 lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
duke@435 119
duke@435 120 // get regs for a given lwp
duke@435 121 bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
duke@435 122
duke@435 123 // get number of shared objects
duke@435 124 int get_num_libs(struct ps_prochandle* ph);
duke@435 125
duke@435 126 // get name of n'th lib
duke@435 127 const char* get_lib_name(struct ps_prochandle* ph, int index);
duke@435 128
duke@435 129 // get base of lib
duke@435 130 uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
duke@435 131
duke@435 132 // returns true if given library is found in lib list
duke@435 133 bool find_lib(struct ps_prochandle* ph, const char *lib_name);
duke@435 134
duke@435 135 // symbol lookup
duke@435 136 uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,
duke@435 137 const char* sym_name);
duke@435 138
duke@435 139 // address->nearest symbol lookup. return NULL for no symbol
duke@435 140 const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
duke@435 141
duke@435 142 #endif //__LIBPROC_H_

mercurial