Blame SOURCES/gdb-rhbz1261564-aarch64-hw-watchpoint-2of5.patch

01917d
http://sourceware.org/ml/gdb-patches/2015-02/msg00733.html
01917d
Subject: [PATCH 4/8] remote+docs: software/hardware breakpoint traps
01917d
01917d
This adjusts target remote to tell the core whether a trap was caused
01917d
by a breakpoint.
01917d
01917d
To that end, the patch teaches GDB about new RSP stop reasons "T05
01917d
swbreak" and "T05 hwbreak", that remote targets report back to GDB,
01917d
similarly to how "T05 watch" indicates a stop caused by a watchpoint.
01917d
01917d
Because targets that can report these events are expected to
01917d
themselves adjust the PC after a software breakpoint, these new stop
01917d
reasons must only be reported if the stub is talking to a GDB that
01917d
understands them.  Because of that, the use of the new stop reasons
01917d
needs to be handshaked on initial connection, using the qSupported
01917d
mechanism.  GDB simply sends "swbreak+" in its qSupports query, and
01917d
the stub reports back "swbreak+" too.
01917d
01917d
Because these new stop reasons are required to fix a fundamental
01917d
non-stop mode problem, this commit extends the remote non-stop intro
01917d
section in the manual, documenting the events as required.
01917d
01917d
To be clear, GDB will still cope with remote targets that don't
01917d
support these new stop reasons; it will behave just like today.
01917d
01917d
Tested on x86-64 Fedora 20, native and gdbserver.
01917d
01917d
gdb/ChangeLog:
01917d
2015-02-25  Pedro Alves  <palves@redhat.com>
01917d
01917d
	* NEWS: Mention the new "swbreak" and "hwbreak" stop reasons.
01917d
	* remote.c (struct remote_state) <remote_stopped_by_watchpoint_p>:
01917d
	Delete field.
01917d
	<stop_reason>: New field.
01917d
	(PACKET_swbreak_feature, PACKET_hwbreak_feature): New enum values.
01917d
	(packet_set_cmd_state): New function.
01917d
	(remote_protocol_features): Register the "swbreak" and "hwbreak"
01917d
	features.
01917d
	(remote_query_supported): If not disabled with the corresponding
01917d
	"set remote foo-packet" command, report support for the swbreak
01917d
	and hwbreak features.
01917d
	(struct stop_reply) <remote_stopped_by_watchpoint_p>: Delete
01917d
	field.
01917d
	<stop_reason>: New field.
01917d
	(remote_parse_stop_reply): Handle "swbreak" and "hwbreak".
01917d
	(remote_wait_as): Adjust.
01917d
	(remote_stopped_by_sw_breakpoint)
01917d
	(remote_supports_stopped_by_sw_breakpoint)
01917d
	(remote_stopped_by_hw_breakpoint)
01917d
	(remote_supports_stopped_by_hw_breakpoint): New functions.
01917d
	(remote_stopped_by_watchpoint): New function.
01917d
	(init_remote_ops): Install them.
01917d
	(_initialize_remote): Register new "set/show remote
01917d
	swbreak-feature-packet" and "set/show remote
01917d
	swbreak-feature-packet" commands.
01917d
01917d
gdb/doc/ChangeLog:
01917d
2015-02-25  Pedro Alves  <palves@redhat.com>
01917d
01917d
	* gdb.texinfo (Remote Configuration): Document the "set/show
01917d
	remote swbreak-feature-packet" and "set/show remote
01917d
	hwbreak-feature-packet" commands.
01917d
	(Packets) <Z0>: Add cross link to the "swbreak" stop reason's
01917d
	decription.
01917d
	(Stop Reply Packets): Document the swbreak and hwbreak stop
01917d
	reasons.
01917d
	(General Query Packets): Document the swbreak and hwbreak
01917d
	qSupported features.
01917d
	(Remote Non-Stop): Explain that swbreak and hwbreak are required.
01917d
---
01917d
 gdb/NEWS            |  10 +++++
01917d
 gdb/doc/gdb.texinfo |  80 +++++++++++++++++++++++++++++++++++
01917d
 gdb/remote.c        | 119 ++++++++++++++++++++++++++++++++++++++++++++++++----
01917d
 3 files changed, 200 insertions(+), 9 deletions(-)
01917d
01917d
Index: gdb-7.6.1/gdb/remote.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/remote.c	2016-03-13 19:41:32.258628611 +0100
01917d
+++ gdb-7.6.1/gdb/remote.c	2016-03-13 19:42:35.787094677 +0100
01917d
@@ -728,6 +728,9 @@
01917d
 /* This is non-zero if target stopped for a watchpoint.  */
01917d
 static int remote_stopped_by_watchpoint_p;
01917d
 
01917d
+/* RHEL: TARGET_STOPPED_BY_HW_BREAKPOINT */
01917d
+static int stopped_by_hw_breakpoint;
01917d
+
01917d
 static struct target_ops remote_ops;
01917d
 
01917d
 static struct target_ops extended_remote_ops;
01917d
@@ -1289,11 +1292,24 @@
01917d
   PACKET_Qbtrace_off,
01917d
   PACKET_Qbtrace_bts,
01917d
   PACKET_qXfer_btrace,
01917d
+
01917d
+  /* Support for hwbreak+ feature.  */
01917d
+  PACKET_hwbreak_feature,
01917d
+
01917d
   PACKET_MAX
01917d
 };
01917d
 
01917d
 static struct packet_config remote_protocol_packets[PACKET_MAX];
01917d
 
