This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix mach setting when reading core file


(Cross-posting to gdb-patches since the discussion originates from there.)

The CRISv32 binutils port exposed a problem concerning the mach setting when reading a core file. The exposure results from checking the bfd's mach setting before touching prstatus and psinfo (see cris_elf_grok_prstatus and cris_elf_grok_psinfo in bfd/elf32-cris.c).

The problem is that the call to bfd_default_set_arch_mach in elf_core_file_p (in elfcore.h) will select the default mach for that arch, and this call immediately precedes the reading of the core file's program headers. As a consequence, if the default mach is not the correct one cris_elf_grok_prstatus and cris_elf_grok_psinfo will not recognize the core file.

The patch below simply moves the call to the elf backend to before processing the program headers. This way we can let the backend set the correct machine like they all do already. (Of course, for this to have any real effect, the e_flags value must be set correctly in the core file.) I checked the other ports' elf_backend_object_p implementations and AFAICT, they will be unaffected by moving the call.

FWIW: No regressions on i386 and CRIS when running the gdb.base testsuite.


2005-01-24 Orjan Friberg <orjanf@axis.com>


    * elfcore.h (elf_core_file_p): Move the call to elf_backend_object_p
    to allow the correct machine to be set before processing the program
    headers.


Index: elfcore.h =================================================================== RCS file: /cvs/src/src/bfd/elfcore.h,v retrieving revision 1.20 diff -u -p -r1.20 elfcore.h --- elfcore.h 7 Aug 2003 08:38:09 -0000 1.20 +++ elfcore.h 14 Jan 2005 17:03:02 -0000 @@ -214,6 +214,15 @@ elf_core_file_p (bfd *abfd) goto fail; }

+  /* Let the backend double check the format and override global
+     information.  We do this before processing the program headers
+     to allow the correct machine (as opposed to just the default
+     machine) to be set, making it possible for grok_prstatus and
+     grok_psinfo to rely on the mach setting.  */
+  if (ebd->elf_backend_object_p
+      && (! (*ebd->elf_backend_object_p) (abfd)))
+    goto wrong;
+
   /* Process each program header.  */
   for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
     if (! bfd_section_from_phdr (abfd, i_phdrp + phindex, (int) phindex))
@@ -222,12 +231,6 @@ elf_core_file_p (bfd *abfd)
   /* Save the entry point from the ELF header.  */
   bfd_get_start_address (abfd) = i_ehdrp->e_entry;

-  /* Let the backend double check the format and override global
-     information.  */
-  if (ebd->elf_backend_object_p
-      && (! (*ebd->elf_backend_object_p) (abfd)))
-    goto wrong;
-
   bfd_preserve_finish (abfd, &preserve);
   return abfd->xvec;


-- Orjan Friberg Axis Communications


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]