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