agent/src/os/bsd/libproc_impl.h

Wed, 13 Feb 2013 09:46:19 +0100

author
rbackman
date
Wed, 13 Feb 2013 09:46:19 +0100
changeset 4599
2394a89e89f4
parent 3156
f08d439fab8c
child 4750
39432a1cefdd
permissions
-rw-r--r--

8008088: SA can hang the VM
Reviewed-by: mgronlun, sla, dholmes

never@3156 1 /*
rbackman@4599 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
never@3156 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@3156 4 *
never@3156 5 * This code is free software; you can redistribute it and/or modify it
never@3156 6 * under the terms of the GNU General Public License version 2 only, as
never@3156 7 * published by the Free Software Foundation.
never@3156 8 *
never@3156 9 * This code is distributed in the hope that it will be useful, but WITHOUT
never@3156 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@3156 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@3156 12 * version 2 for more details (a copy is included in the LICENSE file that
never@3156 13 * accompanied this code).
never@3156 14 *
never@3156 15 * You should have received a copy of the GNU General Public License version
never@3156 16 * 2 along with this work; if not, write to the Free Software Foundation,
never@3156 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@3156 18 *
never@3156 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
never@3156 20 * or visit www.oracle.com if you need additional information or have any
never@3156 21 * questions.
never@3156 22 *
never@3156 23 */
never@3156 24
never@3156 25 #ifndef _LIBPROC_IMPL_H_
never@3156 26 #define _LIBPROC_IMPL_H_
never@3156 27
never@3156 28 #include <unistd.h>
never@3156 29 #include <limits.h>
never@3156 30 #include "libproc.h"
never@3156 31 #include "symtab.h"
never@3156 32
never@3156 33 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
never@3156 34
never@3156 35 #define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
never@3156 36
never@3156 37 // list of shared objects
never@3156 38 typedef struct lib_info {
never@3156 39 char name[BUF_SIZE];
never@3156 40 uintptr_t base;
never@3156 41 struct symtab* symtab;
never@3156 42 int fd; // file descriptor for lib
never@3156 43 struct lib_info* next;
never@3156 44 } lib_info;
never@3156 45
never@3156 46 // list of threads
never@3156 47 typedef struct thread_info {
never@3156 48 lwpid_t lwp_id;
never@3156 49 pthread_t pthread_id; // not used cores, always -1
never@3156 50 struct reg regs; // not for process, core uses for caching regset
never@3156 51 struct thread_info* next;
never@3156 52 } thread_info;
never@3156 53
never@3156 54 // list of virtual memory maps
never@3156 55 typedef struct map_info {
never@3156 56 int fd; // file descriptor
never@3156 57 off_t offset; // file offset of this mapping
never@3156 58 uintptr_t vaddr; // starting virtual address
never@3156 59 size_t memsz; // size of the mapping
never@3156 60 struct map_info* next;
never@3156 61 } map_info;
never@3156 62
never@3156 63 // vtable for ps_prochandle
never@3156 64 typedef struct ps_prochandle_ops {
never@3156 65 // "derived class" clean-up
never@3156 66 void (*release)(struct ps_prochandle* ph);
never@3156 67 // read from debuggee
never@3156 68 bool (*p_pread)(struct ps_prochandle *ph,
never@3156 69 uintptr_t addr, char *buf, size_t size);
never@3156 70 // write into debuggee
never@3156 71 bool (*p_pwrite)(struct ps_prochandle *ph,
never@3156 72 uintptr_t addr, const char *buf , size_t size);
never@3156 73 // get integer regset of a thread
never@3156 74 bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs);
never@3156 75 // get info on thread
never@3156 76 bool (*get_lwp_info)(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
never@3156 77 } ps_prochandle_ops;
never@3156 78
never@3156 79 // the ps_prochandle
never@3156 80
never@3156 81 struct core_data {
never@3156 82 int core_fd; // file descriptor of core file
never@3156 83 int exec_fd; // file descriptor of exec file
never@3156 84 int interp_fd; // file descriptor of interpreter (ld-elf.so.1)
never@3156 85 // part of the class sharing workaround
never@3156 86 int classes_jsa_fd; // file descriptor of class share archive
never@3156 87 uintptr_t dynamic_addr; // address of dynamic section of a.out
never@3156 88 uintptr_t ld_base_addr; // base address of ld.so
never@3156 89 size_t num_maps; // number of maps.
never@3156 90 map_info* maps; // maps in a linked list
never@3156 91 // part of the class sharing workaround
never@3156 92 map_info* class_share_maps;// class share maps in a linked list
never@3156 93 map_info** map_array; // sorted (by vaddr) array of map_info pointers
never@3156 94 };
never@3156 95
never@3156 96 struct ps_prochandle {
never@3156 97 ps_prochandle_ops* ops; // vtable ptr
never@3156 98 pid_t pid;
never@3156 99 int num_libs;
never@3156 100 lib_info* libs; // head of lib list
never@3156 101 lib_info* lib_tail; // tail of lib list - to append at the end
never@3156 102 int num_threads;
never@3156 103 thread_info* threads; // head of thread list
never@3156 104 struct core_data* core; // data only used for core dumps, NULL for process
never@3156 105 };
never@3156 106
never@3156 107 int pathmap_open(const char* name);
never@3156 108
never@3156 109 void print_debug(const char* format,...);
rbackman@4599 110 void print_error(const char* format,...);
never@3156 111 bool is_debug();
never@3156 112
never@3156 113 typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
never@3156 114
never@3156 115 // reads thread info using libthread_db and calls above callback for each thread
never@3156 116 bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
never@3156 117
never@3156 118 // adds a new shared object to lib list, returns NULL on failure
never@3156 119 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
never@3156 120
never@3156 121 // adds a new shared object to lib list, supply open lib file descriptor as well
never@3156 122 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
never@3156 123 uintptr_t base);
never@3156 124
never@3156 125 // adds a new thread to threads list, returns NULL on failure
never@3156 126 thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
never@3156 127
never@3156 128 // a test for ELF signature without using libelf
never@3156 129 bool is_elf_file(int fd);
never@3156 130
never@3156 131 #endif //_LIBPROC_IMPL_H_

mercurial