This is the mail archive of the gdb@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]

Remote Protocol: Z? packet proposal


Here is an implementation of CAN_USE_HW_WATCHPOINT using the Z? packet:

If there is no Z? packet support the function uses the method I
proposed earlier, though, as Andrew pointed out, it is not very robust.

static int
remote_check_watch_resources (int type, int cnt, int ot)
{
  struct remote_state *rs = get_remote_state ();
  char *buf = alloca (rs->remote_packet_size);
  enum Z_packet_type packet;

  if (remote_desc == NULL)
    error ("Cannot set hardware breakpoints before connecting to remote target.\n");
  
  switch (type) 
    {
    case bp_hardware_breakpoint:
      packet = Z_PACKET_HARDWARE_BP;
      break;
    case bp_hardware_watchpoint:
       packet = Z_PACKET_WRITE_WP;
       break;
    case bp_read_watchpoint:
      packet = Z_PACKET_READ_WP;
      break;
    case bp_access_watchpoint:
      packet = Z_PACKET_ACCESS_WP;
      break;
    default: /* Unknown type.  */
      return 0;
    }

  /* Don't bother if we already know that the packet isn't supported.  */
  if (remote_protocol_Z[packet].support == PACKET_DISABLE)
    return 0;

  /* Create the query packet.  */
  sprintf (buf, "Z?,%d,%d",cnt, type);
  
  putpkt (buf);
  getpkt (buf, rs->remote_packet_size, 0);
 
  if (!strlen (buf))  /* Z? not supported.  */
    {
      /* Send a dummy Z packet -- take any non null response as an
         indication that the packet is supported.  */
      /* Note: this is not very robust and may give an incorrect
         reponse.  */
      strcpy (buf, "Z1,1,");
      putpkt (buf);
      getpkt (buf, rs->remote_packet_size, 0);
      
      if (strlen (buf))
	return 1;
      remote_protocol_Z[packet].support = PACKET_DISABLE;
      return 0;
    }
  else if (!strcmp (buf, "OK")) 
    {
      remote_protocol_Z[packet].support = PACKET_ENABLE;
      return 1;
    }
  else if (!strcmp (buf, "E00")) /* Packet type not supported.  */
    {
      remote_protocol_Z[packet].support = PACKET_DISABLE;
      return 0;
    }
  else if (!strcmp (buf, "E01")) /* Exhausted resources.  */
    return -1;
  else if (!strcmp (buf, "E02")) /* Other error  */
    return -2;
  
  /* Should never get here.  */
  internal_error (__FILE__, __LINE__,
		  "remote_can_use_hw_breakpoint: reached end of function");
}

The functions that call CAN_USE_HW_WATCHPOINT must also be changed to
take advantage of the extra information.

The following is the documentation for the new packet:

@item @code{Z?}@code{,}@var{t}@code{,}@var{count} --- probe for breakpoint/watchpoint support @strong{(draft)}
@cindex @code{Z?} packet

@var{t} is type: see @ref{insert breakpoint or watchpoint
packet}. @var{count} is the number of breakpoints of type inserted
(including this one.)

Reply:
@table @samp
@item E00
for error -- packet type not supported
@item E01
for error -- hardware resources exhausted
@item E02
for error -- any other error
@item OK
for success
@item @samp{}
If not supported.
@end table


In use, this would look something like this:

user> hbreak main
 -> Z?,1,1
 <- OK
gdb> Hardware Breakpoint at main
user> hbreak foo
  -> Z?,1,2
  <- E01
gdb> Cannot insert hardware breakpoint -- exhausted resources
user> watch i
  -> Z?,2,1
  <- E00
gdb> Target does not support hardware watchpoints


any suggestions/comments?

grace


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