ee681d3
Index: gdb-7.1/bfd/elf-bfd.h
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/bfd/elf-bfd.h	2010-02-09 13:14:42.000000000 +0100
ee681d3
+++ gdb-7.1/bfd/elf-bfd.h	2010-05-16 20:22:38.000000000 +0200
ee681d3
@@ -2160,7 +2160,7 @@ extern Elf_Internal_Phdr * _bfd_elf_find
3a094fb
 extern char *elfcore_write_note
3a094fb
   (bfd *, char *, int *, const char *, int, const void *, int);
3a094fb
 extern char *elfcore_write_prpsinfo
3a094fb
-  (bfd *, char *, int *, const char *, const char *);
3a094fb
+  (bfd *, char *, int *, void *, const char *, const char *);
3a094fb
 extern char *elfcore_write_prstatus
3a094fb
   (bfd *, char *, int *, long, int, const void *);
3a094fb
 extern char * elfcore_write_pstatus
ee681d3
Index: gdb-7.1/bfd/elf.c
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/bfd/elf.c	2010-02-18 01:09:06.000000000 +0100
ee681d3
+++ gdb-7.1/bfd/elf.c	2010-05-16 20:25:15.000000000 +0200
ee681d3
@@ -8545,6 +8545,7 @@ char *
3a094fb
 elfcore_write_prpsinfo (bfd  *abfd,
3a094fb
 			char *buf,
3a094fb
 			int  *bufsiz,
3a094fb
+			void *info,
3a094fb
 			const char *fname,
3a094fb
 			const char *psargs)
3a094fb
 {
ee681d3
@@ -8571,26 +8572,40 @@ elfcore_write_prpsinfo (bfd  *abfd,
3a094fb
       int note_type = NT_PRPSINFO;
3a094fb
 #endif
3a094fb
 
3a094fb
-      memset (&data, 0, sizeof (data));
3a094fb
-      strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
-      strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+      if (info)
3a094fb
+	memcpy (&data, info, sizeof (data));
3a094fb
+      else
3a094fb
+	{
3a094fb
+	  memset (&data, 0, sizeof (data));
3a094fb
+	  strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
+	  strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+	}
3a094fb
+
3a094fb
       return elfcore_write_note (abfd, buf, bufsiz,
3a094fb
 				 note_name, note_type, &data, sizeof (data));
3a094fb
     }
ee681d3
   else
ee681d3
 #endif
ee681d3
     {
ee681d3
+/* gdb-6.8-bz254229-gcore-prpsinfo.patch misapplication glue.  */
ee681d3
 #if defined (HAVE_PSINFO_T)
ee681d3
       psinfo_t data;
ee681d3
+/* gdb-6.8-bz254229-gcore-prpsinfo.patch misapplication glue.  */
ee681d3
       int note_type = NT_PSINFO;
ee681d3
 #else
ee681d3
       prpsinfo_t data;
3a094fb
       int note_type = NT_PRPSINFO;
3a094fb
 #endif
3a094fb
 
3a094fb
-      memset (&data, 0, sizeof (data));
3a094fb
-      strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
-      strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+      if (info)
3a094fb
+	memcpy (&data, info, sizeof (data));
3a094fb
+      else
3a094fb
+	{
3a094fb
+	  memset (&data, 0, sizeof (data));
3a094fb
+	  strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
+	  strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+	}
3a094fb
+
3a094fb
       return elfcore_write_note (abfd, buf, bufsiz,
3a094fb
 				 note_name, note_type, &data, sizeof (data));
3a094fb
     }
ee681d3
Index: gdb-7.1/gdb/amd64-linux-nat.c
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/gdb/amd64-linux-nat.c	2010-05-16 20:22:38.000000000 +0200
ee681d3
+++ gdb-7.1/gdb/amd64-linux-nat.c	2010-05-16 20:22:38.000000000 +0200
e5611bf
@@ -140,6 +140,7 @@ static int amd64_linux_gregset32_reg_off
3a094fb
 
3a094fb
 static char *
3a094fb
 amd64_linux_elfcore_write_prpsinfo (bfd *abfd, char *buf, int *bufsiz,
3a094fb
+				    void *info,
3a094fb
 				    const char *fname, const char *psargs)
3a094fb
 {
e5611bf
   if (gdbarch_ptr_bit (target_gdbarch) == 32)
e5611bf
@@ -149,14 +150,20 @@ amd64_linux_elfcore_write_prpsinfo (bfd 
3a094fb
       struct elf_prpsinfo32 data;
3a094fb
       note_type = NT_PRPSINFO;
3a094fb
 
3a094fb
-      memset (&data, 0, sizeof (data));
3a094fb
-      strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
-      strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+      if (info)
3a094fb
+	memcpy (&data, info, sizeof (data));
3a094fb
+      else
3a094fb
+	{
3a094fb
+	  memset (&data, 0, sizeof (data));
3a094fb
+	  strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
3a094fb
+	  strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a094fb
+	}
3a094fb
+
3a094fb
       return elfcore_write_note (abfd, buf, bufsiz,
3a094fb
 				 note_name, note_type, &data, sizeof (data));
3a094fb
     }
3a094fb
   else
3a094fb
-    return elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs);
3a094fb
+    return elfcore_write_prpsinfo (abfd, buf, bufsiz, info, fname, psargs);
3a094fb
 }