01917d
+/* Returns the packet's corresponding "set remote foo-packet" command
01917d
+   state.  See struct packet_config for more details.  */
01917d
+
01917d
+static enum auto_boolean
01917d
+packet_set_cmd_state (int packet)
01917d
+{
01917d
+  return remote_protocol_packets[packet].detect;
01917d
+}
01917d
+
01917d
 static void
01917d
 set_remote_protocol_packet_cmd (char *args, int from_tty,
01917d
 				struct cmd_list_element *c)
01917d
@@ -4017,7 +4033,8 @@
01917d
   { "Qbtrace:off", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_off },
01917d
   { "Qbtrace:bts", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_bts },
01917d
   { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
01917d
-    PACKET_qXfer_btrace }
01917d
+    PACKET_qXfer_btrace },
01917d
+  { "hwbreak", PACKET_DISABLE, remote_supported_packet, PACKET_hwbreak_feature }
01917d
 };
01917d
 
01917d
 static char *remote_support_xml;
01917d
@@ -4086,6 +4103,9 @@
01917d
 
01917d
       q = remote_query_supported_append (q, "multiprocess+");
01917d
 
01917d
+      if (packet_set_cmd_state (PACKET_hwbreak_feature) != AUTO_BOOLEAN_FALSE)
01917d
+	q = remote_query_supported_append (q, "hwbreak+");
01917d
+
01917d
       if (remote_support_xml)
01917d
 	q = remote_query_supported_append (q, remote_support_xml);
01917d
 
01917d
@@ -5202,6 +5222,9 @@
01917d
   int stopped_by_watchpoint_p;
01917d
   CORE_ADDR watch_data_address;
01917d
 
01917d
+  /* RHEL: TARGET_STOPPED_BY_HW_BREAKPOINT */
01917d
+  int stopped_by_hw_breakpoint;
01917d
+
01917d
   int solibs_changed;
01917d
   int replay_event;
01917d
 
01917d
@@ -5467,6 +5490,7 @@
01917d
   event->solibs_changed = 0;
01917d
   event->replay_event = 0;
01917d
   event->stopped_by_watchpoint_p = 0;
01917d
+  event->stopped_by_hw_breakpoint = 0;
01917d
   event->regcache = NULL;
01917d
   event->core = -1;
01917d
 
01917d
@@ -5522,6 +5546,23 @@
01917d
 		  p = unpack_varlen_hex (++p1, &addr);
01917d
 		  event->watch_data_address = (CORE_ADDR) addr;
01917d
 		}
01917d
+	      else if (strncmp (p, "hwbreak", p1 - p) == 0)
01917d
+		{
01917d
+		  event->stopped_by_hw_breakpoint = 1;
01917d
+
01917d
+		  /* Make sure the stub doesn't forget to indicate support
01917d
+		     with qSupported.  */
01917d
+		  //if (packet_support (PACKET_hwbreak_feature) != PACKET_ENABLE)
01917d
+		  //  error (_("Unexpected hwbreak stop reason"));
01917d
+
01917d
+		  /* See above.  */
01917d
+		  //p = skip_to_semicolon (p1 + 1);
01917d
+		  p1++;
01917d
+		  p_temp = p1;
01917d
+		  while (*p_temp && *p_temp != ';')
01917d
+		    p_temp++;
01917d
+		  p = p_temp;
01917d
+		}
01917d
 	      else if (strncmp (p, "library", p1 - p) == 0)
01917d
 		{
01917d
 		  p1++;
01917d
@@ -5783,6 +5824,7 @@
01917d
 
01917d
       remote_stopped_by_watchpoint_p = stop_reply->stopped_by_watchpoint_p;
01917d
       remote_watch_data_address = stop_reply->watch_data_address;
01917d
+      stopped_by_hw_breakpoint = stop_reply->stopped_by_hw_breakpoint;
01917d
 
01917d
       remote_notice_new_inferior (ptid, 0);
01917d
       demand_private_info (ptid)->core = stop_reply->core;
01917d
@@ -8310,6 +8352,16 @@
01917d
   return -1;
01917d
 }
01917d
 
01917d
+/* The to_stopped_by_hw_breakpoint method of target remote.  */
01917d
+
01917d
+static int
01917d
+remote_stopped_by_hw_breakpoint (struct target_ops *ops)
01917d
+{
01917d
+  struct remote_state *rs = get_remote_state ();
01917d
+
01917d
+  return stopped_by_hw_breakpoint;
01917d
+}
01917d
+
01917d
 static int
01917d
 remote_stopped_by_watchpoint (void)
01917d
 {
01917d
@@ -11372,6 +11424,7 @@
01917d
   remote_ops.to_files_info = remote_files_info;
01917d
   remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
01917d
   remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
01917d
+  remote_ops.to_stopped_by_hw_breakpoint = remote_stopped_by_hw_breakpoint;
01917d
   remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
01917d
   remote_ops.to_stopped_data_address = remote_stopped_data_address;
01917d
   remote_ops.to_watchpoint_addr_within_range =
01917d
@@ -12010,6 +12063,9 @@
01917d
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_btrace],
01917d
        "qXfer:btrace", "read-btrace", 0);
01917d
 
01917d
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_hwbreak_feature],
01917d
+                         "hwbreak-feature", "hwbreak-feature", 0);
01917d
+
01917d
   /* Keep the old ``set remote Z-packet ...'' working.  Each individual
01917d
      Z sub-packet has its own set and show commands, but users may
01917d
      have sets to this variable in their .gdbinit files (or in their