407ebe9
Index: gdb-6.8.50.20081209/bfd/elf-bfd.h
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/bfd/elf-bfd.h	2008-12-03 15:50:57.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/bfd/elf-bfd.h	2008-12-10 01:35:08.000000000 +0100
407ebe9
@@ -2154,7 +2154,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
407ebe9
Index: gdb-6.8.50.20081209/bfd/elf.c
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/bfd/elf.c	2008-12-03 15:50:57.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/bfd/elf.c	2008-12-10 01:35:08.000000000 +0100
407ebe9
@@ -8345,6 +8345,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
 {
407ebe9
@@ -8371,9 +8372,15 @@ 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
     }
407ebe9
@@ -8388,9 +8395,15 @@ 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
     }
407ebe9
Index: gdb-6.8.50.20081209/gdb/amd64-linux-nat.c
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/gdb/amd64-linux-nat.c	2008-12-10 01:28:28.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/gdb/amd64-linux-nat.c	2008-12-10 01:35:08.000000000 +0100
3a094fb
@@ -139,6 +139,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
 {
3a094fb
   if (gdbarch_ptr_bit(current_gdbarch) == 32)
3a094fb
@@ -148,14 +149,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
407ebe9
Index: gdb-6.8.50.20081209/gdb/fbsd-nat.c
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/gdb/fbsd-nat.c	2008-10-28 16:22:12.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/gdb/fbsd-nat.c	2008-12-10 01:35:08.000000000 +0100
407ebe9
@@ -210,6 +210,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
 
407ebe9
Index: gdb-6.8.50.20081209/gdb/linux-nat.c
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/gdb/linux-nat.c	2008-12-10 01:28:14.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/gdb/linux-nat.c	2008-12-10 01:35:25.000000000 +0100
407ebe9
@@ -53,6 +53,7 @@
407ebe9
 #include <sys/types.h>
407ebe9
 #include "gdb_dirent.h"
407ebe9
 #include "xml-support.h"
3a094fb
+#include "gdb_procfs32.h"	/* for struct elf_prpsinfo32 */
3a094fb
 
407ebe9
 #ifdef HAVE_PERSONALITY
407ebe9
 # include <sys/personality.h>
407ebe9
@@ -216,7 +217,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 *
407ebe9
@@ -3614,6 +3615,159 @@ linux_nat_corefile_thread_callback (stru
407ebe9
   return 0;
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.  */
3a094fb
+  if (gdbarch_ptr_bit (current_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
3a094fb
+  if (gdbarch_ptr_bit (current_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
 
407ebe9
@@ -3633,8 +3787,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;
407ebe9
@@ -3650,9 +3810,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.  */
407ebe9
Index: gdb-6.8.50.20081209/gdb/linux-nat.h
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/gdb/linux-nat.h	2008-12-10 01:27:33.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/gdb/linux-nat.h	2008-12-10 01:35:08.000000000 +0100
407ebe9
@@ -138,7 +138,7 @@ struct siginfo *linux_nat_get_siginfo (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)
407ebe9
Index: gdb-6.8.50.20081209/gdb/procfs.c
407ebe9
===================================================================
407ebe9
--- gdb-6.8.50.20081209.orig/gdb/procfs.c	2008-11-09 12:27:17.000000000 +0100
407ebe9
+++ gdb-6.8.50.20081209/gdb/procfs.c	2008-12-10 01:35:08.000000000 +0100
407ebe9
@@ -6181,6 +6181,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