2013-01-19 22:41:55 +00:00
|
|
|
Index: gdb-7.5.50.20130118/bfd/elf-bfd.h
|
2008-12-14 14:05:20 +00:00
|
|
|
===================================================================
|
2013-01-19 22:41:55 +00:00
|
|
|
--- gdb-7.5.50.20130118.orig/bfd/elf-bfd.h 2013-01-18 23:02:54.809004473 +0100
|
|
|
|
+++ gdb-7.5.50.20130118/bfd/elf-bfd.h 2013-01-18 23:02:59.316010755 +0100
|
|
|
|
@@ -2242,8 +2242,10 @@ extern Elf_Internal_Phdr * _bfd_elf_find
|
2010-07-21 21:30:20 +00:00
|
|
|
/* Exported interface for writing elf corefile notes. */
|
2008-08-01 06:36:43 +00:00
|
|
|
extern char *elfcore_write_note
|
|
|
|
(bfd *, char *, int *, const char *, int, const void *, int);
|
2010-12-27 02:25:06 +00:00
|
|
|
+struct elf_prpsinfo;
|
|
|
|
+typedef struct elf_prpsinfo prpsinfo_t;
|
2008-08-01 06:36:43 +00:00
|
|
|
extern char *elfcore_write_prpsinfo
|
|
|
|
- (bfd *, char *, int *, const char *, const char *);
|
2010-07-21 21:30:20 +00:00
|
|
|
+ (bfd *, char *, int *, const prpsinfo_t *);
|
2008-08-01 06:36:43 +00:00
|
|
|
extern char *elfcore_write_prstatus
|
|
|
|
(bfd *, char *, int *, long, int, const void *);
|
|
|
|
extern char * elfcore_write_pstatus
|
2013-01-19 22:41:55 +00:00
|
|
|
Index: gdb-7.5.50.20130118/bfd/elf.c
|
2008-12-14 14:05:20 +00:00
|
|
|
===================================================================
|
2013-01-19 22:41:55 +00:00
|
|
|
--- gdb-7.5.50.20130118.orig/bfd/elf.c 2013-01-18 23:02:54.812004479 +0100
|
|
|
|
+++ gdb-7.5.50.20130118/bfd/elf.c 2013-01-18 23:02:59.319010836 +0100
|
|
|
|
@@ -9103,56 +9103,61 @@ char *
|
2008-08-01 06:36:43 +00:00
|
|
|
elfcore_write_prpsinfo (bfd *abfd,
|
|
|
|
char *buf,
|
|
|
|
int *bufsiz,
|
2010-07-21 21:30:20 +00:00
|
|
|
- const char *fname,
|
|
|
|
- const char *psargs)
|
|
|
|
+ const prpsinfo_t *input)
|
2008-08-01 06:36:43 +00:00
|
|
|
{
|
2010-07-21 21:30:20 +00:00
|
|
|
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
|
2012-06-03 17:40:44 +00:00
|
|
|
|
2010-07-21 21:30:20 +00:00
|
|
|
if (bed->elf_backend_write_core_note != NULL)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
+ char fname[sizeof (input->pr_fname) + 1];
|
|
|
|
+ char psargs[sizeof (input->pr_psargs) + 1];
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
-#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
|
2010-07-21 21:30:20 +00:00
|
|
|
-#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
|
2012-06-03 17:40:44 +00:00
|
|
|
+#if defined (HAVE_PRPSINFO_T)
|
2010-07-21 21:30:20 +00:00
|
|
|
+#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;
|
2008-08-01 06:36:43 +00:00
|
|
|
int note_type = NT_PRPSINFO;
|
2010-07-21 21:30:20 +00:00
|
|
|
-#endif
|
2008-08-01 06:36:43 +00:00
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
- memset (&data, 0, sizeof (data));
|
2008-08-01 06:36:43 +00:00
|
|
|
- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
|
|
|
|
- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
|
2010-07-21 21:30:20 +00:00
|
|
|
+ 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));
|
2008-08-01 06:36:43 +00:00
|
|
|
return elfcore_write_note (abfd, buf, bufsiz,
|
2012-06-03 17:40:44 +00:00
|
|
|
"CORE", note_type, &data, sizeof (data));
|
2008-08-01 06:36:43 +00:00
|
|
|
}
|
2010-07-11 18:06:33 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2010-07-21 21:30:20 +00:00
|
|
|
-#if defined (HAVE_PSINFO_T)
|
|
|
|
- psinfo_t data;
|
|
|
|
- int note_type = NT_PSINFO;
|
|
|
|
-#else
|
|
|
|
- prpsinfo_t data;
|
2008-08-01 06:36:43 +00:00
|
|
|
int note_type = NT_PRPSINFO;
|
2010-07-21 21:30:20 +00:00
|
|
|
-#endif
|
2008-08-01 06:36:43 +00:00
|
|
|
|
|
|
|
- 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,
|
2012-06-03 17:40:44 +00:00
|
|
|
- "CORE", note_type, &data, sizeof (data));
|
|
|
|
+ "CORE", note_type, input, sizeof (*input));
|
2008-08-01 06:36:43 +00:00
|
|
|
}
|
2010-07-21 21:30:20 +00:00
|
|
|
-#endif /* PSINFO_T or PRPSINFO_T */
|
|
|
|
+#endif /* PRPSINFO_T */
|
2008-08-01 06:36:43 +00:00
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
free (buf);
|
|
|
|
return NULL;
|
2013-01-19 22:41:55 +00:00
|
|
|
Index: gdb-7.5.50.20130118/gdb/procfs.c
|
2012-06-03 17:40:44 +00:00
|
|
|
===================================================================
|
2013-01-19 22:41:55 +00:00
|
|
|
--- gdb-7.5.50.20130118.orig/gdb/procfs.c 2013-01-18 23:02:54.815004487 +0100
|
|
|
|
+++ gdb-7.5.50.20130118/gdb/procfs.c 2013-01-18 23:02:59.320010861 +0100
|
|
|
|
@@ -5502,6 +5502,7 @@ procfs_make_note_section (bfd *obfd, int
|
2012-06-03 17:40:44 +00:00
|
|
|
note_data = (char *) elfcore_write_prpsinfo (obfd,
|
|
|
|
note_data,
|
|
|
|
note_size,
|
|
|
|
+ NULL,
|
|
|
|
fname,
|
|
|
|
psargs);
|
|
|
|
|
2013-01-19 22:41:55 +00:00
|
|
|
Index: gdb-7.5.50.20130118/gdb/linux-tdep.c
|
2008-12-14 14:05:20 +00:00
|
|
|
===================================================================
|
2013-01-19 22:41:55 +00:00
|
|
|
--- gdb-7.5.50.20130118.orig/gdb/linux-tdep.c 2013-01-18 23:02:54.816004489 +0100
|
|
|
|
+++ gdb-7.5.50.20130118/gdb/linux-tdep.c 2013-01-18 23:03:10.727027317 +0100
|
|
|
|
@@ -32,6 +32,7 @@
|
2012-06-03 17:40:44 +00:00
|
|
|
#include "cli/cli-utils.h"
|
2013-01-19 22:41:55 +00:00
|
|
|
#include "arch-utils.h"
|
|
|
|
#include "gdb_obstack.h"
|
2012-06-03 17:40:44 +00:00
|
|
|
+#include <sys/procfs.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2013-01-19 22:41:55 +00:00
|
|
|
@@ -1153,6 +1154,131 @@ linux_corefile_thread_callback (struct t
|
2012-06-03 17:40:44 +00:00
|
|
|
return !args->note_data;
|
2008-08-01 06:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+/* Should be always true for Linux */
|
|
|
|
+#define HAVE_PRPSINFO_T 1
|
|
|
|
+
|
|
|
|
+#if defined (HAVE_PRPSINFO_T)
|
|
|
|
+
|
|
|
|
+/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
|
|
|
|
+ binfmt_elf.c. Unknown values are filled with zeroes. The structure is
|
|
|
|
+ malloced. */
|
|
|
|
+
|
2010-07-21 21:30:20 +00:00
|
|
|
+static const prpsinfo_t *
|
2008-08-01 06:36:43 +00:00
|
|
|
+fill_prpsinfo (void)
|
|
|
|
+{
|
|
|
|
+ struct stat sb;
|
|
|
|
+ char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
|
|
|
|
+ char buf[1024];
|
|
|
|
+ char proc_state[5];
|
|
|
|
+ char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
|
|
|
|
+ unsigned flags;
|
|
|
|
+ long proc_nice;
|
|
|
|
+ unsigned proc_ppid;
|
|
|
|
+ unsigned proc_pgid;
|
|
|
|
+ unsigned proc_sid;
|
|
|
|
+ pid_t pid;
|
|
|
|
+ int fd, n;
|
|
|
|
+ char *cp, *proc_comm, *state_s;
|
|
|
|
+ /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
|
|
|
|
+ obsolete there to <linux/sched.h> TASK_* constants. */
|
|
|
|
+ const char state_string[] = "RSDTZW";
|
|
|
|
+ int state_num;
|
2010-07-21 21:30:20 +00:00
|
|
|
+ static prpsinfo_t retval;
|
2008-08-01 06:36:43 +00:00
|
|
|
+
|
|
|
|
+ /* Get /proc/$PID/stat. */
|
|
|
|
+ pid = ptid_get_pid (inferior_ptid);
|
|
|
|
+ sprintf (filename, "/proc/%u/stat", (unsigned)pid);
|
|
|
|
+ fd = open (filename, O_RDONLY);
|
|
|
|
+ if (fd < 0)
|
|
|
|
+ return NULL;
|
|
|
|
+ fstat (fd, &sb); /* No error checking (can it ever happen?). */
|
|
|
|
+ n = read (fd, buf, sizeof (buf) - 1);
|
|
|
|
+ close (fd);
|
|
|
|
+ if (n < 0)
|
|
|
|
+ return NULL;
|
|
|
|
+ buf[n] = 0;
|
|
|
|
+
|
|
|
|
+ cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
|
|
|
|
+ if (!cp)
|
|
|
|
+ return NULL;
|
|
|
|
+ *cp = 0;
|
|
|
|
+
|
|
|
|
+ /* Grab COMM. */
|
|
|
|
+ proc_comm = strchr (buf, '(');
|
|
|
|
+ if (!proc_comm)
|
|
|
|
+ return NULL;
|
|
|
|
+ proc_comm++;
|
|
|
|
+
|
|
|
|
+ /* Read /proc/$PID/cmdline. */
|
|
|
|
+ proc_cmdline[0] = 0;
|
|
|
|
+ strcpy (strrchr (filename, '/'), "/cmdline");
|
|
|
|
+ fd = open (filename, O_RDONLY);
|
|
|
|
+ if (fd >= 0)
|
|
|
|
+ {
|
|
|
|
+ int n;
|
|
|
|
+
|
|
|
|
+ n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
|
|
|
|
+ if (n < 0)
|
|
|
|
+ n = 0;
|
|
|
|
+ proc_cmdline[n] = 0;
|
|
|
|
+ while (n--) /* Replace NULs with spaces. */
|
|
|
|
+ if (proc_cmdline[n] == 0)
|
|
|
|
+ proc_cmdline[n] = ' ';
|
|
|
|
+ close (fd);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Parse /proc/$PID/stat. */
|
|
|
|
+ n = sscanf (cp + 2, /* skip ") " */
|
|
|
|
+ "%4s %u " /* state, ppid */
|
|
|
|
+ "%u %u %*s %*s " /* pgid, sid, tty, tpgid */
|
|
|
|
+ "%u %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt */
|
|
|
|
+ "%*s " /* cmaj_flt */
|
|
|
|
+ "%*s %*s " /* utime, stime */
|
|
|
|
+ "%*s %*s %*s " /* cutime, cstime, priority */
|
|
|
|
+ "%ld " /* nice */
|
|
|
|
+ /*"%*s %*s " timeout, it_real_value */
|
|
|
|
+ /*"%lu " start_time */
|
|
|
|
+ /*"%lu " vsize */
|
|
|
|
+ /*"%lu " rss */
|
|
|
|
+ /*"%lu %lu %lu " rss_rlim, start_code, end_code */
|
|
|
|
+ /*"%lu %lu %lu " start_stack, kstk_esp, kstk_eip */
|
|
|
|
+ /*"%u %u %u %u " signal, blocked, sigignore, sigcatch */
|
|
|
|
+ /*"%lu %lu %lu" wchan, nswap, cnswap */
|
|
|
|
+ , proc_state, &proc_ppid,
|
|
|
|
+ &proc_pgid, &proc_sid,
|
|
|
|
+ &flags,
|
|
|
|
+ &proc_nice);
|
|
|
|
+ if (n != 6)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ state_s = strchr (state_string, proc_state[0]);
|
|
|
|
+ if (state_s != NULL)
|
|
|
|
+ state_num = state_s - state_string;
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ /* 0 means Running, some more unusal state would be better. */
|
|
|
|
+ state_num = 0;
|
|
|
|
+ }
|
|
|
|
+
|
2010-07-21 21:30:20 +00:00
|
|
|
+ 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));
|
2008-08-01 06:36:43 +00:00
|
|
|
+
|
2010-07-21 21:30:20 +00:00
|
|
|
+ return &retval;
|
2008-08-01 06:36:43 +00:00
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Fills the "to_make_corefile_note" target vector. Builds the note
|
|
|
|
section for a corefile, and returns it in a malloc buffer. */
|
|
|
|
|
2013-01-19 22:41:55 +00:00
|
|
|
@@ -1168,16 +1294,9 @@ linux_make_corefile_notes (struct gdbarc
|
2012-06-03 17:40:44 +00:00
|
|
|
/* Process information. */
|
2008-08-01 06:36:43 +00:00
|
|
|
if (get_exec_file (0))
|
|
|
|
{
|
2012-06-03 17:40:44 +00:00
|
|
|
- const char *fname = lbasename (get_exec_file (0));
|
|
|
|
- char *psargs = xstrdup (fname);
|
2010-07-21 21:30:20 +00:00
|
|
|
+ const prpsinfo_t *data = fill_prpsinfo ();
|
2008-08-01 06:36:43 +00:00
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
- 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);
|
2008-08-01 06:36:43 +00:00
|
|
|
|
2012-06-03 17:40:44 +00:00
|
|
|
if (!note_data)
|
|
|
|
return NULL;
|