hotspot/agent/src/os/bsd/libproc_impl.h
changeset 16351 032b310a3e2f
parent 15734 68f78eb98356
equal deleted inserted replaced
15935:50da9e5eb858 16351:032b310a3e2f
    27 
    27 
    28 #include <unistd.h>
    28 #include <unistd.h>
    29 #include <limits.h>
    29 #include <limits.h>
    30 #include "libproc.h"
    30 #include "libproc.h"
    31 #include "symtab.h"
    31 #include "symtab.h"
       
    32 
       
    33 #ifdef __APPLE__
       
    34 #include <inttypes.h>     // for PRIx64, 32, ...
       
    35 #include <pthread.h>
       
    36 #include <mach-o/loader.h>
       
    37 #include <mach-o/nlist.h>
       
    38 #include <mach-o/fat.h>
       
    39 
       
    40 #ifndef register_t
       
    41 #define register_t uint64_t
       
    42 #endif
       
    43 
       
    44 /*** registers copied from bsd/amd64 */
       
    45 typedef struct reg {
       
    46   register_t      r_r15;
       
    47   register_t      r_r14;
       
    48   register_t      r_r13;
       
    49   register_t      r_r12;
       
    50   register_t      r_r11;
       
    51   register_t      r_r10;
       
    52   register_t      r_r9;
       
    53   register_t      r_r8;
       
    54   register_t      r_rdi;
       
    55   register_t      r_rsi;
       
    56   register_t      r_rbp;
       
    57   register_t      r_rbx;
       
    58   register_t      r_rdx;
       
    59   register_t      r_rcx;
       
    60   register_t      r_rax;
       
    61   uint32_t        r_trapno;      // not used
       
    62   uint16_t        r_fs;
       
    63   uint16_t        r_gs;
       
    64   uint32_t        r_err;         // not used
       
    65   uint16_t        r_es;          // not used
       
    66   uint16_t        r_ds;          // not used
       
    67   register_t      r_rip;
       
    68   register_t      r_cs;
       
    69   register_t      r_rflags;
       
    70   register_t      r_rsp;
       
    71   register_t      r_ss;          // not used
       
    72 } reg;
       
    73 
       
    74 // convenient defs
       
    75 typedef struct mach_header_64 mach_header_64;
       
    76 typedef struct load_command load_command;
       
    77 typedef struct segment_command_64 segment_command_64;
       
    78 typedef struct thread_command thread_command;
       
    79 typedef struct dylib_command dylib_command;
       
    80 typedef struct symtab_command symtab_command;
       
    81 typedef struct nlist_64 nlist_64;
       
    82 #else
       
    83 #include <thread_db.h>
       
    84 #include "salibelf.h"
       
    85 #endif //  __APPLE__
    32 
    86 
    33 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
    87 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
    34 
    88 
    35 #define BUF_SIZE     (PATH_MAX + NAME_MAX + 1)
    89 #define BUF_SIZE     (PATH_MAX + NAME_MAX + 1)
    36 
    90 
    42   int              fd;        // file descriptor for lib
    96   int              fd;        // file descriptor for lib
    43   struct lib_info* next;
    97   struct lib_info* next;
    44 } lib_info;
    98 } lib_info;
    45 
    99 
    46 // list of threads
   100 // list of threads
    47 typedef struct thread_info {
   101 typedef struct sa_thread_info {
    48    lwpid_t                  lwp_id;
   102    lwpid_t                  lwp_id;     // same as pthread_t
    49    pthread_t                pthread_id; // not used cores, always -1
   103    pthread_t                pthread_id; //
    50    struct reg               regs;       // not for process, core uses for caching regset
   104    struct reg               regs;       // not for process, core uses for caching regset
    51    struct thread_info*      next;
   105    struct sa_thread_info*   next;
    52 } thread_info;
   106 } sa_thread_info;
    53 
   107 
    54 // list of virtual memory maps
   108 // list of virtual memory maps
    55 typedef struct map_info {
   109 typedef struct map_info {
    56    int              fd;       // file descriptor
   110    int              fd;       // file descriptor
    57    off_t            offset;   // file offset of this mapping
   111    off_t            offset;   // file offset of this mapping
    89    size_t             num_maps;  // number of maps.
   143    size_t             num_maps;  // number of maps.
    90    map_info*          maps;      // maps in a linked list
   144    map_info*          maps;      // maps in a linked list
    91    // part of the class sharing workaround
   145    // part of the class sharing workaround
    92    map_info*          class_share_maps;// class share maps in a linked list
   146    map_info*          class_share_maps;// class share maps in a linked list
    93    map_info**         map_array; // sorted (by vaddr) array of map_info pointers
   147    map_info**         map_array; // sorted (by vaddr) array of map_info pointers
       
   148    char               exec_path[4096];  // file name java
    94 };
   149 };
    95 
   150 
    96 struct ps_prochandle {
   151 struct ps_prochandle {
    97    ps_prochandle_ops* ops;       // vtable ptr
   152    ps_prochandle_ops* ops;       // vtable ptr
    98    pid_t              pid;
   153    pid_t              pid;
    99    int                num_libs;
   154    int                num_libs;
   100    lib_info*          libs;      // head of lib list
   155    lib_info*          libs;      // head of lib list
   101    lib_info*          lib_tail;  // tail of lib list - to append at the end
   156    lib_info*          lib_tail;  // tail of lib list - to append at the end
   102    int                num_threads;
   157    int                num_threads;
   103    thread_info*       threads;   // head of thread list
   158    sa_thread_info*    threads;   // head of thread list
   104    struct core_data*  core;      // data only used for core dumps, NULL for process
   159    struct core_data*  core;      // data only used for core dumps, NULL for process
   105 };
   160 };
   106 
   161 
   107 int pathmap_open(const char* name);
   162 int pathmap_open(const char* name);
   108 
       
   109 void print_debug(const char* format,...);
   163 void print_debug(const char* format,...);
   110 void print_error(const char* format,...);
   164 void print_error(const char* format,...);
   111 bool is_debug();
   165 bool is_debug();
   112 
   166 
   113 typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
   167 typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
   120 
   174 
   121 // adds a new shared object to lib list, supply open lib file descriptor as well
   175 // adds a new shared object to lib list, supply open lib file descriptor as well
   122 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
   176 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
   123                           uintptr_t base);
   177                           uintptr_t base);
   124 
   178 
   125 // adds a new thread to threads list, returns NULL on failure
   179 sa_thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
   126 thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
       
   127 
       
   128 // a test for ELF signature without using libelf
   180 // a test for ELF signature without using libelf
       
   181 
       
   182 #ifdef __APPLE__
       
   183 // a test for Mach-O signature
       
   184 bool is_macho_file(int fd);
       
   185 // skip fat head to get image start offset of cpu_type_t
       
   186 // return false if any error happens, else value in offset.
       
   187 bool get_arch_off(int fd, cpu_type_t cputype, off_t *offset);
       
   188 #else
   129 bool is_elf_file(int fd);
   189 bool is_elf_file(int fd);
   130 
   190 #endif // __APPLE__
       
   191 
       
   192 lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
       
   193 bool set_lwp_id(struct ps_prochandle* ph, int index, lwpid_t lwpid);
       
   194 bool get_nth_lwp_regs(struct ps_prochandle* ph, int index, struct reg* regs);
       
   195 
       
   196 // ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
       
   197 // of the load object object_name in the target process identified by ph.
       
   198 // It returns the symbol's value as an address in the target process in
       
   199 // *sym_addr.
       
   200 
       
   201 ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
       
   202                     const char *sym_name, psaddr_t *sym_addr);
       
   203 
       
   204 // read "size" bytes info "buf" from address "addr"
       
   205 ps_err_e ps_pread(struct ps_prochandle *ph, psaddr_t  addr,
       
   206                   void *buf, size_t size);
       
   207 
       
   208 // write "size" bytes of data to debuggee at address "addr"
       
   209 ps_err_e ps_pwrite(struct ps_prochandle *ph, psaddr_t addr,
       
   210                    const void *buf, size_t size);
       
   211 
       
   212 // fill in ptrace_lwpinfo for lid
       
   213 ps_err_e ps_linfo(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
       
   214 
       
   215 // needed for when libthread_db is compiled with TD_DEBUG defined
       
   216 void ps_plog (const char *format, ...);
       
   217 
       
   218 // untility, tells the position in file
       
   219 off_t ltell(int fd);
   131 #endif //_LIBPROC_IMPL_H_
   220 #endif //_LIBPROC_IMPL_H_