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

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

mercurial