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]

Re: [RFC] Bug in remote.c


While trying to get gdbserver working on FreeBSD, I discovered
something that really smells like a bug in remote.c.

Yes.


In remote_prepare_to_store() we have the following:

  /* Make sure the entire registers array is valid.  */
  switch (remote_protocol_P.support)
    {
    case PACKET_DISABLE:
    case PACKET_SUPPORT_UNKNOWN:
      /* NOTE: This isn't rs->sizeof_g_packet because here, we are
         forcing the register cache to read its and not the target
         registers.  */
      deprecated_read_register_bytes (0, (char *) NULL,
				      DEPRECATED_REGISTER_BYTES); /* OK */

Recently, Andrew has removed the need to set REGISTER_BYTES and turned
it into DEPRECATED_REGISTER_BYTES.  On targets that don't set it,
DEPRECATED_REGISTER_BYTES will be zero, which reduces this
deprecated_read_register_bytes call to a no-op.  As a result GDB tries
to write garbage into the registers on the remote target, and sooner
or later things blow up in your face.

A possible solution would be to introduce a new function that
completely fills the register cache upon request.  Comments?

I'd change it to:


	for (i = 0; i < NUM_REGS; i++)
	  if (...->in_g_packet)
	    regcache_raw_read (...);

which will ensure that all G packet registers are valid.

The sequence the code is trying to prevent is:

-> Continue
<- T<status>,R0=...,R1=...
	target stops returning a few registers
-> G.....
	the G packet won't be valid for all registers

If you're feeling adventerious you could persue:

- add an assert to regcache_collect checking that the collected register is valid (you need to be really adventerous here :-)

- probe for P-packet support before doing the read (but, off hand, I can't think of a register number that would be safe to probe :-/)

Andrew



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