1 Index: gdb-6.8.50.20090910/bfd/elf-bfd.h
2 ===================================================================
3 --- gdb-6.8.50.20090910.orig/bfd/elf-bfd.h 2009-09-09 23:38:57.000000000 +0200
4 +++ gdb-6.8.50.20090910/bfd/elf-bfd.h 2009-09-10 23:01:15.000000000 +0200
5 @@ -2121,7 +2121,7 @@ extern Elf_Internal_Phdr * _bfd_elf_find
6 extern char *elfcore_write_note
7 (bfd *, char *, int *, const char *, int, const void *, int);
8 extern char *elfcore_write_prpsinfo
9 - (bfd *, char *, int *, const char *, const char *);
10 + (bfd *, char *, int *, void *, const char *, const char *);
11 extern char *elfcore_write_prstatus
12 (bfd *, char *, int *, long, int, const void *);
13 extern char * elfcore_write_pstatus
14 Index: gdb-6.8.50.20090910/bfd/elf.c
15 ===================================================================
16 --- gdb-6.8.50.20090910.orig/bfd/elf.c 2009-09-09 23:38:57.000000000 +0200
17 +++ gdb-6.8.50.20090910/bfd/elf.c 2009-09-10 23:04:17.000000000 +0200
18 @@ -8398,6 +8398,7 @@ char *
19 elfcore_write_prpsinfo (bfd *abfd,
26 @@ -8424,9 +8425,15 @@ elfcore_write_prpsinfo (bfd *abfd,
27 int note_type = NT_PRPSINFO;
30 - memset (&data, 0, sizeof (data));
31 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
32 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
34 + memcpy (&data, info, sizeof (data));
37 + memset (&data, 0, sizeof (data));
38 + strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
39 + strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
42 return elfcore_write_note (abfd, buf, bufsiz,
43 note_name, note_type, &data, sizeof (data));
45 @@ -8441,9 +8448,15 @@ elfcore_write_prpsinfo (bfd *abfd,
46 int note_type = NT_PRPSINFO;
49 - memset (&data, 0, sizeof (data));
50 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
51 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
53 + memcpy (&data, info, sizeof (data));
56 + memset (&data, 0, sizeof (data));
57 + strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
58 + strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
61 return elfcore_write_note (abfd, buf, bufsiz,
62 note_name, note_type, &data, sizeof (data));
64 Index: gdb-6.8.50.20090910/gdb/amd64-linux-nat.c
65 ===================================================================
66 --- gdb-6.8.50.20090910.orig/gdb/amd64-linux-nat.c 2009-09-10 23:01:07.000000000 +0200
67 +++ gdb-6.8.50.20090910/gdb/amd64-linux-nat.c 2009-09-10 23:01:15.000000000 +0200
68 @@ -140,6 +140,7 @@ static int amd64_linux_gregset32_reg_off
71 amd64_linux_elfcore_write_prpsinfo (bfd *abfd, char *buf, int *bufsiz,
73 const char *fname, const char *psargs)
75 if (gdbarch_ptr_bit (target_gdbarch) == 32)
76 @@ -149,14 +150,20 @@ amd64_linux_elfcore_write_prpsinfo (bfd
77 struct elf_prpsinfo32 data;
78 note_type = NT_PRPSINFO;
80 - memset (&data, 0, sizeof (data));
81 - strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
82 - strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
84 + memcpy (&data, info, sizeof (data));
87 + memset (&data, 0, sizeof (data));
88 + strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
89 + strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
92 return elfcore_write_note (abfd, buf, bufsiz,
93 note_name, note_type, &data, sizeof (data));
96 - return elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs);
97 + return elfcore_write_prpsinfo (abfd, buf, bufsiz, info, fname, psargs);
101 Index: gdb-6.8.50.20090910/gdb/fbsd-nat.c
102 ===================================================================
103 --- gdb-6.8.50.20090910.orig/gdb/fbsd-nat.c 2009-07-02 19:21:06.000000000 +0200
104 +++ gdb-6.8.50.20090910/gdb/fbsd-nat.c 2009-09-10 23:01:15.000000000 +0200
105 @@ -211,6 +211,7 @@ fbsd_make_corefile_notes (bfd *obfd, int
106 psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL);
108 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
113 Index: gdb-6.8.50.20090910/gdb/linux-nat.c
114 ===================================================================
115 --- gdb-6.8.50.20090910.orig/gdb/linux-nat.c 2009-09-10 23:01:06.000000000 +0200
116 +++ gdb-6.8.50.20090910/gdb/linux-nat.c 2009-09-10 23:01:15.000000000 +0200
118 #include "xml-support.h"
119 #include "terminal.h"
121 +#include "gdb_procfs32.h" /* for struct elf_prpsinfo32 */
124 #define SPUFS_MAGIC 0x23c9b64e
125 @@ -222,7 +223,7 @@ static LONGEST (*super_xfer_partial) (st
126 /* This functions make elfcore note sections.
127 They may get overriden by code adjusting data for multi-target builds. */
128 char *(*linux_elfcore_write_prpsinfo)
129 - (bfd *, char *, int *, const char *, const char *) = elfcore_write_prpsinfo;
130 + (bfd *, char *, int *, void *, const char *, const char *) = elfcore_write_prpsinfo;
131 char *(*linux_elfcore_write_prstatus)
132 (bfd *, char *, int *, long, int, const void *) = elfcore_write_prstatus;
134 @@ -3946,6 +3947,159 @@ linux_spu_make_corefile_notes (bfd *obfd
135 return args.note_data;
138 +/* Should be always true for Linux */
139 +#define HAVE_PRPSINFO_T 1
141 +#if defined (HAVE_PRPSINFO_T)
143 +/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
144 + binfmt_elf.c. Unknown values are filled with zeroes. The structure is
148 +fill_prpsinfo (void)
151 + char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
153 + char proc_state[5];
154 + char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
157 + unsigned proc_ppid;
158 + unsigned proc_pgid;
162 + char *cp, *proc_comm, *state_s;
163 + /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
164 + obsolete there to <linux/sched.h> TASK_* constants. */
165 + const char state_string[] = "RSDTZW";
168 + /* Get /proc/$PID/stat. */
169 + pid = ptid_get_pid (inferior_ptid);
170 + sprintf (filename, "/proc/%u/stat", (unsigned)pid);
171 + fd = open (filename, O_RDONLY);
174 + fstat (fd, &sb); /* No error checking (can it ever happen?). */
175 + n = read (fd, buf, sizeof (buf) - 1);
181 + cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
187 + proc_comm = strchr (buf, '(');
192 + /* Read /proc/$PID/cmdline. */
193 + proc_cmdline[0] = 0;
194 + strcpy (strrchr (filename, '/'), "/cmdline");
195 + fd = open (filename, O_RDONLY);
200 + n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
203 + proc_cmdline[n] = 0;
204 + while (n--) /* Replace NULs with spaces. */
205 + if (proc_cmdline[n] == 0)
206 + proc_cmdline[n] = ' ';
210 + /* Parse /proc/$PID/stat. */
211 + n = sscanf (cp + 2, /* skip ") " */
212 + "%4s %u " /* state, ppid */
213 + "%u %u %*s %*s " /* pgid, sid, tty, tpgid */
214 + "%u %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt */
215 + "%*s " /* cmaj_flt */
216 + "%*s %*s " /* utime, stime */
217 + "%*s %*s %*s " /* cutime, cstime, priority */
219 + /*"%*s %*s " timeout, it_real_value */
220 + /*"%lu " start_time */
223 + /*"%lu %lu %lu " rss_rlim, start_code, end_code */
224 + /*"%lu %lu %lu " start_stack, kstk_esp, kstk_eip */
225 + /*"%u %u %u %u " signal, blocked, sigignore, sigcatch */
226 + /*"%lu %lu %lu" wchan, nswap, cnswap */
227 + , proc_state, &proc_ppid,
228 + &proc_pgid, &proc_sid,
234 + state_s = strchr (state_string, proc_state[0]);
235 + if (state_s != NULL)
236 + state_num = state_s - state_string;
239 + /* 0 means Running, some more unusal state would be better. */
243 +#if ULONG_MAX > 0xffffffffU
244 + /* We skip this code on 32-bit gdb. */
245 + if (gdbarch_ptr_bit (target_gdbarch) == 64)
247 + struct elf_prpsinfo *info = xzalloc (sizeof (*info));
249 + info->pr_state = state_num;
250 + info->pr_sname = proc_state[0];
251 + info->pr_zomb = (proc_state[0] == 'Z');
252 + info->pr_nice = proc_nice;
253 + info->pr_flag = flags;
254 + info->pr_uid = sb.st_uid;
255 + info->pr_gid = sb.st_gid;
256 + info->pr_pid = pid;
257 + info->pr_ppid = proc_ppid;
258 + info->pr_pgrp = proc_pgid;
259 + info->pr_sid = proc_sid;
260 + strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
261 + strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
266 + if (gdbarch_ptr_bit (target_gdbarch) == 32)
268 + struct elf_prpsinfo32 *info = xzalloc (sizeof (*info));
270 + info->pr_state = state_num;
271 + info->pr_sname = proc_state[0];
272 + info->pr_zomb = (proc_state[0] == 'Z');
273 + info->pr_nice = proc_nice;
274 + info->pr_flag = flags;
275 + info->pr_uid = sb.st_uid;
276 + info->pr_gid = sb.st_gid;
277 + info->pr_pid = pid;
278 + info->pr_ppid = proc_ppid;
279 + info->pr_pgrp = proc_pgid;
280 + info->pr_sid = proc_sid;
281 + strncpy (info->pr_fname, proc_comm, sizeof (info->pr_fname));
282 + strncpy (info->pr_psargs, proc_cmdline, sizeof (info->pr_psargs));
291 /* Fills the "to_make_corefile_note" target vector. Builds the note
292 section for a corefile, and returns it in a malloc buffer. */
294 @@ -3966,8 +4120,14 @@ linux_nat_make_corefile_notes (bfd *obfd
296 if (get_exec_file (0))
298 +#if defined (HAVE_PRPSINFO_T)
299 + void *data = fill_prpsinfo ();
300 +#define DATAPTR data
302 +#define DATAPTR NULL
303 strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
304 strncpy (psargs, get_exec_file (0), sizeof (psargs));
306 if (get_inferior_args ())
309 @@ -3983,9 +4143,15 @@ linux_nat_make_corefile_notes (bfd *obfd
310 psargs_end - string_end);
313 - note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
315 + note_data = (char *) linux_elfcore_write_prpsinfo (obfd,
316 + note_data, note_size,
320 +#if defined (HAVE_PRPSINFO_T)
326 /* Dump information for threads. */
327 Index: gdb-6.8.50.20090910/gdb/linux-nat.h
328 ===================================================================
329 --- gdb-6.8.50.20090910.orig/gdb/linux-nat.h 2009-09-10 23:01:06.000000000 +0200
330 +++ gdb-6.8.50.20090910/gdb/linux-nat.h 2009-09-10 23:01:15.000000000 +0200
331 @@ -154,7 +154,7 @@ struct siginfo *linux_nat_get_siginfo (p
332 /* These functions make elfcore note sections.
333 They may get overriden by code adjusting data for multi-target builds. */
334 extern char *(*linux_elfcore_write_prpsinfo)
335 - (bfd *, char *, int *, const char *, const char *);
336 + (bfd *, char *, int *, void *, const char *, const char *);
337 extern char *(*linux_elfcore_write_prstatus)
338 (bfd *, char *, int *, long, int, const void *);
339 extern char *(*linux_elfcore_write_prfpreg)
340 Index: gdb-6.8.50.20090910/gdb/procfs.c
341 ===================================================================
342 --- gdb-6.8.50.20090910.orig/gdb/procfs.c 2009-08-01 02:02:04.000000000 +0200
343 +++ gdb-6.8.50.20090910/gdb/procfs.c 2009-09-10 23:01:15.000000000 +0200
344 @@ -6147,6 +6147,7 @@ procfs_make_note_section (bfd *obfd, int
345 note_data = (char *) elfcore_write_prpsinfo (obfd,