annotate agent/src/os/linux/libproc.h @ 17524:89152779163c

Merge with jdk8-b132
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 11:59:32 +0200
parents 4ca6dc0799b6
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17524
89152779163c Merge with jdk8-b132
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14909
diff changeset
2 * Copyright (c) 2003, 2013, 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
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
28 #include <jni.h>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #include <unistd.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #include <stdint.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include "proc_service.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
32
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
33 #if defined(arm) || defined(ppc)
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
34 #include "libproc_md.h"
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
35 #endif
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
36
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #if defined(sparc) || defined(sparcv9)
a61af66fc99e Initial load
duke
parents:
diff changeset
38 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
39 If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64
a61af66fc99e Initial load
duke
parents:
diff changeset
40 otherwise it should be from /usr/include/asm-sparc
a61af66fc99e Initial load
duke
parents:
diff changeset
41 These two files define pt_regs structure differently
a61af66fc99e Initial load
duke
parents:
diff changeset
42 */
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #include "asm-sparc64/ptrace.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
45 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #include "asm-sparc/ptrace.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
47 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #endif //sparc or sparcv9
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 /************************************************************************************
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 0. This is very minimal subset of Solaris libproc just enough for current application.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Please note that the bulk of the functionality is from proc_service interface. This
a61af66fc99e Initial load
duke
parents:
diff changeset
55 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
a61af66fc99e Initial load
duke
parents:
diff changeset
56 file by this interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
a61af66fc99e Initial load
duke
parents:
diff changeset
59 OSThread::_pthread_id in JVM code.
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 2. All threads see the same pid when they call getpid() under NPTL.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 Threads receive different pid under LinuxThreads. We used to save the result of
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
64 was lost under NPTL. Now, we store the result of ::gettid() call in
a61af66fc99e Initial load
duke
parents:
diff changeset
65 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
a61af66fc99e Initial load
duke
parents:
diff changeset
66 unique again. We therefore use OSThread::_thread_id as unique identifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
69 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
a61af66fc99e Initial load
duke
parents:
diff changeset
70 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
71 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
72 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
a61af66fc99e Initial load
duke
parents:
diff changeset
75 ptrace call, we refer to lwp_id of the thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 5. for core file, we parse ELF files and read data from them. For processes we use
a61af66fc99e Initial load
duke
parents:
diff changeset
78 combination of ptrace and /proc calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 *************************************************************************************/
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82
14909
4ca6dc0799b6 Backout jdk9 merge
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14456
diff changeset
83 #if defined(sparc) || defined(sparcv9)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #define user_regs_struct pt_regs
a61af66fc99e Initial load
duke
parents:
diff changeset
85 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // This C bool type must be int for compatibility with Linux calls and
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // it would be a mistake to equivalence it to C++ bool on many platforms
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 typedef int bool;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 #define true 1
a61af66fc99e Initial load
duke
parents:
diff changeset
92 #define false 0
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 struct ps_prochandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // attach to a process
a61af66fc99e Initial load
duke
parents:
diff changeset
97 struct ps_prochandle* Pgrab(pid_t pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // attach to a core dump
a61af66fc99e Initial load
duke
parents:
diff changeset
100 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // release a process or core
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void Prelease(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // functions not directly available in Solaris libproc
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // initialize libproc (call this only once per app)
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // pass true to make library verbose
a61af66fc99e Initial load
duke
parents:
diff changeset
109 bool init_libproc(bool verbose);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // get number of threads
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int get_num_threads(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // get lwp_id of n'th thread
a61af66fc99e Initial load
duke
parents:
diff changeset
115 lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // get regs for a given lwp
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // get number of shared objects
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int get_num_libs(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // get name of n'th lib
a61af66fc99e Initial load
duke
parents:
diff changeset
124 const char* get_lib_name(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // get base of lib
a61af66fc99e Initial load
duke
parents:
diff changeset
127 uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // returns true if given library is found in lib list
a61af66fc99e Initial load
duke
parents:
diff changeset
130 bool find_lib(struct ps_prochandle* ph, const char *lib_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // symbol lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
133 uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,
a61af66fc99e Initial load
duke
parents:
diff changeset
134 const char* sym_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // address->nearest symbol lookup. return NULL for no symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
137 const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
139 struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj);
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
140
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
141 void throw_new_debugger_exception(JNIEnv* env, const char* errMsg);
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
142
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 #endif //__LIBPROC_H_