[RFA] i386-tdep.c, check target_read_memory for error.

Mark Kettenis mark.kettenis@xs4all.nl
Sun Mar 6 17:00:00 GMT 2011


> Date: Sun, 6 Mar 2011 15:15:16 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> 
> On Fri, 04 Mar 2011 22:37:52 +0100, Michael Snyder wrote:
> > Call error if target_read_memory fails.
> [...]
> > -  target_read_memory (pc, &op, 1);
> > +  if (target_read_memory (pc, &op, 1))
> > +    error (_("Couldn't read memory at pc (%s)"), 
> > +	   paddress (gdbarch, pc));
> 
> There is the function `read_memory' for such purpose.

But read_memory() will throw an exception if reading fails.  That is
not necessarily what we want here.  In fact, most of these reads
should silently fail.  They are part of the prologue analysis code,
which to some of extent is based on heuristics.  And one of the
heristics here is that if we fail to read an instruction at a certain
address, we're no longer looking at a function prologue.  Higher level
code will try an alternative strategy or issue an error message.
Spamming the user with more error messages isn't going to be terribly
helpful.

But Michael is right that there is an issue here.  The code is relying
on uninitialized stack variables not matching the specific opcodes we
check against.  I think most of the:

    target_read_memory(pc, &op, 1);

statements, should be replaced with

    if (target_read_memory(pc, &op, 1))
      return pc;

Cheers,

Mark



More information about the Gdb-patches mailing list