annotate agent/src/os/linux/libproc.h @ 17991:a07a3a29df67

8046408: Build failure from multiple ptrace.h Summary: prefer <sys/ptrace.h> over <linux/ptrace.h> Reviewed-by: sla, mikael Contributed-by: kim.barrett@oracle.com
author jwilhelm
date Fri, 13 Jun 2014 17:07:39 -0400
parents 7f77d17d0f13
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 7994
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
17991
a07a3a29df67 8046408: Build failure from multiple ptrace.h
jwilhelm
parents: 17940
diff changeset
37 #include <sys/ptrace.h>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 /************************************************************************************
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 0. This is very minimal subset of Solaris libproc just enough for current application.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 Please note that the bulk of the functionality is from proc_service interface. This
a61af66fc99e Initial load
duke
parents:
diff changeset
43 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
a61af66fc99e Initial load
duke
parents:
diff changeset
44 file by this interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
a61af66fc99e Initial load
duke
parents:
diff changeset
47 OSThread::_pthread_id in JVM code.
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 2. All threads see the same pid when they call getpid() under NPTL.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 Threads receive different pid under LinuxThreads. We used to save the result of
a61af66fc99e Initial load
duke
parents:
diff changeset
51 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
52 was lost under NPTL. Now, we store the result of ::gettid() call in
a61af66fc99e Initial load
duke
parents:
diff changeset
53 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
a61af66fc99e Initial load
duke
parents:
diff changeset
54 unique again. We therefore use OSThread::_thread_id as unique identifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
57 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
a61af66fc99e Initial load
duke
parents:
diff changeset
58 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
59 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
a61af66fc99e Initial load
duke
parents:
diff changeset
60 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ptrace call, we refer to lwp_id of the thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 5. for core file, we parse ELF files and read data from them. For processes we use
a61af66fc99e Initial load
duke
parents:
diff changeset
66 combination of ptrace and /proc calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 *************************************************************************************/
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70
14391
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 7994
diff changeset
71 #if defined(sparc) || defined(sparcv9) || defined(ppc64)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
72 #define user_regs_struct pt_regs
a61af66fc99e Initial load
duke
parents:
diff changeset
73 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // This C bool type must be int for compatibility with Linux calls and
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // it would be a mistake to equivalence it to C++ bool on many platforms
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 typedef int bool;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 #define true 1
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #define false 0
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 struct ps_prochandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // attach to a process
a61af66fc99e Initial load
duke
parents:
diff changeset
85 struct ps_prochandle* Pgrab(pid_t pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // attach to a core dump
a61af66fc99e Initial load
duke
parents:
diff changeset
88 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // release a process or core
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void Prelease(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // functions not directly available in Solaris libproc
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // initialize libproc (call this only once per app)
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // pass true to make library verbose
a61af66fc99e Initial load
duke
parents:
diff changeset
97 bool init_libproc(bool verbose);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // get number of threads
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int get_num_threads(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // get lwp_id of n'th thread
a61af66fc99e Initial load
duke
parents:
diff changeset
103 lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // get regs for a given lwp
a61af66fc99e Initial load
duke
parents:
diff changeset
106 bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // get number of shared objects
a61af66fc99e Initial load
duke
parents:
diff changeset
109 int get_num_libs(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // get name of n'th lib
a61af66fc99e Initial load
duke
parents:
diff changeset
112 const char* get_lib_name(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // get base of lib
a61af66fc99e Initial load
duke
parents:
diff changeset
115 uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // returns true if given library is found in lib list
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bool find_lib(struct ps_prochandle* ph, const char *lib_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // symbol lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
121 uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,
a61af66fc99e Initial load
duke
parents:
diff changeset
122 const char* sym_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // address->nearest symbol lookup. return NULL for no symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
125 const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
126
6641
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
127 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
128
a9fed06c01d2 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 1552
diff changeset
129 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
130
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 #endif //__LIBPROC_H_