author | duke |
Wed, 05 Jul 2017 19:45:37 +0200 | |
changeset 24908 | 2dcf544eb7ed |
parent 24327 | d8d91481f76e |
child 25072 | 44b2042a8aba |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22234
da823d78ad65
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
15475
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
#ifndef _LIBPROC_H_ |
|
26 |
#define _LIBPROC_H_ |
|
27 |
||
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
28 |
#include <jni.h> |
1 | 29 |
#include <unistd.h> |
30 |
#include <stdint.h> |
|
31 |
#include "proc_service.h" |
|
32 |
||
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
33 |
#if defined(arm) || defined(ppc) |
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
34 |
#include "libproc_md.h" |
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
35 |
#endif |
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
36 |
|
24327 | 37 |
#include <linux/ptrace.h> |
1 | 38 |
|
39 |
/************************************************************************************ |
|
40 |
||
41 |
0. This is very minimal subset of Solaris libproc just enough for current application. |
|
42 |
Please note that the bulk of the functionality is from proc_service interface. This |
|
43 |
adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core |
|
44 |
file by this interface. |
|
45 |
||
46 |
1. pthread_id unique in both NPTL & LinuxThreads. We store this in |
|
47 |
OSThread::_pthread_id in JVM code. |
|
48 |
||
49 |
2. All threads see the same pid when they call getpid() under NPTL. |
|
50 |
Threads receive different pid under LinuxThreads. We used to save the result of |
|
51 |
::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id |
|
52 |
was lost under NPTL. Now, we store the result of ::gettid() call in |
|
53 |
OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is |
|
54 |
unique again. We therefore use OSThread::_thread_id as unique identifier. |
|
55 |
||
56 |
3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id |
|
57 |
to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores |
|
58 |
lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But |
|
59 |
unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id |
|
60 |
only for processes. For core dumps, we don't use libthread_db at all (like gdb). |
|
61 |
||
62 |
4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for |
|
63 |
ptrace call, we refer to lwp_id of the thread. |
|
64 |
||
65 |
5. for core file, we parse ELF files and read data from them. For processes we use |
|
66 |
combination of ptrace and /proc calls. |
|
67 |
||
68 |
*************************************************************************************/ |
|
69 |
||
70 |
||
22807 | 71 |
#if defined(sparc) || defined(sparcv9) || defined(ppc64) |
1 | 72 |
#define user_regs_struct pt_regs |
73 |
#endif |
|
74 |
||
75 |
// This C bool type must be int for compatibility with Linux calls and |
|
76 |
// it would be a mistake to equivalence it to C++ bool on many platforms |
|
77 |
||
78 |
typedef int bool; |
|
79 |
#define true 1 |
|
80 |
#define false 0 |
|
81 |
||
82 |
struct ps_prochandle; |
|
83 |
||
84 |
// attach to a process |
|
85 |
struct ps_prochandle* Pgrab(pid_t pid); |
|
86 |
||
87 |
// attach to a core dump |
|
88 |
struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile); |
|
89 |
||
90 |
// release a process or core |
|
91 |
void Prelease(struct ps_prochandle* ph); |
|
92 |
||
93 |
// functions not directly available in Solaris libproc |
|
94 |
||
95 |
// initialize libproc (call this only once per app) |
|
96 |
// pass true to make library verbose |
|
97 |
bool init_libproc(bool verbose); |
|
98 |
||
99 |
// get number of threads |
|
100 |
int get_num_threads(struct ps_prochandle* ph); |
|
101 |
||
102 |
// get lwp_id of n'th thread |
|
103 |
lwpid_t get_lwp_id(struct ps_prochandle* ph, int index); |
|
104 |
||
105 |
// get regs for a given lwp |
|
106 |
bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs); |
|
107 |
||
108 |
// get number of shared objects |
|
109 |
int get_num_libs(struct ps_prochandle* ph); |
|
110 |
||
111 |
// get name of n'th lib |
|
112 |
const char* get_lib_name(struct ps_prochandle* ph, int index); |
|
113 |
||
114 |
// get base of lib |
|
115 |
uintptr_t get_lib_base(struct ps_prochandle* ph, int index); |
|
116 |
||
117 |
// returns true if given library is found in lib list |
|
118 |
bool find_lib(struct ps_prochandle* ph, const char *lib_name); |
|
119 |
||
120 |
// symbol lookup |
|
121 |
uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name, |
|
122 |
const char* sym_name); |
|
123 |
||
124 |
// address->nearest symbol lookup. return NULL for no symbol |
|
125 |
const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset); |
|
126 |
||
13529
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
127 |
struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj); |
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
128 |
|
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
129 |
void throw_new_debugger_exception(JNIEnv* env, const char* errMsg); |
dc25e69fd16d
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
5547
diff
changeset
|
130 |
|
1 | 131 |
#endif //__LIBPROC_H_ |