libproc_impl.h revision 0
0N/A/*
0N/A * Copyright 2003-2005 Sun Microsystems, Inc. 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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any 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>
288N/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
void (*release)(struct ps_prochandle* ph);
// read from debuggee
bool (*p_pread)(struct ps_prochandle *ph,
uintptr_t addr, char *buf, size_t size);
// write into debuggee
bool (*p_pwrite)(struct ps_prochandle *ph,
uintptr_t addr, const char *buf , size_t size);
// get integer regset of a thread
bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
} ps_prochandle_ops;
// the ps_prochandle
struct core_data {
int core_fd; // file descriptor of core file
int exec_fd; // file descriptor of exec file
int interp_fd; // file descriptor of interpreter (ld-linux.so.2)
// part of the class sharing workaround
int classes_jsa_fd; // file descriptor of class share archive
uintptr_t dynamic_addr; // address of dynamic section of a.out
uintptr_t ld_base_addr; // base address of ld.so
size_t num_maps; // number of maps.
map_info* maps; // maps in a linked list
// part of the class sharing workaround
map_info* class_share_maps;// class share maps in a linked list
map_info** map_array; // sorted (by vaddr) array of map_info pointers
};
struct ps_prochandle {
ps_prochandle_ops* ops; // vtable ptr
pid_t pid;
int num_libs;
lib_info* libs; // head of lib list
lib_info* lib_tail; // tail of lib list - to append at the end
int num_threads;
thread_info* threads; // head of thread list
struct core_data* core; // data only used for core dumps, NULL for process
};
int pathmap_open(const char* name);
void print_debug(const char* format,...);
bool is_debug();
typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
// reads thread info using libthread_db and calls above callback for each thread
bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
// adds a new shared object to lib list, returns NULL on failure
lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
// adds a new shared object to lib list, supply open lib file descriptor as well
lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
uintptr_t base);
// adds a new thread to threads list, returns NULL on failure
thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
// a test for ELF signature without using libelf
bool is_elf_file(int fd);
#endif //_LIBPROC_IMPL_H_