0N/A/*
3991N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#ifndef _LIBPROC_H_
0N/A#define _LIBPROC_H_
0N/A
3991N/A#include <jni.h>
0N/A#include <unistd.h>
0N/A#include <stdint.h>
0N/A#include "proc_service.h"
0N/A
3991N/A#if defined(arm) || defined(ppc)
3991N/A#include "libproc_md.h"
3991N/A#endif
3991N/A
0N/A#if defined(sparc) || defined(sparcv9)
0N/A/*
0N/A If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64
0N/A otherwise it should be from /usr/include/asm-sparc
0N/A These two files define pt_regs structure differently
0N/A*/
0N/A#ifdef _LP64
0N/A#include "asm-sparc64/ptrace.h"
0N/A#else
0N/A#include "asm-sparc/ptrace.h"
0N/A#endif
0N/A
0N/A#endif //sparc or sparcv9
0N/A
0N/A/************************************************************************************
0N/A
0N/A0. This is very minimal subset of Solaris libproc just enough for current application.
0N/APlease note that the bulk of the functionality is from proc_service interface. This
0N/Aadds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
0N/Afile by this interface.
0N/A
0N/A1. pthread_id unique in both NPTL & LinuxThreads. We store this in
0N/AOSThread::_pthread_id in JVM code.
0N/A
0N/A2. All threads see the same pid when they call getpid() under NPTL.
0N/AThreads receive different pid under LinuxThreads. We used to save the result of
0N/A::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
0N/Awas lost under NPTL. Now, we store the result of ::gettid() call in
0N/AOSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
0N/Aunique again. We therefore use OSThread::_thread_id as unique identifier.
0N/A
0N/A3. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id
0N/Ato its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
0N/Alwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
0N/Aunfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
0N/Aonly for processes. For core dumps, we don't use libthread_db at all (like gdb).
0N/A
0N/A4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
0N/Aptrace call, we refer to lwp_id of the thread.
0N/A
0N/A5. for core file, we parse ELF files and read data from them. For processes we use
0N/Acombination of ptrace and /proc calls.
0N/A
0N/A*************************************************************************************/
0N/A
0N/A#ifdef ia64
0N/Astruct user_regs_struct {
0N/A/* copied from user.h which doesn't define this in a struct */
0N/A
0N/A#define IA64_REG_COUNT (EF_SIZE/8+32) /* integer and fp regs */
0N/Aunsigned long regs[IA64_REG_COUNT]; /* integer and fp regs */
0N/A};
0N/A#endif
0N/A
0N/A#if defined(sparc) || defined(sparcv9)
0N/A#define user_regs_struct pt_regs
0N/A#endif
0N/A
0N/A// This C bool type must be int for compatibility with Linux calls and
0N/A// it would be a mistake to equivalence it to C++ bool on many platforms
0N/A
0N/Atypedef int bool;
0N/A#define true 1
0N/A#define false 0
0N/A
0N/Astruct ps_prochandle;
0N/A
0N/A// attach to a process
0N/Astruct ps_prochandle* Pgrab(pid_t pid);
0N/A
0N/A// attach to a core dump
0N/Astruct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
0N/A
0N/A// release a process or core
0N/Avoid Prelease(struct ps_prochandle* ph);
0N/A
0N/A// functions not directly available in Solaris libproc
0N/A
0N/A// initialize libproc (call this only once per app)
0N/A// pass true to make library verbose
0N/Abool init_libproc(bool verbose);
0N/A
0N/A// get number of threads
0N/Aint get_num_threads(struct ps_prochandle* ph);
0N/A
0N/A// get lwp_id of n'th thread
0N/Alwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
0N/A
0N/A// get regs for a given lwp
0N/Abool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
0N/A
0N/A// get number of shared objects
0N/Aint get_num_libs(struct ps_prochandle* ph);
0N/A
0N/A// get name of n'th lib
0N/Aconst char* get_lib_name(struct ps_prochandle* ph, int index);
0N/A
0N/A// get base of lib
0N/Auintptr_t get_lib_base(struct ps_prochandle* ph, int index);
0N/A
0N/A// returns true if given library is found in lib list
0N/Abool find_lib(struct ps_prochandle* ph, const char *lib_name);
0N/A
0N/A// symbol lookup
0N/Auintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,
0N/A const char* sym_name);
0N/A
0N/A// address->nearest symbol lookup. return NULL for no symbol
0N/Aconst char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
0N/A
3991N/Astruct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj);
3991N/A
3991N/Avoid throw_new_debugger_exception(JNIEnv* env, const char* errMsg);
3991N/A
0N/A#endif //__LIBPROC_H_