src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.h
author michaelm
Tue, 29 Oct 2019 19:55:34 +0000
branchunixdomainchannels
changeset 58848 c3df0f8b6d93
parent 53379 e47074d2d8cc
permissions -rw-r--r--
second part of cleanup reducing number of files touched in main line
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53379
e47074d2d8cc 8181313: SA: Remove libthread_db dependency on Linux
ysuenaga
parents: 53004
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#ifndef _LIBPROC_IMPL_H_
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#define _LIBPROC_IMPL_H_
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#include <unistd.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#include <limits.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#include "libproc.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#include "symtab.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#define BUF_SIZE     (PATH_MAX + NAME_MAX + 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// list of shared objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
typedef struct lib_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  char             name[BUF_SIZE];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  uintptr_t        base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  struct symtab*   symtab;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  int              fd;        // file descriptor for lib
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  struct lib_info* next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
} lib_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// list of threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
typedef struct thread_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
   lwpid_t                  lwp_id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
   struct user_regs_struct  regs;       // not for process, core uses for caching regset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   struct thread_info*      next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
} thread_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// list of virtual memory maps
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
typedef struct map_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
   int              fd;       // file descriptor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
   off_t            offset;   // file offset of this mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
   uintptr_t        vaddr;    // starting virtual address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
   size_t           memsz;    // size of the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   struct map_info* next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
} map_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// vtable for ps_prochandle
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
typedef struct ps_prochandle_ops {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
   // "derived class" clean-up
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
   void (*release)(struct ps_prochandle* ph);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
   // read from debuggee
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
   bool (*p_pread)(struct ps_prochandle *ph,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
            uintptr_t addr, char *buf, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
   // write into debuggee
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
   bool (*p_pwrite)(struct ps_prochandle *ph,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
            uintptr_t addr, const char *buf , size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
   // get integer regset of a thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
   bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
} ps_prochandle_ops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// the ps_prochandle
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
struct core_data {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
   int                core_fd;   // file descriptor of core file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
   int                exec_fd;   // file descriptor of exec file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
   int                interp_fd; // file descriptor of interpreter (ld-linux.so.2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
   // part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
   int                classes_jsa_fd; // file descriptor of class share archive
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
   uintptr_t          dynamic_addr;  // address of dynamic section of a.out
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
   uintptr_t          ld_base_addr;  // base address of ld.so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
   size_t             num_maps;  // number of maps.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
   map_info*          maps;      // maps in a linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
   // part of the class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
   map_info*          class_share_maps;// class share maps in a linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
   map_info**         map_array; // sorted (by vaddr) array of map_info pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
struct ps_prochandle {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
   ps_prochandle_ops* ops;       // vtable ptr
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
   pid_t              pid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
   int                num_libs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
   lib_info*          libs;      // head of lib list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
   lib_info*          lib_tail;  // tail of lib list - to append at the end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
   int                num_threads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
   thread_info*       threads;   // head of thread list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
   struct core_data*  core;      // data only used for core dumps, NULL for process
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
int pathmap_open(const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void print_debug(const char* format,...);
15734
68f78eb98356 8008088: SA can hang the VM
rbackman
parents: 5547
diff changeset
   107
void print_error(const char* format,...);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
bool is_debug();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
53004
b9d34a97a4be 8202884: SA: Attach/detach might fail on Linux if debugee application create/destroy threads during attaching
jgeorge
parents: 47216
diff changeset
   110
// deletes a thread from the thread list
b9d34a97a4be 8202884: SA: Attach/detach might fail on Linux if debugee application create/destroy threads during attaching
jgeorge
parents: 47216
diff changeset
   111
void delete_thread_info(struct ps_prochandle* ph, thread_info* thr);
b9d34a97a4be 8202884: SA: Attach/detach might fail on Linux if debugee application create/destroy threads during attaching
jgeorge
parents: 47216
diff changeset
   112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// adds a new shared object to lib list, returns NULL on failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// adds a new shared object to lib list, supply open lib file descriptor as well
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
                          uintptr_t base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// adds a new thread to threads list, returns NULL on failure
53379
e47074d2d8cc 8181313: SA: Remove libthread_db dependency on Linux
ysuenaga
parents: 53004
diff changeset
   121
thread_info* add_thread_info(struct ps_prochandle* ph, lwpid_t lwp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// a test for ELF signature without using libelf
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
bool is_elf_file(int fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
#endif //_LIBPROC_IMPL_H_