| Index: gdb/gnu-nat.c
 | 
| diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
 | 
| index 0c45f2026d1a85f9d8eb943318fba55159b78f3d..329d090b315ee685c55124d763915de29da4f395 100644
 | 
| --- a/gdb/gnu-nat.c
 | 
| +++ b/gdb/gnu-nat.c
 | 
| @@ -1,6 +1,5 @@
 | 
|  /* Interface GDB to the GNU Hurd.
 | 
| -   Copyright (C) 1992, 1995-2001, 2006-2012 Free Software Foundation,
 | 
| -   Inc.
 | 
| +   Copyright (C) 1992-2013 Free Software Foundation, Inc.
 | 
|  
 | 
|     This file is part of GDB.
 | 
|  
 | 
| @@ -19,8 +18,9 @@
 | 
|     GNU General Public License for more details.
 | 
|  
 | 
|     You should have received a copy of the GNU General Public License
 | 
| -   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
| - */
 | 
| +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 | 
| +
 | 
| +#include "defs.h"
 | 
|  
 | 
|  #include <ctype.h>
 | 
|  #include <errno.h>
 | 
| @@ -28,7 +28,7 @@
 | 
|  #include <setjmp.h>
 | 
|  #include <signal.h>
 | 
|  #include <stdio.h>
 | 
| -#include "gdb_string.h"
 | 
| +#include <string.h>
 | 
|  #include <sys/ptrace.h>
 | 
|  
 | 
|  #include <mach.h>
 | 
| @@ -52,7 +52,6 @@
 | 
|  
 | 
|  #include <portinfo.h>
 | 
|  
 | 
| -#include "defs.h"
 | 
|  #include "inferior.h"
 | 
|  #include "symtab.h"
 | 
|  #include "value.h"
 | 
| @@ -1084,7 +1083,7 @@ inf_validate_procs (struct inf *inf)
 | 
|  	    last = thread;
 | 
|  	    proc_debug (thread, "new thread: %d", threads[i]);
 | 
|  
 | 
| -	    ptid = ptid_build (inf->pid, 0, thread->tid);
 | 
| +	    ptid = ptid_build (inf->pid, thread->tid, 0);
 | 
|  
 | 
|  	    /* Tell GDB's generic thread code.  */
 | 
|  
 | 
| @@ -1614,17 +1613,17 @@ rewait:
 | 
|  
 | 
|    thread = inf->wait.thread;
 | 
|    if (thread)
 | 
| -    ptid = ptid_build (inf->pid, 0, thread->tid);
 | 
| +    ptid = ptid_build (inf->pid, thread->tid, 0);
 | 
|    else if (ptid_equal (ptid, minus_one_ptid))
 | 
|      thread = inf_tid_to_thread (inf, -1);
 | 
|    else
 | 
| -    thread = inf_tid_to_thread (inf, ptid_get_tid (ptid));
 | 
| +    thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
 | 
|  
 | 
|    if (!thread || thread->port == MACH_PORT_NULL)
 | 
