ps_proc.c revision 1472
5390N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. 5390N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5390N/A * This code is free software; you can redistribute it and/or modify it 5390N/A * under the terms of the GNU General Public License version 2 only, as 5390N/A * published by the Free Software Foundation. 5390N/A * This code is distributed in the hope that it will be useful, but WITHOUT 5390N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5390N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5390N/A * version 2 for more details (a copy is included in the LICENSE file that 5390N/A * You should have received a copy of the GNU General Public License version 5390N/A * 2 along with this work; if not, write to the Free Software Foundation, 5390N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5390N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5390N/A// This file has the libproc implementation specific to live process 5390N/A// --------------------------------------------- 5390N/A// --------------------------------------------- 5390N/A// read "size" bytes of data from "addr" within the target process. 5390N/A// unlike the standard ptrace() function, process_read_data() can handle 5390N/A// unaligned address - alignment check, if required, should be done 5390N/A// before calling process_read_data. 5390N/A // assert((intptr_t)aligned_addr % sizeof(long) == 0); // null implementation for write // "user" should be a pointer to a user_regs_struct // we have already attached to all thread 'pid's, just use ptrace call // to get regset now. Note that we don't cache regset upfront for processes. // Linux on x86 and sparc are different. On x86 ptrace(PTRACE_GETREGS, ...) // uses pointer from 4th argument and ignores 3rd argument. On sparc it uses // pointer from 3rd argument and ignores 4th argument print_debug(
"ptrace(PTRACE_GETREGS, ...) not supported\n");
// Wait for debuggee to stop. print_debug(
"waitpid() failed. Child process pid (%d) does not exist \n",
pid);
print_debug(
"waitpid() failed. Invalid options argument.\n");
// ------------------------------------------------------- // functions for obtaining library information // ------------------------------------------------------- * splits a string _str_ into substrings with delimiter _delim_ by replacing old * delimiters with _new_delim_ (ideally, '\0'). the address of each substring * is stored in array _ptrs_ as the return value. the maximum capacity of _ptrs_ * array is specified by parameter _n_. * RETURN VALUE: total number of substrings (always <= _n_) * NOTE: string _str_ is modified if _delim_!=_new_delim_ if (
str ==
NULL || n <
1 )
return 0;
// skipping leading blanks * fgets without storing '\n' at the end of the string // callback for read_thread_info continue;
// ignore, add_lib_info prints error // we don't need to keep the library open, symtab is already // built. Only for core dump we need to keep the fd open. // detach all pids of a ps_prochandle // attach to the process. One and only one exposed stuff print_debug(
"can't allocate memory for ps_prochandle\n");
// initialize ps_prochandle // read library info and symbol tables, must do this before attaching threads, // as the symbols in the pthread library will be used to figure out // the list of threads within the same process. // don't attach to the main thread again // even if one attach fails, we get return NULL