1 Index: gdb-7.4.50.20120602/bfd/elf-bfd.h
2 ===================================================================
3 --- gdb-7.4.50.20120602.orig/bfd/elf-bfd.h 2012-06-02 21:26:09.928717069 +0200
4 +++ gdb-7.4.50.20120602/bfd/elf-bfd.h 2012-06-02 21:27:21.727689625 +0200
5 @@ -2221,8 +2221,10 @@ extern Elf_Internal_Phdr * _bfd_elf_find
6 /* Exported interface for writing elf corefile notes. */
7 extern char *elfcore_write_note
8 (bfd *, char *, int *, const char *, int, const void *, int);
10 +typedef struct elf_prpsinfo prpsinfo_t;
11 extern char *elfcore_write_prpsinfo
12 - (bfd *, char *, int *, const char *, const char *);
13 + (bfd *, char *, int *, const prpsinfo_t *);
14 extern char *elfcore_write_prstatus
15 (bfd *, char *, int *, long, int, const void *);
16 extern char * elfcore_write_pstatus
17 Index: gdb-7.4.50.20120602/bfd/elf.c
18 ===================================================================
19 --- gdb-7.4.50.20120602.orig/bfd/elf.c 2012-06-02 21:26:09.928717069 +0200
20 +++ gdb-7.4.50.20120602/bfd/elf.c 2012-06-02 21:27:21.732689623 +0200
21 @@ -8917,56 +8917,61 @@ char *
22 elfcore_write_prpsinfo (bfd *abfd,
27 + const prpsinfo_t *input)
29 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
31 if (bed->elf_backend_write_core_note != NULL)
34 + char fname[sizeof (input->pr_fname) + 1];
35 + char psargs[sizeof (input->pr_psargs) + 1];
37 + strncpy (fname, input->pr_fname, sizeof (input->pr_fname));
38 + fname[sizeof (input->pr_fname)] = 0;
39 + strncpy (psargs, input->pr_psargs, sizeof (input->pr_psargs));
40 + psargs[sizeof (input->pr_psargs)] = 0;
42 ret = (*bed->elf_backend_write_core_note) (abfd, buf, bufsiz,
43 NT_PRPSINFO, fname, psargs);
48 -#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
49 -#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
50 +#if defined (HAVE_PRPSINFO_T)
51 +#if defined (HAVE_PRPSINFO32_T)
52 if (bed->s->elfclass == ELFCLASS32)
54 -#if defined (HAVE_PSINFO32_T)
56 - int note_type = NT_PSINFO;
59 int note_type = NT_PRPSINFO;
62 - memset (&data, 0, sizeof (data));
63 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
64 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
65 + data.pr_state = input->pr_state;
66 + data.pr_sname = input->pr_sname;
67 + data.pr_zomb = input->pr_zomb;
68 + data.pr_nice = input->pr_nice;
69 + data.pr_flag = input->pr_flag;
70 + data.pr_uid = input->pr_uid;
71 + data.pr_gid = input->pr_gid;
72 + data.pr_pid = input->pr_pid;
73 + data.pr_ppid = input->pr_ppid;
74 + data.pr_pgrp = input->pr_pgrp;
75 + data.pr_sid = input->pr_sid;
76 + BFD_ASSERT (sizeof (data.pr_fname) == sizeof (input->pr_fname));
77 + memcpy (data.pr_fname, input->pr_fname, sizeof (data.pr_fname));
78 + BFD_ASSERT (sizeof (data.pr_psargs) == sizeof (input->pr_psargs));
79 + memcpy (data.pr_psargs, input->pr_psargs, sizeof (data.pr_psargs));
80 return elfcore_write_note (abfd, buf, bufsiz,
81 "CORE", note_type, &data, sizeof (data));
86 -#if defined (HAVE_PSINFO_T)
88 - int note_type = NT_PSINFO;
91 int note_type = NT_PRPSINFO;
94 - memset (&data, 0, sizeof (data));
95 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
96 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
97 return elfcore_write_note (abfd, buf, bufsiz,
98 - "CORE", note_type, &data, sizeof (data));
99 + "CORE", note_type, input, sizeof (*input));
101 -#endif /* PSINFO_T or PRPSINFO_T */
102 +#endif /* PRPSINFO_T */
106 Index: gdb-7.4.50.20120602/gdb/procfs.c
107 ===================================================================
108 --- gdb-7.4.50.20120602.orig/gdb/procfs.c 2012-06-02 21:26:09.928717069 +0200
109 +++ gdb-7.4.50.20120602/gdb/procfs.c 2012-06-02 21:27:21.745689618 +0200
110 @@ -5541,6 +5541,7 @@ procfs_make_note_section (bfd *obfd, int
111 note_data = (char *) elfcore_write_prpsinfo (obfd,
118 Index: gdb-7.4.50.20120602/gdb/linux-tdep.c
119 ===================================================================
120 --- gdb-7.4.50.20120602.orig/gdb/linux-tdep.c 2012-06-02 21:26:09.928717069 +0200
121 +++ gdb-7.4.50.20120602/gdb/linux-tdep.c 2012-06-02 21:31:12.051601510 +0200
123 #include "elf-bfd.h" /* for elfcore_write_* */
124 #include "inferior.h"
125 #include "cli/cli-utils.h"
126 +#include <sys/procfs.h>
130 @@ -769,6 +770,131 @@ linux_corefile_thread_callback (struct t
131 return !args->note_data;
134 +/* Should be always true for Linux */
135 +#define HAVE_PRPSINFO_T 1
137 +#if defined (HAVE_PRPSINFO_T)
139 +/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
140 + binfmt_elf.c. Unknown values are filled with zeroes. The structure is
143 +static const prpsinfo_t *
144 +fill_prpsinfo (void)
147 + char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
149 + char proc_state[5];
150 + char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
153 + unsigned proc_ppid;
154 + unsigned proc_pgid;
158 + char *cp, *proc_comm, *state_s;
159 + /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
160 + obsolete there to <linux/sched.h> TASK_* constants. */
161 + const char state_string[] = "RSDTZW";
163 + static prpsinfo_t retval;
165 + /* Get /proc/$PID/stat. */
166 + pid = ptid_get_pid (inferior_ptid);
167 + sprintf (filename, "/proc/%u/stat", (unsigned)pid);
168 + fd = open (filename, O_RDONLY);
171 + fstat (fd, &sb); /* No error checking (can it ever happen?). */
172 + n = read (fd, buf, sizeof (buf) - 1);
178 + cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
184 + proc_comm = strchr (buf, '(');
189 + /* Read /proc/$PID/cmdline. */
190 + proc_cmdline[0] = 0;
191 + strcpy (strrchr (filename, '/'), "/cmdline");
192 + fd = open (filename, O_RDONLY);
197 + n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
200 + proc_cmdline[n] = 0;
201 + while (n--) /* Replace NULs with spaces. */
202 + if (proc_cmdline[n] == 0)
203 + proc_cmdline[n] = ' ';
207 + /* Parse /proc/$PID/stat. */
208 + n = sscanf (cp + 2, /* skip ") " */
209 + "%4s %u " /* state, ppid */
210 + "%u %u %*s %*s " /* pgid, sid, tty, tpgid */
211 + "%u %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt */
212 + "%*s " /* cmaj_flt */
213 + "%*s %*s " /* utime, stime */
214 + "%*s %*s %*s " /* cutime, cstime, priority */
216 + /*"%*s %*s " timeout, it_real_value */
217 + /*"%lu " start_time */
220 + /*"%lu %lu %lu " rss_rlim, start_code, end_code */
221 + /*"%lu %lu %lu " start_stack, kstk_esp, kstk_eip */
222 + /*"%u %u %u %u " signal, blocked, sigignore, sigcatch */
223 + /*"%lu %lu %lu" wchan, nswap, cnswap */
224 + , proc_state, &proc_ppid,
225 + &proc_pgid, &proc_sid,
231 + state_s = strchr (state_string, proc_state[0]);
232 + if (state_s != NULL)
233 + state_num = state_s - state_string;
236 + /* 0 means Running, some more unusal state would be better. */
240 + memset (&retval, 0, sizeof (retval));
241 + retval.pr_state = state_num;
242 + retval.pr_sname = proc_state[0];
243 + retval.pr_zomb = (proc_state[0] == 'Z');
244 + retval.pr_nice = proc_nice;
245 + retval.pr_flag = flags;
246 + retval.pr_uid = sb.st_uid;
247 + retval.pr_gid = sb.st_gid;
248 + retval.pr_pid = pid;
249 + retval.pr_ppid = proc_ppid;
250 + retval.pr_pgrp = proc_pgid;
251 + retval.pr_sid = proc_sid;
252 + strncpy (retval.pr_fname, proc_comm, sizeof (retval.pr_fname));
253 + strncpy (retval.pr_psargs, proc_cmdline, sizeof (retval.pr_psargs));
259 /* Fills the "to_make_corefile_note" target vector. Builds the note
260 section for a corefile, and returns it in a malloc buffer. */
262 @@ -784,16 +910,9 @@ linux_make_corefile_notes (struct gdbarc
263 /* Process information. */
264 if (get_exec_file (0))
266 - const char *fname = lbasename (get_exec_file (0));
267 - char *psargs = xstrdup (fname);
268 + const prpsinfo_t *data = fill_prpsinfo ();
270 - if (get_inferior_args ())
271 - psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
274 - note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
277 + note_data = elfcore_write_prpsinfo (obfd, note_data, note_size, data);