OLD | NEW |
1 /* Core dump and executable file functions below target vector, for GDB. | 1 /* Core dump and executable file functions below target vector, for GDB. |
2 | 2 |
3 Copyright (C) 1986-1987, 1989, 1991-2001, 2003-2012 Free Software | 3 Copyright (C) 1986-1987, 1989, 1991-2001, 2003-2012 Free Software |
4 Foundation, Inc. | 4 Foundation, Inc. |
5 | 5 |
6 This file is part of GDB. | 6 This file is part of GDB. |
7 | 7 |
8 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "regset.h" | 39 #include "regset.h" |
40 #include "symfile.h" | 40 #include "symfile.h" |
41 #include "exec.h" | 41 #include "exec.h" |
42 #include "readline/readline.h" | 42 #include "readline/readline.h" |
43 #include "gdb_assert.h" | 43 #include "gdb_assert.h" |
44 #include "exceptions.h" | 44 #include "exceptions.h" |
45 #include "solib.h" | 45 #include "solib.h" |
46 #include "filenames.h" | 46 #include "filenames.h" |
47 #include "progspace.h" | 47 #include "progspace.h" |
48 #include "objfiles.h" | 48 #include "objfiles.h" |
49 #include "wrapper.h" | |
50 | |
51 | 49 |
52 #ifndef O_LARGEFILE | 50 #ifndef O_LARGEFILE |
53 #define O_LARGEFILE 0 | 51 #define O_LARGEFILE 0 |
54 #endif | 52 #endif |
55 | 53 |
56 /* List of all available core_fns. On gdb startup, each core file | 54 /* List of all available core_fns. On gdb startup, each core file |
57 register reader calls deprecated_add_core_fns() to register | 55 register reader calls deprecated_add_core_fns() to register |
58 information on each core format it is prepared to read. */ | 56 information on each core format it is prepared to read. */ |
59 | 57 |
60 static struct core_fns *core_file_fns = NULL; | 58 static struct core_fns *core_file_fns = NULL; |
61 | 59 |
62 /* The core_fns for a core file handler that is prepared to read the | 60 /* The core_fns for a core file handler that is prepared to read the |
63 core file currently open on core_bfd. */ | 61 core file currently open on core_bfd. */ |
64 | 62 |
65 static struct core_fns *core_vec = NULL; | 63 static struct core_fns *core_vec = NULL; |
66 | 64 |
67 /* FIXME: kettenis/20031023: Eventually this variable should | 65 /* FIXME: kettenis/20031023: Eventually this variable should |
68 disappear. */ | 66 disappear. */ |
69 | 67 |
70 struct gdbarch *core_gdbarch = NULL; | 68 struct gdbarch *core_gdbarch = NULL; |
71 | 69 |
72 /* Per-core data. Currently, only the section table. Note that these | 70 /* Per-core data. Currently, only the section table. Note that these |
73 target sections are *not* mapped in the current address spaces' set | 71 target sections are *not* mapped in the current address spaces' set |
74 of target sections --- those should come only from pure executable | 72 of target sections --- those should come only from pure executable |
75 or shared library bfds. The core bfd sections are an | 73 or shared library bfds. The core bfd sections are an |
76 implementation detail of the core target, just like ptrace is for | 74 implementation detail of the core target, just like ptrace is for |
77 unix child targets. */ | 75 unix child targets. */ |
78 static struct target_section_table *core_data; | 76 static struct target_section_table *core_data; |
79 | 77 |
80 /* True if we needed to fake the pid of the loaded core inferior. */ | |
81 static int core_has_fake_pid = 0; | |
82 | |
83 static void core_files_info (struct target_ops *); | 78 static void core_files_info (struct target_ops *); |
84 | 79 |
85 static struct core_fns *sniff_core_bfd (bfd *); | 80 static struct core_fns *sniff_core_bfd (bfd *); |
86 | 81 |
87 static int gdb_check_format (bfd *); | 82 static int gdb_check_format (bfd *); |
88 | 83 |
89 static void core_open (char *, int); | 84 static void core_open (char *, int); |
90 | 85 |
91 static void core_detach (struct target_ops *ops, char *, int); | 86 static void core_detach (struct target_ops *ops, char *, int); |
92 | 87 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 int | 119 int |
125 default_core_sniffer (struct core_fns *our_fns, bfd *abfd) | 120 default_core_sniffer (struct core_fns *our_fns, bfd *abfd) |
126 { | 121 { |
127 int result; | 122 int result; |
128 | 123 |
129 result = (bfd_get_flavour (abfd) == our_fns -> core_flavour); | 124 result = (bfd_get_flavour (abfd) == our_fns -> core_flavour); |
130 return (result); | 125 return (result); |
131 } | 126 } |
132 | 127 |
133 /* Walk through the list of core functions to find a set that can | 128 /* Walk through the list of core functions to find a set that can |
134 handle the core file open on ABFD. Default to the first one in the | 129 handle the core file open on ABFD. Returns pointer to set that is |
135 list if nothing matches. Returns pointer to set that is | |
136 selected. */ | 130 selected. */ |
137 | 131 |
138 static struct core_fns * | 132 static struct core_fns * |
139 sniff_core_bfd (bfd *abfd) | 133 sniff_core_bfd (bfd *abfd) |
140 { | 134 { |
141 struct core_fns *cf; | 135 struct core_fns *cf; |
142 struct core_fns *yummy = NULL; | 136 struct core_fns *yummy = NULL; |
143 int matches = 0;; | 137 int matches = 0;; |
144 | 138 |
145 /* Don't sniff if we have support for register sets in | 139 /* Don't sniff if we have support for register sets in |
146 CORE_GDBARCH. */ | 140 CORE_GDBARCH. */ |
147 if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch)) | 141 if (core_gdbarch && gdbarch_regset_from_core_section_p (core_gdbarch)) |
148 return NULL; | 142 return NULL; |
149 | 143 |
150 for (cf = core_file_fns; cf != NULL; cf = cf->next) | 144 for (cf = core_file_fns; cf != NULL; cf = cf->next) |
151 { | 145 { |
152 if (cf->core_sniffer (cf, abfd)) | 146 if (cf->core_sniffer (cf, abfd)) |
153 { | 147 { |
154 yummy = cf; | 148 yummy = cf; |
155 matches++; | 149 matches++; |
156 } | 150 } |
157 } | 151 } |
158 if (matches > 1) | 152 if (matches > 1) |
159 { | 153 { |
160 warning (_("\"%s\": ambiguous core format, %d handlers match"), | 154 warning (_("\"%s\": ambiguous core format, %d handlers match"), |
161 bfd_get_filename (abfd), matches); | 155 bfd_get_filename (abfd), matches); |
162 } | 156 } |
163 else if (matches == 0) | 157 else if (matches == 0) |
164 { | 158 error (_("\"%s\": no core file handler recognizes format"), |
165 warning (_("\"%s\": no core file handler " | 159 » bfd_get_filename (abfd)); |
166 » » "recognizes format, using default"), | 160 |
167 » bfd_get_filename (abfd)); | |
168 } | |
169 if (yummy == NULL) | |
170 { | |
171 yummy = core_file_fns; | |
172 } | |
173 return (yummy); | 161 return (yummy); |
174 } | 162 } |
175 | 163 |
176 /* The default is to reject every core file format we see. Either | 164 /* The default is to reject every core file format we see. Either |
177 BFD has to recognize it, or we have to provide a function in the | 165 BFD has to recognize it, or we have to provide a function in the |
178 core file handler that recognizes it. */ | 166 core file handler that recognizes it. */ |
179 | 167 |
180 int | 168 int |
181 default_check_format (bfd *abfd) | 169 default_check_format (bfd *abfd) |
182 { | 170 { |
(...skipping 23 matching lines...) Expand all Loading... |
206 static void | 194 static void |
207 core_close (int quitting) | 195 core_close (int quitting) |
208 { | 196 { |
209 char *name; | 197 char *name; |
210 | 198 |
211 if (core_bfd) | 199 if (core_bfd) |
212 { | 200 { |
213 int pid = ptid_get_pid (inferior_ptid); | 201 int pid = ptid_get_pid (inferior_ptid); |
214 inferior_ptid = null_ptid; /* Avoid confusion from thread | 202 inferior_ptid = null_ptid; /* Avoid confusion from thread |
215 stuff. */ | 203 stuff. */ |
216 exit_inferior_silent (pid); | 204 if (pid != 0) |
| 205 » exit_inferior_silent (pid); |
217 | 206 |
218 /* Clear out solib state while the bfd is still open. See | 207 /* Clear out solib state while the bfd is still open. See |
219 comments in clear_solib in solib.c. */ | 208 comments in clear_solib in solib.c. */ |
220 clear_solib (); | 209 clear_solib (); |
221 | 210 |
222 xfree (core_data->sections); | 211 if (core_data) |
223 xfree (core_data); | 212 » { |
224 core_data = NULL; | 213 » xfree (core_data->sections); |
225 core_has_fake_pid = 0; | 214 » xfree (core_data); |
| 215 » core_data = NULL; |
| 216 » } |
226 | 217 |
227 name = bfd_get_filename (core_bfd); | 218 name = bfd_get_filename (core_bfd); |
228 gdb_bfd_close_or_warn (core_bfd); | 219 gdb_bfd_close_or_warn (core_bfd); |
229 xfree (name); | 220 xfree (name); |
230 core_bfd = NULL; | 221 core_bfd = NULL; |
231 } | 222 } |
232 core_vec = NULL; | 223 core_vec = NULL; |
233 core_gdbarch = NULL; | 224 core_gdbarch = NULL; |
234 } | 225 } |
235 | 226 |
236 static void | 227 static void |
237 core_close_cleanup (void *ignore) | 228 core_close_cleanup (void *ignore) |
238 { | 229 { |
239 core_close (0/*ignored*/); | 230 core_close (0/*ignored*/); |
240 } | 231 } |
241 | 232 |
242 /* Look for sections whose names start with `.reg/' so that we can | 233 /* Look for sections whose names start with `.reg/' so that we can |
243 extract the list of threads in a core file. */ | 234 extract the list of threads in a core file. */ |
244 | 235 |
245 static void | 236 static void |
246 add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg) | 237 add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg) |
247 { | 238 { |
248 ptid_t ptid; | 239 ptid_t ptid; |
249 int core_tid; | 240 int core_tid; |
250 int pid, lwpid; | 241 int pid, lwpid; |
251 asection *reg_sect = (asection *) reg_sect_arg; | 242 asection *reg_sect = (asection *) reg_sect_arg; |
| 243 int fake_pid_p = 0; |
| 244 struct inferior *inf; |
252 | 245 |
253 if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) | 246 if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) |
254 return; | 247 return; |
255 | 248 |
256 core_tid = atoi (bfd_section_name (abfd, asect) + 5); | 249 core_tid = atoi (bfd_section_name (abfd, asect) + 5); |
257 | 250 |
258 pid = bfd_core_file_pid (core_bfd); | 251 pid = bfd_core_file_pid (core_bfd); |
259 if (pid == 0) | 252 if (pid == 0) |
260 { | 253 { |
261 core_has_fake_pid = 1; | 254 fake_pid_p = 1; |
262 pid = CORELOW_PID; | 255 pid = CORELOW_PID; |
263 } | 256 } |
264 | 257 |
265 lwpid = core_tid; | 258 lwpid = core_tid; |
266 | 259 |
267 if (current_inferior ()->pid == 0) | 260 inf = current_inferior (); |
268 inferior_appeared (current_inferior (), pid); | 261 if (inf->pid == 0) |
| 262 { |
| 263 inferior_appeared (inf, pid); |
| 264 inf->fake_pid_p = fake_pid_p; |
| 265 } |
269 | 266 |
270 ptid = ptid_build (pid, lwpid, 0); | 267 ptid = ptid_build (pid, lwpid, 0); |
271 | 268 |
272 add_thread (ptid); | 269 add_thread (ptid); |
273 | 270 |
274 /* Warning, Will Robinson, looking at BFD private data! */ | 271 /* Warning, Will Robinson, looking at BFD private data! */ |
275 | 272 |
276 if (reg_sect != NULL | 273 if (reg_sect != NULL |
277 && asect->filepos == reg_sect->filepos) /* Did we find .reg? */ | 274 && asect->filepos == reg_sect->filepos) /* Did we find .reg? */ |
278 inferior_ptid = ptid; /* Yes, make it current. */ | 275 inferior_ptid = ptid; /* Yes, make it current. */ |
279 } | 276 } |
280 | 277 |
281 /* This routine opens and sets up the core file bfd. */ | 278 /* This routine opens and sets up the core file bfd. */ |
282 | 279 |
283 static void | 280 static void |
284 core_open (char *filename, int from_tty) | 281 core_open (char *filename, int from_tty) |
285 { | 282 { |
286 const char *p; | 283 const char *p; |
287 int siggy; | 284 int siggy; |
288 struct cleanup *old_chain; | 285 struct cleanup *old_chain; |
289 char *temp; | 286 char *temp; |
290 bfd *temp_bfd; | 287 bfd *temp_bfd; |
291 int scratch_chan; | 288 int scratch_chan; |
292 int flags; | 289 int flags; |
| 290 volatile struct gdb_exception except; |
293 | 291 |
294 target_preopen (from_tty); | 292 target_preopen (from_tty); |
295 if (!filename) | 293 if (!filename) |
296 { | 294 { |
297 if (core_bfd) | 295 if (core_bfd) |
298 error (_("No core file specified. (Use `detach' " | 296 error (_("No core file specified. (Use `detach' " |
299 "to stop debugging a core file.)")); | 297 "to stop debugging a core file.)")); |
300 else | 298 else |
301 error (_("No core file specified.")); | 299 error (_("No core file specified.")); |
302 } | 300 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 push_target (&core_ops); | 377 push_target (&core_ops); |
380 discard_cleanups (old_chain); | 378 discard_cleanups (old_chain); |
381 | 379 |
382 /* Do this before acknowledging the inferior, so if | 380 /* Do this before acknowledging the inferior, so if |
383 post_create_inferior throws (can happen easilly if you're loading | 381 post_create_inferior throws (can happen easilly if you're loading |
384 a core file with the wrong exec), we aren't left with threads | 382 a core file with the wrong exec), we aren't left with threads |
385 from the previous inferior. */ | 383 from the previous inferior. */ |
386 init_thread_list (); | 384 init_thread_list (); |
387 | 385 |
388 inferior_ptid = null_ptid; | 386 inferior_ptid = null_ptid; |
389 core_has_fake_pid = 0; | |
390 | 387 |
391 /* Need to flush the register cache (and the frame cache) from a | 388 /* Need to flush the register cache (and the frame cache) from a |
392 previous debug session. If inferior_ptid ends up the same as the | 389 previous debug session. If inferior_ptid ends up the same as the |
393 last debug session --- e.g., b foo; run; gcore core1; step; gcore | 390 last debug session --- e.g., b foo; run; gcore core1; step; gcore |
394 core2; core core1; core core2 --- then there's potential for | 391 core2; core core1; core core2 --- then there's potential for |
395 get_current_regcache to return the cached regcache of the | 392 get_current_regcache to return the cached regcache of the |
396 previous session, and the frame cache being stale. */ | 393 previous session, and the frame cache being stale. */ |
397 registers_changed (); | 394 registers_changed (); |
398 | 395 |
399 /* Build up thread list from BFD sections, and possibly set the | 396 /* Build up thread list from BFD sections, and possibly set the |
(...skipping 21 matching lines...) Expand all Loading... |
421 else | 418 else |
422 switch_to_thread (thread->ptid); | 419 switch_to_thread (thread->ptid); |
423 } | 420 } |
424 | 421 |
425 post_create_inferior (&core_ops, from_tty); | 422 post_create_inferior (&core_ops, from_tty); |
426 | 423 |
427 /* Now go through the target stack looking for threads since there | 424 /* Now go through the target stack looking for threads since there |
428 may be a thread_stratum target loaded on top of target core by | 425 may be a thread_stratum target loaded on top of target core by |
429 now. The layer above should claim threads found in the BFD | 426 now. The layer above should claim threads found in the BFD |
430 sections. */ | 427 sections. */ |
431 gdb_target_find_new_threads (); | 428 TRY_CATCH (except, RETURN_MASK_ERROR) |
| 429 { |
| 430 target_find_new_threads (); |
| 431 } |
| 432 |
| 433 if (except.reason < 0) |
| 434 exception_print (gdb_stderr, except); |
432 | 435 |
433 p = bfd_core_file_failing_command (core_bfd); | 436 p = bfd_core_file_failing_command (core_bfd); |
434 if (p) | 437 if (p) |
435 printf_filtered (_("Core was generated by `%s'.\n"), p); | 438 printf_filtered (_("Core was generated by `%s'.\n"), p); |
436 | 439 |
437 siggy = bfd_core_file_failing_signal (core_bfd); | 440 siggy = bfd_core_file_failing_signal (core_bfd); |
438 if (siggy > 0) | 441 if (siggy > 0) |
439 { | 442 { |
440 /* NOTE: target_signal_from_host() converts a target signal | 443 /* If we don't have a CORE_GDBARCH to work with, assume a native |
441 » value into gdb's internal signal value. Unfortunately gdb's | 444 » core (map gdb_signal from host signals). If we do have |
442 » internal value is called ``target_signal'' and this function | 445 » CORE_GDBARCH to work with, but no gdb_signal_from_target |
443 » got the name ..._from_host(). */ | 446 » implementation for that gdbarch, as a fallback measure, |
444 enum target_signal sig = (core_gdbarch != NULL | 447 » assume the host signal mapping. It'll be correct for native |
445 » » ? gdbarch_target_signal_from_host (core_gdbarch, | 448 » cores, but most likely incorrect for cross-cores. */ |
446 » » » » » » » siggy) | 449 enum gdb_signal sig = (core_gdbarch != NULL |
447 » » : target_signal_from_host (siggy)); | 450 » » » && gdbarch_gdb_signal_from_target_p (core_gdbarch) |
| 451 » » » ? gdbarch_gdb_signal_from_target (core_gdbarch, |
| 452 » » » » » » » siggy) |
| 453 » » » : gdb_signal_from_host (siggy)); |
448 | 454 |
449 printf_filtered (_("Program terminated with signal %d, %s.\n"), | 455 printf_filtered (_("Program terminated with signal %d, %s.\n"), |
450 » » siggy, target_signal_to_string (sig)); | 456 » » siggy, gdb_signal_to_string (sig)); |
451 } | 457 } |
452 | 458 |
453 /* Fetch all registers from core file. */ | 459 /* Fetch all registers from core file. */ |
454 target_fetch_registers (get_current_regcache (), -1); | 460 target_fetch_registers (get_current_regcache (), -1); |
455 | 461 |
456 /* Now, set up the frame cache, and print the top of stack. */ | 462 /* Now, set up the frame cache, and print the top of stack. */ |
457 reinit_frame_cache (); | 463 reinit_frame_cache (); |
458 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); | 464 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC); |
459 } | 465 } |
460 | 466 |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 843 |
838 static const struct target_desc * | 844 static const struct target_desc * |
839 core_read_description (struct target_ops *target) | 845 core_read_description (struct target_ops *target) |
840 { | 846 { |
841 if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch)) | 847 if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch)) |
842 return gdbarch_core_read_description (core_gdbarch, | 848 return gdbarch_core_read_description (core_gdbarch, |
843 target, core_bfd); | 849 target, core_bfd); |
844 | 850 |
845 return NULL; | 851 return NULL; |
846 } | 852 } |
error: old chunk mismatch |
None
OLD | NEW |