]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.8-bz254229-gcore-prpsinfo.patch
- remove old and unused patches.
[packages/gdb.git] / gdb-6.8-bz254229-gcore-prpsinfo.patch
CommitLineData
51a5ef0f 1Index: gdb-7.1.90.20100711/bfd/elf-bfd.h
3a58abaf 2===================================================================
51a5ef0f
PS
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. */
3a58abaf
AM
7 extern char *elfcore_write_note
8 (bfd *, char *, int *, const char *, int, const void *, int);
51a5ef0f 9+#include <sys/procfs.h>
3a58abaf
AM
10 extern char *elfcore_write_prpsinfo
11- (bfd *, char *, int *, const char *, const char *);
51a5ef0f 12+ (bfd *, char *, int *, const prpsinfo_t *);
3a58abaf
AM
13 extern char *elfcore_write_prstatus
14 (bfd *, char *, int *, long, int, const void *);
15 extern char * elfcore_write_pstatus
51a5ef0f 16Index: gdb-7.1.90.20100711/bfd/elf.c
3a58abaf 17===================================================================
51a5ef0f
PS
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,
21 return buf;
22 }
23
24-#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
25+#if defined (HAVE_PRPSINFO_T)
26 char *
3a58abaf
AM
27 elfcore_write_prpsinfo (bfd *abfd,
28 char *buf,
29 int *bufsiz,
51a5ef0f
PS
30- const char *fname,
31- const char *psargs)
32+ const prpsinfo_t *input)
3a58abaf 33 {
51a5ef0f
PS
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)
38 {
39 char *ret;
40+ char fname[sizeof (input->pr_fname) + 1];
41+ char psargs[sizeof (input->pr_psargs) + 1];
3a58abaf 42+
51a5ef0f
PS
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;
47+
48 ret = (*bed->elf_backend_write_core_note) (abfd, buf, bufsiz,
49 NT_PRPSINFO, fname, psargs);
50 if (ret != NULL)
51 return ret;
3a58abaf 52 }
51a5ef0f
PS
53
54-#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
55+#if defined (HAVE_PRPSINFO32_T)
56 if (bed->s->elfclass == ELFCLASS32)
57 {
58-#if defined (HAVE_PSINFO32_T)
59- psinfo32_t data;
60- int note_type = NT_PSINFO;
61-#else
62 prpsinfo32_t data;
3a58abaf 63 int note_type = NT_PRPSINFO;
51a5ef0f 64-#endif
3a58abaf 65
51a5ef0f 66 memset (&data, 0, sizeof (data));
3a58abaf
AM
67- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
68- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
51a5ef0f
PS
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));
3a58abaf
AM
84 return elfcore_write_note (abfd, buf, bufsiz,
85 note_name, note_type, &data, sizeof (data));
86 }
51a5ef0f
PS
87 else
88 #endif
89 {
90-#if defined (HAVE_PSINFO_T)
91- psinfo_t data;
92- int note_type = NT_PSINFO;
93-#else
94- prpsinfo_t data;
95 int note_type = NT_PRPSINFO;
96-#endif
3a58abaf
AM
97
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));
3a58abaf 101 return elfcore_write_note (abfd, buf, bufsiz,
51a5ef0f
PS
102- note_name, note_type, &data, sizeof (data));
103+ note_name, note_type, input, sizeof (*input));
3a58abaf 104 }
3a58abaf 105 }
51a5ef0f
PS
106-#endif /* PSINFO_T or PRPSINFO_T */
107+#endif /* PRPSINFO_T */
3a58abaf 108
51a5ef0f
PS
109 #if defined (HAVE_PRSTATUS_T)
110 char *
111Index: gdb-7.1.90.20100711/gdb/linux-nat.c
3a58abaf 112===================================================================
51a5ef0f
PS
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
7566401a 116 return args.note_data;
3a58abaf
AM
117 }
118
119+/* Should be always true for Linux */
120+#define HAVE_PRPSINFO_T 1
121+
122+#if defined (HAVE_PRPSINFO_T)
123+
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
126+ malloced. */
127+
51a5ef0f 128+static const prpsinfo_t *
3a58abaf
AM
129+fill_prpsinfo (void)
130+{
131+ struct stat sb;
132+ char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
133+ char buf[1024];
134+ char proc_state[5];
135+ char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
136+ unsigned flags;
137+ long proc_nice;
138+ unsigned proc_ppid;
139+ unsigned proc_pgid;
140+ unsigned proc_sid;
141+ pid_t pid;
142+ int fd, n;
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";
147+ int state_num;
51a5ef0f 148+ static prpsinfo_t retval;
3a58abaf
AM
149+
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);
154+ if (fd < 0)
155+ return NULL;
156+ fstat (fd, &sb); /* No error checking (can it ever happen?). */
157+ n = read (fd, buf, sizeof (buf) - 1);
158+ close (fd);
159+ if (n < 0)
160+ return NULL;
161+ buf[n] = 0;
162+
163+ cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
164+ if (!cp)
165+ return NULL;
166+ *cp = 0;
167+
168+ /* Grab COMM. */
169+ proc_comm = strchr (buf, '(');
170+ if (!proc_comm)
171+ return NULL;
172+ proc_comm++;
173+
174+ /* Read /proc/$PID/cmdline. */
175+ proc_cmdline[0] = 0;
176+ strcpy (strrchr (filename, '/'), "/cmdline");
177+ fd = open (filename, O_RDONLY);
178+ if (fd >= 0)
179+ {
180+ int n;
181+
182+ n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
183+ if (n < 0)
184+ n = 0;
185+ proc_cmdline[n] = 0;
186+ while (n--) /* Replace NULs with spaces. */
187+ if (proc_cmdline[n] == 0)
188+ proc_cmdline[n] = ' ';
189+ close (fd);
190+ }
191+
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 */
200+ "%ld " /* nice */
201+ /*"%*s %*s " timeout, it_real_value */
202+ /*"%lu " start_time */
203+ /*"%lu " vsize */
204+ /*"%lu " rss */
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,
211+ &flags,
212+ &proc_nice);
213+ if (n != 6)
214+ return NULL;
215+
216+ state_s = strchr (state_string, proc_state[0]);
217+ if (state_s != NULL)
218+ state_num = state_s - state_string;
219+ else
220+ {
221+ /* 0 means Running, some more unusal state would be better. */
222+ state_num = 0;
223+ }
224+
51a5ef0f
PS
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));
3a58abaf 239+
51a5ef0f 240+ return &retval;
3a58abaf
AM
241+}
242+#endif
243+
244 /* Fills the "to_make_corefile_note" target vector. Builds the note
245 section for a corefile, and returns it in a malloc buffer. */
246
51a5ef0f 247@@ -4484,26 +4609,11 @@ linux_nat_make_corefile_notes (bfd *obfd
3a58abaf
AM
248
249 if (get_exec_file (0))
250 {
51a5ef0f
PS
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 ())
254- {
255- char *string_end;
256- char *psargs_end = psargs + sizeof (psargs);
257-
258- /* linux_elfcore_write_prpsinfo () handles zero unterminated
259- strings fine. */
260- string_end = memchr (psargs, 0, sizeof (psargs));
261- if (string_end != NULL)
262- {
263- *string_end++ = ' ';
264- strncpy (string_end, get_inferior_args (),
265- psargs_end - string_end);
266- }
267- }
268+ const prpsinfo_t *data = fill_prpsinfo ();
269+
270 note_data = (char *) elfcore_write_prpsinfo (obfd,
271 note_data,
272- note_size, fname, psargs);
273+ note_size, data);
3a58abaf
AM
274 }
275
276 /* Dump information for threads. */
51a5ef0f 277Index: gdb-7.1.90.20100711/gdb/procfs.c
3a58abaf 278===================================================================
51a5ef0f
PS
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
3a58abaf
AM
282 note_data = (char *) elfcore_write_prpsinfo (obfd,
283 note_data,
284 note_size,
285+ NULL,
286 fname,
287 psargs);
288
This page took 0.148471 seconds and 4 git commands to generate.