static struct core_fns *core_file_fns = NULL;
+/* The core_fns for a core file handler that is prepared to read the core
+ file currently open on core_bfd. */
+
+static struct core_fns *core_vec = NULL;
+
static void core_files_info PARAMS ((struct target_ops *));
#ifdef SOLIB_ADD
static int solib_add_stub PARAMS ((PTR));
#endif
+static struct core_fns *sniff_core_bfd PARAMS ((bfd *));
+
+static boolean gdb_check_format PARAMS ((bfd *));
+
static void core_open PARAMS ((char *, int));
static void core_detach PARAMS ((char *, int));
core_file_fns = cf;
}
+/* The default function that core file handlers can use to examine a
+ core file BFD and decide whether or not to accept the job of
+ reading the core file. */
+
+int
+default_core_sniffer (our_fns, abfd)
+ struct core_fns *our_fns;
+ bfd *abfd;
+{
+ int result;
+
+ result = (bfd_get_flavour (abfd) == our_fns -> core_flavour);
+ return (result);
+}
+
+/* Walk through the list of core functions to find a set that can
+ handle the core file open on ABFD. Default to the first one in the
+ list of nothing matches. Returns pointer to set that is
+ selected. */
+
+static struct core_fns *
+sniff_core_bfd (abfd)
+ bfd *abfd;
+{
+ struct core_fns *cf;
+ struct core_fns *yummy = NULL;
+ int matches = 0;;
+
+ for (cf = core_file_fns; cf != NULL; cf = cf->next)
+ {
+ if (cf->core_sniffer (cf, abfd))
+ {
+ yummy = cf;
+ matches++;
+ }
+ }
+ if (matches > 1)
+ {
+ warning ("\"%s\": ambiguous core format, %d handlers match",
+ bfd_get_filename (abfd), matches);
+ }
+ else if (matches == 0)
+ {
+ warning ("\"%s\": no core file handler recognizes format, using default",
+ bfd_get_filename (abfd));
+ }
+ if (yummy == NULL)
+ {
+ yummy = core_file_fns;
+ }
+ return (yummy);
+}
+
+/* The default is to reject every core file format we see. Either
+ BFD has to recognize it, or we have to provide a function in the
+ core file handler that recognizes it. */
+
+int
+default_check_format (abfd)
+ bfd *abfd;
+{
+ return (0);
+}
+
+/* Attempt to recognize core file formats that BFD rejects. */
+
+static boolean
+gdb_check_format (abfd)
+ bfd *abfd;
+{
+ struct core_fns *cf;
+
+ for (cf = core_file_fns; cf != NULL; cf = cf->next)
+ {
+ if (cf->check_format (abfd))
+ {
+ return (true);
+ }
+ }
+ return (false);
+}
/* Discard all vestiges of any previous core file and mark data and stack
spaces as empty. */
core_ops.to_sections_end = NULL;
}
}
+ core_vec = NULL;
}
#ifdef SOLIB_ADD
if (temp_bfd == NULL)
perror_with_name (filename);
- if (!bfd_check_format (temp_bfd, bfd_core))
+ if (!bfd_check_format (temp_bfd, bfd_core) &&
+ !gdb_check_format (temp_bfd))
{
/* Do it after the err msg */
/* FIXME: should be checking for errors from bfd_close (for one thing,
core_bfd = temp_bfd;
old_chain = make_cleanup ((make_cleanup_func) core_close, core_bfd);
+ /* Find a suitable core file handler to munch on core_bfd */
+ core_vec = sniff_core_bfd (core_bfd);
+
validate_files ();
/* Find the data section */
printf_filtered ("No core file now.\n");
}
+
+/* Try to retrieve registers from a section in core_bfd, and supply
+ them to core_vec->core_read_registers, as the register set numbered
+ WHICH.
+
+ If inferior_pid is zero, do the single-threaded thing: look for a
+ section named NAME. If inferior_pid is non-zero, do the
+ multi-threaded thing: look for a section named "NAME/PID", where
+ PID is the shortest ASCII decimal representation of inferior_pid.
+
+ HUMAN_NAME is a human-readable name for the kind of registers the
+ NAME section contains, for use in error messages.
+
+ If REQUIRED is non-zero, print an error if the core file doesn't
+ have a section by the appropriate name. Otherwise, just do nothing. */
+
+static void
+get_core_register_section (char *name,
+ int which,
+ char *human_name,
+ int required)
+{
+ char section_name[100];
+ sec_ptr section;
+ bfd_size_type size;
+ char *contents;
+
+ if (inferior_pid)
+ sprintf (section_name, "%s/%d", name, inferior_pid);
+ else
+ strcpy (section_name, name);
+
+ section = bfd_get_section_by_name (core_bfd, section_name);
+ if (! section)
+ {
+ if (required)
+ warning ("Couldn't find %s registers in core file.\n", human_name);
+ return;
+ }
+
+ size = bfd_section_size (core_bfd, section);
+ contents = alloca (size);
+ if (! bfd_get_section_contents (core_bfd, section, contents,
+ (file_ptr) 0, size))
+ {
+ warning ("Couldn't read %s registers from `%s' section in core file.\n",
+ human_name, name);
+ return;
+ }
+
+ core_vec->core_read_registers (contents, size, which,
+ ((CORE_ADDR)
+ bfd_section_vma (core_bfd, section)));
+}
+
+
/* Get the registers out of a core file. This is the machine-
independent part. Fetch_core_registers is the machine-dependent
part, typically implemented in the xm-file for each architecture. */
get_core_registers (regno)
int regno;
{
- sec_ptr reg_sec;
- unsigned size;
- char *the_regs;
- char secname[30];
- enum bfd_flavour our_flavour = bfd_get_flavour (core_bfd);
- struct core_fns *cf = NULL;
-
- if (core_file_fns == NULL)
+ int status;
+
+ if (core_vec == NULL
+ || core_vec->core_read_registers == NULL)
{
fprintf_filtered (gdb_stderr,
"Can't fetch registers from this type of core file\n");
return;
}
- /* Thread support. If inferior_pid is non-zero, then we have found a core
- file with threads (or multiple processes). In that case, we need to
- use the appropriate register section, else we just use `.reg'. */
-
- /* XXX - same thing needs to be done for floating-point (.reg2) sections. */
+ get_core_register_section (".reg", 0, "general-purpose", 1);
+ get_core_register_section (".reg2", 2, "floating-point", 0);
+ get_core_register_section (".reg-xfp", 3, "extended floating-point", 0);
- if (inferior_pid)
- sprintf (secname, ".reg/%d", inferior_pid);
- else
- strcpy (secname, ".reg");
-
- reg_sec = bfd_get_section_by_name (core_bfd, secname);
- if (!reg_sec)
- goto cant;
- size = bfd_section_size (core_bfd, reg_sec);
- the_regs = alloca (size);
- /* Look for the core functions that match this flavor. Default to the
- first one if nothing matches. */
- for (cf = core_file_fns; cf != NULL; cf = cf->next)
- {
- if (our_flavour == cf->core_flavour)
- {
- break;
- }
- }
- if (cf == NULL)
- {
- cf = core_file_fns;
- }
- if (cf != NULL &&
- bfd_get_section_contents (core_bfd, reg_sec, the_regs, (file_ptr) 0, size) &&
- cf->core_read_registers != NULL)
- {
- (cf->core_read_registers (the_regs, size, 0,
- (unsigned) bfd_section_vma (abfd, reg_sec)));
- }
- else
- {
- cant:
- fprintf_filtered (gdb_stderr,
- "Couldn't fetch registers from core file: %s\n",
- bfd_errmsg (bfd_get_error ()));
- }
-
- /* Now do it again for the float registers, if they exist. */
- reg_sec = bfd_get_section_by_name (core_bfd, ".reg2");
- if (reg_sec)
- {
- size = bfd_section_size (core_bfd, reg_sec);
- the_regs = alloca (size);
- if (cf != NULL &&
- bfd_get_section_contents (core_bfd, reg_sec, the_regs, (file_ptr) 0, size) &&
- cf->core_read_registers != NULL)
- {
- (cf->core_read_registers (the_regs, size, 2,
- (unsigned) bfd_section_vma (abfd, reg_sec)));
- }
- else
- {
- fprintf_filtered (gdb_stderr,
- "Couldn't fetch register set 2 from core file: %s\n",
- bfd_errmsg (bfd_get_error ()));
- }
- }
registers_fetched ();
}