0N/A/*
4204N/A * Copyright (c) 2003, 2013, 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_IMPL_H_
0N/A#define _LIBPROC_IMPL_H_
0N/A
0N/A#include <unistd.h>
0N/A#include <limits.h>
0N/A#include "libproc.h"
0N/A#include "symtab.h"
0N/A
0N/A// data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
0N/A
0N/A#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
0N/A
0N/A// list of shared objects
0N/Atypedef struct lib_info {
0N/A char name[BUF_SIZE];
0N/A uintptr_t base;
0N/A struct symtab* symtab;
0N/A int fd; // file descriptor for lib
0N/A struct lib_info* next;
0N/A} lib_info;
0N/A
0N/A// list of threads
0N/Atypedef struct thread_info {
0N/A lwpid_t lwp_id;
0N/A pthread_t pthread_id; // not used cores, always -1
0N/A struct user_regs_struct regs; // not for process, core uses for caching regset
0N/A struct thread_info* next;
0N/A} thread_info;
0N/A
0N/A// list of virtual memory maps
0N/Atypedef struct map_info {
0N/A int fd; // file descriptor
0N/A off_t offset; // file offset of this mapping
0N/A uintptr_t vaddr; // starting virtual address
0N/A size_t memsz; // size of the mapping
0N/A struct map_info* next;
0N/A} map_info;
0N/A
0N/A// vtable for ps_prochandle
0N/Atypedef struct ps_prochandle_ops {
0N/A // "derived class" clean-up
0N/A void (*release)(struct ps_prochandle* ph);
0N/A // read from debuggee
0N/A bool (*p_pread)(struct ps_prochandle *ph,
0N/A uintptr_t addr, char *buf, size_t size);
0N/A // write into debuggee
0N/A bool (*p_pwrite)(struct ps_prochandle *ph,
0N/A uintptr_t addr, const char *buf , size_t size);
0N/A // get integer regset of a thread
0N/A bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
0N/A} ps_prochandle_ops;
0N/A
0N/A// the ps_prochandle
0N/A
0N/Astruct core_data {
0N/A int core_fd; // file descriptor of core file
0N/A int exec_fd; // file descriptor of exec file
0N/A int interp_fd; // file descriptor of interpreter (ld-linux.so.2)
0N/A // part of the class sharing workaround
0N/A int classes_jsa_fd; // file descriptor of class share archive
0N/A uintptr_t dynamic_addr; // address of dynamic section of a.out
0N/A uintptr_t ld_base_addr; // base address of ld.so
0N/A size_t num_maps; // number of maps.
0N/A map_info* maps; // maps in a linked list
0N/A // part of the class sharing workaround
0N/A map_info* class_share_maps;// class share maps in a linked list
0N/A map_info** map_array; // sorted (by vaddr) array of map_info pointers
0N/A};
0N/A
0N/Astruct ps_prochandle {
0N/A ps_prochandle_ops* ops; // vtable ptr
0N/A pid_t pid;
0N/A int num_libs;
0N/A lib_info* libs; // head of lib list
0N/A lib_info* lib_tail; // tail of lib list - to append at the end
0N/A int num_threads;
0N/A thread_info* threads; // head of thread list
0N/A struct core_data* core; // data only used for core dumps, NULL for process
0N/A};
0N/A
0N/Aint pathmap_open(const char* name);
0N/A
0N/Avoid print_debug(const char* format,...);
4204N/Avoid print_error(const char* format,...);
0N/Abool is_debug();
0N/A
0N/Atypedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
0N/A
0N/A// reads thread info using libthread_db and calls above callback for each thread
0N/Abool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
0N/A
0N/A// adds a new shared object to lib list, returns NULL on failure
0N/Alib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
0N/A
0N/A// adds a new shared object to lib list, supply open lib file descriptor as well
0N/Alib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
0N/A uintptr_t base);
0N/A
0N/A// adds a new thread to threads list, returns NULL on failure
0N/Athread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
0N/A
0N/A// a test for ELF signature without using libelf
0N/Abool is_elf_file(int fd);
0N/A
0N/A#endif //_LIBPROC_IMPL_H_