annotate agent/src/os/linux/libproc.h @ 3237:399aa66d375e

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