X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Finf-ptrace.c;h=e6729ac5679c05ca1b5484b28528c6c86367347a;hb=ffda88b4801e1ea163e7eb0962008c60f353c229;hp=89a37a6db9bf8d5d4c77547452f994111fa56a5b;hpb=e58b0e63bb0a42e99f6fb1e6d697a1b29caa02c2;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 89a37a6db9..e6729ac567 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -1,8 +1,7 @@ /* Low-level child interface to ptrace. - Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, - 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright (C) 1988-1996, 1998-2002, 2004-2012 Free Software + Foundation, Inc. This file is part of GDB. @@ -67,6 +66,8 @@ inf_ptrace_follow_fork (struct target_ops *ops, int follow_child) child_inf = add_inferior (fpid); child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); + child_inf->pspace = parent_inf->pspace; + child_inf->aspace = parent_inf->aspace; /* Before detaching from the parent, remove all breakpoints from it. */ @@ -119,17 +120,23 @@ inf_ptrace_create_inferior (struct target_ops *ops, { int pid; - pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL, - NULL, NULL); + /* Do not change either targets above or the same target if already present. + The reason is the target stack is shared across multiple inferiors. */ + int ops_already_pushed = target_is_pushed (ops); + struct cleanup *back_to = NULL; - push_target (ops); + if (! ops_already_pushed) + { + /* Clear possible core file with its process_stratum. */ + push_target (ops); + back_to = make_cleanup_unpush_target (ops); + } - /* On some targets, there must be some explicit synchronization - between the parent and child processes after the debugger - forks, and before the child execs the debuggee program. This - call basically gives permission for the child to exec. */ + pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL, + NULL, NULL, NULL); - target_acknowledge_created_inferior (pid); + if (! ops_already_pushed) + discard_cleanups (back_to); /* START_INFERIOR_TRAPS_EXPECTED is defined in inferior.h, and will be 1 or 2 depending on whether we're starting without or with a @@ -185,21 +192,26 @@ inf_ptrace_attach (struct target_ops *ops, char *args, int from_tty) { char *exec_file; pid_t pid; - char *dummy; struct inferior *inf; - if (!args) - error_no_arg (_("process-id to attach")); + /* Do not change either targets above or the same target if already present. + The reason is the target stack is shared across multiple inferiors. */ + int ops_already_pushed = target_is_pushed (ops); + struct cleanup *back_to = NULL; - dummy = args; - pid = strtol (args, &dummy, 0); - /* Some targets don't set errno on errors, grrr! */ - if (pid == 0 && args == dummy) - error (_("Illegal process-id: %s."), args); + pid = parse_pid_to_attach (args); if (pid == getpid ()) /* Trying to masturbate? */ error (_("I refuse to debug myself!")); + if (! ops_already_pushed) + { + /* target_pid_to_str already uses the target. Also clear possible core + file with its process_stratum. */ + push_target (ops); + back_to = make_cleanup_unpush_target (ops); + } + if (from_tty) { exec_file = get_exec_file (0); @@ -223,21 +235,22 @@ inf_ptrace_attach (struct target_ops *ops, char *args, int from_tty) error (_("This system does not support attaching to a process")); #endif - inferior_ptid = pid_to_ptid (pid); - - inf = add_inferior (pid); + inf = current_inferior (); + inferior_appeared (inf, pid); inf->attach_flag = 1; + inferior_ptid = pid_to_ptid (pid); /* Always add a main thread. If some target extends the ptrace target, it should decorate the ptid later with more info. */ add_thread_silent (inferior_ptid); - push_target(ops); + if (! ops_already_pushed) + discard_cleanups (back_to); } #ifdef PT_GET_PROCESS_STATE -void +static void inf_ptrace_post_attach (int pid) { ptrace_event_t pe; @@ -329,16 +342,21 @@ inf_ptrace_stop (ptid_t ptid) static void inf_ptrace_resume (struct target_ops *ops, - ptid_t ptid, int step, enum target_signal signal) + ptid_t ptid, int step, enum gdb_signal signal) { pid_t pid = ptid_get_pid (ptid); - int request = PT_CONTINUE; + int request; if (pid == -1) /* Resume all threads. Traditionally ptrace() only supports single-threaded processes, so simply resume the inferior. */ pid = ptid_get_pid (inferior_ptid); + if (catch_syscall_enabled () > 0) + request = PT_SYSCALL; + else + request = PT_CONTINUE; + if (step) { /* If this system does not support PT_STEP, a higher level @@ -353,7 +371,7 @@ inf_ptrace_resume (struct target_ops *ops, where it was. If GDB wanted it to start some other way, we have already written a new program counter value to the child. */ errno = 0; - ptrace (request, pid, (PTRACE_TYPE_ARG3)1, target_signal_to_host (signal)); + ptrace (request, pid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal)); if (errno != 0) perror_with_name (("ptrace")); } @@ -390,7 +408,7 @@ inf_ptrace_wait (struct target_ops *ops, /* Claim it exited with unknown signal. */ ourstatus->kind = TARGET_WAITKIND_SIGNALLED; - ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN; + ourstatus->value.sig = GDB_SIGNAL_UNKNOWN; return inferior_ptid; } @@ -563,6 +581,26 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object, return -1; case TARGET_OBJECT_AUXV: +#if defined (PT_IO) && defined (PIOD_READ_AUXV) + /* OpenBSD 4.5 has a new PIOD_READ_AUXV operation for the PT_IO + request that allows us to read the auxilliary vector. Other + BSD's may follow if they feel the need to support PIE. */ + { + struct ptrace_io_desc piod; + + if (writebuf) + return -1; + piod.piod_op = PIOD_READ_AUXV; + piod.piod_addr = readbuf; + piod.piod_offs = (void *) (long) offset; + piod.piod_len = len; + + errno = 0; + if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0) + /* Return the actual number of bytes read or written. */ + return piod.piod_len; + } +#endif return -1; case TARGET_OBJECT_WCOOKIE: @@ -600,6 +638,41 @@ inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid) return normal_pid_to_str (ptid); } +#if defined (PT_IO) && defined (PIOD_READ_AUXV) + +/* Read one auxv entry from *READPTR, not reading locations >= ENDPTR. + Return 0 if *READPTR is already at the end of the buffer. + Return -1 if there is insufficient buffer for a whole entry. + Return 1 if an entry was read into *TYPEP and *VALP. */ + +static int +inf_ptrace_auxv_parse (struct target_ops *ops, gdb_byte **readptr, + gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) +{ + struct type *int_type = builtin_type (target_gdbarch)->builtin_int; + struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; + const int sizeof_auxv_type = TYPE_LENGTH (int_type); + const int sizeof_auxv_val = TYPE_LENGTH (ptr_type); + enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); + gdb_byte *ptr = *readptr; + + if (endptr == ptr) + return 0; + + if (endptr - ptr < 2 * sizeof_auxv_val) + return -1; + + *typep = extract_unsigned_integer (ptr, sizeof_auxv_type, byte_order); + ptr += sizeof_auxv_val; /* Alignment. */ + *valp = extract_unsigned_integer (ptr, sizeof_auxv_val, byte_order); + ptr += sizeof_auxv_val; + + *readptr = ptr; + return 1; +} + +#endif + /* Create a prototype ptrace target. The client can override it with local methods. */ @@ -625,6 +698,9 @@ inf_ptrace_target (void) t->to_pid_to_str = inf_ptrace_pid_to_str; t->to_stop = inf_ptrace_stop; t->to_xfer_partial = inf_ptrace_xfer_partial; +#if defined (PT_IO) && defined (PIOD_READ_AUXV) + t->to_auxv_parse = inf_ptrace_auxv_parse; +#endif return t; }