3a094fb
 
3a094fb
 static void
ee681d3
Index: gdb-7.1/gdb/fbsd-nat.c
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/gdb/fbsd-nat.c	2010-01-01 08:31:31.000000000 +0100
ee681d3
+++ gdb-7.1/gdb/fbsd-nat.c	2010-05-16 20:22:38.000000000 +0200
e5611bf
@@ -211,6 +211,7 @@ fbsd_make_corefile_notes (bfd *obfd, int
3a094fb
 	psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL);
3a094fb
 
3a094fb
       note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
3a094fb
+				          NULL,
3a094fb
 					  fname, psargs);
3a094fb
     }
3a094fb
 
ee681d3
Index: gdb-7.1/gdb/linux-nat.c
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/gdb/linux-nat.c	2010-05-16 20:22:38.000000000 +0200
ee681d3
+++ gdb-7.1/gdb/linux-nat.c	2010-05-16 20:22:38.000000000 +0200
8c4c91e
@@ -56,6 +56,7 @@
e5611bf
 #include "terminal.h"
e5611bf
 #include <sys/vfs.h>
8c4c91e
 #include "solib.h"
3a094fb
+#include "gdb_procfs32.h"	/* for struct elf_prpsinfo32 */
3a094fb
 
e5611bf
 #ifndef SPUFS_MAGIC
e5611bf
 #define SPUFS_MAGIC 0x23c9b64e
