[testsuite] for: [PATCH] [PR corefiles/17808] i386: Fix internal error when prstatus in core file is too big

Message ID 87vbkf7o19.fsf@br87z6lw.de.ibm.com
State New, archived
Headers

Commit Message

Andreas Arnez Jan. 9, 2015, 7:27 p.m. UTC
  On Fri, Jan 09 2015, Pedro Alves wrote:

>> Any other comments?
>
> Do we need to do the same in other places?  This grep seems to suggest yes:
>
> $ grep assert * | grep sizeof | grep regset
> amd64obsd-tdep.c:  gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE);
> amd64-tdep.c:  gdb_assert (len == tdep->sizeof_fpregset);
> amd64-tdep.c:  gdb_assert (len == tdep->sizeof_fpregset);
> i386obsd-tdep.c:  gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
> i386-tdep.c:  gdb_assert (len == tdep->sizeof_gregset);
> i386-tdep.c:  gdb_assert (len == tdep->sizeof_gregset);
> i386-tdep.c:  gdb_assert (len == tdep->sizeof_fpregset);
> i386-tdep.c:  gdb_assert (len == tdep->sizeof_fpregset);
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips_elf_gregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips_elf_gregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips_elf_fpregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips_elf_fpregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips64_elf_gregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips64_elf_gregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips64_elf_fpregset_t));
> mips-linux-tdep.c:  gdb_assert (len == sizeof (mips64_elf_fpregset_t));
> mn10300-linux-tdep.c:  gdb_assert (len == sizeof (mn10300_elf_gregset_t));
> mn10300-linux-tdep.c:  gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
> mn10300-linux-tdep.c:  gdb_assert (len == sizeof (mn10300_elf_gregset_t));

Right, these should be handled as well.  Once we agree on how to handle
them, I can provide an updated patch.

> On 01/08/2015 04:16 PM, Andreas Arnez wrote:
>> Note that this behavior deviates from the default policy: In general, if
>> some future kernel adds new registers to a register set, then a GDB
>> unaware of this extension would read the known subset and just ignore
>> the unknown bytes.
>
> That's a good point.
>
> get_core_register_section checks the section size already:
>
> get_core_register_section (struct regcache *regcache,
> 			   const struct regset *regset,
> 			   const char *name,
> 			   int min_size,
> 			   int which,
> 			   const char *human_name,
> 			   int required)
> {
> ...
>   size = bfd_section_size (core_bfd, section);
>   if (size < min_size)
>     {
>       warning (_("Section `%s' in core file too small."), section_name);
>       return;
>     }
> ...
>
> Should we remove all those asserts, and make it the
> job of get_core_register_section to warn if the section
> size is bigger than expected?  We may need to pass
> the "expected" section size to the callback, in addition
> to the "minimum" size though.

Good point.  Or maybe instead of adding the expected size to the
callback we could allow the regset supply functions to pass back their
"recognized" size?  For instance:




(And then, for symmetry, the regset collect functions could also
indicate how much data they produced, i.e., how large the resulting
register section should be.  But I'm not sure whether there is currently
any application for this.)

A more "lazy" approach would be to assume that the "recognized" size
always equals the "minimum" size.  Then we could emit the warning like
this:

  if (size < min_size)
    {
      warning (_("Section `%s' in core file too small."), section_name);
      return;
    }
  else if (size != min_size)
    warning (_("Section `%s' in core file has unexpected size."),
             section_name);

This is certainly less flexible, but might be good enough.
  

Patch

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 0750506..3ad491d 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3720,14 +3720,14 @@  i386_value_to_register (struct frame_info *frame, int regnum,
 
 void
 i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
-		     int regnum, const void *gregs, size_t len)
+		     int regnum, const void *gregs, size_t *len)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   const gdb_byte *regs = gregs;
   int i;
 
-  gdb_assert (len == tdep->sizeof_gregset);
+  *len = tdep->sizeof_gregset;
 
   for (i = 0; i < tdep->gregset_num_regs; i++)
     {