]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.8-bz254229-gcore-prpsinfo.patch
- NOTE: does not build with -j2
[packages/gdb.git] / gdb-6.8-bz254229-gcore-prpsinfo.patch
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,
20                         char *buf,
21                         int  *bufsiz,
22 +                       void *info,
23                         const char *fname,
24                         const char *psargs)
25  {
26 @@ -8424,9 +8425,15 @@ elfcore_write_prpsinfo (bfd  *abfd,
27        int note_type = NT_PRPSINFO;
28  #endif
29  
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));
33 +      if (info)
34 +       memcpy (&data, info, sizeof (data));
35 +      else
36 +       {
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));
40 +       }
41 +
42        return elfcore_write_note (abfd, buf, bufsiz,
43                                  note_name, note_type, &data, sizeof (data));
44      }
45 @@ -8441,9 +8448,15 @@ elfcore_write_prpsinfo (bfd  *abfd,
46        int note_type = NT_PRPSINFO;
47  #endif
48  
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));
52 +      if (info)
53 +       memcpy (&data, info, sizeof (data));
54 +      else
55 +       {
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));
59 +       }
60 +
61        return elfcore_write_note (abfd, buf, bufsiz,
62                                  note_name, note_type, &data, sizeof (data));
63      }
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
69  
70  static char *
71  amd64_linux_elfcore_write_prpsinfo (bfd *abfd, char *buf, int *bufsiz,
72 +                                   void *info,
73                                     const char *fname, const char *psargs)
74  {
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;
79  
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));
83 +      if (info)
84 +       memcpy (&data, info, sizeof (data));
85 +      else
86 +       {
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));
90 +       }
91 +
92        return elfcore_write_note (abfd, buf, bufsiz,
93                                  note_name, note_type, &data, sizeof (data));
94      }
95    else
96 -    return elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs);
97 +    return elfcore_write_prpsinfo (abfd, buf, bufsiz, info, fname, psargs);
98  }
99  
100  static void
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);
107  
108        note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
109 +                                         NULL,
110                                           fname, psargs);
111      }
112  
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
117 @@ -55,6 +55,7 @@
118  #include "xml-support.h"
119  #include "terminal.h"
120  #include <sys/vfs.h>
121 +#include "gdb_procfs32.h"      /* for struct elf_prpsinfo32 */
122  
123  #ifndef SPUFS_MAGIC
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;
133  static char *
134 @@ -3946,6 +3947,159 @@ linux_spu_make_corefile_notes (bfd *obfd
135    return args.note_data;
136  }
137  
138 +/* Should be always true for Linux */
139 +#define HAVE_PRPSINFO_T 1
140 +
141 +#if defined (HAVE_PRPSINFO_T)
142 +
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
145 +   malloced.  */
146 +
147 +static void*
148 +fill_prpsinfo (void)
149 +{
150 +  struct stat sb;
151 +  char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
152 +  char buf[1024];
153 +  char proc_state[5];
154 +  char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
155 +  unsigned flags;
156 +  long proc_nice;
157 +  unsigned proc_ppid;
158 +  unsigned proc_pgid;
159 +  unsigned proc_sid;
160 +  pid_t pid;
161 +  int fd, n;
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";
166 +  int state_num;
167 +
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);
172 +  if (fd < 0)
173 +    return NULL;
174 +  fstat (fd, &sb); /* No error checking (can it ever happen?).  */
175 +  n = read (fd, buf, sizeof (buf) - 1);
176 +  close (fd);
177 +  if (n < 0)
178 +    return NULL;
179 +  buf[n] = 0;
180 +
181 +  cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>".  */
182 +  if (!cp)
183 +    return NULL;
184 +  *cp = 0;
185 +
186 +  /* Grab COMM.  */
187 +  proc_comm = strchr (buf, '(');
188 +  if (!proc_comm)
189 +    return NULL;
190 +  proc_comm++;
191 +
192 +  /* Read /proc/$PID/cmdline.  */
193 +  proc_cmdline[0] = 0;
194 +  strcpy (strrchr (filename, '/'), "/cmdline");
195 +  fd = open (filename, O_RDONLY);
196 +  if (fd >= 0)
197 +    {
198 +      int n;
199 +
200 +      n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
201 +      if (n < 0)
202 +       n = 0;
203 +      proc_cmdline[n] = 0;
204 +      while (n--) /* Replace NULs with spaces.  */
205 +       if (proc_cmdline[n] == 0)
206 +         proc_cmdline[n] = ' ';
207 +      close (fd);
208 +    }
209 +
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 */
218 +             "%ld "             /* nice */
219 +             /*"%*s %*s "          timeout, it_real_value */
220 +             /*"%lu "              start_time */
221 +             /*"%lu "              vsize */
222 +             /*"%lu "              rss */
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,
229 +             &flags,
230 +             &proc_nice);
231 +  if (n != 6)
232 +    return NULL;
233 +
234 +  state_s = strchr (state_string, proc_state[0]);
235 +  if (state_s != NULL)
236 +    state_num = state_s - state_string;
237 +  else
238 +    {
239 +      /* 0 means Running, some more unusal state would be better.  */
240 +      state_num = 0;
241 +    }
242 +
243 +#if ULONG_MAX > 0xffffffffU
244 +  /* We skip this code on 32-bit gdb.  */
245 +  if (gdbarch_ptr_bit (target_gdbarch) == 64)
246 +    {
247 +      struct elf_prpsinfo *info = xzalloc (sizeof (*info));
248 +
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));
262 +
263 +      return info;
264 +    }
265 +#endif
266 +  if (gdbarch_ptr_bit (target_gdbarch) == 32)
267 +    {
268 +      struct elf_prpsinfo32 *info = xzalloc (sizeof (*info));
269 +
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));
283 +
284 +      return info;
285 +    }
286 +
287 +  return NULL;
288 +}
289 +#endif
290 +
291  /* Fills the "to_make_corefile_note" target vector.  Builds the note
292     section for a corefile, and returns it in a malloc buffer.  */
293  
294 @@ -3966,8 +4120,14 @@ linux_nat_make_corefile_notes (bfd *obfd
295  
296    if (get_exec_file (0))
297      {
298 +#if defined (HAVE_PRPSINFO_T)
299 +      void *data = fill_prpsinfo ();
300 +#define DATAPTR data
301 +#else
302 +#define DATAPTR NULL
303        strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
304        strncpy (psargs, get_exec_file (0), sizeof (psargs));
305 +#endif
306        if (get_inferior_args ())
307         {
308           char *string_end;
309 @@ -3983,9 +4143,15 @@ linux_nat_make_corefile_notes (bfd *obfd
310                        psargs_end - string_end);
311             }
312         }
313 -      note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
314 -                                                        note_size, fname,
315 +      note_data = (char *) linux_elfcore_write_prpsinfo (obfd,
316 +                                                        note_data, note_size,
317 +                                                        DATAPTR,
318 +                                                        fname,
319                                                          psargs);
320 +#if defined (HAVE_PRPSINFO_T)
321 +      xfree (DATAPTR);
322 +#endif
323 +#undef DATAPTR
324      }
325  
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,
346                                                note_data,
347                                                note_size,
348 +                                              NULL,
349                                                fname,
350                                                psargs);
351  
This page took 0.074494 seconds and 3 git commands to generate.