8c4c91e
@@ -228,7 +229,7 @@ static LONGEST (*super_xfer_partial) (st
3a094fb
 /* This functions make elfcore note sections.
3a094fb
    They may get overriden by code adjusting data for multi-target builds.  */
3a094fb
 char *(*linux_elfcore_write_prpsinfo)
3a094fb
-  (bfd *, char *, int *, const char *, const char *) = elfcore_write_prpsinfo;
3a094fb
+  (bfd *, char *, int *, void *, const char *, const char *) = elfcore_write_prpsinfo;
3a094fb
 char *(*linux_elfcore_write_prstatus)
3a094fb
   (bfd *, char *, int *, long, int, const void *) = elfcore_write_prstatus;
3a094fb
 static char *
ee681d3
@@ -4507,6 +4508,159 @@ linux_spu_make_corefile_notes (bfd *obfd
e5611bf
   return args.note_data;
3a094fb
 }
3a094fb
 
3a094fb
+/* Should be always true for Linux */
3a094fb
+#define HAVE_PRPSINFO_T 1
3a094fb
+
3a094fb
+#if defined (HAVE_PRPSINFO_T)
3a094fb
+
3a094fb
+/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
3a094fb
+   binfmt_elf.c.  Unknown values are filled with zeroes.  The structure is
3a094fb
+   malloced.  */
3a094fb
+
3a094fb
+static void*
3a094fb
+fill_prpsinfo (void)
3a094fb
+{
3a094fb
+  struct stat sb;
3a094fb
+  char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
3a094fb
+  char buf[1024];
3a094fb
+  char proc_state[5];
3a094fb
+  char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
3a094fb
+  unsigned flags;
3a094fb
+  long proc_nice;
3a094fb
+  unsigned proc_ppid;
3a094fb
+  unsigned proc_pgid;
3a094fb
+  unsigned proc_sid;
3a094fb
+  pid_t pid;
3a094fb
+  int fd, n;
3a094fb
+  char *cp, *proc_comm, *state_s;
3a094fb
+  /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
3a094fb
+     obsolete there to <linux/sched.h> TASK_* constants.  */
3a094fb
+  const char state_string[] = "RSDTZW";
3a094fb
+  int state_num;
3a094fb
+
3a094fb
+  /* Get /proc/$PID/stat.  */
3a094fb
+  pid = ptid_get_pid (inferior_ptid);
3a094fb
+  sprintf (filename, "/proc/%u/stat", (unsigned)pid);
3a094fb
+  fd = open (filename, O_RDONLY);
3a094fb
+  if (fd < 0)
3a094fb
+    return NULL;
3a094fb
+  fstat (fd, &sb); /* No error checking (can it ever happen?).  */
3a094fb
+  n = read (fd, buf, sizeof (buf) - 1);
3a094fb
+  close (fd);
3a094fb
+  if (n < 0)
3a094fb
+    return NULL;
3a094fb
+  buf[n] = 0;
3a094fb
+
3a094fb
+  cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>".  */
3a094fb
+  if (!cp)
3a094fb
+    return NULL;
3a094fb
+  *cp = 0;
3a094fb
+
3a094fb
+  /* Grab COMM.  */
3a094fb
+  proc_comm = strchr (buf, '(');
3a094fb
+  if (!proc_comm)
3a094fb
+    return NULL;
3a094fb
+  proc_comm++;
3a094fb
+
3a094fb
+  /* Read /proc/$PID/cmdline.  */
3a094fb
+  proc_cmdline[0] = 0;
3a094fb
+  strcpy (strrchr (filename, '/'), "/cmdline");
3a094fb
+  fd = open (filename, O_RDONLY);
3a094fb
+  if (fd >= 0)
3a094fb
+    {
3a094fb
+      int n;
3a094fb
+
3a094fb
+      n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
3a094fb
+      if (n < 0)
3a094fb
+	n = 0;
3a094fb
+      proc_cmdline[n] = 0;
3a094fb
+      while (n--) /* Replace NULs with spaces.  */
3a094fb
+	if (proc_cmdline[n] == 0)
3a094fb
+	  proc_cmdline[n] = ' ';
3a094fb
+      close (fd);
3a094fb
+    }
3a094fb
+
3a094fb
+  /* Parse /proc/$PID/stat.  */
3a094fb
+  n = sscanf (cp + 2, /* skip ") " */
3a094fb
+	      "%4s %u "          /* state, ppid */
3a094fb
+	      "%u %u %*s %*s "   /* pgid, sid, tty, tpgid */
3a094fb
+	      "%u %*s %*s %*s "  /* flags, min_flt, cmin_flt, maj_flt */
3a094fb
+	      "%*s "             /* cmaj_flt */
3a094fb
+	      "%*s %*s "         /* utime, stime */
3a094fb
+	      "%*s %*s %*s "     /* cutime, cstime, priority */
3a094fb
+	      "%ld "             /* nice */
3a094fb
+	      /*"%*s %*s "          timeout, it_real_value */
3a094fb
+	      /*"%lu "              start_time */
3a094fb
+	      /*"%lu "              vsize */
3a094fb
+	      /*"%lu "              rss */
3a094fb
+	      /*"%lu %lu %lu "      rss_rlim, start_code, end_code */
3a094fb
+	      /*"%lu %lu %lu "      start_stack, kstk_esp, kstk_eip */
3a094fb
+	      /*"%u %u %u %u "      signal, blocked, sigignore, sigcatch */
3a094fb
+	      /*"%lu %lu %lu"       wchan, nswap, cnswap */
3a094fb
+	      , proc_state, &proc_ppid,
3a094fb
+	      &proc_pgid, &proc_sid,
3a094fb
+	      &flags,
3a094fb
+	      &proc_nice);
3a094fb
+  if (n != 6)
3a094fb
+    return NULL;
3a094fb
+
3a094fb
+  state_s = strchr (state_string, proc_state[0]);
3a094fb
+  if (state_s != NULL)
3a094fb
+    state_num = state_s - state_string;
3a094fb
+  else
3a094fb
+    {
3a094fb
+      /* 0 means Running, some more unusal state would be better.  */
3a094fb
+      state_num = 0;
3a094fb
+    }
3a094fb
+
3a094fb
+#if ULONG_MAX > 0xffffffffU
3a094fb
+  /* We skip this code on 32-bit gdb.  */
e5611bf
+  if (gdbarch_ptr_bit (target_gdbarch) == 64)
3a094fb
+    {
3a094fb
+      struct elf_prpsinfo *info = xzalloc (sizeof (*info));
3a094fb
+
3a094fb
+      info->pr_state = state_num;
3a094fb
+      info->pr_sname = proc_state[0];
3a094fb
+      info->pr_zomb = (proc_state[0] == 'Z');
3a094fb
+      info->pr_nice = proc_nice;
3a094fb
+      info->pr_flag = flags;
3a094fb
+      info->pr_uid = sb.st_uid;
3a094fb
+      info->pr_gid = sb.st_gid;
3a094fb
+      info->pr_pid = pid;
3a094fb
+      info->pr_ppid = proc_ppid;
3a094fb
+      info->pr_pgrp = proc_pgid;
3a094fb
+      info->pr_sid = proc_sid;
3a094fb
+      strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
3a094fb
+      strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
3a094fb
+
3a094fb
+      return info;
3a094fb
+    }
3a094fb
+#endif
e5611bf
+  if (gdbarch_ptr_bit (target_gdbarch) == 32)
3a094fb
+    {
3a094fb
+      struct elf_prpsinfo32 *info = xzalloc (sizeof (*info));
3a094fb
+
3a094fb
+      info->pr_state = state_num;
3a094fb
+      info->pr_sname = proc_state[0];
3a094fb
+      info->pr_zomb = (proc_state[0] == 'Z');
3a094fb
+      info->pr_nice = proc_nice;
3a094fb
+      info->pr_flag = flags;
3a094fb
+      info->pr_uid = sb.st_uid;
3a094fb
+      info->pr_gid = sb.st_gid;
3a094fb
+      info->pr_pid = pid;
3a094fb
+      info->pr_ppid = proc_ppid;
3a094fb
+      info->pr_pgrp = proc_pgid;
3a094fb
+      info->pr_sid = proc_sid;
3a094fb
+      strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
3a094fb
+      strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
3a094fb
+
3a094fb
+      return info;
3a094fb
+    }
3a094fb
+
3a094fb
+  return NULL;
3a094fb
+}
3a094fb
+#endif
3a094fb
+
3a094fb
 /* Fills the "to_make_corefile_note" target vector.  Builds the note
3a094fb
    section for a corefile, and returns it in a malloc buffer.  */
3a094fb
 
ee681d3
@@ -4527,8 +4681,14 @@ linux_nat_make_corefile_notes (bfd *obfd
3a094fb
 
3a094fb
   if (get_exec_file (0))
3a094fb
     {
3a094fb
+#if defined (HAVE_PRPSINFO_T)
3a094fb
+      void *data = fill_prpsinfo ();
3a094fb
+#define DATAPTR data
3a094fb
+#else
3a094fb
+#define DATAPTR NULL
3a094fb
       strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
3a094fb
       strncpy (psargs, get_exec_file (0), sizeof (psargs));
3a094fb
+#endif
3a094fb
       if (get_inferior_args ())
3a094fb
 	{
3a094fb
 	  char *string_end;
ee681d3
@@ -4544,9 +4704,15 @@ linux_nat_make_corefile_notes (bfd *obfd
3a094fb
 		       psargs_end - string_end);
3a094fb
 	    }
3a094fb
 	}
3a094fb
-      note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
3a094fb
-							 note_size, fname,
3a094fb
+      note_data = (char *) linux_elfcore_write_prpsinfo (obfd,
3a094fb
+							 note_data, note_size,
3a094fb
+							 DATAPTR,
3a094fb
+							 fname,
3a094fb
 							 psargs);
3a094fb
+#if defined (HAVE_PRPSINFO_T)
3a094fb
+      xfree (DATAPTR);
3a094fb
+#endif
3a094fb
+#undef DATAPTR
3a094fb
     }
3a094fb
 
3a094fb
   /* Dump information for threads.  */
ee681d3
Index: gdb-7.1/gdb/linux-nat.h
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/gdb/linux-nat.h	2010-05-16 20:22:37.000000000 +0200
ee681d3
+++ gdb-7.1/gdb/linux-nat.h	2010-05-16 20:22:38.000000000 +0200
8c4c91e
@@ -173,7 +173,7 @@ int linux_nat_core_of_thread_1 (ptid_t p
3a094fb
 /* These functions make elfcore note sections.
3a094fb
    They may get overriden by code adjusting data for multi-target builds.  */
3a094fb
 extern char *(*linux_elfcore_write_prpsinfo)
3a094fb
-  (bfd *, char *, int *, const char *, const char *);
3a094fb
+  (bfd *, char *, int *, void *, const char *, const char *);
3a094fb
 extern char *(*linux_elfcore_write_prstatus)
3a094fb
   (bfd *, char *, int *, long, int, const void *);
3a094fb
 extern char *(*linux_elfcore_write_prfpreg)
ee681d3
Index: gdb-7.1/gdb/procfs.c
407ebe9
===================================================================
ee681d3
--- gdb-7.1.orig/gdb/procfs.c	2010-02-15 18:35:49.000000000 +0100
ee681d3
+++ gdb-7.1/gdb/procfs.c	2010-05-16 20:22:38.000000000 +0200
ee681d3
@@ -6184,6 +6184,7 @@ procfs_make_note_section (bfd *obfd, int
3a094fb
   note_data = (char *) elfcore_write_prpsinfo (obfd,
3a094fb
 					       note_data,
3a094fb
 					       note_size,
3a094fb
+					       NULL,
3a094fb
 					       fname,
3a094fb
 					       psargs);
3a094fb