Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef _LIBPROC_H_
32 #define _LIBPROC_H_
34 #include <jni.h>
35 #include <unistd.h>
36 #include <stdint.h>
37 #include "proc_service.h"
39 #if defined(arm) || defined(ppc)
40 #include "libproc_md.h"
41 #endif
43 #include <sys/ptrace.h>
45 #if defined(mips) || defined(mipsel) || defined(mips64) || defined(mips64el)
46 #include <asm/ptrace.h>
47 #endif
48 /************************************************************************************
50 0. This is very minimal subset of Solaris libproc just enough for current application.
51 Please note that the bulk of the functionality is from proc_service interface. This
52 adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
53 file by this interface.
55 1. pthread_id unique in both NPTL & LinuxThreads. We store this in
56 OSThread::_pthread_id in JVM code.
58 2. All threads see the same pid when they call getpid() under NPTL.
59 Threads receive different pid under LinuxThreads. We used to save the result of
60 ::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
61 was lost under NPTL. Now, we store the result of ::gettid() call in
62 OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
63 unique again. We therefore use OSThread::_thread_id as unique identifier.
65 3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
66 to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
67 lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
68 unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
69 only for processes. For core dumps, we don't use libthread_db at all (like gdb).
71 4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
72 ptrace call, we refer to lwp_id of the thread.
74 5. for core file, we parse ELF files and read data from them. For processes we use
75 combination of ptrace and /proc calls.
77 *************************************************************************************/
80 #if defined(sparc) || defined(sparcv9) || defined(ppc64)
81 #define user_regs_struct pt_regs
82 #endif
84 #if defined(mips) || defined(mipsel) || defined(mips64) || defined(mips64el)
85 #define user_regs_struct pt_regs
86 #endif
88 // This C bool type must be int for compatibility with Linux calls and
89 // it would be a mistake to equivalence it to C++ bool on many platforms
91 typedef int bool;
92 #define true 1
93 #define false 0
95 struct ps_prochandle;
97 // attach to a process
98 struct ps_prochandle* Pgrab(pid_t pid);
100 // attach to a core dump
101 struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
103 // release a process or core
104 void Prelease(struct ps_prochandle* ph);
106 // functions not directly available in Solaris libproc
108 // initialize libproc (call this only once per app)
109 // pass true to make library verbose
110 bool init_libproc(bool verbose);
112 // get number of threads
113 int get_num_threads(struct ps_prochandle* ph);
115 // get lwp_id of n'th thread
116 lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
118 // get regs for a given lwp
119 bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
121 // get number of shared objects
122 int get_num_libs(struct ps_prochandle* ph);
124 // get name of n'th lib
125 const char* get_lib_name(struct ps_prochandle* ph, int index);
127 // get base of lib
128 uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
130 // returns true if given library is found in lib list
131 bool find_lib(struct ps_prochandle* ph, const char *lib_name);
133 // symbol lookup
134 uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,
135 const char* sym_name);
137 // address->nearest symbol lookup. return NULL for no symbol
138 const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
140 struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj);
142 void throw_new_debugger_exception(JNIEnv* env, const char* errMsg);
144 #endif //__LIBPROC_H_