]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.8-bz254229-gcore-prpsinfo.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-6.8-bz254229-gcore-prpsinfo.patch
CommitLineData
6ed6bacf 1Index: gdb-7.2.50.20110320/bfd/elf-bfd.h
3a58abaf 2===================================================================
6ed6bacf
AM
3--- gdb-7.2.50.20110320.orig/bfd/elf-bfd.h 2011-03-20 15:17:42.000000000 +0100
4+++ gdb-7.2.50.20110320/bfd/elf-bfd.h 2011-03-20 15:24:02.000000000 +0100
5@@ -2193,8 +2193,10 @@ extern Elf_Internal_Phdr * _bfd_elf_find
51a5ef0f 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);
e5178960
PS
9+struct elf_prpsinfo;
10+typedef struct elf_prpsinfo prpsinfo_t;
3a58abaf
AM
11 extern char *elfcore_write_prpsinfo
12- (bfd *, char *, int *, const char *, const char *);
51a5ef0f 13+ (bfd *, char *, int *, const prpsinfo_t *);
3a58abaf
AM
14 extern char *elfcore_write_prstatus
15 (bfd *, char *, int *, long, int, const void *);
16 extern char * elfcore_write_pstatus
6ed6bacf 17Index: gdb-7.2.50.20110320/bfd/elf.c
3a58abaf 18===================================================================
6ed6bacf
AM
19--- gdb-7.2.50.20110320.orig/bfd/elf.c 2011-03-20 15:17:42.000000000 +0100
20+++ gdb-7.2.50.20110320/bfd/elf.c 2011-03-20 15:24:02.000000000 +0100
21@@ -8814,13 +8814,12 @@ elfcore_write_note (bfd *abfd,
51a5ef0f
PS
22 return buf;
23 }
24
25-#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
26+#if defined (HAVE_PRPSINFO_T)
27 char *
3a58abaf
AM
28 elfcore_write_prpsinfo (bfd *abfd,
29 char *buf,
30 int *bufsiz,
51a5ef0f
PS
31- const char *fname,
32- const char *psargs)
33+ const prpsinfo_t *input)
3a58abaf 34 {
51a5ef0f
PS
35 const char *note_name = "CORE";
36 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6ed6bacf 37@@ -8828,48 +8827,55 @@ elfcore_write_prpsinfo (bfd *abfd,
51a5ef0f
PS
38 if (bed->elf_backend_write_core_note != NULL)
39 {
40 char *ret;
41+ char fname[sizeof (input->pr_fname) + 1];
42+ char psargs[sizeof (input->pr_psargs) + 1];
3a58abaf 43+
51a5ef0f
PS
44+ strncpy (fname, input->pr_fname, sizeof (input->pr_fname));
45+ fname[sizeof (input->pr_fname)] = 0;
46+ strncpy (psargs, input->pr_psargs, sizeof (input->pr_psargs));
47+ psargs[sizeof (input->pr_psargs)] = 0;
48+
49 ret = (*bed->elf_backend_write_core_note) (abfd, buf, bufsiz,
50 NT_PRPSINFO, fname, psargs);
51 if (ret != NULL)
52 return ret;
3a58abaf 53 }
51a5ef0f
PS
54
55-#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
56+#if defined (HAVE_PRPSINFO32_T)
57 if (bed->s->elfclass == ELFCLASS32)
58 {
59-#if defined (HAVE_PSINFO32_T)
60- psinfo32_t data;
61- int note_type = NT_PSINFO;
62-#else
63 prpsinfo32_t data;
3a58abaf 64 int note_type = NT_PRPSINFO;
51a5ef0f 65-#endif
3a58abaf 66
51a5ef0f 67 memset (&data, 0, sizeof (data));
3a58abaf
AM
68- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
69- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
51a5ef0f
PS
70+ data.pr_state = input->pr_state;
71+ data.pr_sname = input->pr_sname;
72+ data.pr_zomb = input->pr_zomb;
73+ data.pr_nice = input->pr_nice;
74+ data.pr_flag = input->pr_flag;
75+ data.pr_uid = input->pr_uid;
76+ data.pr_gid = input->pr_gid;
77+ data.pr_pid = input->pr_pid;
78+ data.pr_ppid = input->pr_ppid;
79+ data.pr_pgrp = input->pr_pgrp;
80+ data.pr_sid = input->pr_sid;
81+ BFD_ASSERT (sizeof (data.pr_fname) == sizeof (input->pr_fname));
82+ memcpy (data.pr_fname, input->pr_fname, sizeof (data.pr_fname));
83+ BFD_ASSERT (sizeof (data.pr_psargs) == sizeof (input->pr_psargs));
84+ memcpy (data.pr_psargs, input->pr_psargs, sizeof (data.pr_psargs));
3a58abaf
AM
85 return elfcore_write_note (abfd, buf, bufsiz,
86 note_name, note_type, &data, sizeof (data));
87 }
51a5ef0f
PS
88 else
89 #endif
90 {
91-#if defined (HAVE_PSINFO_T)
92- psinfo_t data;
93- int note_type = NT_PSINFO;
94-#else
95- prpsinfo_t data;
96 int note_type = NT_PRPSINFO;
97-#endif
3a58abaf
AM
98
99- memset (&data, 0, sizeof (data));
100- strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
101- strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
3a58abaf 102 return elfcore_write_note (abfd, buf, bufsiz,
51a5ef0f
PS
103- note_name, note_type, &data, sizeof (data));
104+ note_name, note_type, input, sizeof (*input));
3a58abaf 105 }
3a58abaf 106 }
51a5ef0f
PS
107-#endif /* PSINFO_T or PRPSINFO_T */
108+#endif /* PRPSINFO_T */
3a58abaf 109
51a5ef0f
PS
110 #if defined (HAVE_PRSTATUS_T)
111 char *
6ed6bacf 112Index: gdb-7.2.50.20110320/gdb/linux-nat.c
3a58abaf 113===================================================================
6ed6bacf
AM
114--- gdb-7.2.50.20110320.orig/gdb/linux-nat.c 2011-03-20 15:17:46.000000000 +0100
115+++ gdb-7.2.50.20110320/gdb/linux-nat.c 2011-03-20 15:25:36.000000000 +0100
116@@ -4603,6 +4603,131 @@ linux_spu_make_corefile_notes (bfd *obfd
7566401a 117 return args.note_data;
3a58abaf
AM
118 }
119
120+/* Should be always true for Linux */
121+#define HAVE_PRPSINFO_T 1
122+
123+#if defined (HAVE_PRPSINFO_T)
124+
125+/* Fills struct elf_prpsinfo{32,64} as much as possible, imitate Linux kernel
126+ binfmt_elf.c. Unknown values are filled with zeroes. The structure is
127+ malloced. */
128+
51a5ef0f 129+static const prpsinfo_t *
3a58abaf
AM
130+fill_prpsinfo (void)
131+{
132+ struct stat sb;
133+ char filename[sizeof ("/proc//cmdline") + sizeof (int) * 3 + 2];
134+ char buf[1024];
135+ char proc_state[5];
136+ char proc_cmdline[sizeof (((struct elf_prpsinfo*)0)->pr_psargs) + 1];
137+ unsigned flags;
138+ long proc_nice;
139+ unsigned proc_ppid;
140+ unsigned proc_pgid;
141+ unsigned proc_sid;
142+ pid_t pid;
143+ int fd, n;
144+ char *cp, *proc_comm, *state_s;
145+ /* String comes from Linux kernel binfmt_elf.c FILL_PSINFO but it is already
146+ obsolete there to <linux/sched.h> TASK_* constants. */
147+ const char state_string[] = "RSDTZW";
148+ int state_num;
51a5ef0f 149+ static prpsinfo_t retval;
3a58abaf
AM
150+
151+ /* Get /proc/$PID/stat. */
152+ pid = ptid_get_pid (inferior_ptid);
153+ sprintf (filename, "/proc/%u/stat", (unsigned)pid);
154+ fd = open (filename, O_RDONLY);
155+ if (fd < 0)
156+ return NULL;
157+ fstat (fd, &sb); /* No error checking (can it ever happen?). */
158+ n = read (fd, buf, sizeof (buf) - 1);
159+ close (fd);
160+ if (n < 0)
161+ return NULL;
162+ buf[n] = 0;
163+
164+ cp = strrchr (buf, ')'); /* Split into "PID (COMM" and "<rest>". */
165+ if (!cp)
166+ return NULL;
167+ *cp = 0;
168+
169+ /* Grab COMM. */
170+ proc_comm = strchr (buf, '(');
171+ if (!proc_comm)
172+ return NULL;
173+ proc_comm++;
174+
175+ /* Read /proc/$PID/cmdline. */
176+ proc_cmdline[0] = 0;
177+ strcpy (strrchr (filename, '/'), "/cmdline");
178+ fd = open (filename, O_RDONLY);
179+ if (fd >= 0)
180+ {
181+ int n;
182+
183+ n = read (fd, proc_cmdline, sizeof (proc_cmdline) - 1);
184+ if (n < 0)
185+ n = 0;
186+ proc_cmdline[n] = 0;
187+ while (n--) /* Replace NULs with spaces. */
188+ if (proc_cmdline[n] == 0)
189+ proc_cmdline[n] = ' ';
190+ close (fd);
191+ }
192+
193+ /* Parse /proc/$PID/stat. */
194+ n = sscanf (cp + 2, /* skip ") " */
195+ "%4s %u " /* state, ppid */
196+ "%u %u %*s %*s " /* pgid, sid, tty, tpgid */
197+ "%u %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt */
198+ "%*s " /* cmaj_flt */
199+ "%*s %*s " /* utime, stime */
200+ "%*s %*s %*s " /* cutime, cstime, priority */
201+ "%ld " /* nice */
202+ /*"%*s %*s " timeout, it_real_value */
203+ /*"%lu " start_time */
204+ /*"%lu " vsize */
205+ /*"%lu " rss */
206+ /*"%lu %lu %lu " rss_rlim, start_code, end_code */
207+ /*"%lu %lu %lu " start_stack, kstk_esp, kstk_eip */
208+ /*"%u %u %u %u " signal, blocked, sigignore, sigcatch */
209+ /*"%lu %lu %lu" wchan, nswap, cnswap */
210+ , proc_state, &proc_ppid,
211+ &proc_pgid, &proc_sid,
212+ &flags,
213+ &proc_nice);
214+ if (n != 6)
215+ return NULL;
216+
217+ state_s = strchr (state_string, proc_state[0]);
218+ if (state_s != NULL)
219+ state_num = state_s - state_string;
220+ else
221+ {
222+ /* 0 means Running, some more unusal state would be better. */
223+ state_num = 0;
224+ }
225+
51a5ef0f
PS
226+ memset (&retval, 0, sizeof (retval));
227+ retval.pr_state = state_num;
228+ retval.pr_sname = proc_state[0];
229+ retval.pr_zomb = (proc_state[0] == 'Z');
230+ retval.pr_nice = proc_nice;
231+ retval.pr_flag = flags;
232+ retval.pr_uid = sb.st_uid;
233+ retval.pr_gid = sb.st_gid;
234+ retval.pr_pid = pid;
235+ retval.pr_ppid = proc_ppid;
236+ retval.pr_pgrp = proc_pgid;
237+ retval.pr_sid = proc_sid;
238+ strncpy (retval.pr_fname, proc_comm, sizeof (retval.pr_fname));
239+ strncpy (retval.pr_psargs, proc_cmdline, sizeof (retval.pr_psargs));
3a58abaf 240+
51a5ef0f 241+ return &retval;
3a58abaf
AM
242+}
243+#endif
244+
245 /* Fills the "to_make_corefile_note" target vector. Builds the note
246 section for a corefile, and returns it in a malloc buffer. */
247
6ed6bacf 248@@ -4621,26 +4746,11 @@ linux_nat_make_corefile_notes (bfd *obfd
3a58abaf
AM
249
250 if (get_exec_file (0))
251 {
6ed6bacf 252- strncpy (fname, lbasename (get_exec_file (0)), sizeof (fname));
51a5ef0f
PS
253- strncpy (psargs, get_exec_file (0), sizeof (psargs));
254- if (get_inferior_args ())
255- {
256- char *string_end;
257- char *psargs_end = psargs + sizeof (psargs);
258-
259- /* linux_elfcore_write_prpsinfo () handles zero unterminated
260- strings fine. */
261- string_end = memchr (psargs, 0, sizeof (psargs));
262- if (string_end != NULL)
263- {
264- *string_end++ = ' ';
265- strncpy (string_end, get_inferior_args (),
266- psargs_end - string_end);
267- }
268- }
269+ const prpsinfo_t *data = fill_prpsinfo ();
270+
271 note_data = (char *) elfcore_write_prpsinfo (obfd,
272 note_data,
273- note_size, fname, psargs);
274+ note_size, data);
3a58abaf
AM
275 }
276
277 /* Dump information for threads. */
6ed6bacf 278Index: gdb-7.2.50.20110320/gdb/procfs.c
3a58abaf 279===================================================================
6ed6bacf
AM
280--- gdb-7.2.50.20110320.orig/gdb/procfs.c 2011-03-09 13:48:55.000000000 +0100
281+++ gdb-7.2.50.20110320/gdb/procfs.c 2011-03-20 15:24:02.000000000 +0100
282@@ -5752,6 +5752,7 @@ procfs_make_note_section (bfd *obfd, int
3a58abaf
AM
283 note_data = (char *) elfcore_write_prpsinfo (obfd,
284 note_data,
285 note_size,
286+ NULL,
287 fname,
288 psargs);
289
This page took 0.082625 seconds and 4 git commands to generate.