1 Index: gdb-7.1.90.20100711/bfd/elf-bfd.h
2 ===================================================================
3 --- gdb-7.1.90.20100711.orig/bfd/elf-bfd.h 2010-06-27 06:07:51.000000000 +0200
4 +++ gdb-7.1.90.20100711/bfd/elf-bfd.h 2010-07-12 23:00:04.000000000 +0200
5 @@ -2171,8 +2171,9 @@ 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);
9 +#include <sys/procfs.h>
10 extern char *elfcore_write_prpsinfo
11 - (bfd *, char *, int *, const char *, const char *);
12 + (bfd *, char *, int *, const prpsinfo_t *);
13 extern char *elfcore_write_prstatus
14 (bfd *, char *, int *, long, int, const void *);
15 extern char * elfcore_write_pstatus
16 Index: gdb-7.1.90.20100711/bfd/elf.c
17 ===================================================================
18 --- gdb-7.1.90.20100711.orig/bfd/elf.c 2010-05-18 05:31:05.000000000 +0200
19 +++ gdb-7.1.90.20100711/bfd/elf.c 2010-07-12 22:51:17.000000000 +0200
20 @@ -8582,13 +8582,12 @@ elfcore_write_note (bfd *abfd,
24 -#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
25 +#if defined (HAVE_PRPSINFO_T)
27 elfcore_write_prpsinfo (bfd *abfd,
32 + const prpsinfo_t *input)
34 const char *note_name = "CORE";
35 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
36 @@ -8596,48 +8595,55 @@ elfcore_write_prpsinfo (bfd *abfd,
37 if (bed->elf_backend_write_core_note != NULL)
40 + char fname[sizeof (input->pr_fname) + 1];
41 + char psargs[sizeof (input->pr_psargs) + 1];
43 + strncpy (fname, input->pr_fname, sizeof (input->pr_fname));
44 + fname[sizeof (input->pr_fname)] = 0;
45 + strncpy (psargs, input->pr_psargs, sizeof (input->pr_psargs));
46 + psargs[sizeof (input->pr_psargs)] = 0;
48 ret = (*bed->elf_backend_write_core_note) (abfd, buf, bufsiz,
49 NT_PRPSINFO, fname, psargs);
54 -#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
55 +#if defined (HAVE_PRPSINFO32_T)
56 if (bed->s->elfclass == ELFCLASS32)
58 -#if defined (HAVE_PSINFO32_T)
60 - int note_type = NT_PSINFO;
63 int note_type = NT_PRPSINFO;
66 memset (&data, 0, sizeof (data));
67 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
68 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
69 + data.pr_state = input->pr_state;
70 + data.pr_sname = input->pr_sname;
71 + data.pr_zomb = input->pr_zomb;
72 + data.pr_nice = input->pr_nice;
73 + data.pr_flag = input->pr_flag;
74 + data.pr_uid = input->pr_uid;
75 + data.pr_gid = input->pr_gid;
76 + data.pr_pid = input->pr_pid;
77 + data.pr_ppid = input->pr_ppid;
78 + data.pr_pgrp = input->pr_pgrp;
79 + data.pr_sid = input->pr_sid;
80 + BFD_ASSERT (sizeof (data.pr_fname) == sizeof (input->pr_fname));
81 + memcpy (data.pr_fname, input->pr_fname, sizeof (data.pr_fname));
82 + BFD_ASSERT (sizeof (data.pr_psargs) == sizeof (input->pr_psargs));
83 + memcpy (data.pr_psargs, input->pr_psargs, sizeof (data.pr_psargs));
84 return elfcore_write_note (abfd, buf, bufsiz,
85 note_name, note_type, &data, sizeof (data));
90 -#if defined (HAVE_PSINFO_T)
92 - int note_type = NT_PSINFO;
95 int note_type = NT_PRPSINFO;
98 - memset (&data, 0, sizeof (data));
99 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
100 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
101 return elfcore_write_note (abfd, buf, bufsiz,
102 - note_name, note_type, &data, sizeof (data));
103 + note_name, note_type, input, sizeof (*input));
106 -#endif /* PSINFO_T or PRPSINFO_T */
107 +#endif /* PRPSINFO_T */
109 #if defined (HAVE_PRSTATUS_T)
111 Index: gdb-7.1.90.20100711/gdb/linux-nat.c
112 ===================================================================
113 --- gdb-7.1.90.20100711.orig/gdb/linux-nat.c 2010-07-12 23:05:22.000000000 +0200
114 +++ gdb-7.1.90.20100711/gdb/linux-nat.c 2010-07-12 22:57:34.000000000 +0200
115 @@ -4466,6 +4466,131 @@ linux_spu_make_corefile_notes (bfd *obfd
116 return args.note_data;
119 +/* Should be always true for Linux */
120 +#define HAVE_PRPSINFO_T 1
122 +#if defined (HAVE_PRPSINFO_T)
124 +/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
125 + binfmt_elf.c. Unknown values are filled with zeroes. The structure is
128 +static const prpsinfo_t *
129 +fill_prpsinfo (void)
132 + char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
134 + char proc_state[5];
135 + char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
138 + unsigned proc_ppid;
139 + unsigned proc_pgid;
143 + char *cp, *proc_comm, *state_s;
144 + /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
145 + obsolete there to <linux/sched.h> TASK_* constants. */
146 + const char state_string[] = "RSDTZW";
148 + static prpsinfo_t retval;
150 + /* Get /proc/$PID/stat. */
151 + pid = ptid_get_pid (inferior_ptid);
152 + sprintf (filename, "/proc/%u/stat", (unsigned)pid);
153 + fd = open (filename, O_RDONLY);
156 + fstat (fd, &sb); /* No error checking (can it ever happen?). */
157 + n = read (fd, buf, sizeof (buf) - 1);
163 + cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
169 + proc_comm = strchr (buf, '(');
174 + /* Read /proc/$PID/cmdline. */
175 + proc_cmdline[0] = 0;
176 + strcpy (strrchr (filename, '/'), "/cmdline");
177 + fd = open (filename, O_RDONLY);
182 + n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
185 + proc_cmdline[n] = 0;
186 + while (n--) /* Replace NULs with spaces. */
187 + if (proc_cmdline[n] == 0)
188 + proc_cmdline[n] = ' ';
192 + /* Parse /proc/$PID/stat. */
193 + n = sscanf (cp + 2, /* skip ") " */
194 + "%4s %u " /* state, ppid */
195 + "%u %u %*s %*s " /* pgid, sid, tty, tpgid */
196 + "%u %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt */
197 + "%*s " /* cmaj_flt */
198 + "%*s %*s " /* utime, stime */
199 + "%*s %*s %*s " /* cutime, cstime, priority */
201 + /*"%*s %*s " timeout, it_real_value */
202 + /*"%lu " start_time */
205 + /*"%lu %lu %lu " rss_rlim, start_code, end_code */
206 + /*"%lu %lu %lu " start_stack, kstk_esp, kstk_eip */
207 + /*"%u %u %u %u " signal, blocked, sigignore, sigcatch */
208 + /*"%lu %lu %lu" wchan, nswap, cnswap */
209 + , proc_state, &proc_ppid,
210 + &proc_pgid, &proc_sid,
216 + state_s = strchr (state_string, proc_state[0]);
217 + if (state_s != NULL)
218 + state_num = state_s - state_string;
221 + /* 0 means Running, some more unusal state would be better. */
225 + memset (&retval, 0, sizeof (retval));
226 + retval.pr_state = state_num;
227 + retval.pr_sname = proc_state[0];
228 + retval.pr_zomb = (proc_state[0] == 'Z');
229 + retval.pr_nice = proc_nice;
230 + retval.pr_flag = flags;
231 + retval.pr_uid = sb.st_uid;
232 + retval.pr_gid = sb.st_gid;
233 + retval.pr_pid = pid;
234 + retval.pr_ppid = proc_ppid;
235 + retval.pr_pgrp = proc_pgid;
236 + retval.pr_sid = proc_sid;
237 + strncpy (retval.pr_fname, proc_comm, sizeof (retval.pr_fname));
238 + strncpy (retval.pr_psargs, proc_cmdline, sizeof (retval.pr_psargs));
244 /* Fills the "to_make_corefile_note" target vector. Builds the note
245 section for a corefile, and returns it in a malloc buffer. */
247 @@ -4484,26 +4609,11 @@ linux_nat_make_corefile_notes (bfd *obfd
249 if (get_exec_file (0))
251 - strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
252 - strncpy (psargs, get_exec_file (0), sizeof (psargs));
253 - if (get_inferior_args ())
256 - char *psargs_end = psargs + sizeof (psargs);
258 - /* linux_elfcore_write_prpsinfo () handles zero unterminated
260 - string_end = memchr (psargs, 0, sizeof (psargs));
261 - if (string_end != NULL)
263 - *string_end++ = ' ';
264 - strncpy (string_end, get_inferior_args (),
265 - psargs_end - string_end);
268 + const prpsinfo_t *data = fill_prpsinfo ();
270 note_data = (char *) elfcore_write_prpsinfo (obfd,
272 - note_size, fname, psargs);
276 /* Dump information for threads. */
277 Index: gdb-7.1.90.20100711/gdb/procfs.c
278 ===================================================================
279 --- gdb-7.1.90.20100711.orig/gdb/procfs.c 2010-07-07 18:15:16.000000000 +0200
280 +++ gdb-7.1.90.20100711/gdb/procfs.c 2010-07-12 23:05:23.000000000 +0200
281 @@ -5770,6 +5770,7 @@ procfs_make_note_section (bfd *obfd, int
282 note_data = (char *) elfcore_write_prpsinfo (obfd,