src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
changeset 49440 396ea30afbd5
parent 47216 71c04702a3d5
child 53004 b9d34a97a4be
child 56721 01b558efd286
equal deleted inserted replaced
49439:bf53d82a51e5 49440:396ea30afbd5
     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.
   110 bool is_debug() {
   110 bool is_debug() {
   111    return _libsaproc_debug;
   111    return _libsaproc_debug;
   112 }
   112 }
   113 
   113 
   114 // initialize libproc
   114 // initialize libproc
   115 bool init_libproc(bool debug) {
   115 JNIEXPORT bool JNICALL
       
   116 init_libproc(bool debug) {
   116    // init debug mode
   117    // init debug mode
   117    _libsaproc_debug = debug;
   118    _libsaproc_debug = debug;
   118 
   119 
   119    // initialize the thread_db library
   120    // initialize the thread_db library
   120    if (td_init() != TD_OK) {
   121    if (td_init() != TD_OK) {
   147 }
   148 }
   148 
   149 
   149 // ps_prochandle cleanup
   150 // ps_prochandle cleanup
   150 
   151 
   151 // ps_prochandle cleanup
   152 // ps_prochandle cleanup
   152 void Prelease(struct ps_prochandle* ph) {
   153 JNIEXPORT void JNICALL
       
   154 Prelease(struct ps_prochandle* ph) {
   153    // do the "derived class" clean-up first
   155    // do the "derived class" clean-up first
   154    ph->ops->release(ph);
   156    ph->ops->release(ph);
   155    destroy_lib_info(ph);
   157    destroy_lib_info(ph);
   156    destroy_thread_info(ph);
   158    destroy_thread_info(ph);
   157    free(ph);
   159    free(ph);
   396 
   398 
   397 //--------------------------------------------------------------------------
   399 //--------------------------------------------------------------------------
   398 // proc service functions
   400 // proc service functions
   399 
   401 
   400 // get process id
   402 // get process id
   401 pid_t ps_getpid(struct ps_prochandle *ph) {
   403 JNIEXPORT pid_t JNICALL
       
   404 ps_getpid(struct ps_prochandle *ph) {
   402    return ph->pid;
   405    return ph->pid;
   403 }
   406 }
   404 
   407 
   405 // ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
   408 // 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.
   409 // 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
   410 // It returns the symbol's value as an address in the target process in
   408 // *sym_addr.
   411 // *sym_addr.
   409 
   412 
   410 ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
   413 JNIEXPORT ps_err_e JNICALL
       
   414 ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
   411                     const char *sym_name, psaddr_t *sym_addr) {
   415                     const char *sym_name, psaddr_t *sym_addr) {
   412   *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
   416   *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
   413   return (*sym_addr ? PS_OK : PS_NOSYM);
   417   return (*sym_addr ? PS_OK : PS_NOSYM);
   414 }
   418 }
   415 
   419 
   416 // read "size" bytes info "buf" from address "addr"
   420 // read "size" bytes info "buf" from address "addr"
   417 ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
   421 JNIEXPORT ps_err_e JNICALL
       
   422 ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
   418                    void *buf, size_t size) {
   423                    void *buf, size_t size) {
   419   return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
   424   return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
   420 }
   425 }
   421 
   426 
   422 // write "size" bytes of data to debuggee at address "addr"
   427 // write "size" bytes of data to debuggee at address "addr"
   423 ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
   428 JNIEXPORT ps_err_e JNICALL
       
   429 ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
   424                     const void *buf, size_t size) {
   430                     const void *buf, size_t size) {
   425   return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
   431   return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
   426 }
   432 }
   427 
   433 
   428 // ------------------------------------------------------------------------
   434 // ------------------------------------------------------------------------
   429 // Functions below this point are not yet implemented. They are here only
   435 // Functions below this point are not yet implemented. They are here only
   430 // to make the linker happy.
   436 // to make the linker happy.
   431 
   437 
   432 ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
   438 JNIEXPORT ps_err_e JNICALL
       
   439 ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
   433   print_debug("ps_lsetfpregs not implemented\n");
   440   print_debug("ps_lsetfpregs not implemented\n");
   434   return PS_OK;
   441   return PS_OK;
   435 }
   442 }
   436 
   443 
   437 ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
   444 JNIEXPORT ps_err_e JNICALL
       
   445 ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
   438   print_debug("ps_lsetregs not implemented\n");
   446   print_debug("ps_lsetregs not implemented\n");
   439   return PS_OK;
   447   return PS_OK;
   440 }
   448 }
   441 
   449 
   442 ps_err_e  ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
   450 JNIEXPORT ps_err_e  JNICALL
       
   451 ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
   443   print_debug("ps_lgetfpregs not implemented\n");
   452   print_debug("ps_lgetfpregs not implemented\n");
   444   return PS_OK;
   453   return PS_OK;
   445 }
   454 }
   446 
   455 
   447 ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
   456 JNIEXPORT ps_err_e JNICALL
       
   457 ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
   448   print_debug("ps_lgetfpregs not implemented\n");
   458   print_debug("ps_lgetfpregs not implemented\n");
   449   return PS_OK;
   459   return PS_OK;
   450 }
   460 }
   451 
   461 
   452 // new libthread_db of NPTL seem to require this symbol
   462 // new libthread_db of NPTL seem to require this symbol
   453 ps_err_e ps_get_thread_area() {
   463 JNIEXPORT ps_err_e JNICALL
       
   464 ps_get_thread_area() {
   454   print_debug("ps_get_thread_area not implemented\n");
   465   print_debug("ps_get_thread_area not implemented\n");
   455   return PS_OK;
   466   return PS_OK;
   456 }
   467 }