-Index: gdb-6.8.50.20081209/bfd/elf-bfd.h
+Index: gdb-7.4.50.20120602/bfd/elf-bfd.h
===================================================================
---- gdb-6.8.50.20081209.orig/bfd/elf-bfd.h 2008-12-03 15:50:57.000000000 +0100
-+++ gdb-6.8.50.20081209/bfd/elf-bfd.h 2008-12-10 01:35:08.000000000 +0100
-@@ -2154,7 +2154,7 @@ extern Elf_Internal_Phdr * _bfd_elf_find
+--- gdb-7.4.50.20120602.orig/bfd/elf-bfd.h 2012-06-02 21:26:09.928717069 +0200
++++ gdb-7.4.50.20120602/bfd/elf-bfd.h 2012-06-02 21:27:21.727689625 +0200
+@@ -2221,8 +2221,10 @@ extern Elf_Internal_Phdr * _bfd_elf_find
+ /* Exported interface for writing elf corefile notes. */
extern char *elfcore_write_note
(bfd *, char *, int *, const char *, int, const void *, int);
++struct elf_prpsinfo;
++typedef struct elf_prpsinfo prpsinfo_t;
extern char *elfcore_write_prpsinfo
- (bfd *, char *, int *, const char *, const char *);
-+ (bfd *, char *, int *, void *, const char *, const char *);
++ (bfd *, char *, int *, const prpsinfo_t *);
extern char *elfcore_write_prstatus
(bfd *, char *, int *, long, int, const void *);
extern char * elfcore_write_pstatus
-Index: gdb-6.8.50.20081209/bfd/elf.c
+Index: gdb-7.4.50.20120602/bfd/elf.c
===================================================================
---- gdb-6.8.50.20081209.orig/bfd/elf.c 2008-12-03 15:50:57.000000000 +0100
-+++ gdb-6.8.50.20081209/bfd/elf.c 2008-12-10 01:35:08.000000000 +0100
-@@ -8345,6 +8345,7 @@ char *
+--- gdb-7.4.50.20120602.orig/bfd/elf.c 2012-06-02 21:26:09.928717069 +0200
++++ gdb-7.4.50.20120602/bfd/elf.c 2012-06-02 21:27:21.732689623 +0200
+@@ -8917,56 +8917,61 @@ char *
elfcore_write_prpsinfo (bfd *abfd,
char *buf,
int *bufsiz,
-+ void *info,
- const char *fname,
- const char *psargs)
+- const char *fname,
+- const char *psargs)
++ const prpsinfo_t *input)
{
-@@ -8371,9 +8372,15 @@ elfcore_write_prpsinfo (bfd *abfd,
- int note_type = NT_PRPSINFO;
- #endif
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-- memset (&data, 0, sizeof (data));
-- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
-- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ if (info)
-+ memcpy (&data, info, sizeof (data));
-+ else
-+ {
-+ memset (&data, 0, sizeof (data));
-+ strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
-+ strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ }
+ if (bed->elf_backend_write_core_note != NULL)
+ {
+ char *ret;
++ char fname[sizeof (input->pr_fname) + 1];
++ char psargs[sizeof (input->pr_psargs) + 1];
+
- return elfcore_write_note (abfd, buf, bufsiz,
- note_name, note_type, &data, sizeof (data));
++ strncpy (fname, input->pr_fname, sizeof (input->pr_fname));
++ fname[sizeof (input->pr_fname)] = 0;
++ strncpy (psargs, input->pr_psargs, sizeof (input->pr_psargs));
++ psargs[sizeof (input->pr_psargs)] = 0;
++
+ ret = (*bed->elf_backend_write_core_note) (abfd, buf, bufsiz,
+ NT_PRPSINFO, fname, psargs);
+ if (ret != NULL)
+ return ret;
}
-@@ -8388,9 +8395,15 @@ elfcore_write_prpsinfo (bfd *abfd,
+
+-#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
+-#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
++#if defined (HAVE_PRPSINFO_T)
++#if defined (HAVE_PRPSINFO32_T)
+ if (bed->s->elfclass == ELFCLASS32)
+ {
+-#if defined (HAVE_PSINFO32_T)
+- psinfo32_t data;
+- int note_type = NT_PSINFO;
+-#else
+ prpsinfo32_t data;
int note_type = NT_PRPSINFO;
- #endif
+-#endif
- memset (&data, 0, sizeof (data));
- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ if (info)
-+ memcpy (&data, info, sizeof (data));
-+ else
-+ {
-+ memset (&data, 0, sizeof (data));
-+ strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
-+ strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ }
-+
++ data.pr_state = input->pr_state;
++ data.pr_sname = input->pr_sname;
++ data.pr_zomb = input->pr_zomb;
++ data.pr_nice = input->pr_nice;
++ data.pr_flag = input->pr_flag;
++ data.pr_uid = input->pr_uid;
++ data.pr_gid = input->pr_gid;
++ data.pr_pid = input->pr_pid;
++ data.pr_ppid = input->pr_ppid;
++ data.pr_pgrp = input->pr_pgrp;
++ data.pr_sid = input->pr_sid;
++ BFD_ASSERT (sizeof (data.pr_fname) == sizeof (input->pr_fname));
++ memcpy (data.pr_fname, input->pr_fname, sizeof (data.pr_fname));
++ BFD_ASSERT (sizeof (data.pr_psargs) == sizeof (input->pr_psargs));
++ memcpy (data.pr_psargs, input->pr_psargs, sizeof (data.pr_psargs));
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, note_type, &data, sizeof (data));
+ "CORE", note_type, &data, sizeof (data));
}
-Index: gdb-6.8.50.20081209/gdb/amd64-linux-nat.c
-===================================================================
---- gdb-6.8.50.20081209.orig/gdb/amd64-linux-nat.c 2008-12-10 01:28:28.000000000 +0100
-+++ gdb-6.8.50.20081209/gdb/amd64-linux-nat.c 2008-12-10 01:35:08.000000000 +0100
-@@ -139,6 +139,7 @@ static int amd64_linux_gregset32_reg_off
-
- static char *
- amd64_linux_elfcore_write_prpsinfo (bfd *abfd, char *buf, int *bufsiz,
-+ void *info,
- const char *fname, const char *psargs)
- {
- if (gdbarch_ptr_bit(current_gdbarch) == 32)
-@@ -148,14 +149,20 @@ amd64_linux_elfcore_write_prpsinfo (bfd
- struct elf_prpsinfo32 data;
- note_type = NT_PRPSINFO;
+ else
+ #endif
+ {
+-#if defined (HAVE_PSINFO_T)
+- psinfo_t data;
+- int note_type = NT_PSINFO;
+-#else
+- prpsinfo_t data;
+ int note_type = NT_PRPSINFO;
+-#endif
- memset (&data, 0, sizeof (data));
- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ if (info)
-+ memcpy (&data, info, sizeof (data));
-+ else
-+ {
-+ memset (&data, 0, sizeof (data));
-+ strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
-+ strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
-+ }
-+
return elfcore_write_note (abfd, buf, bufsiz,
- note_name, note_type, &data, sizeof (data));
+- "CORE", note_type, &data, sizeof (data));
++ "CORE", note_type, input, sizeof (*input));
}
- else
-- return elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs);
-+ return elfcore_write_prpsinfo (abfd, buf, bufsiz, info, fname, psargs);
- }
+-#endif /* PSINFO_T or PRPSINFO_T */
++#endif /* PRPSINFO_T */
- static void
-Index: gdb-6.8.50.20081209/gdb/fbsd-nat.c
+ free (buf);
+ return NULL;
+Index: gdb-7.4.50.20120602/gdb/procfs.c
===================================================================
---- gdb-6.8.50.20081209.orig/gdb/fbsd-nat.c 2008-10-28 16:22:12.000000000 +0100
-+++ gdb-6.8.50.20081209/gdb/fbsd-nat.c 2008-12-10 01:35:08.000000000 +0100
-@@ -210,6 +210,7 @@ fbsd_make_corefile_notes (bfd *obfd, int
- psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL);
-
- note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
-+ NULL,
- fname, psargs);
- }
+--- gdb-7.4.50.20120602.orig/gdb/procfs.c 2012-06-02 21:26:09.928717069 +0200
++++ gdb-7.4.50.20120602/gdb/procfs.c 2012-06-02 21:27:21.745689618 +0200
+@@ -5541,6 +5541,7 @@ procfs_make_note_section (bfd *obfd, int
+ note_data = (char *) elfcore_write_prpsinfo (obfd,
+ note_data,
+ note_size,
++ NULL,
+ fname,
+ psargs);
-Index: gdb-6.8.50.20081209/gdb/linux-nat.c
+Index: gdb-7.4.50.20120602/gdb/linux-tdep.c
===================================================================
---- gdb-6.8.50.20081209.orig/gdb/linux-nat.c 2008-12-10 01:28:14.000000000 +0100
-+++ gdb-6.8.50.20081209/gdb/linux-nat.c 2008-12-10 01:35:25.000000000 +0100
-@@ -53,6 +53,7 @@
- #include <sys/types.h>
- #include "gdb_dirent.h"
- #include "xml-support.h"
-+#include "gdb_procfs32.h" /* for struct elf_prpsinfo32 */
+--- gdb-7.4.50.20120602.orig/gdb/linux-tdep.c 2012-06-02 21:26:09.928717069 +0200
++++ gdb-7.4.50.20120602/gdb/linux-tdep.c 2012-06-02 21:31:12.051601510 +0200
+@@ -30,6 +30,7 @@
+ #include "elf-bfd.h" /* for elfcore_write_* */
+ #include "inferior.h"
+ #include "cli/cli-utils.h"
++#include <sys/procfs.h>
- #ifdef HAVE_PERSONALITY
- # include <sys/personality.h>
-@@ -216,7 +217,7 @@ static LONGEST (*super_xfer_partial) (st
- /* This functions make elfcore note sections.
- They may get overriden by code adjusting data for multi-target builds. */
- char *(*linux_elfcore_write_prpsinfo)
-- (bfd *, char *, int *, const char *, const char *) = elfcore_write_prpsinfo;
-+ (bfd *, char *, int *, void *, const char *, const char *) = elfcore_write_prpsinfo;
- char *(*linux_elfcore_write_prstatus)
- (bfd *, char *, int *, long, int, const void *) = elfcore_write_prstatus;
- static char *
-@@ -3614,6 +3615,159 @@ linux_nat_corefile_thread_callback (stru
- return 0;
+ #include <ctype.h>
+
+@@ -769,6 +770,131 @@ linux_corefile_thread_callback (struct t
+ return !args->note_data;
}
+/* Should be always true for Linux */
+ binfmt_elf.c. Unknown values are filled with zeroes. The structure is
+ malloced. */
+
-+static void*
++static const prpsinfo_t *
+fill_prpsinfo (void)
+{
+ struct stat sb;
+ obsolete there to <linux/sched.h> TASK_* constants. */
+ const char state_string[] = "RSDTZW";
+ int state_num;
++ static prpsinfo_t retval;
+
+ /* Get /proc/$PID/stat. */
+ pid = ptid_get_pid (inferior_ptid);
+ state_num = 0;
+ }
+
-+#if ULONG_MAX > 0xffffffffU
-+ /* We skip this code on 32-bit gdb. */
-+ if (gdbarch_ptr_bit (current_gdbarch) == 64)
-+ {
-+ struct elf_prpsinfo *info = xzalloc (sizeof (*info));
-+
-+ info->pr_state = state_num;
-+ info->pr_sname = proc_state[0];
-+ info->pr_zomb = (proc_state[0] == 'Z');
-+ info->pr_nice = proc_nice;
-+ info->pr_flag = flags;
-+ info->pr_uid = sb.st_uid;
-+ info->pr_gid = sb.st_gid;
-+ info->pr_pid = pid;
-+ info->pr_ppid = proc_ppid;
-+ info->pr_pgrp = proc_pgid;
-+ info->pr_sid = proc_sid;
-+ strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
-+ strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
-+
-+ return info;
-+ }
-+#endif
-+ if (gdbarch_ptr_bit (current_gdbarch) == 32)
-+ {
-+ struct elf_prpsinfo32 *info = xzalloc (sizeof (*info));
-+
-+ info->pr_state = state_num;
-+ info->pr_sname = proc_state[0];
-+ info->pr_zomb = (proc_state[0] == 'Z');
-+ info->pr_nice = proc_nice;
-+ info->pr_flag = flags;
-+ info->pr_uid = sb.st_uid;
-+ info->pr_gid = sb.st_gid;
-+ info->pr_pid = pid;
-+ info->pr_ppid = proc_ppid;
-+ info->pr_pgrp = proc_pgid;
-+ info->pr_sid = proc_sid;
-+ strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
-+ strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
++ memset (&retval, 0, sizeof (retval));
++ retval.pr_state = state_num;
++ retval.pr_sname = proc_state[0];
++ retval.pr_zomb = (proc_state[0] == 'Z');
++ retval.pr_nice = proc_nice;
++ retval.pr_flag = flags;
++ retval.pr_uid = sb.st_uid;
++ retval.pr_gid = sb.st_gid;
++ retval.pr_pid = pid;
++ retval.pr_ppid = proc_ppid;
++ retval.pr_pgrp = proc_pgid;
++ retval.pr_sid = proc_sid;
++ strncpy (retval.pr_fname, proc_comm, sizeof (retval.pr_fname));
++ strncpy (retval.pr_psargs, proc_cmdline, sizeof (retval.pr_psargs));
+
-+ return info;
-+ }
-+
-+ return NULL;
++ return &retval;
+}
+#endif
+
/* Fills the "to_make_corefile_note" target vector. Builds the note
section for a corefile, and returns it in a malloc buffer. */
-@@ -3633,8 +3787,14 @@ linux_nat_make_corefile_notes (bfd *obfd
-
+@@ -784,16 +910,9 @@ linux_make_corefile_notes (struct gdbarc
+ /* Process information. */
if (get_exec_file (0))
{
-+#if defined (HAVE_PRPSINFO_T)
-+ void *data = fill_prpsinfo ();
-+#define DATAPTR data
-+#else
-+#define DATAPTR NULL
- strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
- strncpy (psargs, get_exec_file (0), sizeof (psargs));
-+#endif
- if (get_inferior_args ())
- {
- char *string_end;
-@@ -3650,9 +3810,15 @@ linux_nat_make_corefile_notes (bfd *obfd
- psargs_end - string_end);
- }
- }
-- note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
-- note_size, fname,
-+ note_data = (char *) linux_elfcore_write_prpsinfo (obfd,
-+ note_data, note_size,
-+ DATAPTR,
-+ fname,
- psargs);
-+#if defined (HAVE_PRPSINFO_T)
-+ xfree (DATAPTR);
-+#endif
-+#undef DATAPTR
- }
+- const char *fname = lbasename (get_exec_file (0));
+- char *psargs = xstrdup (fname);
++ const prpsinfo_t *data = fill_prpsinfo ();
- /* Dump information for threads. */
-Index: gdb-6.8.50.20081209/gdb/linux-nat.h
-===================================================================
---- gdb-6.8.50.20081209.orig/gdb/linux-nat.h 2008-12-10 01:27:33.000000000 +0100
-+++ gdb-6.8.50.20081209/gdb/linux-nat.h 2008-12-10 01:35:08.000000000 +0100
-@@ -138,7 +138,7 @@ struct siginfo *linux_nat_get_siginfo (p
- /* These functions make elfcore note sections.
- They may get overriden by code adjusting data for multi-target builds. */
- extern char *(*linux_elfcore_write_prpsinfo)
-- (bfd *, char *, int *, const char *, const char *);
-+ (bfd *, char *, int *, void *, const char *, const char *);
- extern char *(*linux_elfcore_write_prstatus)
- (bfd *, char *, int *, long, int, const void *);
- extern char *(*linux_elfcore_write_prfpreg)
-Index: gdb-6.8.50.20081209/gdb/procfs.c
-===================================================================
---- gdb-6.8.50.20081209.orig/gdb/procfs.c 2008-11-09 12:27:17.000000000 +0100
-+++ gdb-6.8.50.20081209/gdb/procfs.c 2008-12-10 01:35:08.000000000 +0100
-@@ -6181,6 +6181,7 @@ procfs_make_note_section (bfd *obfd, int
- note_data = (char *) elfcore_write_prpsinfo (obfd,
- note_data,
- note_size,
-+ NULL,
- fname,
- psargs);
+- if (get_inferior_args ())
+- psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
+- (char *) NULL);
+-
+- note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
+- fname, psargs);
+- xfree (psargs);
++ note_data = elfcore_write_prpsinfo (obfd, note_data, note_size, data);
+ if (!note_data)
+ return NULL;