src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
branchihse-remove-mapfiles-branch
changeset 56109 5bf57be44328
parent 47216 71c04702a3d5
child 56721 01b558efd286
equal deleted inserted replaced
56108:88838a55535b 56109:5bf57be44328
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25 #include <stdio.h>
    25 #include <stdio.h>
    26 #include <stdlib.h>
    26 #include <stdlib.h>
    27 #include <string.h>
    27 #include <string.h>
    28 #include <fcntl.h>
    28 #include <fcntl.h>
    29 #include <thread_db.h>
    29 #include <thread_db.h>
       
    30 #include "jni.h"
    30 #include "libproc_impl.h"
    31 #include "libproc_impl.h"
    31 
    32 
    32 #define SA_ALTROOT "SA_ALTROOT"
    33 #define SA_ALTROOT "SA_ALTROOT"
    33 
    34 
    34 int pathmap_open(const char* name) {
    35 int pathmap_open(const char* name) {
   110 bool is_debug() {
   111 bool is_debug() {
   111    return _libsaproc_debug;
   112    return _libsaproc_debug;
   112 }
   113 }
   113 
   114 
   114 // initialize libproc
   115 // initialize libproc
   115 bool init_libproc(bool debug) {
   116 JNIEXPORT bool
       
   117 init_libproc(bool debug) {
   116    // init debug mode
   118    // init debug mode
   117    _libsaproc_debug = debug;
   119    _libsaproc_debug = debug;
   118 
   120 
   119    // initialize the thread_db library
   121    // initialize the thread_db library
   120    if (td_init() != TD_OK) {
   122    if (td_init() != TD_OK) {
   147 }
   149 }
   148 
   150 
   149 // ps_prochandle cleanup
   151 // ps_prochandle cleanup
   150 
   152 
   151 // ps_prochandle cleanup
   153 // ps_prochandle cleanup
   152 void Prelease(struct ps_prochandle* ph) {
   154 JNIEXPORT void
       
   155 Prelease(struct ps_prochandle* ph) {
   153    // do the "derived class" clean-up first
   156    // do the "derived class" clean-up first
   154    ph->ops->release(ph);
   157    ph->ops->release(ph);
   155    destroy_lib_info(ph);
   158    destroy_lib_info(ph);
   156    destroy_thread_info(ph);
   159    destroy_thread_info(ph);
   157    free(ph);
   160    free(ph);
   396 
   399 
   397 //--------------------------------------------------------------------------
   400 //--------------------------------------------------------------------------
   398 // proc service functions
   401 // proc service functions
   399 
   402 
   400 // get process id
   403 // get process id
   401 pid_t ps_getpid(struct ps_prochandle *ph) {
   404 JNIEXPORT pid_t
       
   405 ps_getpid(struct ps_prochandle *ph) {
   402    return ph->pid;
   406    return ph->pid;
   403 }
   407 }
   404 
   408 
   405 // ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
   409 // ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
   406 // of the load object object_name in the target process identified by ph.
   410 // of the load object object_name in the target process identified by ph.
   407 // It returns the symbol's value as an address in the target process in
   411 // It returns the symbol's value as an address in the target process in
   408 // *sym_addr.
   412 // *sym_addr.
   409 
   413 
   410 ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
   414 JNIEXPORT ps_err_e
       
   415 ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
   411                     const char *sym_name, psaddr_t *sym_addr) {
   416                     const char *sym_name, psaddr_t *sym_addr) {
   412   *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
   417   *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
   413   return (*sym_addr ? PS_OK : PS_NOSYM);
   418   return (*sym_addr ? PS_OK : PS_NOSYM);
   414 }
   419 }
   415 
   420 
   416 // read "size" bytes info "buf" from address "addr"
   421 // read "size" bytes info "buf" from address "addr"
   417 ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
   422 JNIEXPORT ps_err_e
       
   423 ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
   418                    void *buf, size_t size) {
   424                    void *buf, size_t size) {
   419   return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
   425   return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
   420 }
   426 }
   421 
   427 
   422 // write "size" bytes of data to debuggee at address "addr"
   428 // write "size" bytes of data to debuggee at address "addr"
   423 ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
   429 JNIEXPORT ps_err_e
       
   430 ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
   424                     const void *buf, size_t size) {
   431                     const void *buf, size_t size) {
   425   return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
   432   return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
   426 }
   433 }
   427 
   434 
   428 // ------------------------------------------------------------------------
   435 // ------------------------------------------------------------------------
   429 // Functions below this point are not yet implemented. They are here only
   436 // Functions below this point are not yet implemented. They are here only
   430 // to make the linker happy.
   437 // to make the linker happy.
   431 
   438 
   432 ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
   439 JNIEXPORT ps_err_e
       
   440 ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
   433   print_debug("ps_lsetfpregs not implemented\n");
   441   print_debug("ps_lsetfpregs not implemented\n");
   434   return PS_OK;
   442   return PS_OK;
   435 }
   443 }
   436 
   444 
   437 ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
   445 JNIEXPORT ps_err_e
       
   446 ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
   438   print_debug("ps_lsetregs not implemented\n");
   447   print_debug("ps_lsetregs not implemented\n");
   439   return PS_OK;
   448   return PS_OK;
   440 }
   449 }
   441 
   450 
   442 ps_err_e  ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
   451 JNIEXPORT ps_err_e
       
   452 ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
   443   print_debug("ps_lgetfpregs not implemented\n");
   453   print_debug("ps_lgetfpregs not implemented\n");
   444   return PS_OK;
   454   return PS_OK;
   445 }
   455 }
   446 
   456 
   447 ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
   457 JNIEXPORT ps_err_e
       
   458 ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
   448   print_debug("ps_lgetfpregs not implemented\n");
   459   print_debug("ps_lgetfpregs not implemented\n");
   449   return PS_OK;
   460   return PS_OK;
   450 }
   461 }
   451 
   462 
   452 // new libthread_db of NPTL seem to require this symbol
   463 // new libthread_db of NPTL seem to require this symbol
   453 ps_err_e ps_get_thread_area() {
   464 JNIEXPORT ps_err_e
       
   465 ps_get_thread_area() {
   454   print_debug("ps_get_thread_area not implemented\n");
   466   print_debug("ps_get_thread_area not implemented\n");
   455   return PS_OK;
   467   return PS_OK;
   456 }
   468 }