< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c

Print this page

113        *(buf++) = *(ptr++);
114   }
115   return true;
116 }
117 
118 // null implementation for write
119 static bool process_write_data(struct ps_prochandle* ph,
120                              uintptr_t addr, const char *buf , size_t size) {
121   return false;
122 }
123 
124 // "user" should be a pointer to a user_regs_struct
125 static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
126   // we have already attached to all thread 'pid's, just use ptrace call
127   // to get regset now. Note that we don't cache regset upfront for processes.
128 // Linux on x86 and sparc are different.  On x86 ptrace(PTRACE_GETREGS, ...)
129 // uses pointer from 4th argument and ignores 3rd argument.  On sparc it uses
130 // pointer from 3rd argument and ignores 4th argument
131 #define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)
132 



133 #if defined(_LP64) && defined(PTRACE_GETREGS64)
134 #define PTRACE_GETREGS_REQ PTRACE_GETREGS64
135 #elif defined(PTRACE_GETREGS)
136 #define PTRACE_GETREGS_REQ PTRACE_GETREGS
137 #elif defined(PT_GETREGS)
138 #define PTRACE_GETREGS_REQ PT_GETREGS
139 #endif

140 
141 #ifdef PTRACE_GETREGS_REQ
142  if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
143    print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp(%d) errno(%d) \"%s\"\n", pid,
144                errno, strerror(errno));
145    return false;
146  }
147  return true;
148 #elif defined(PTRACE_GETREGSET)
149  struct iovec iov;
150  iov.iov_base = user;
151  iov.iov_len = sizeof(*user);
152  if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void*) &iov) < 0) {
153    print_debug("ptrace(PTRACE_GETREGSET, ...) failed for lwp %d\n", pid);
154    return false;
155  }
156  return true;
157 #else
158  print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
159  return false;

113        *(buf++) = *(ptr++);
114   }
115   return true;
116 }
117 
118 // null implementation for write
119 static bool process_write_data(struct ps_prochandle* ph,
120                              uintptr_t addr, const char *buf , size_t size) {
121   return false;
122 }
123 
124 // "user" should be a pointer to a user_regs_struct
125 static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
126   // we have already attached to all thread 'pid's, just use ptrace call
127   // to get regset now. Note that we don't cache regset upfront for processes.
128 // Linux on x86 and sparc are different.  On x86 ptrace(PTRACE_GETREGS, ...)
129 // uses pointer from 4th argument and ignores 3rd argument.  On sparc it uses
130 // pointer from 3rd argument and ignores 4th argument
131 #define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)
132 
133 // riscv kernel didn't implement compat_arch_ptrace function that will handle PT_GETREGS case
134 // like other platforms, so call ptrace with PTRACE_GETREGSET here.
135 #ifndef riscv64
136 #if defined(_LP64) && defined(PTRACE_GETREGS64)
137 #define PTRACE_GETREGS_REQ PTRACE_GETREGS64
138 #elif defined(PTRACE_GETREGS)
139 #define PTRACE_GETREGS_REQ PTRACE_GETREGS
140 #elif defined(PT_GETREGS)
141 #define PTRACE_GETREGS_REQ PT_GETREGS
142 #endif
143 #endif
144 
145 #ifdef PTRACE_GETREGS_REQ
146  if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
147    print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp(%d) errno(%d) \"%s\"\n", pid,
148                errno, strerror(errno));
149    return false;
150  }
151  return true;
152 #elif defined(PTRACE_GETREGSET)
153  struct iovec iov;
154  iov.iov_base = user;
155  iov.iov_len = sizeof(*user);
156  if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void*) &iov) < 0) {
157    print_debug("ptrace(PTRACE_GETREGSET, ...) failed for lwp %d\n", pid);
158    return false;
159  }
160  return true;
161 #else
162  print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
163  return false;
< prev index next >