|      {
 | 
|        /* TID is dead; try and find a new thread.  */
 | 
|        if (inf_update_procs (inf) && inf->threads)
 | 
| -	ptid = ptid_build (inf->pid, 0, inf->threads->tid); /* The first
 | 
| +	ptid = ptid_build (inf->pid, inf->threads->tid, 0); /* The first
 | 
|  							       available
 | 
|  							       thread.  */
 | 
|        else
 | 
| @@ -2016,14 +2015,15 @@ gnu_resume (struct target_ops *ops,
 | 
|    if (resume_all)
 | 
|      /* Allow all threads to run, except perhaps single-stepping one.  */
 | 
|      {
 | 
| -      inf_debug (inf, "running all threads; tid = %d", PIDGET (inferior_ptid));
 | 
| +      inf_debug (inf, "running all threads; tid = %d",
 | 
| +		 ptid_get_pid (inferior_ptid));
 | 
|        ptid = inferior_ptid;	/* What to step.  */
 | 
|        inf_set_threads_resume_sc (inf, 0, 1);
 | 
|      }
 | 
|    else
 | 
|      /* Just allow a single thread to run.  */
 | 
|      {
 | 
| -      struct proc *thread = inf_tid_to_thread (inf, ptid_get_tid (ptid));
 | 
| +      struct proc *thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
 | 
|  
 | 
|        if (!thread)
 | 
|  	error (_("Can't run single thread id %s: no such thread!"),
 | 
| @@ -2034,7 +2034,7 @@ gnu_resume (struct target_ops *ops,
 | 
|  
 | 
|    if (step)
 | 
|      {
 | 
| -      step_thread = inf_tid_to_thread (inf, ptid_get_tid (ptid));
 | 
| +      step_thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
 | 
|        if (!step_thread)
 | 
|  	warning (_("Can't step thread id %s: no such thread."),
 | 
|  		 target_pid_to_str (ptid));
 | 
| @@ -2134,7 +2134,7 @@ gnu_create_inferior (struct target_ops *ops,
 | 
|  
 | 
|    /* We now have thread info.  */
 | 
|    thread_change_ptid (inferior_ptid,
 | 
| -		      ptid_build (inf->pid, 0, inf_pick_first_thread ()));
 | 
| +		      ptid_build (inf->pid, inf_pick_first_thread (), 0));
 | 
|  
 | 
|    startup_inferior (inf->pending_execs);
 | 
|  
 | 
| @@ -2191,7 +2191,7 @@ gnu_attach (struct target_ops *ops, char *args, int from_tty)
 | 
|  
 | 
|    inf_update_procs (inf);
 | 
|  
 | 
| -  inferior_ptid = ptid_build (pid, 0, inf_pick_first_thread ());
 | 
| +  inferior_ptid = ptid_build (pid, inf_pick_first_thread (), 0);
 | 
|  
 | 
|    /* We have to initialize the terminal settings now, since the code
 | 
|       below might try to restore them.  */
 | 
| @@ -2218,7 +2218,7 @@ gnu_attach (struct target_ops *ops, char *args, int from_tty)
 | 
|     previously attached.  It *might* work if the program was
 | 
|     started via fork.  */
 | 
|  static void
 | 
| -gnu_detach (struct target_ops *ops, char *args, int from_tty)
 | 
| +gnu_detach (struct target_ops *ops, const char *args, int from_tty)
 | 
|  {
 | 
|    int pid;
 | 
|  
 | 
| @@ -2262,15 +2262,15 @@ gnu_thread_alive (struct target_ops *ops, ptid_t ptid)
 | 
|  {
 | 
|    inf_update_procs (gnu_current_inf);
 | 
|    return !!inf_tid_to_thread (gnu_current_inf,
 | 
| -			      ptid_get_tid (ptid));
 | 
| +			      ptid_get_lwp (ptid));
 | 
|  }
 | 
|  
 | 
|  
 | 
|  /* Read inferior task's LEN bytes from ADDR and copy it to MYADDR in
 | 
|     gdb's address space.  Return 0 on failure; number of bytes read
 | 
|     otherwise.  */
 | 
| -int
 | 
| -gnu_read_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
 | 
| +static int
 | 
| +gnu_read_inferior (task_t task, CORE_ADDR addr, gdb_byte *myaddr, int length)
 | 
|  {
 | 
|    error_t err;
 | 
|    vm_address_t low_address = (vm_address_t) trunc_page (addr);
 | 
| @@ -2315,8 +2315,9 @@ struct obstack region_obstack;
 | 
|  
 | 
|  /* Write gdb's LEN bytes from MYADDR and copy it to ADDR in inferior
 | 
|     task's address space.  */
 | 
| -int
 | 
| -gnu_write_inferior (task_t task, CORE_ADDR addr, char *myaddr, int length)
 | 
| +static int
 | 
| +gnu_write_inferior (task_t task, CORE_ADDR addr,
 | 
| +		    const gdb_byte *myaddr, int length)
 | 
|  {
 | 
|    error_t err = 0;
 | 
|    vm_address_t low_address = (vm_address_t) trunc_page (addr);
 | 
| @@ -2472,30 +2473,55 @@ out:
 | 
|  }
 | 
|  
 | 
|  
 | 
| -/* Return 0 on failure, number of bytes handled otherwise.  TARGET
 | 
| -   is ignored.  */
 | 
| -static int
 | 
| -gnu_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
 | 
| -		 struct mem_attrib *attrib,
 | 
| -		 struct target_ops *target)
 | 
| +
 | 
| +/* Helper for gnu_xfer_partial that handles memory transfers.  */
 | 
| +
 | 
| +static LONGEST
 | 
| +gnu_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf,
 | 
| +		 CORE_ADDR memaddr, LONGEST len)
 | 
|  {
 | 
|    task_t task = (gnu_current_inf
 | 
|  		 ? (gnu_current_inf->task
 | 
|  		    ? gnu_current_inf->task->port : 0)
 | 
|  		 : 0);
 | 
| +  int res;
 | 
|  
 | 
|    if (task == MACH_PORT_NULL)
 | 
| -    return 0;
 | 
| +    return TARGET_XFER_E_IO;
 | 
| +
 | 
| +  if (writebuf != NULL)
 | 
| +    {
 | 
| +      inf_debug (gnu_current_inf, "writing %s[%s] <-- %s",
 | 
| +		 paddress (target_gdbarch (), memaddr), plongest (len),
 | 
| +		 host_address_to_string (writebuf));
 | 
| +      res = gnu_write_inferior (task, memaddr, writebuf, len);
 | 
| +    }
 | 
|    else
 | 
|      {
 | 
| -      inf_debug (gnu_current_inf, "%s %s[%d] %s %s",
 | 
| -		 write ? "writing" : "reading",
 | 
| -		 paddress (target_gdbarch, memaddr), len,
 | 
| -		 write ? "<--" : "-->", host_address_to_string (myaddr));
 | 
| -      if (write)
 | 
| -	return gnu_write_inferior (task, memaddr, myaddr, len);
 | 
| -      else
 | 
| -	return gnu_read_inferior (task, memaddr, myaddr, len);
 | 
| +      inf_debug (gnu_current_inf, "reading %s[%s] --> %s",
 | 
| +		 paddress (target_gdbarch (), memaddr), plongest (len),
 | 
| +		 host_address_to_string (readbuf));
 | 
| +      res = gnu_read_inferior (task, memaddr, readbuf, len);
 | 
| +    }
 | 
| +  if (res == 0)
 | 
| +    return TARGET_XFER_E_IO;
 | 
| +  return res;
 | 
| +}
 | 
| +
 | 
| +/* Target to_xfer_partial implementation.  */
 | 
| +
 | 
| +static LONGEST
 | 
| +gnu_xfer_partial (struct target_ops *ops, enum target_object object,
 | 
| +		  const char *annex, gdb_byte *readbuf,
 | 
| +		  const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 | 
| +{
 | 
| +  switch (object)
 | 
| +    {
 | 
| +    case TARGET_OBJECT_MEMORY:
 | 
| +      return gnu_xfer_memory (readbuf, writebuf, offset, len);
 | 
| +
 | 
| +    default:
 | 
| +      return -1;
 | 
|      }
 | 
|  }
 | 
|  
 | 
| @@ -2558,6 +2584,7 @@ gnu_find_memory_regions (find_memory_region_ftype func, void *data)
 | 
|  		     last_protection & VM_PROT_READ,
 | 
|  		     last_protection & VM_PROT_WRITE,
 | 
|  		     last_protection & VM_PROT_EXECUTE,
 | 
| +		     1, /* MODIFIED is unknown, pass it as true.  */
 | 
|  		     data);
 | 
|  	  last_region_address = region_address;
 | 
|  	  last_region_end = region_address += region_length;
 | 
| @@ -2571,6 +2598,7 @@ gnu_find_memory_regions (find_memory_region_ftype func, void *data)
 | 
|  	     last_protection & VM_PROT_READ,
 | 
|  	     last_protection & VM_PROT_WRITE,
 | 
|  	     last_protection & VM_PROT_EXECUTE,
 | 
| +	     1, /* MODIFIED is unknown, pass it as true.  */
 | 
|  	     data);
 | 
|  
 | 
|    return 0;
 | 
| @@ -2584,10 +2612,10 @@ proc_string (struct proc *proc)
 | 
|    static char tid_str[80];
 | 
|  
 | 
|    if (proc_is_task (proc))
 | 
| -    sprintf (tid_str, "process %d", proc->inf->pid);
 | 
| +    xsnprintf (tid_str, sizeof (tid_str), "process %d", proc->inf->pid);
 | 
|    else
 | 
| -    sprintf (tid_str, "Thread %d.%d",
 | 
| -	     proc->inf->pid, proc->tid);
 | 
| +    xsnprintf (tid_str, sizeof (tid_str), "Thread %d.%d",
 | 
| +	       proc->inf->pid, proc->tid);
 | 
|    return tid_str;
 | 
|  }
 | 
|  
 | 
| @@ -2595,7 +2623,7 @@ static char *
 | 
|  gnu_pid_to_str (struct target_ops *ops, ptid_t ptid)
 | 
|  {
 | 
|    struct inf *inf = gnu_current_inf;
 | 
| -  int tid = ptid_get_tid (ptid);
 | 
| +  int tid = ptid_get_lwp (ptid);
 | 
|    struct proc *thread = inf_tid_to_thread (inf, tid);
 | 
|  
 | 
|    if (thread)
 | 
| @@ -2604,7 +2632,7 @@ gnu_pid_to_str (struct target_ops *ops, ptid_t ptid)
 | 
|      {
 | 
|        static char tid_str[80];
 | 
|  
 | 
| -      sprintf (tid_str, "bogus thread id %d", tid);
 | 
| +      xsnprintf (tid_str, sizeof (tid_str), "bogus thread id %d", tid);
 | 
|        return tid_str;
 | 
|      }
 | 
|  }
 | 
| @@ -2627,7 +2655,7 @@ gnu_target (void)
 | 
|    t->to_detach = gnu_detach;
 | 
|    t->to_resume = gnu_resume;
 | 
|    t->to_wait = gnu_wait;
 | 
| -  t->deprecated_xfer_memory = gnu_xfer_memory;
 | 
| +  t->to_xfer_partial = gnu_xfer_partial;
 | 
|    t->to_find_memory_regions = gnu_find_memory_regions;
 | 
|    t->to_terminal_init = gnu_terminal_init_inferior;
 | 
|    t->to_kill = gnu_kill_inferior;
 | 
| @@ -2643,8 +2671,8 @@ gnu_target (void)
 | 
|  
 | 
|  /* User task commands.  */
 | 
|  
 | 
| -struct cmd_list_element *set_task_cmd_list = 0;
 | 
| -struct cmd_list_element *show_task_cmd_list = 0;
 | 
| +static struct cmd_list_element *set_task_cmd_list = 0;
 | 
| +static struct cmd_list_element *show_task_cmd_list = 0;
 | 
|  /* User thread commands.  */
 | 
|  
 | 
|  /* Commands with a prefix of `set/show thread'.  */
 | 
| @@ -2728,7 +2756,7 @@ cur_thread (void)
 | 
|  {
 | 
|    struct inf *inf = cur_inf ();
 | 
|    struct proc *thread = inf_tid_to_thread (inf,
 | 
| -					   ptid_get_tid (inferior_ptid));
 | 
| +					   ptid_get_lwp (inferior_ptid));
 | 
|    if (!thread)
 | 
|      error (_("No current thread."));
 | 
|    return thread;
 | 
| @@ -2921,13 +2949,13 @@ set_sig_thread_cmd (char *args, int from_tty)
 | 
|      inf->signal_thread = 0;
 | 
|    else
 | 
|      {
 | 
| -      int tid = ptid_get_tid (thread_id_to_pid (atoi (args)));
 | 
| +      ptid_t ptid = thread_id_to_pid (atoi (args));
 | 
|  
 | 
| -      if (tid < 0)
 | 
| +      if (ptid_equal (ptid, minus_one_ptid))
 | 
|  	error (_("Thread ID %s not known.  "
 | 
|  		 "Use the \"info threads\" command to\n"
 | 
|  	       "see the IDs of currently known threads."), args);
 | 
| -      inf->signal_thread = inf_tid_to_thread (inf, tid);
 | 
| +      inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
 | 
|      }
 | 
|  }
 | 
|  
 | 
| 
 |