public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 08/13] New gdbarch methods breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (9 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 12/13] Determine the kind of single step breakpoint Yao Qi
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch adds two gdbarch methods breakpoint_kind_from_pc and
sw_breakpoint_from_kind, and uses target_info.placed_size as "kind"
of the breakpoint.  This patch updates the usages of
target_info.placed_size.

The "kind" of a breakpoint is determined by gdbarch rather than
target, so we have gdbarch method breakpoint_kind_from_pc, and we
should set target_info.placed_size out of each implementation of
target to_insert_breakpoint.  In this way, each target doesn't have
to set target_info.placed_size any more.

This patch also sets target_info.placed_address before
target_insert_breakpoint too, so that target to_insert_breakpoint
can use it, see record_full_insert_breakpoint.

Before we call target_insert_breakpoint, we set
target_info.placed_address and target_info.placed_size like this,

      CORE_ADDR addr = bl->target_info.reqstd_address;

      bl->target_info.placed_size = gdbarch_breakpoint_kind_from_pc (bl->gdbarch, &addr);
      bl->target_info.placed_address = addr;

      return target_insert_breakpoint (bl->gdbarch, &bl->target_info);

target_insert_breakpoint may fail, but it doesn't matter to the "kind"
and "placed_address" of a breakpoint.  They should be determined by
gdbarch.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_MANIPULATION): Define
	breakpoint_kind_from_pc and sw_breakpoint_from_kind.
	(GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): Likewise.
	(SET_GDBARCH_BREAKPOINT_MANIPULATION): Call
	set_gdbarch_breakpoint_kind_from_pc and
	set_gdbarch_sw_breakpoint_from_kind.
	* arm-tdep.c: Add comments.
	* bfin-tdep.c: Likewise.
	* breakpoint.c (breakpoint_kind): New function.
	(insert_bp_location): Set target_info.placed_size and
	target_info.placed_address.
	(bkpt_insert_location): Likewise.
	* cris-tdep.c: Add comments.
	* gdbarch.sh (breakpoint_kind_from_pc): New.
	(sw_breakpoint_from_kind): New.
	* gdbarch.c, gdbarch.h: Regenerated.
	* ia64-tdep.c (ia64_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	(ia64_memory_remove_breakpoint): Don't assert
	bp_tgt->placed_size.
	(ia64_breakpoint_kind_from_pc): New function.
	(ia64_gdbarch_init): Install ia64_breakpoint_kind_from_pc.
	* m32r-tdep.c (m32r_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	* mem-break.c (default_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.  Call gdbarch_sw_breakpoint_from_kind.
	(default_memory_remove_breakpoint): Call
	gdbarch_sw_breakpoint_from_kind.
	(memory_validate_breakpoint): Don't check bp_tgt->placed_size.
	* mips-tdep.c: Add comments.
	* mt-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* record-full.c (record_full_insert_breakpoint): Don't call
	gdbarch_breakpoint_from_pc.  Don't set bp_tgt->placed_address
	and bp_tgt->placed_size.
	* remote.c (remote_insert_breakpoint): Don't call
	gdbarch_remote_breakpoint_from_pc.  Use bp_tgt->placed_size.
	Don't set bp_tgt->placed_address and bp_tgt->placed_size.
	(remote_insert_hw_breakpoint): Likewise.
	* score-tdep.c: Likewise.
	* sh-tdep.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* v850-tdep.c: Likewise.
	* xtensa-tdep.c: Likewise.
---
 gdb/arch-utils.h  | 50 +++++++++++++++++++++++++++++++++-----------------
 gdb/arm-tdep.c    |  4 ++++
 gdb/bfin-tdep.c   |  4 ++++
 gdb/breakpoint.c  | 16 ++++++++++++++++
 gdb/cris-tdep.c   |  4 ++++
 gdb/gdbarch.c     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbarch.h     | 14 ++++++++++++++
 gdb/gdbarch.sh    |  9 +++++++++
 gdb/ia64-tdep.c   | 15 +++++++++++----
 gdb/m32r-tdep.c   |  6 +++++-
 gdb/mem-break.c   | 13 +++++++------
 gdb/mips-tdep.c   |  4 ++++
 gdb/mt-tdep.c     |  4 ++++
 gdb/nios2-tdep.c  |  4 ++++
 gdb/record-full.c | 10 ----------
 gdb/remote.c      | 16 ++--------------
 gdb/score-tdep.c  |  8 ++++++++
 gdb/sh-tdep.c     |  4 ++++
 gdb/tic6x-tdep.c  |  4 ++++
 gdb/v850-tdep.c   |  4 ++++
 gdb/xtensa-tdep.c |  4 ++++
 21 files changed, 191 insertions(+), 52 deletions(-)

diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 8efc4a8..0386d3d 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -38,34 +38,50 @@ struct gdbarch_info;
   }
 
 #define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
+  static int							      \
+  ARCH##_breakpoint_kind_from_pc (struct gdbarch *gdbarch,	      \
+				  CORE_ADDR *pcptr)		      \
+  {								      \
+    return sizeof (BREAK_INSN);				      \
+  }								      \
   static const gdb_byte *					      \
-  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		      \
-			     CORE_ADDR *pcptr,			      \
-			     int *lenptr)			      \
+  ARCH##_sw_breakpoint_from_kind (struct gdbarch *gdbarch,	      \
+				  int kind, int *size)		      \
   {								      \
-    *lenptr = sizeof (BREAK_INSN);				      \
+    *size = kind;						      \
     return BREAK_INSN;						      \
-  }
+  }								      \
+  GDBARCH_BREAKPOINT_FROM_PC (ARCH)
 
-#define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)	\
-  set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc)
+#define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)			\
+  set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc);	\
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch,			\
+				       ARCH##_breakpoint_kind_from_pc); \
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch,			\
+				       ARCH##_sw_breakpoint_from_kind)
 
 #define GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN(ARCH, \
 					       LITTLE_BREAK_INSN,	\
 					       BIG_BREAK_INSN)		\
-  static const gdb_byte *						\
-  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,			\
-			     CORE_ADDR *pcptr,				\
-			     int *lenptr)				\
+  static int								\
+  ARCH##_breakpoint_kind_from_pc (struct gdbarch *gdbarch,		\
+				  CORE_ADDR *pcptr)			\
   {									\
     gdb_static_assert (ARRAY_SIZE (LITTLE_BREAK_INSN)			\
 		       == ARRAY_SIZE (BIG_BREAK_INSN));		\
-    *lenptr = sizeof (LITTLE_BREAK_INSN);				\
-    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)		\
-      return BIG_BREAK_INSN;						\
-    else								\
-      return LITTLE_BREAK_INSN;					\
-  }
+    return sizeof (BIG_BREAK_INSN);					\
+  }									\
+  static const gdb_byte *					      \
+  ARCH##_sw_breakpoint_from_kind (struct gdbarch *gdbarch,	      \
+				  int kind, int *size)		      \
+  {								      \
+    *size = kind;						      \
+    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)	      \
+      return BIG_BREAK_INSN;					      \
+    else							      \
+      return LITTLE_BREAK_INSN;				      \
+  }								      \
+  GDBARCH_BREAKPOINT_FROM_PC (ARCH)
 
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 2513707..065d177 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7795,6 +7795,8 @@ static const gdb_byte arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -7828,6 +7830,8 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index d895997..c75858b 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -568,6 +568,8 @@ bfin_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   return map_gcc_gdb[reg];
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 bfin_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -583,6 +585,8 @@ bfin_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
     return 2;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6bb6bbf..f00c6c3 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2602,6 +2602,14 @@ build_target_command_list (struct bp_location *bl)
     bl->target_info.persist = 1;
 }
 
+/* Return the kind of breakpoint on address *ADDR.  */
+
+static int
+breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
+{
+  return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
+}
+
 /* Insert a low-level "breakpoint" of some type.  BL is the breakpoint
    location.  Any error messages are printed to TMP_ERROR_STREAM; and
    DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
@@ -2761,6 +2769,9 @@ insert_bp_location (struct bp_location *bl,
 		    {
 		      int val;
 
+		      bl->overlay_target_info.placed_size
+			= breakpoint_kind (bl, &addr);
+		      bl->overlay_target_info.placed_address = addr;
 		      val = target_insert_breakpoint (bl->gdbarch,
 						      &bl->overlay_target_info);
 		      if (val)
@@ -13116,6 +13127,11 @@ bkpt_re_set (struct breakpoint *b)
 static int
 bkpt_insert_location (struct bp_location *bl)
 {
+  CORE_ADDR addr = bl->target_info.reqstd_address;
+
+  bl->target_info.placed_size = breakpoint_kind (bl, &addr);
+  bl->target_info.placed_address = addr;
+
   if (bl->loc_type == bp_loc_hardware_breakpoint)
     return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index bee95cf..b202730 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -1391,12 +1391,16 @@ cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
   return sp;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   return 2;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index af7359e..a1cf602 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -229,6 +229,8 @@ struct gdbarch
   gdbarch_skip_entrypoint_ftype *skip_entrypoint;
   gdbarch_inner_than_ftype *inner_than;
   gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
+  gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc;
+  gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind;
   gdbarch_remote_breakpoint_from_pc_ftype *remote_breakpoint_from_pc;
   gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
   gdbarch_memory_insert_breakpoint_ftype *memory_insert_breakpoint;
@@ -401,6 +403,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->pointer_to_address = unsigned_pointer_to_address;
   gdbarch->address_to_pointer = unsigned_address_to_pointer;
   gdbarch->return_in_first_hidden_param_p = default_return_in_first_hidden_param_p;
+  gdbarch->sw_breakpoint_from_kind = NULL;
   gdbarch->remote_breakpoint_from_pc = default_remote_breakpoint_from_pc;
   gdbarch->memory_insert_breakpoint = default_memory_insert_breakpoint;
   gdbarch->memory_remove_breakpoint = default_memory_remove_breakpoint;
@@ -580,6 +583,9 @@ verify_gdbarch (struct gdbarch *gdbarch)
     fprintf_unfiltered (log, "\n\tinner_than");
   if (gdbarch->breakpoint_from_pc == 0)
     fprintf_unfiltered (log, "\n\tbreakpoint_from_pc");
+  if (gdbarch->breakpoint_kind_from_pc == 0)
+    fprintf_unfiltered (log, "\n\tbreakpoint_kind_from_pc");
+  /* Skip verify of sw_breakpoint_from_kind, invalid_p == 0 */
   /* Skip verify of remote_breakpoint_from_pc, invalid_p == 0 */
   /* Skip verify of adjust_breakpoint_address, has predicate.  */
   /* Skip verify of memory_insert_breakpoint, invalid_p == 0 */
@@ -790,6 +796,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: breakpoint_from_pc = <%s>\n",
                       host_address_to_string (gdbarch->breakpoint_from_pc));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: breakpoint_kind_from_pc = <%s>\n",
+                      host_address_to_string (gdbarch->breakpoint_kind_from_pc));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: byte_order = %s\n",
                       plongest (gdbarch->byte_order));
   fprintf_unfiltered (file,
@@ -1393,6 +1402,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: static_transform_name = <%s>\n",
                       host_address_to_string (gdbarch->static_transform_name));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: sw_breakpoint_from_kind = <%s>\n",
+                      host_address_to_string (gdbarch->sw_breakpoint_from_kind));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: syscalls_info = %s\n",
                       host_address_to_string (gdbarch->syscalls_info));
   fprintf_unfiltered (file,
@@ -2759,6 +2771,40 @@ set_gdbarch_breakpoint_from_pc (struct gdbarch *gdbarch,
   gdbarch->breakpoint_from_pc = breakpoint_from_pc;
 }
 
+int
+gdbarch_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->breakpoint_kind_from_pc != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_breakpoint_kind_from_pc called\n");
+  return gdbarch->breakpoint_kind_from_pc (gdbarch, pcptr);
+}
+
+void
+set_gdbarch_breakpoint_kind_from_pc (struct gdbarch *gdbarch,
+                                     gdbarch_breakpoint_kind_from_pc_ftype breakpoint_kind_from_pc)
+{
+  gdbarch->breakpoint_kind_from_pc = breakpoint_kind_from_pc;
+}
+
+const gdb_byte *
+gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->sw_breakpoint_from_kind != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_sw_breakpoint_from_kind called\n");
+  return gdbarch->sw_breakpoint_from_kind (gdbarch, kind, size);
+}
+
+void
+set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch,
+                                     gdbarch_sw_breakpoint_from_kind_ftype sw_breakpoint_from_kind)
+{
+  gdbarch->sw_breakpoint_from_kind = sw_breakpoint_from_kind;
+}
+
 void
 gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *kindptr)
 {
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index bc0f692..29abf65 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -542,6 +542,20 @@ typedef const gdb_byte * (gdbarch_breakpoint_from_pc_ftype) (struct gdbarch *gdb
 extern const gdb_byte * gdbarch_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr);
 extern void set_gdbarch_breakpoint_from_pc (struct gdbarch *gdbarch, gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc);
 
+/* Return the breakpoint kind for this target based on *PCPTR. */
+
+typedef int (gdbarch_breakpoint_kind_from_pc_ftype) (struct gdbarch *gdbarch, CORE_ADDR *pcptr);
+extern int gdbarch_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr);
+extern void set_gdbarch_breakpoint_kind_from_pc (struct gdbarch *gdbarch, gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc);
+
+/* Return the software breakpoint from KIND.  KIND can have target
+   specific meaning like the Z0 kind parameter.
+   SIZE is set to the software breakpoint's length in memory. */
+
+typedef const gdb_byte * (gdbarch_sw_breakpoint_from_kind_ftype) (struct gdbarch *gdbarch, int kind, int *size);
+extern const gdb_byte * gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size);
+extern void set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind);
+
 /* Return the adjusted address and kind to use for Z0/Z1 packets.
    KIND is usually the memory length of the breakpoint, but may have a
    different target-specific meaning. */
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index d8e0eeb..b73c6fa 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -555,6 +555,15 @@ M:CORE_ADDR:skip_entrypoint:CORE_ADDR ip:ip
 
 f:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs:0:0
 m:const gdb_byte *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr::0:
+
+# Return the breakpoint kind for this target based on *PCPTR.
+m:int:breakpoint_kind_from_pc:CORE_ADDR *pcptr:pcptr::0:
+
+# Return the software breakpoint from KIND.  KIND can have target
+# specific meaning like the Z0 kind parameter.
+# SIZE is set to the software breakpoint's length in memory.
+m:const gdb_byte *:sw_breakpoint_from_kind:int kind, int *size:kind, size::NULL::0
+
 # Return the adjusted address and kind to use for Z0/Z1 packets.
 # KIND is usually the memory length of the breakpoint, but may have a
 # different target-specific meaning.
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 5a14409..475decd 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -719,8 +719,6 @@ ia64_memory_insert_breakpoint (struct gdbarch *gdbarch,
 		    paddress (gdbarch, bp_tgt->placed_address));
   replace_slotN_contents (bundle, IA64_BREAKPOINT, slotnum);
 
-  bp_tgt->placed_size = bp_tgt->shadow_len;
-
   val = target_write_memory (addr + shadow_slotnum, bundle + shadow_slotnum,
 			     bp_tgt->shadow_len);
 
@@ -783,8 +781,7 @@ ia64_memory_remove_breakpoint (struct gdbarch *gdbarch,
       slotnum = 2;
     }
 
-  gdb_assert (bp_tgt->placed_size == BUNDLE_LEN - shadow_slotnum);
-  gdb_assert (bp_tgt->placed_size == bp_tgt->shadow_len);
+  gdb_assert (bp_tgt->shadow_len == BUNDLE_LEN - shadow_slotnum);
 
   instr_breakpoint = slotN_contents (bundle_mem, slotnum);
   if (instr_breakpoint != IA64_BREAKPOINT)
@@ -812,6 +809,15 @@ ia64_memory_remove_breakpoint (struct gdbarch *gdbarch,
   return val;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
+static int
+ia64_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  /* A place holder of gdbarch method breakpoint_kind_from_pc.   */
+  return 0;
+}
+
 /* As gdbarch_breakpoint_from_pc ranges have byte granularity and ia64
    instruction slots ranges are bit-granular (41 bits) we have to provide an
    extended range as described for ia64_memory_insert_breakpoint.  We also take
@@ -4009,6 +4015,7 @@ ia64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_memory_remove_breakpoint (gdbarch,
 					ia64_memory_remove_breakpoint);
   set_gdbarch_breakpoint_from_pc (gdbarch, ia64_breakpoint_from_pc);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch, ia64_breakpoint_kind_from_pc);
   set_gdbarch_read_pc (gdbarch, ia64_read_pc);
   set_gdbarch_write_pc (gdbarch, ia64_write_pc);
 
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 105fb9e..86ba44a 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -91,7 +91,7 @@ m32r_memory_insert_breakpoint (struct gdbarch *gdbarch,
     return val;			/* return error */
 
   memcpy (bp_tgt->shadow_contents, contents_cache, 4);
-  bp_tgt->placed_size = bp_tgt->shadow_len = 4;
+  bp_tgt->shadow_len = 4;
 
   /* Determine appropriate breakpoint contents and size for this address.  */
   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
@@ -165,6 +165,8 @@ m32r_memory_remove_breakpoint (struct gdbarch *gdbarch,
   return val;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 m32r_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -174,6 +176,8 @@ m32r_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
     return 2;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/mem-break.c b/gdb/mem-break.c
index cc8145c..dafe834 100644
--- a/gdb/mem-break.c
+++ b/gdb/mem-break.c
@@ -44,10 +44,7 @@ default_memory_insert_breakpoint (struct gdbarch *gdbarch,
   int val;
 
   /* Determine appropriate breakpoint contents and size for this address.  */
-  bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
-
-  bp_tgt->placed_address = addr;
-  bp_tgt->placed_size = bplen;
+  bp = gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->placed_size, &bplen);
 
   /* Save the memory contents in the shadow_contents buffer and then
      write the breakpoint instruction.  */
@@ -77,8 +74,12 @@ int
 default_memory_remove_breakpoint (struct gdbarch *gdbarch,
 				  struct bp_target_info *bp_tgt)
 {
+  int bplen;
+
+  gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->placed_size, &bplen);
+
   return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
-				  bp_tgt->placed_size);
+				  bplen);
 }
 
 
@@ -113,7 +114,7 @@ memory_validate_breakpoint (struct gdbarch *gdbarch,
      address.  */
   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
 
-  if (bp == NULL || bp_tgt->placed_size != bplen)
+  if (bp == NULL)
     return 0;
 
   /* Make sure we see the memory breakpoints.  */
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 1a9cfa5..e73b6e1 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -7050,6 +7050,8 @@ gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
   return gdb_print_insn_mips (memaddr, info);
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -7076,6 +7078,8 @@ mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
     return MIPS_BP_KIND_32BIT;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
index 0adf413..ffc03fb 100644
--- a/gdb/mt-tdep.c
+++ b/gdb/mt-tdep.c
@@ -449,12 +449,16 @@ mt_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   return pc;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 mt_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   return 4;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 mt_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index d48e156..8d879d7 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1693,6 +1693,8 @@ nios2_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   return nios2_analyze_prologue (gdbarch, start_pc, start_pc, &cache, NULL);
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 nios2_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -1713,6 +1715,8 @@ nios2_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
     return NIOS2_OPCODE_SIZE;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 nios2_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/record-full.c b/gdb/record-full.c
index e4dd55b..d5e1f8d 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1663,16 +1663,6 @@ record_full_insert_breakpoint (struct target_ops *ops,
 
       in_target_beneath = 1;
     }
-  else
-    {
-      CORE_ADDR addr = bp_tgt->reqstd_address;
-      int bplen;
-
-      gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
-
-      bp_tgt->placed_address = addr;
-      bp_tgt->placed_size = bplen;
-    }
 
   /* Use the existing entries if found in order to avoid duplication
      in record_full_breakpoints.  */
diff --git a/gdb/remote.c b/gdb/remote.c
index 910ac81..9eb1d4b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -9288,8 +9288,6 @@ remote_insert_breakpoint (struct target_ops *ops,
       if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
 	set_general_process ();
 
-      gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
-
       rs = get_remote_state ();
       p = rs->buf;
       endbuf = rs->buf + get_remote_packet_size ();
@@ -9299,7 +9297,7 @@ remote_insert_breakpoint (struct target_ops *ops,
       *(p++) = ',';
       addr = (ULONGEST) remote_address_masked (addr);
       p += hexnumstr (p, addr);
-      xsnprintf (p, endbuf - p, ",%d", bpsize);
+      xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
 
       if (remote_supports_cond_breakpoints (ops))
 	remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
@@ -9315,8 +9313,6 @@ remote_insert_breakpoint (struct target_ops *ops,
 	case PACKET_ERROR:
 	  return -1;
 	case PACKET_OK:
-	  bp_tgt->placed_address = addr;
-	  bp_tgt->placed_size = bpsize;
 	  return 0;
 	case PACKET_UNKNOWN:
 	  break;
@@ -9593,12 +9589,6 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
   struct remote_state *rs;
   char *p, *endbuf;
   char *message;
-  int bpsize;
-
-  /* The length field should be set to the size of a breakpoint
-     instruction, even though we aren't inserting one ourselves.  */
-
-  gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
 
   if (packet_support (PACKET_Z1) == PACKET_DISABLE)
     return -1;
@@ -9618,7 +9608,7 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 
   addr = remote_address_masked (addr);
   p += hexnumstr (p, (ULONGEST) addr);
-  xsnprintf (p, endbuf - p, ",%x", bpsize);
+  xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
 
   if (remote_supports_cond_breakpoints (self))
     remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
@@ -9642,8 +9632,6 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
     case PACKET_UNKNOWN:
       return -1;
     case PACKET_OK:
-      bp_tgt->placed_address = addr;
-      bp_tgt->placed_size = bpsize;
       return 0;
     }
   internal_error (__FILE__, __LINE__,
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index c325d48..715a092 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -306,6 +306,8 @@ score3_adjust_pc_and_fetch_inst (CORE_ADDR *pcptr, int *lenptr,
   return &inst;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 score7_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -335,6 +337,8 @@ score7_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
     }
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
@@ -366,6 +370,8 @@ score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 
 GDBARCH_BREAKPOINT_FROM_PC (score7)
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 score3_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -377,6 +383,8 @@ score3_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
   return len;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 score3_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 0ea5716..4ab29f0 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -417,12 +417,16 @@ sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
   return register_names[reg_nr];
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 sh_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   return 2;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index cf8a30f..b4ca757 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -317,12 +317,16 @@ tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 				 NULL);
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   return 4;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 9cc1b8b..85392a2 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -1168,12 +1168,16 @@ v850_return_value (struct gdbarch *gdbarch, struct value *function,
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 v850_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   return 2;
 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 v850_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 213f343..ed0664b 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1958,6 +1958,8 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
   return sp + SP_ALIGNMENT;
 }
 
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
@@ -1976,6 +1978,8 @@ xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 #define DENSITY_BIG_BREAKPOINT { 0xd2, 0x0f }
 #define DENSITY_LITTLE_BREAKPOINT { 0x2d, 0xf0 }
 
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
 static const gdb_byte *
 xtensa_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
@ 2016-08-31 15:06 Yao Qi
  2016-08-31 15:06 ` [PATCH 05/13] Share enum arm_breakpoint_kinds Yao Qi
                   ` (13 more replies)
  0 siblings, 14 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch series is to split gdbarch method brekapoint_from_pc to
methods breakpoint_kind_from_pc and sw_breakpoint_from_kind.  After
these changes, new gdbarch methods breakpoint_kind_from_pc and
sw_breakpoint_from_kind are more preferred than brekapoint_from_pc.

In this patch https://sourceware.org/ml/gdb-patches/2016-05/msg00201.html,
I wanted to remove a global variable arm_override_mode, and the
discussion leads to a design here
https://sourceware.org/ml/gdb-patches/2016-07/msg00211.html  In short,
we reuse bp_target_info.placed_size as the "kind" of a breakpoint,
which can be got by gdbarch breakpoint_kind_from_pc or
breakpoint_kind_from_current_state.

I choose a way that I can change the code incrementally, and make the
review easier.  Patch #1, #2, #5, and #8 are obvious, IMO.  Patch #7
and #12 do the major work, and the rest are code refactor.

Regression tested on arm-linux and x86_64-linux.  Tests on other
architectures are welcome!

*** BLURB HERE ***

Yao Qi (13):
  Remove v850_dbtrap_breakpoint_from_pc
  Rename 'arch' by 'gdbarch' in m32c_gdbarch_init
  gdbarch_breakpoint_from_pc doesn't return NULL
  GDBARCH_BREAKPOINT_MANIPULATION and
    SET_GDBARCH_BREAKPOINT_MANIPULATION
  Share enum arm_breakpoint_kinds
  Add enum for mips breakpoint kinds
  Split brekapoint_from_pc to breakpoint_kind_from_pc and
    sw_breakpoint_from_kind
  New gdbarch methods breakpoint_kind_from_pc and
    sw_breakpoint_from_kind
  Rename placed_size to kind
  Remove gdbarch_remote_breakpoint_from_pc
  Add default_breakpoint_from_pc
  Determine the kind of single step breakpoint
  Remove arm_override_mode

 gdb/aarch64-tdep.c                |  12 +-
 gdb/alpha-tdep.c                  |  12 +-
 gdb/arch-utils.c                  |  18 ++-
 gdb/arch-utils.h                  |  52 ++++++++-
 gdb/arch/arm.h                    |   8 ++
 gdb/arm-tdep.c                    | 125 +++++++++++++-------
 gdb/avr-tdep.c                    |  13 +--
 gdb/bfin-tdep.c                   |  32 +++---
 gdb/breakpoint.c                  |  27 +++++
 gdb/breakpoint.h                  |  10 +-
 gdb/cris-tdep.c                   |  24 ++--
 gdb/frv-tdep.c                    |  12 +-
 gdb/ft32-tdep.c                   |  13 +--
 gdb/gdbarch.c                     |  76 +++++++++---
 gdb/gdbarch.h                     |  26 ++++-
 gdb/gdbarch.sh                    |  20 +++-
 gdb/gdbserver/linux-aarch32-low.c |   8 --
 gdb/h8300-tdep.c                  |  14 +--
 gdb/hppa-tdep.c                   |  12 +-
 gdb/i386-tdep.c                   |  11 +-
 gdb/ia64-tdep.c                   |  15 ++-
 gdb/iq2000-tdep.c                 |  21 ++--
 gdb/lm32-tdep.c                   |  12 +-
 gdb/m32c-tdep.c                   |  53 ++++-----
 gdb/m32r-tdep.c                   |  51 ++++----
 gdb/m68hc11-tdep.c                |  13 +--
 gdb/m68k-tdep.c                   |  13 +--
 gdb/m88k-tdep.c                   |  15 +--
 gdb/mem-break.c                   |  15 ++-
 gdb/mep-tdep.c                    |  12 +-
 gdb/microblaze-linux-tdep.c       |   2 -
 gdb/microblaze-tdep.c             |  13 +--
 gdb/mips-tdep.c                   | 236 +++++++++++++++++++-------------------
 gdb/mn10300-tdep.c                |  12 +-
 gdb/moxie-tdep.c                  |  14 +--
 gdb/msp430-tdep.c                 |  14 +--
 gdb/mt-tdep.c                     |  27 +++--
 gdb/nios2-tdep.c                  |  98 +++++++++-------
 gdb/ppc-linux-tdep.c              |   2 -
 gdb/record-full.c                 |  10 --
 gdb/remote.c                      |  20 +---
 gdb/rl78-tdep.c                   |  22 ++--
 gdb/rs6000-tdep.c                 |  19 +--
 gdb/rx-tdep.c                     |  13 +--
 gdb/s390-linux-tdep.c             |  14 +--
 gdb/score-tdep.c                  | 119 ++++++++++---------
 gdb/sh-tdep.c                     |  38 +++---
 gdb/sh64-tdep.c                   |  69 +++++------
 gdb/sparc-tdep.c                  |  12 +-
 gdb/spu-tdep.c                    |  13 +--
 gdb/tic6x-tdep.c                  |  17 ++-
 gdb/tilegx-tdep.c                 |  18 +--
 gdb/v850-tdep.c                   |  60 +++++-----
 gdb/vax-tdep.c                    |  13 +--
 gdb/xstormy16-tdep.c              |  13 +--
 gdb/xtensa-tdep.c                 |  55 ++++-----
 56 files changed, 879 insertions(+), 809 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (8 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 02/13] Rename 'arch' by 'gdbarch' in m32c_gdbarch_init Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-10-10 10:05   ` Yao Qi
  2016-10-27 14:55   ` Pedro Alves
  2016-08-31 15:06 ` [PATCH 08/13] New gdbarch methods " Yao Qi
                   ` (3 subsequent siblings)
  13 siblings, 2 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

We convert each ARCH_brekapoint_from_pc to ARCH_breakpoint_kind_from_pc
and ARCH_sw_breakpoint_from_kind.  Note that gdbarch doesn't have methods
breakpoint_kind_from_pc and sw_breakpoint_from_kind so far.

gdb:

2016-08-31  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_FROM_PC): New macro.
	(GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): New macro.
	* arm-tdep.c (arm_breakpoint_from_pc): Remove.
	(arm_breakpoint_kind_from_pc): New function.
	(arm_sw_breakpoint_from_kind): New function.
	(arm_breakpoint_from_pc): Call arm_breakpoint_kind_from_pc
	and arm_sw_breakpoint_from_kind.
	Use GDBARCH_BREAKPOINT_FROM_PC.
	(arm_remote_breakpoint_from_pc): Call
	arm_breakpoint_kind_from_pc.
	(arm_gdbarch_init): Replace set_gdbarch_breakpoint_from_pc
	with SET_GDBARCH_BREAKPOINT_MANIPULATION.
	* bfin-tdep.c: Likewise.
	* cris-tdep.c: Likewise.
	* iq2000-tdep.c: Likewise.
	* m32r-tdep.c: Likewise.
	* mips-tdep.c: Likewise.
	* mt-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* rs6000-tdep.c: Likewise.
	* score-tdep.c: Likewise.
	* sh-tdep.c: Likewise.
	* sh64-tdep.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* v850-tdep.c: Likewise.
	* xtensa-tdep.c: Likewise.
---
 gdb/arch-utils.h  |  28 +++++++
 gdb/arm-tdep.c    |  61 ++++++++------
 gdb/bfin-tdep.c   |  36 +++++----
 gdb/cris-tdep.c   |  28 ++++---
 gdb/iq2000-tdep.c |  23 ++++--
 gdb/m32r-tdep.c   |  45 +++++------
 gdb/mips-tdep.c   | 234 +++++++++++++++++++++++++++---------------------------
 gdb/mt-tdep.c     |  27 ++++---
 gdb/nios2-tdep.c  |  98 ++++++++++++++---------
 gdb/rs6000-tdep.c |  19 ++---
 gdb/score-tdep.c  | 115 ++++++++++++++-------------
 gdb/sh-tdep.c     |  36 +++++----
 gdb/sh64-tdep.c   |  71 +++++++++--------
 gdb/tic6x-tdep.c  |  17 ++--
 gdb/v850-tdep.c   |  19 +++--
 gdb/xtensa-tdep.c |  53 ++++++-------
 16 files changed, 506 insertions(+), 404 deletions(-)

diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 77d4fb5..8efc4a8 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -26,6 +26,17 @@ struct minimal_symbol;
 struct type;
 struct gdbarch_info;
 
+#define GDBARCH_BREAKPOINT_FROM_PC(ARCH)			       \
+  static const gdb_byte *					       \
+  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		       \
+			     CORE_ADDR *pcptr,				\
+			     int *lenptr)				\
+  {									\
+    int kind = ARCH##_breakpoint_kind_from_pc (gdbarch, pcptr);	\
+								     \
+    return ARCH##_sw_breakpoint_from_kind (gdbarch, kind, lenptr);   \
+  }
+
 #define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
   static const gdb_byte *					      \
   ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		      \
@@ -39,6 +50,23 @@ struct gdbarch_info;
 #define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)	\
   set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc)
 
+#define GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN(ARCH, \
+					       LITTLE_BREAK_INSN,	\
+					       BIG_BREAK_INSN)		\
+  static const gdb_byte *						\
+  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,			\
+			     CORE_ADDR *pcptr,				\
+			     int *lenptr)				\
+  {									\
+    gdb_static_assert (ARRAY_SIZE (LITTLE_BREAK_INSN)			\
+		       == ARRAY_SIZE (BIG_BREAK_INSN));		\
+    *lenptr = sizeof (LITTLE_BREAK_INSN);				\
+    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)		\
+      return BIG_BREAK_INSN;						\
+    else								\
+      return LITTLE_BREAK_INSN;					\
+  }
+
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
    single-stepping the displaced copy.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 16dc574..2513707 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7795,16 +7795,8 @@ static const gdb_byte arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 
-/* Determine the type and size of breakpoint to insert at PCPTR.  Uses
-   the program counter value to determine whether a 16-bit or 32-bit
-   breakpoint should be used.  It returns a pointer to a string of
-   bytes that encode a breakpoint instruction, stores the length of
-   the string to *lenptr, and adjusts the program counter (if
-   necessary) to point to the actual memory location where the
-   breakpoint should be inserted.  */
-
-static const unsigned char *
-arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
+static int
+arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
@@ -7818,38 +7810,61 @@ arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
       if (tdep->thumb2_breakpoint != NULL)
 	{
 	  gdb_byte buf[2];
+
 	  if (target_read_memory (*pcptr, buf, 2) == 0)
 	    {
 	      unsigned short inst1;
+
 	      inst1 = extract_unsigned_integer (buf, 2, byte_order_for_code);
 	      if (thumb_insn_size (inst1) == 4)
-		{
-		  *lenptr = tdep->thumb2_breakpoint_size;
-		  return tdep->thumb2_breakpoint;
-		}
+		return ARM_BP_KIND_THUMB2;
 	    }
 	}
 
-      *lenptr = tdep->thumb_breakpoint_size;
-      return tdep->thumb_breakpoint;
+      return ARM_BP_KIND_THUMB;
     }
   else
+    return ARM_BP_KIND_ARM;
+
+}
+
+static const gdb_byte *
+arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  switch (kind)
     {
-      *lenptr = tdep->arm_breakpoint_size;
+    case ARM_BP_KIND_ARM:
+      *size = tdep->arm_breakpoint_size;
       return tdep->arm_breakpoint;
+    case ARM_BP_KIND_THUMB:
+      *size = tdep->thumb_breakpoint_size;
+      return tdep->thumb_breakpoint;
+    case ARM_BP_KIND_THUMB2:
+      *size = tdep->thumb2_breakpoint_size;
+      return tdep->thumb2_breakpoint;
+    default:
+      gdb_assert_not_reached ("unexpected arm breakpoint kind");
     }
 }
 
+/* Determine the type and size of breakpoint to insert at PCPTR.  Uses
+   the program counter value to determine whether a 16-bit or 32-bit
+   breakpoint should be used.  It returns a pointer to a string of
+   bytes that encode a breakpoint instruction, stores the length of
+   the string to *lenptr, and adjusts the program counter (if
+   necessary) to point to the actual memory location where the
+   breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (arm)
+
 static void
 arm_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
 			       int *kindptr)
 {
-  arm_breakpoint_from_pc (gdbarch, pcptr, kindptr);
 
-  if (arm_pc_is_thumb (gdbarch, *pcptr) && *kindptr == 4)
-    /* The documented magic value for a 32-bit Thumb-2 breakpoint, so
-       that this is not confused with a 32-bit ARM breakpoint.  */
-    *kindptr = ARM_BP_KIND_THUMB2;
+  *kindptr = arm_breakpoint_kind_from_pc (gdbarch, pcptr);
 }
 
 /* Extract from an array REGBUF containing the (raw) register state a
@@ -9359,7 +9374,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   /* Breakpoint manipulation.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, arm_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (arm);
   set_gdbarch_remote_breakpoint_from_pc (gdbarch,
 					 arm_remote_breakpoint_from_pc);
 
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index d07bf6e..d895997 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -568,28 +568,28 @@ bfin_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   return map_gcc_gdb[reg];
 }
 
-/* This function implements the 'breakpoint_from_pc' gdbarch method.
-   It returns a pointer to a string of bytes that encode a breakpoint
-   instruction, stores the length of the string to *lenptr, and
-   adjusts the program counter (if necessary) to point to the actual
-   memory location where the breakpoint should be inserted.  */
-
-static const unsigned char *
-bfin_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static int
+bfin_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned short iw;
-  static unsigned char bfin_breakpoint[] = {0xa1, 0x00, 0x00, 0x00};
-  static unsigned char bfin_sim_breakpoint[] = {0x25, 0x00, 0x00, 0x00};
 
   iw = read_memory_unsigned_integer (*pcptr, 2, byte_order);
 
   if ((iw & 0xf000) >= 0xc000)
     /* 32-bit instruction.  */
-    *lenptr = 4;
+    return 4;
   else
-    *lenptr = 2;
+    return 2;
+}
+
+static const gdb_byte *
+bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  static unsigned char bfin_breakpoint[] = {0xa1, 0x00, 0x00, 0x00};
+  static unsigned char bfin_sim_breakpoint[] = {0x25, 0x00, 0x00, 0x00};
+
+  *size = kind;
 
   if (strcmp (target_shortname, "sim") == 0)
     return bfin_sim_breakpoint;
@@ -597,6 +597,14 @@ bfin_breakpoint_from_pc (struct gdbarch *gdbarch,
     return bfin_breakpoint;
 }
 
+/* This function implements the 'breakpoint_from_pc' gdbarch method.
+   It returns a pointer to a string of bytes that encode a breakpoint
+   instruction, stores the length of the string to *lenptr, and
+   adjusts the program counter (if necessary) to point to the actual
+   memory location where the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (bfin)
+
 static void
 bfin_extract_return_value (struct type *type,
 			   struct regcache *regs,
@@ -826,7 +834,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_return_value (gdbarch, bfin_return_value);
   set_gdbarch_skip_prologue (gdbarch, bfin_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, bfin_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (bfin);
   set_gdbarch_decr_pc_after_break (gdbarch, 2);
   set_gdbarch_frame_args_skip (gdbarch, 8);
   set_gdbarch_unwind_pc (gdbarch, bfin_unwind_pc);
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 1d29524..bee95cf 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -1391,20 +1391,20 @@ cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
   return sp;
 }
 
-/* Use the program counter to determine the contents and size of a breakpoint
-   instruction.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pcptr (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
+static int
+cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 2;
+}
 
-static const unsigned char *
-cris_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static const gdb_byte *
+cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
-  *lenptr = 2;
+
+  *size = kind;
 
   if (tdep->cris_mode == cris_mode_guru)
     return break15_insn;
@@ -1412,6 +1412,14 @@ cris_breakpoint_from_pc (struct gdbarch *gdbarch,
     return break8_insn;
 }
 
+/* Use the program counter to determine the contents and size of a breakpoint
+   instruction.  It returns a pointer to a string of bytes that encode a
+   breakpoint instruction, stores the length of the string to *lenptr, and
+   adjusts pcptr (if necessary) to point to the actual memory location where
+   the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (cris)
+
 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
    0 otherwise.  */
 
@@ -4123,7 +4131,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* The stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (cris);
   
   set_gdbarch_unwind_pc (gdbarch, cris_unwind_pc);
   set_gdbarch_unwind_sp (gdbarch, cris_unwind_sp);
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 600d70a..ecd9074 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -469,22 +469,29 @@ static const struct frame_base iq2000_frame_base = {
   iq2000_frame_base_address
 };
 
-static const unsigned char *
-iq2000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static int
+iq2000_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
-  static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
-
   if ((*pcptr & 3) != 0)
     error (_("breakpoint_from_pc: invalid breakpoint address 0x%lx"),
 	   (long) *pcptr);
 
-  *lenptr = 4;
+  return 4;
+}
+
+static const gdb_byte *
+iq2000_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
+  static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
+  *size = kind;
+
   return (gdbarch_byte_order (gdbarch)
 	  == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (iq2000)
+
 /* Target function return value methods: */
 
 /* Function: store_return_value
@@ -826,7 +833,7 @@ iq2000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_double_format        (gdbarch, floatformats_ieee_double);
   set_gdbarch_long_double_format   (gdbarch, floatformats_ieee_double);
   set_gdbarch_return_value	   (gdbarch, iq2000_return_value);
-  set_gdbarch_breakpoint_from_pc   (gdbarch, iq2000_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (iq2000);
   set_gdbarch_frame_args_skip      (gdbarch, 0);
   set_gdbarch_skip_prologue        (gdbarch, iq2000_skip_prologue);
   set_gdbarch_inner_than           (gdbarch, core_addr_lessthan);
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index bc4b2d2..105fb9e 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -165,9 +165,17 @@ m32r_memory_remove_breakpoint (struct gdbarch *gdbarch,
   return val;
 }
 
+static int
+m32r_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  if ((*pcptr & 3) == 0)
+    return 4;
+  else
+    return 2;
+}
+
 static const gdb_byte *
-m32r_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   static gdb_byte be_bp_entry[] = {
     0x10, 0xf1, 0x70, 0x00
@@ -175,39 +183,22 @@ m32r_breakpoint_from_pc (struct gdbarch *gdbarch,
   static gdb_byte le_bp_entry[] = {
     0x00, 0x70, 0xf1, 0x10
   };	/* dpt -> nop */
-  gdb_byte *bp;
+
+  *size = kind;
 
   /* Determine appropriate breakpoint.  */
   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    {
-      if ((*pcptr & 3) == 0)
-	{
-	  bp = be_bp_entry;
-	  *lenptr = 4;
-	}
-      else
-	{
-	  bp = be_bp_entry;
-	  *lenptr = 2;
-	}
-    }
+    return be_bp_entry;
   else
     {
-      if ((*pcptr & 3) == 0)
-	{
-	  bp = le_bp_entry;
-	  *lenptr = 4;
-	}
+      if (kind == 4)
+	return le_bp_entry;
       else
-	{
-	  bp = le_bp_entry + 2;
-	  *lenptr = 2;
-	}
+	return le_bp_entry + 2;
     }
-
-  return bp;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (m32r)
 
 char *m32r_register_names[] = {
   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
@@ -929,7 +920,7 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, m32r_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m32r_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m32r);
   set_gdbarch_memory_insert_breakpoint (gdbarch,
 					m32r_memory_insert_breakpoint);
   set_gdbarch_memory_remove_breakpoint (gdbarch,
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 34df8d0..1a9cfa5 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -7050,141 +7050,137 @@ gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
   return gdb_print_insn_mips (memaddr, info);
 }
 
-/* This function implements gdbarch_breakpoint_from_pc.  It uses the
-   program counter value to determine whether a 16- or 32-bit breakpoint
-   should be used.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pc (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
-
-static const gdb_byte *
-mips_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
-{
-  CORE_ADDR pc = *pcptr;
-
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    {
-      if (mips_pc_is_mips16 (gdbarch, pc))
-	{
-	  static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = sizeof (mips16_big_breakpoint);
-	  return mips16_big_breakpoint;
-	}
-      else if (mips_pc_is_micromips (gdbarch, pc))
-	{
-	  static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
-	  static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
-	  ULONGEST insn;
-	  int err;
-	  int size;
-
-	  insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &err);
-	  size = err ? 2 : mips_insn_size (ISA_MICROMIPS, insn);
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = size;
-	  return (size == 2) ? micromips16_big_breakpoint
-			     : micromips32_big_breakpoint;
-	}
-      else
-	{
-	  /* The IDT board uses an unusual breakpoint value, and
-	     sometimes gets confused when it sees the usual MIPS
-	     breakpoint instruction.  */
-	  static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
-	  static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
-	  static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
-	  /* Likewise, IRIX appears to expect a different breakpoint,
-	     although this is not apparent until you try to use pthreads.  */
-	  static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
-
-	  *lenptr = sizeof (big_breakpoint);
-
-	  if (strcmp (target_shortname, "mips") == 0)
-	    return idt_big_breakpoint;
-	  else if (strcmp (target_shortname, "ddb") == 0
-		   || strcmp (target_shortname, "pmon") == 0
-		   || strcmp (target_shortname, "lsi") == 0)
-	    return pmon_big_breakpoint;
-	  else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
-	    return irix_big_breakpoint;
-	  else
-	    return big_breakpoint;
-	}
-    }
-  else
-    {
-      if (mips_pc_is_mips16 (gdbarch, pc))
-	{
-	  static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = sizeof (mips16_little_breakpoint);
-	  return mips16_little_breakpoint;
-	}
-      else if (mips_pc_is_micromips (gdbarch, pc))
-	{
-	  static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 };
-	  static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 };
-	  ULONGEST insn;
-	  int err;
-	  int size;
-
-	  insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &err);
-	  size = err ? 2 : mips_insn_size (ISA_MICROMIPS, insn);
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = size;
-	  return (size == 2) ? micromips16_little_breakpoint
-			     : micromips32_little_breakpoint;
-	}
-      else
-	{
-	  static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
-	  static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
-	  static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
-
-	  *lenptr = sizeof (little_breakpoint);
-
-	  if (strcmp (target_shortname, "mips") == 0)
-	    return idt_little_breakpoint;
-	  else if (strcmp (target_shortname, "ddb") == 0
-		   || strcmp (target_shortname, "pmon") == 0
-		   || strcmp (target_shortname, "lsi") == 0)
-	    return pmon_little_breakpoint;
-	  else
-	    return little_breakpoint;
-	}
-    }
-}
-
-/* Determine the remote breakpoint kind suitable for the PC.  */
-
-static void
-mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-				int *kindptr)
+static int
+mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   CORE_ADDR pc = *pcptr;
 
   if (mips_pc_is_mips16 (gdbarch, pc))
     {
       *pcptr = unmake_compact_addr (pc);
-      *kindptr = MIPS_BP_KIND_16BIT_MIPS16;
+      return MIPS_BP_KIND_16BIT_MIPS16;
     }
   else if (mips_pc_is_micromips (gdbarch, pc))
     {
       ULONGEST insn;
       int status;
 
+      *pcptr = unmake_compact_addr (pc);
       insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status);
       if (status || (mips_insn_size (ISA_MICROMIPS, insn) == 2))
-	*kindptr = MIPS_BP_KIND_16BIT_MICROMIPS;
+	return MIPS_BP_KIND_16BIT_MICROMIPS;
       else
-	*kindptr = MIPS_BP_KIND_32BIT_MICROMIPS;
-
-      *pcptr = unmake_compact_addr (pc);
+	return MIPS_BP_KIND_32BIT_MICROMIPS;
     }
   else
-    *kindptr = MIPS_BP_KIND_32BIT;
+    return MIPS_BP_KIND_32BIT;
+}
+
+static const gdb_byte *
+mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
+
+  switch (kind)
+    {
+    case MIPS_BP_KIND_16BIT_MIPS16:
+      {
+	static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
+	static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
+
+	*size = 2;
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return mips16_big_breakpoint;
+	else
+	  return mips16_little_breakpoint;
+      }
+    case MIPS_BP_KIND_16BIT_MICROMIPS:
+      {
+	static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
+	static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 };
+
+	*size = 2;
+
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return micromips16_big_breakpoint;
+	else
+	  return micromips16_little_breakpoint;
+      }
+    case MIPS_BP_KIND_32BIT_MICROMIPS:
+      {
+	static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
+	static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 };
+
+	*size = 4;
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return micromips32_big_breakpoint;
+	else
+	  return micromips32_little_breakpoint;
+      }
+    case MIPS_BP_KIND_32BIT:
+      {
+	/* The IDT board uses an unusual breakpoint value, and
+	   sometimes gets confused when it sees the usual MIPS
+	   breakpoint instruction.  */
+	static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
+	static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
+	static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
+	static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
+	static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
+	static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
+	/* Likewise, IRIX appears to expect a different breakpoint,
+	   although this is not apparent until you try to use pthreads.  */
+	static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
+
+	*size = 4;
+
+	if (strcmp (target_shortname, "mips") == 0)
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return idt_big_breakpoint;
+	    else
+	      return idt_little_breakpoint;
+	  }
+	else if (strcmp (target_shortname, "ddb") == 0
+		 || strcmp (target_shortname, "pmon") == 0
+		 || strcmp (target_shortname, "lsi") == 0)
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return pmon_big_breakpoint;
+	    else
+	      return pmon_little_breakpoint;
+	  }
+	else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
+	  return irix_big_breakpoint;
+	else
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return big_breakpoint;
+	    else
+	      return little_breakpoint;
+	  }
+      }
+    default:
+      gdb_assert_not_reached ("unexpected mips breakpoint kind");
+    };
+}
+
+/* This function implements gdbarch_breakpoint_from_pc.  It uses the
+   program counter value to determine whether a 16- or 32-bit breakpoint
+   should be used.  It returns a pointer to a string of bytes that encode a
+   breakpoint instruction, stores the length of the string to *lenptr, and
+   adjusts pc (if necessary) to point to the actual memory location where
+   the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (mips)
+
+/* Determine the remote breakpoint kind suitable for the PC.  */
+
+static void
+mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
+				int *kindptr)
+{
+  *kindptr = mips_breakpoint_kind_from_pc (gdbarch, pcptr);
 }
 
 /* Return non-zero if the standard MIPS instruction INST has a branch
@@ -8797,7 +8793,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mips);
   set_gdbarch_remote_breakpoint_from_pc (gdbarch,
 					 mips_remote_breakpoint_from_pc);
   set_gdbarch_adjust_breakpoint_address (gdbarch,
diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
index 5d7f31c..0adf413 100644
--- a/gdb/mt-tdep.c
+++ b/gdb/mt-tdep.c
@@ -449,26 +449,33 @@ mt_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   return pc;
 }
 
-/* The breakpoint instruction must be the same size as the smallest
-   instruction in the instruction set.
-
-   The BP for ms1 is defined as 0x68000000 (BREAK).
-   The BP for ms2 is defined as 0x69000000 (illegal).  */
+static int
+mt_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 4;
+}
 
 static const gdb_byte *
-mt_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-		       int *bp_size)
+mt_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
+  /* The breakpoint instruction must be the same size as the smallest
+     instruction in the instruction set.
+
+     The BP for ms1 is defined as 0x68000000 (BREAK).
+     The BP for ms2 is defined as 0x69000000 (illegal).  */
   static gdb_byte ms1_breakpoint[] = { 0x68, 0, 0, 0 };
   static gdb_byte ms2_breakpoint[] = { 0x69, 0, 0, 0 };
 
-  *bp_size = 4;
+  *size = kind;
+
   if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
     return ms2_breakpoint;
-  
+
   return ms1_breakpoint;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (mt)
+
 /* Select the correct coprocessor register bank.  Return the pseudo
    regnum we really want to read.  */
 
@@ -1162,7 +1169,7 @@ mt_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pseudo_register_write (gdbarch, mt_pseudo_register_write);
   set_gdbarch_skip_prologue (gdbarch, mt_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, mt_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mt);
   set_gdbarch_decr_pc_after_break (gdbarch, 0);
   set_gdbarch_frame_args_skip (gdbarch, 0);
   set_gdbarch_print_insn (gdbarch, print_insn_mt);
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 8bfd8b3..d48e156 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1693,9 +1693,30 @@ nios2_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   return nios2_analyze_prologue (gdbarch, start_pc, start_pc, &cache, NULL);
 }
 
-/* Implement the breakpoint_from_pc gdbarch hook.
+static int
+nios2_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+
+  if (mach == bfd_mach_nios2r2)
+    {
+      unsigned int insn;
+      const struct nios2_opcode *op
+	= nios2_fetch_insn (gdbarch, *pcptr, &insn);
+
+      if (op && op->size == NIOS2_CDX_OPCODE_SIZE)
+	return NIOS2_CDX_OPCODE_SIZE;
+      else
+	return NIOS2_OPCODE_SIZE;
+    }
+  else
+    return NIOS2_OPCODE_SIZE;
+}
 
-   The Nios II ABI for Linux says: "Userspace programs should not use
+static const gdb_byte *
+nios2_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+/* The Nios II ABI for Linux says: "Userspace programs should not use
    the break instruction and userspace debuggers should not insert
    one." and "Userspace breakpoints are accomplished using the trap
    instruction with immediate operand 31 (all ones)."
@@ -1703,54 +1724,53 @@ nios2_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
    So, we use "trap 31" consistently as the breakpoint on bare-metal
    as well as Linux targets.  */
 
-static const gdb_byte*
-nios2_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			  int *bp_size)
-{
-  enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
-  unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+  /* R2 trap encoding:
+     ((0x2d << 26) | (0x1f << 21) | (0x1d << 16) | (0x20 << 0))
+     0xb7fd0020
+     CDX trap.n encoding:
+     ((0xd << 12) | (0x1f << 6) | (0x9 << 0))
+     0xd7c9
+     Note that code is always little-endian on R2.  */
+  *size = kind;
 
-  if (mach == bfd_mach_nios2r2)
+  if (kind == NIOS2_CDX_OPCODE_SIZE)
     {
-      /* R2 trap encoding:
-	   ((0x2d << 26) | (0x1f << 21) | (0x1d << 16) | (0x20 << 0))
-	   0xb7fd0020
-	 CDX trap.n encoding:
-	   ((0xd << 12) | (0x1f << 6) | (0x9 << 0))
-	   0xd7c9
-         Note that code is always little-endian on R2.  */
-      static const gdb_byte r2_breakpoint_le[] = {0x20, 0x00, 0xfd, 0xb7};
       static const gdb_byte cdx_breakpoint_le[] = {0xc9, 0xd7};
-      unsigned int insn;
-      const struct nios2_opcode *op
-	= nios2_fetch_insn (gdbarch, *bp_addr, &insn);
 
-      if (op && op->size == NIOS2_CDX_OPCODE_SIZE)
+      return cdx_breakpoint_le;
+    }
+  else
+    {
+      unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+
+      if (mach == bfd_mach_nios2r2)
 	{
-	  *bp_size = NIOS2_CDX_OPCODE_SIZE;
-	  return cdx_breakpoint_le;
+	  static const gdb_byte r2_breakpoint_le[] = {0x20, 0x00, 0xfd, 0xb7};
+
+	  return r2_breakpoint_le;
 	}
       else
 	{
-	  *bp_size = NIOS2_OPCODE_SIZE;
-	  return r2_breakpoint_le;
+	  enum bfd_endian byte_order_for_code
+	    = gdbarch_byte_order_for_code (gdbarch);
+	  /* R1 trap encoding:
+	     ((0x1d << 17) | (0x2d << 11) | (0x1f << 6) | (0x3a << 0))
+	     0x003b6ffa */
+	  static const gdb_byte r1_breakpoint_le[] = {0xfa, 0x6f, 0x3b, 0x0};
+	  static const gdb_byte r1_breakpoint_be[] = {0x0, 0x3b, 0x6f, 0xfa};
+
+	  if (byte_order_for_code == BFD_ENDIAN_BIG)
+	    return r1_breakpoint_be;
+	  else
+	    return r1_breakpoint_le;
 	}
     }
-  else
-    {
-      /* R1 trap encoding:
-	 ((0x1d << 17) | (0x2d << 11) | (0x1f << 6) | (0x3a << 0))
-	 0x003b6ffa */
-      static const gdb_byte r1_breakpoint_le[] = {0xfa, 0x6f, 0x3b, 0x0};
-      static const gdb_byte r1_breakpoint_be[] = {0x0, 0x3b, 0x6f, 0xfa};
-      *bp_size = NIOS2_OPCODE_SIZE;
-      if (byte_order_for_code == BFD_ENDIAN_BIG)
-	return r1_breakpoint_be;
-      else
-	return r1_breakpoint_le;
-    }
 }
 
+/* Implement the breakpoint_from_pc gdbarch hook.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (nios2)
+
 /* Implement the print_insn gdbarch method.  */
 
 static int
@@ -2315,7 +2335,7 @@ nios2_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, nios2_skip_prologue);
   set_gdbarch_stack_frame_destroyed_p (gdbarch, nios2_stack_frame_destroyed_p);
-  set_gdbarch_breakpoint_from_pc (gdbarch, nios2_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (nios2);
 
   set_gdbarch_dummy_id (gdbarch, nios2_dummy_id);
   set_gdbarch_unwind_pc (gdbarch, nios2_unwind_pc);
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index e180641..9f19ad2 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -966,18 +966,11 @@ rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
 
 /* Sequence of bytes for breakpoint instruction.  */
 
-static const unsigned char *
-rs6000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			   int *bp_size)
-{
-  static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
-  static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
-  *bp_size = 4;
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    return big_breakpoint;
-  else
-    return little_breakpoint;
-}
+static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
+static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
+
+GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN (rs6000, little_breakpoint,
+					big_breakpoint)
 
 /* Instruction masks for displaced stepping.  */
 #define BRANCH_MASK 0xfc000000
@@ -6039,7 +6032,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (rs6000);
 
   /* The value of symbols of type N_SO and N_FUN maybe null when
      it shouldn't be.  */
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index 8e08d05..c325d48 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -306,69 +306,82 @@ score3_adjust_pc_and_fetch_inst (CORE_ADDR *pcptr, int *lenptr,
   return &inst;
 }
 
-static const gdb_byte *
-score7_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static int
+score7_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  gdb_byte buf[SCORE_INSTLEN] = { 0 };
   int ret;
   unsigned int raw;
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  gdb_byte buf[SCORE_INSTLEN] = { 0 };
 
   if ((ret = target_read_memory (*pcptr & ~0x3, buf, SCORE_INSTLEN)) != 0)
     {
       error (_("Error: target_read_memory in file:%s, line:%d!"),
-             __FILE__, __LINE__);
+	     __FILE__, __LINE__);
     }
   raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order);
 
-  if (byte_order == BFD_ENDIAN_BIG)
+  if (!(raw & 0x80008000))
     {
-      if (!(raw & 0x80008000))
-        {
-          /* 16bits instruction.  */
-          static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
-          *pcptr &= ~0x1;
-          *lenptr = sizeof (big_breakpoint16);
-          return big_breakpoint16;
-        }
+      /* 16bits instruction.  */
+      *pcptr &= ~0x1;
+      return 2;
+    }
+  else
+    {
+      /* 32bits instruction.  */
+      *pcptr &= ~0x3;
+      return 4;
+    }
+}
+
+static const gdb_byte *
+score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  *size = kind;
+
+  if (kind == 4)
+    {
+      static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
+      static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
+
+      if (byte_order == BFD_ENDIAN_BIG)
+	return big_breakpoint32;
       else
-        {
-          /* 32bits instruction.  */
-          static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
-          *pcptr &= ~0x3;
-          *lenptr = sizeof (big_breakpoint32);
-          return big_breakpoint32;
-        }
+	return little_breakpoint32;
     }
   else
     {
-      if (!(raw & 0x80008000))
-        {
-          /* 16bits instruction.  */
-          static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
-          *pcptr &= ~0x1;
-          *lenptr = sizeof (little_breakpoint16);
-          return little_breakpoint16;
-        }
+      static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
+      static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
+
+      if (byte_order == BFD_ENDIAN_BIG)
+	return big_breakpoint16;
       else
-        {
-          /* 32bits instruction.  */
-          static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
-          *pcptr &= ~0x3;
-          *lenptr = sizeof (little_breakpoint32);
-          return little_breakpoint32;
-        }
+	return little_breakpoint16;
     }
 }
 
-static const gdb_byte *
-score3_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+GDBARCH_BREAKPOINT_FROM_PC (score7)
+
+static int
+score3_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  CORE_ADDR adjust_pc = *pcptr; 
   int len;
+
+  score3_adjust_pc_and_fetch_inst (pcptr, &len, byte_order);
+
+  return len;
+}
+
+static const gdb_byte *
+score3_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  int index = 0;
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   static gdb_byte score_break_insns[6][6] = {
     /* The following three instructions are big endian.  */
     { 0x00, 0x20 },
@@ -379,20 +392,14 @@ score3_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
     { 0x00, 0x80, 0x06, 0x00 },
     { 0x00, 0x80, 0x00, 0x80, 0x00, 0x00 }};
 
-  gdb_byte *p = NULL;
-  int index = 0;
-
-  score3_adjust_pc_and_fetch_inst (&adjust_pc, &len, byte_order);
-
-  index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (len / 2 - 1);
-  p = score_break_insns[index];
+  *size = kind;
 
-  *pcptr = adjust_pc;
-  *lenptr = len;
-
-  return p;
+  index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (kind / 2 - 1);
+  return score_break_insns[index];
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (score3)
+
 static CORE_ADDR
 score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
 {
@@ -1485,7 +1492,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   switch (target_mach)
     {
     case bfd_mach_score7:
-      set_gdbarch_breakpoint_from_pc (gdbarch, score7_breakpoint_from_pc);
+      SET_GDBARCH_BREAKPOINT_MANIPULATION (score7);
       set_gdbarch_skip_prologue (gdbarch, score7_skip_prologue);
       set_gdbarch_stack_frame_destroyed_p (gdbarch,
 					   score7_stack_frame_destroyed_p);
@@ -1497,7 +1504,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       break;
 
     case bfd_mach_score3:
-      set_gdbarch_breakpoint_from_pc (gdbarch, score3_breakpoint_from_pc);
+      SET_GDBARCH_BREAKPOINT_MANIPULATION (score3);
       set_gdbarch_skip_prologue (gdbarch, score3_skip_prologue);
       set_gdbarch_stack_frame_destroyed_p (gdbarch,
 					   score3_stack_frame_destroyed_p);
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 694f5f7..0ea5716 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -417,11 +417,16 @@ sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
   return register_names[reg_nr];
 }
 
-static const unsigned char *
-sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
+static int
+sh_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  /* 0xc3c3 is trapa #c3, and it works in big and little endian modes.  */
-  static unsigned char breakpoint[] = { 0xc3, 0xc3 };
+  return 2;
+}
+
+static const gdb_byte *
+sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
 
   /* For remote stub targets, trapa #20 is used.  */
   if (strcmp (target_shortname, "remote") == 0)
@@ -430,21 +435,22 @@ sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
 
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (big_remote_breakpoint);
-	  return big_remote_breakpoint;
-	}
+	return big_remote_breakpoint;
       else
-	{
-	  *lenptr = sizeof (little_remote_breakpoint);
-	  return little_remote_breakpoint;
-	}
+	return little_remote_breakpoint;
     }
+  else
+    {
+      /* 0xc3c3 is trapa #c3, and it works in big and little endian
+	 modes.  */
+      static unsigned char breakpoint[] = { 0xc3, 0xc3 };
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
+      return breakpoint;
+    }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (sh)
+
 /* Prologue looks like
    mov.l	r14,@-r15
    sts.l	pr,@-r15
@@ -2273,7 +2279,7 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_register_type (gdbarch, sh_default_register_type);
   set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sh);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index ee8d19c..4f97223 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -252,11 +252,24 @@ pc_is_isa32 (bfd_vma memaddr)
     return 0;
 }
 
-static const unsigned char *
-sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static int
+sh64_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  /* The BRK instruction for shmedia is 
+  if (pc_is_isa32 (*pcptr))
+    {
+      *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
+      return 4;
+    }
+  else
+    return 2;
+}
+
+static const gdb_byte *
+sh64_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+  /* The BRK instruction for shmedia is
      01101111 11110101 11111111 11110000
      which translates in big endian mode to 0x6f, 0xf5, 0xff, 0xf0
      and in little endian mode to 0xf0, 0xff, 0xf5, 0x6f */
@@ -266,44 +279,34 @@ sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
      which translates in big endian mode to 0x0, 0x3b
      and in little endian mode to 0x3b, 0x0 */
 
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+  if (kind == 4)
     {
-      if (pc_is_isa32 (*pcptr))
-	{
-	  static unsigned char big_breakpoint_media[] = {
-	    0x6f, 0xf5, 0xff, 0xf0
-	  };
-	  *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-	  *lenptr = sizeof (big_breakpoint_media);
-	  return big_breakpoint_media;
-	}
+      static unsigned char big_breakpoint_media[] = {
+	0x6f, 0xf5, 0xff, 0xf0
+      };
+      static unsigned char little_breakpoint_media[] = {
+	0xf0, 0xff, 0xf5, 0x6f
+      };
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	return big_breakpoint_media;
       else
-	{
-	  static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
-	  *lenptr = sizeof (big_breakpoint_compact);
-	  return big_breakpoint_compact;
-	}
+	return little_breakpoint_media;
     }
   else
     {
-      if (pc_is_isa32 (*pcptr))
-	{
-	  static unsigned char little_breakpoint_media[] = {
-	    0xf0, 0xff, 0xf5, 0x6f
-	  };
-	  *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-	  *lenptr = sizeof (little_breakpoint_media);
-	  return little_breakpoint_media;
-	}
+      static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
+      static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	return big_breakpoint_compact;
       else
-	{
-	  static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
-	  *lenptr = sizeof (little_breakpoint_compact);
-	  return little_breakpoint_compact;
-	}
+	return little_breakpoint_compact;
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (sh64)
+
 /* Prologue looks like
    [mov.l       <regs>,@-r15]...
    [sts.l       pr,@-r15]
@@ -2409,7 +2412,7 @@ sh64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
   set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh64_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sh64);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index af53938..cf8a30f 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -317,15 +317,18 @@ tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 				 NULL);
 }
 
-/* This is the implementation of gdbarch method breakpiont_from_pc.  */
+static int
+tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 4;
+}
 
 static const gdb_byte *
-tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			  int *bp_size)
+tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  *bp_size = 4;
+  *size = kind;
 
   if (tdep == NULL || tdep->breakpoint == NULL)
     {
@@ -338,6 +341,10 @@ tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
     return tdep->breakpoint;
 }
 
+/* This is the implementation of gdbarch method breakpiont_from_pc.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (tic6x)
+
 /* This is the implementation of gdbarch method print_insn.  */
 
 static int
@@ -1294,7 +1301,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   set_gdbarch_skip_prologue (gdbarch, tic6x_skip_prologue);
-  set_gdbarch_breakpoint_from_pc (gdbarch, tic6x_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (tic6x);
 
   set_gdbarch_unwind_pc (gdbarch, tic6x_unwind_pc);
   set_gdbarch_unwind_sp (gdbarch, tic6x_unwind_sp);
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index d03334e..9cc1b8b 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -1168,13 +1168,18 @@ v850_return_value (struct gdbarch *gdbarch, struct value *function,
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
 
-static const unsigned char *
-v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			 int *lenptr)
+static int
+v850_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  *lenptr = 2;
+  return 2;
+}
 
-  switch (gdbarch_bfd_arch_info (gdbarch)->mach)
+static const gdb_byte *
+v850_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+    switch (gdbarch_bfd_arch_info (gdbarch)->mach)
     {
     case bfd_mach_v850e2:
     case bfd_mach_v850e2v3:
@@ -1199,6 +1204,8 @@ v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (v850)
+
 static struct v850_frame_cache *
 v850_alloc_frame_cache (struct frame_info *this_frame)
 {
@@ -1448,7 +1455,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (v850);
   set_gdbarch_return_value (gdbarch, v850_return_value);
   set_gdbarch_push_dummy_call (gdbarch, v850_push_dummy_call);
   set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 32beafd..213f343 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1958,6 +1958,14 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
   return sp + SP_ALIGNMENT;
 }
 
+static int
+xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  if (gdbarch_tdep (gdbarch)->isa_use_density_instructions)
+    return 2;
+  else
+    return 4;
+}
 
 /* Return a breakpoint for the current location of PC.  We always use
    the density version if we have density instructions (regardless of the
@@ -1968,45 +1976,36 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 #define DENSITY_BIG_BREAKPOINT { 0xd2, 0x0f }
 #define DENSITY_LITTLE_BREAKPOINT { 0x2d, 0xf0 }
 
-static const unsigned char *
-xtensa_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static const gdb_byte *
+xtensa_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
-  static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
-  static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
-  static unsigned char density_little_breakpoint[] = DENSITY_LITTLE_BREAKPOINT;
+  *size = kind;
 
-  DEBUGTRACE ("xtensa_breakpoint_from_pc (pc = 0x%08x)\n", (int) *pcptr);
-
-  if (gdbarch_tdep (gdbarch)->isa_use_density_instructions)
+  if (kind == 4)
     {
+      static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
+      static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
+
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (density_big_breakpoint);
-	  return density_big_breakpoint;
-	}
+	return big_breakpoint;
       else
-	{
-	  *lenptr = sizeof (density_little_breakpoint);
-	  return density_little_breakpoint;
-	}
+	return little_breakpoint;
     }
   else
     {
+      static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
+      static unsigned char density_little_breakpoint[]
+	= DENSITY_LITTLE_BREAKPOINT;
+
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (big_breakpoint);
-	  return big_breakpoint;
-	}
+	return density_big_breakpoint;
       else
-	{
-	  *lenptr = sizeof (little_breakpoint);
-	  return little_breakpoint;
-	}
+	return density_little_breakpoint;
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (xtensa)
+
 /* Call0 ABI support routines.  */
 
 /* Return true, if PC points to "ret" or "ret.n".  */ 
@@ -3238,7 +3237,7 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   /* Set breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, xtensa_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (xtensa);
 
   /* After breakpoint instruction or illegal instruction, pc still
      points at break instruction, so don't decrement.  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (2 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 11/13] Add default_breakpoint_from_pc Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-09-28 15:23   ` Michael Eager
  2016-08-31 15:06 ` [PATCH 04/13] GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION Yao Qi
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

gdbarch_breakpoint_from_pc doesn't return NULL except for
ia64_breakpoint_from_pc, and we checked its return value in three
places. In microblaze_linux_memory_remove_breakpoint and
ppc_linux_memory_remove_breakpoint, gdbarch_breakpoint_from_pc never
returns NULL, so we can remove the NULL checking.  In
default_memory_insert_breakpoint, gdbarch_breakpoint_from_pc can't
returns NULL too because ia64 defines its own memory_insert_breakpoint.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* mem-break.c (default_memory_insert_breakpoint): Don't check
	'bp' against NULL.
	* microblaze-linux-tdep.c (microblaze_linux_memory_remove_breakpoint):
	Likewise.
	* ppc-linux-tdep.c (ppc_linux_memory_remove_breakpoint): Likewise.
---
 gdb/mem-break.c             | 2 --
 gdb/microblaze-linux-tdep.c | 2 --
 gdb/ppc-linux-tdep.c        | 2 --
 3 files changed, 6 deletions(-)

diff --git a/gdb/mem-break.c b/gdb/mem-break.c
index 803f62b..cc8145c 100644
--- a/gdb/mem-break.c
+++ b/gdb/mem-break.c
@@ -45,8 +45,6 @@ default_memory_insert_breakpoint (struct gdbarch *gdbarch,
 
   /* Determine appropriate breakpoint contents and size for this address.  */
   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
-  if (bp == NULL)
-    error (_("Software breakpoints not implemented for this target."));
 
   bp_tgt->placed_address = addr;
   bp_tgt->placed_size = bplen;
diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
index 18ddfea..22e5959 100644
--- a/gdb/microblaze-linux-tdep.c
+++ b/gdb/microblaze-linux-tdep.c
@@ -49,8 +49,6 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
 
   /* Determine appropriate breakpoint contents and size for this address.  */
   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
-  if (bp == NULL)
-    error (_("Software breakpoints not implemented for this target."));
 
   val = target_read_memory (addr, old_contents, bplen);
 
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index cde4f2e..5ce58d8 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -222,8 +222,6 @@ ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
 
   /* Determine appropriate breakpoint contents and size for this address.  */
   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
-  if (bp == NULL)
-    error (_("Software breakpoints not implemented for this target."));
 
   /* Make sure we see the memory breakpoints.  */
   cleanup = make_show_memory_breakpoints_cleanup (1);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 13/13] Remove arm_override_mode
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (5 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 09/13] Rename placed_size to kind Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-10-27 14:56   ` Pedro Alves
  2016-08-31 15:06 ` [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc Yao Qi
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

GDB can determine the kind of single step breakpoint by gdbarch
breakpoint_kind_from_current_state, so global variable
arm_override_mode is no longer needed.  This patch removes it.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* arm-tdep.c (arm_override_mode): Remove.
	(arm_pc_is_thumb): Update.
	(arm_insert_single_step_breakpoint): Update.
---
 gdb/arm-tdep.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 37b68ed..3e5a775 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -143,13 +143,6 @@ static const char *const arm_mode_strings[] =
 static const char *arm_fallback_mode_string = "auto";
 static const char *arm_force_mode_string = "auto";
 
-/* Internal override of the execution mode.  -1 means no override,
-   0 means override to ARM mode, 1 means override to Thumb mode.
-   The effect is the same as if arm_force_mode has been set by the
-   user (except the internal override has precedence over a user's
-   arm_force_mode override).  */
-static int arm_override_mode = -1;
-
 /* Number of different reg name sets (options).  */
 static int num_disassembly_options;
 
@@ -422,10 +415,6 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   if (IS_THUMB_ADDR (memaddr))
     return 1;
 
-  /* Respect internal mode override if active.  */
-  if (arm_override_mode != -1)
-    return arm_override_mode;
-
   /* If the user wants to override the symbol table, let him.  */
   if (strcmp (arm_force_mode_string, "arm") == 0)
     return 0;
@@ -4204,15 +4193,9 @@ arm_insert_single_step_breakpoint (struct gdbarch *gdbarch,
 				   struct address_space *aspace,
 				   CORE_ADDR pc)
 {
-  struct cleanup *old_chain
-    = make_cleanup_restore_integer (&arm_override_mode);
-
-  arm_override_mode = IS_THUMB_ADDR (pc);
   pc = gdbarch_addr_bits_remove (gdbarch, pc);
 
   insert_single_step_breakpoint (gdbarch, aspace, pc);
-
-  do_cleanups (old_chain);
 }
 
 /* Given BUF, which is OLD_LEN bytes ending at ENDADDR, expand
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 05/13] Share enum arm_breakpoint_kinds
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 01/13] Remove v850_dbtrap_breakpoint_from_pc Yao Qi
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch shares "enum arm_breakpoint_kinds", and use ARM_BP_KIND_THUMB2
in GDB.

gdb:

2016-08-31  Yao Qi  <yao.qi@linaro.org>

	* arch/arm.h (enum arm_breakpoint_kinds): New.
	* arm-tdep.c (arm_remote_breakpoint_from_pc): Use
	ARM_BP_KIND_THUMB2.

gdb/gdbserver:

2016-08-31  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch32-low.c (enum arm_breakpoint_kinds): Remove.
---
 gdb/arch/arm.h                    | 8 ++++++++
 gdb/arm-tdep.c                    | 2 +-
 gdb/gdbserver/linux-aarch32-low.c | 8 --------
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/arch/arm.h b/gdb/arch/arm.h
index fcde3d0..8d9c34e 100644
--- a/gdb/arch/arm.h
+++ b/gdb/arch/arm.h
@@ -58,6 +58,14 @@ enum gdb_regnum {
   ARM_LAST_FP_ARG_REGNUM = ARM_F3_REGNUM
 };
 
+/* Enum describing the different kinds of breakpoints.  */
+enum arm_breakpoint_kinds
+{
+   ARM_BP_KIND_THUMB = 2,
+   ARM_BP_KIND_THUMB2 = 3,
+   ARM_BP_KIND_ARM = 4,
+};
+
 /* Instruction condition field values.  */
 #define INST_EQ		0x0
 #define INST_NE		0x1
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d2661cb..16dc574 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7849,7 +7849,7 @@ arm_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
   if (arm_pc_is_thumb (gdbarch, *pcptr) && *kindptr == 4)
     /* The documented magic value for a 32-bit Thumb-2 breakpoint, so
        that this is not confused with a 32-bit ARM breakpoint.  */
-    *kindptr = 3;
+    *kindptr = ARM_BP_KIND_THUMB2;
 }
 
 /* Extract from an array REGBUF containing the (raw) register state a
diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch32-low.c
index e6971d5..ffc7ace 100644
--- a/gdb/gdbserver/linux-aarch32-low.c
+++ b/gdb/gdbserver/linux-aarch32-low.c
@@ -215,14 +215,6 @@ arm_breakpoint_at (CORE_ADDR where)
   return 0;
 }
 
-/* Enum describing the different kinds of breakpoints.  */
-enum arm_breakpoint_kinds
-{
-   ARM_BP_KIND_THUMB = 2,
-   ARM_BP_KIND_THUMB2 = 3,
-   ARM_BP_KIND_ARM = 4,
-};
-
 /* Implementation of linux_target_ops method "breakpoint_kind_from_pc".
 
    Determine the type and size of breakpoint to insert at PCPTR.  Uses the
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (6 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 13/13] Remove arm_override_mode Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-10-27 14:55   ` Pedro Alves
  2016-08-31 15:06 ` [PATCH 02/13] Rename 'arch' by 'gdbarch' in m32c_gdbarch_init Yao Qi
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch removes gdbarch method remote_breakpoint_from_pc, as it
is no longer used.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.c (default_remote_breakpoint_from_pc): Remove.
	* arch-utils.h (default_remote_breakpoint_from_pc): Remove.
	* arm-tdep.c (arm_remote_breakpoint_from_pc): Remove.
	(arm_gdbarch_init): Don't call
	set_gdbarch_remote_breakpoint_from_pc.
	* gdbarch.sh (remote_breakpoint_from_pc): Remove.
	* gdbarch.c, gdbarch.h: Regenerate.
	* mips-tdep.c (mips_remote_breakpoint_from_pc): Remove.
	(mips_gdbarch_init): Don't call
	set_gdbarch_remote_breakpoint_from_pc.
---
 gdb/arch-utils.c |  7 -------
 gdb/arch-utils.h |  3 ---
 gdb/arm-tdep.c   | 10 ----------
 gdb/gdbarch.c    | 23 -----------------------
 gdb/gdbarch.h    |  8 --------
 gdb/gdbarch.sh   |  4 ----
 gdb/mips-tdep.c  | 24 ++++++++++++------------
 7 files changed, 12 insertions(+), 67 deletions(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 53121bc..b562716 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -813,13 +813,6 @@ default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
 }
 
 void
-default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-				   int *kindptr)
-{
-  gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
-}
-
-void
 default_gen_return_address (struct gdbarch *gdbarch,
 			    struct agent_expr *ax, struct axs_value *value,
 			    CORE_ADDR scope)
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 0386d3d..263f4d5 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -223,9 +223,6 @@ extern int default_has_shared_address_space (struct gdbarch *);
 extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
 					     CORE_ADDR addr, char **msg);
 
-extern void default_remote_breakpoint_from_pc (struct gdbarch *,
-					       CORE_ADDR *pcptr, int *kindptr);
-
 extern void default_gen_return_address (struct gdbarch *gdbarch,
 					struct agent_expr *ax,
 					struct axs_value *value,
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 065d177..eba59a5 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7863,14 +7863,6 @@ arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 
 GDBARCH_BREAKPOINT_FROM_PC (arm)
 
-static void
-arm_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			       int *kindptr)
-{
-
-  *kindptr = arm_breakpoint_kind_from_pc (gdbarch, pcptr);
-}
-
 /* Extract from an array REGBUF containing the (raw) register state a
    function return value of type TYPE, and copy that, in virtual
    format, into VALBUF.  */
@@ -9379,8 +9371,6 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Breakpoint manipulation.  */
   SET_GDBARCH_BREAKPOINT_MANIPULATION (arm);
-  set_gdbarch_remote_breakpoint_from_pc (gdbarch,
-					 arm_remote_breakpoint_from_pc);
 
   /* Information about registers, etc.  */
   set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index a1cf602..c85dc9a 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -231,7 +231,6 @@ struct gdbarch
   gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
   gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc;
   gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind;
-  gdbarch_remote_breakpoint_from_pc_ftype *remote_breakpoint_from_pc;
   gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
   gdbarch_memory_insert_breakpoint_ftype *memory_insert_breakpoint;
   gdbarch_memory_remove_breakpoint_ftype *memory_remove_breakpoint;
@@ -404,7 +403,6 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->address_to_pointer = unsigned_address_to_pointer;
   gdbarch->return_in_first_hidden_param_p = default_return_in_first_hidden_param_p;
   gdbarch->sw_breakpoint_from_kind = NULL;
-  gdbarch->remote_breakpoint_from_pc = default_remote_breakpoint_from_pc;
   gdbarch->memory_insert_breakpoint = default_memory_insert_breakpoint;
   gdbarch->memory_remove_breakpoint = default_memory_remove_breakpoint;
   gdbarch->remote_register_number = default_remote_register_number;
@@ -586,7 +584,6 @@ verify_gdbarch (struct gdbarch *gdbarch)
   if (gdbarch->breakpoint_kind_from_pc == 0)
     fprintf_unfiltered (log, "\n\tbreakpoint_kind_from_pc");
   /* Skip verify of sw_breakpoint_from_kind, invalid_p == 0 */
-  /* Skip verify of remote_breakpoint_from_pc, invalid_p == 0 */
   /* Skip verify of adjust_breakpoint_address, has predicate.  */
   /* Skip verify of memory_insert_breakpoint, invalid_p == 0 */
   /* Skip verify of memory_remove_breakpoint, invalid_p == 0 */
@@ -1285,9 +1282,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: relocate_instruction = <%s>\n",
                       host_address_to_string (gdbarch->relocate_instruction));
   fprintf_unfiltered (file,
-                      "gdbarch_dump: remote_breakpoint_from_pc = <%s>\n",
-                      host_address_to_string (gdbarch->remote_breakpoint_from_pc));
-  fprintf_unfiltered (file,
                       "gdbarch_dump: remote_register_number = <%s>\n",
                       host_address_to_string (gdbarch->remote_register_number));
   fprintf_unfiltered (file,
@@ -2805,23 +2799,6 @@ set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch,
   gdbarch->sw_breakpoint_from_kind = sw_breakpoint_from_kind;
 }
 
-void
-gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *kindptr)
-{
-  gdb_assert (gdbarch != NULL);
-  gdb_assert (gdbarch->remote_breakpoint_from_pc != NULL);
-  if (gdbarch_debug >= 2)
-    fprintf_unfiltered (gdb_stdlog, "gdbarch_remote_breakpoint_from_pc called\n");
-  gdbarch->remote_breakpoint_from_pc (gdbarch, pcptr, kindptr);
-}
-
-void
-set_gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch,
-                                       gdbarch_remote_breakpoint_from_pc_ftype remote_breakpoint_from_pc)
-{
-  gdbarch->remote_breakpoint_from_pc = remote_breakpoint_from_pc;
-}
-
 int
 gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch)
 {
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 29abf65..65a6a6e 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -556,14 +556,6 @@ typedef const gdb_byte * (gdbarch_sw_breakpoint_from_kind_ftype) (struct gdbarch
 extern const gdb_byte * gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size);
 extern void set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind);
 
-/* Return the adjusted address and kind to use for Z0/Z1 packets.
-   KIND is usually the memory length of the breakpoint, but may have a
-   different target-specific meaning. */
-
-typedef void (gdbarch_remote_breakpoint_from_pc_ftype) (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *kindptr);
-extern void gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *kindptr);
-extern void set_gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, gdbarch_remote_breakpoint_from_pc_ftype *remote_breakpoint_from_pc);
-
 extern int gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_adjust_breakpoint_address_ftype) (struct gdbarch *gdbarch, CORE_ADDR bpaddr);
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index b73c6fa..d7e4d87 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -564,10 +564,6 @@ m:int:breakpoint_kind_from_pc:CORE_ADDR *pcptr:pcptr::0:
 # SIZE is set to the software breakpoint's length in memory.
 m:const gdb_byte *:sw_breakpoint_from_kind:int kind, int *size:kind, size::NULL::0
 
-# Return the adjusted address and kind to use for Z0/Z1 packets.
-# KIND is usually the memory length of the breakpoint, but may have a
-# different target-specific meaning.
-m:void:remote_breakpoint_from_pc:CORE_ADDR *pcptr, int *kindptr:pcptr, kindptr:0:default_remote_breakpoint_from_pc::0
 M:CORE_ADDR:adjust_breakpoint_address:CORE_ADDR bpaddr:bpaddr
 m:int:memory_insert_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_insert_breakpoint::0
 m:int:memory_remove_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_remove_breakpoint::0
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index e73b6e1..10a1b08 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -7050,7 +7050,18 @@ gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
   return gdb_print_insn_mips (memaddr, info);
 }
 
-/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+/* Implement the breakpoint_kind_from_pc gdbarch method.
+
+   Determine the remote breakpoint kind suitable for the PC.  The following
+   kinds are used:
+
+   * 2 -- 16-bit MIPS16 mode breakpoint,
+
+   * 3 -- 16-bit microMIPS mode breakpoint,
+
+   * 4 -- 32-bit standard MIPS mode breakpoint,
+
+   * 5 -- 32-bit microMIPS mode breakpoint.  */
 
 static int
 mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
@@ -7178,15 +7189,6 @@ mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 
 GDBARCH_BREAKPOINT_FROM_PC (mips)
 
-/* Determine the remote breakpoint kind suitable for the PC.  */
-
-static void
-mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-				int *kindptr)
-{
-  *kindptr = mips_breakpoint_kind_from_pc (gdbarch, pcptr);
-}
-
 /* Return non-zero if the standard MIPS instruction INST has a branch
    delay slot (i.e. it is a jump or branch instruction).  This function
    is based on mips32_next_pc.  */
@@ -8798,8 +8800,6 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   SET_GDBARCH_BREAKPOINT_MANIPULATION (mips);
-  set_gdbarch_remote_breakpoint_from_pc (gdbarch,
-					 mips_remote_breakpoint_from_pc);
   set_gdbarch_adjust_breakpoint_address (gdbarch,
 					 mips_adjust_breakpoint_address);
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 09/13] Rename placed_size to kind
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (4 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 04/13] GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 13/13] Remove arm_override_mode Yao Qi
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch renames placed_size to kind.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.h (struct bp_target_info) <placed_size>: Remove.
	<kind>: New field.
	Update all users.
---
 gdb/breakpoint.c |  4 ++--
 gdb/breakpoint.h | 10 +++-------
 gdb/mem-break.c  |  4 ++--
 gdb/remote.c     |  8 ++++----
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f00c6c3..cc672f7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2769,7 +2769,7 @@ insert_bp_location (struct bp_location *bl,
 		    {
 		      int val;
 
-		      bl->overlay_target_info.placed_size
+		      bl->overlay_target_info.kind
 			= breakpoint_kind (bl, &addr);
 		      bl->overlay_target_info.placed_address = addr;
 		      val = target_insert_breakpoint (bl->gdbarch,
@@ -13129,7 +13129,7 @@ bkpt_insert_location (struct bp_location *bl)
 {
   CORE_ADDR addr = bl->target_info.reqstd_address;
 
-  bl->target_info.placed_size = breakpoint_kind (bl, &addr);
+  bl->target_info.kind = breakpoint_kind (bl, &addr);
   bl->target_info.placed_address = addr;
 
   if (bl->loc_type == bp_loc_hardware_breakpoint)
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4bdf0d5..95b5731 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -260,13 +260,9 @@ struct bp_target_info
   /* The length of the data cached in SHADOW_CONTENTS.  */
   int shadow_len;
 
-  /* The size of the placed breakpoint, according to
-     gdbarch_breakpoint_from_pc, when the breakpoint was inserted.
-     This is generally the same as SHADOW_LEN, unless we did not need
-     to read from the target to implement the memory breakpoint
-     (e.g. if a remote stub handled the details).  We may still need
-     the size to remove the breakpoint safely.  */
-  int placed_size;
+  /* The breakpoint's kind.  It is used in 'kind' parameter in Z
+     packets.  */
+  int kind;
 
   /* Vector of conditions the target should evaluate if it supports target-side
      breakpoint conditions.  */
diff --git a/gdb/mem-break.c b/gdb/mem-break.c
index dafe834..50f7d9c 100644
--- a/gdb/mem-break.c
+++ b/gdb/mem-break.c
@@ -44,7 +44,7 @@ default_memory_insert_breakpoint (struct gdbarch *gdbarch,
   int val;
 
   /* Determine appropriate breakpoint contents and size for this address.  */
-  bp = gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->placed_size, &bplen);
+  bp = gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->kind, &bplen);
 
   /* Save the memory contents in the shadow_contents buffer and then
      write the breakpoint instruction.  */
@@ -76,7 +76,7 @@ default_memory_remove_breakpoint (struct gdbarch *gdbarch,
 {
   int bplen;
 
-  gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->placed_size, &bplen);
+  gdbarch_sw_breakpoint_from_kind (gdbarch, bp_tgt->kind, &bplen);
 
   return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
 				  bplen);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9eb1d4b..9c85608 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -9297,7 +9297,7 @@ remote_insert_breakpoint (struct target_ops *ops,
       *(p++) = ',';
       addr = (ULONGEST) remote_address_masked (addr);
       p += hexnumstr (p, addr);
-      xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
+      xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
 
       if (remote_supports_cond_breakpoints (ops))
 	remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
@@ -9353,7 +9353,7 @@ remote_remove_breakpoint (struct target_ops *ops,
 
       addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
       p += hexnumstr (p, addr);
-      xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
+      xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
 
       putpkt (rs->buf);
       getpkt (&rs->buf, &rs->buf_size, 0);
@@ -9608,7 +9608,7 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 
   addr = remote_address_masked (addr);
   p += hexnumstr (p, (ULONGEST) addr);
-  xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
+  xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
 
   if (remote_supports_cond_breakpoints (self))
     remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
@@ -9662,7 +9662,7 @@ remote_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 
   addr = remote_address_masked (bp_tgt->placed_address);
   p += hexnumstr (p, (ULONGEST) addr);
-  xsnprintf (p, endbuf  - p, ",%x", bp_tgt->placed_size);
+  xsnprintf (p, endbuf  - p, ",%x", bp_tgt->kind);
 
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 11/13] Add default_breakpoint_from_pc
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
  2016-08-31 15:06 ` [PATCH 05/13] Share enum arm_breakpoint_kinds Yao Qi
  2016-08-31 15:06 ` [PATCH 01/13] Remove v850_dbtrap_breakpoint_from_pc Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL Yao Qi
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch adds the default implementation of gdbarch breakpoint_from_pc,
which is,

const gdb_byte *
default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
                           int *lenptr)
{
  int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);

  return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
}

so gdbarch can only defines sw_breakpoint_from_kind and
breakpoint_kind_from_pc.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.c (default_breakpoint_from_pc): New function.
	* arch-utils.h (GDBARCH_BREAKPOINT_FROM_PC): Remove.
	(GDBARCH_BREAKPOINT_MANIPULATION): Don't use
	GDBARCH_BREAKPOINT_FROM_PC.
	(SET_GDBARCH_BREAKPOINT_MANIPULATION): Don't call
	set_gdbarch_breakpoint_from_pc.
	(default_breakpoint_from_pc): Remove declaration.
	* gdbarch.sh (breakpoint_from_pc): Add its default implementation.
	* gdbarch.c, gdbarch.h: Regenerate.
	* arm-tdep.c: Don't use GDBARCH_BREAKPOINT_FROM_PC.
	* bfin-tdep.c, cris-tdep.c, iq2000-tdep.c: Likewise.
	* m32r-tdep.c, mips-tdep.c, mt-tdep.c: Likewise.
	* nios2-tdep.c, score-tdep.c, sh-tdep.c: Likewise.
	* sh64-tdep.c, tic6x-tdep.c, v850-tdep.c, xtensa-tdep.c: Likewise.
---
 gdb/arch-utils.c  |  9 +++++++++
 gdb/arch-utils.h  | 22 ++++++----------------
 gdb/arm-tdep.c    | 10 ----------
 gdb/bfin-tdep.c   |  8 --------
 gdb/cris-tdep.c   |  8 --------
 gdb/gdbarch.c     |  4 ++--
 gdb/gdbarch.sh    |  2 +-
 gdb/iq2000-tdep.c |  2 --
 gdb/m32r-tdep.c   |  2 --
 gdb/mips-tdep.c   |  9 ---------
 gdb/mt-tdep.c     |  2 --
 gdb/nios2-tdep.c  |  4 ----
 gdb/score-tdep.c  |  4 ----
 gdb/sh-tdep.c     |  2 --
 gdb/sh64-tdep.c   |  2 --
 gdb/tic6x-tdep.c  |  4 ----
 gdb/v850-tdep.c   |  2 --
 gdb/xtensa-tdep.c |  2 --
 18 files changed, 18 insertions(+), 80 deletions(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index b562716..e236877 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -812,6 +812,15 @@ default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
   return 1;
 }
 
+const gdb_byte *
+default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
+			    int *lenptr)
+{
+  int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
+
+  return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
+}
+
 void
 default_gen_return_address (struct gdbarch *gdbarch,
 			    struct agent_expr *ax, struct axs_value *value,
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 263f4d5..4af8b9f 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -26,17 +26,6 @@ struct minimal_symbol;
 struct type;
 struct gdbarch_info;
 
-#define GDBARCH_BREAKPOINT_FROM_PC(ARCH)			       \
-  static const gdb_byte *					       \
-  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		       \
-			     CORE_ADDR *pcptr,				\
-			     int *lenptr)				\
-  {									\
-    int kind = ARCH##_breakpoint_kind_from_pc (gdbarch, pcptr);	\
-								     \
-    return ARCH##_sw_breakpoint_from_kind (gdbarch, kind, lenptr);   \
-  }
-
 #define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
   static int							      \
   ARCH##_breakpoint_kind_from_pc (struct gdbarch *gdbarch,	      \
@@ -50,11 +39,9 @@ struct gdbarch_info;
   {								      \
     *size = kind;						      \
     return BREAK_INSN;						      \
-  }								      \
-  GDBARCH_BREAKPOINT_FROM_PC (ARCH)
+  }
 
 #define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)			\
-  set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc);	\
   set_gdbarch_breakpoint_kind_from_pc (gdbarch,			\
 				       ARCH##_breakpoint_kind_from_pc); \
   set_gdbarch_sw_breakpoint_from_kind (gdbarch,			\
@@ -80,8 +67,7 @@ struct gdbarch_info;
       return BIG_BREAK_INSN;					      \
     else							      \
       return LITTLE_BREAK_INSN;				      \
-  }								      \
-  GDBARCH_BREAKPOINT_FROM_PC (ARCH)
+  }
 
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
@@ -223,6 +209,10 @@ extern int default_has_shared_address_space (struct gdbarch *);
 extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
 					     CORE_ADDR addr, char **msg);
 
+extern const gdb_byte *default_breakpoint_from_pc (struct gdbarch *gdbarch,
+						   CORE_ADDR *pcptr,
+						   int *lenptr);
+
 extern void default_gen_return_address (struct gdbarch *gdbarch,
 					struct agent_expr *ax,
 					struct axs_value *value,
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index eba59a5..f03897c 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7853,16 +7853,6 @@ arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-/* Determine the type and size of breakpoint to insert at PCPTR.  Uses
-   the program counter value to determine whether a 16-bit or 32-bit
-   breakpoint should be used.  It returns a pointer to a string of
-   bytes that encode a breakpoint instruction, stores the length of
-   the string to *lenptr, and adjusts the program counter (if
-   necessary) to point to the actual memory location where the
-   breakpoint should be inserted.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (arm)
-
 /* Extract from an array REGBUF containing the (raw) register state a
    function return value of type TYPE, and copy that, in virtual
    format, into VALBUF.  */
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index c75858b..989912e 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -601,14 +601,6 @@ bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     return bfin_breakpoint;
 }
 
-/* This function implements the 'breakpoint_from_pc' gdbarch method.
-   It returns a pointer to a string of bytes that encode a breakpoint
-   instruction, stores the length of the string to *lenptr, and
-   adjusts the program counter (if necessary) to point to the actual
-   memory location where the breakpoint should be inserted.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (bfin)
-
 static void
 bfin_extract_return_value (struct type *type,
 			   struct regcache *regs,
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index b202730..3103f1c 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -1416,14 +1416,6 @@ cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     return break8_insn;
 }
 
-/* Use the program counter to determine the contents and size of a breakpoint
-   instruction.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pcptr (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (cris)
-
 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
    0 otherwise.  */
 
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index c85dc9a..ca430a9 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -402,6 +402,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->pointer_to_address = unsigned_pointer_to_address;
   gdbarch->address_to_pointer = unsigned_address_to_pointer;
   gdbarch->return_in_first_hidden_param_p = default_return_in_first_hidden_param_p;
+  gdbarch->breakpoint_from_pc = default_breakpoint_from_pc;
   gdbarch->sw_breakpoint_from_kind = NULL;
   gdbarch->memory_insert_breakpoint = default_memory_insert_breakpoint;
   gdbarch->memory_remove_breakpoint = default_memory_remove_breakpoint;
@@ -579,8 +580,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of skip_entrypoint, has predicate.  */
   if (gdbarch->inner_than == 0)
     fprintf_unfiltered (log, "\n\tinner_than");
-  if (gdbarch->breakpoint_from_pc == 0)
-    fprintf_unfiltered (log, "\n\tbreakpoint_from_pc");
+  /* Skip verify of breakpoint_from_pc, invalid_p == 0 */
   if (gdbarch->breakpoint_kind_from_pc == 0)
     fprintf_unfiltered (log, "\n\tbreakpoint_kind_from_pc");
   /* Skip verify of sw_breakpoint_from_kind, invalid_p == 0 */
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index d7e4d87..c999f30 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -554,7 +554,7 @@ M:CORE_ADDR:skip_main_prologue:CORE_ADDR ip:ip
 M:CORE_ADDR:skip_entrypoint:CORE_ADDR ip:ip
 
 f:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs:0:0
-m:const gdb_byte *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr::0:
+m:const gdb_byte *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr:0:default_breakpoint_from_pc::0
 
 # Return the breakpoint kind for this target based on *PCPTR.
 m:int:breakpoint_kind_from_pc:CORE_ADDR *pcptr:pcptr::0:
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index ecd9074..874fc6a 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -490,8 +490,6 @@ iq2000_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 	  == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint;
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (iq2000)
-
 /* Target function return value methods: */
 
 /* Function: store_return_value
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 86ba44a..00e7767 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -202,8 +202,6 @@ m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (m32r)
-
 char *m32r_register_names[] = {
   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
   "r8", "r9", "r10", "r11", "r12", "fp", "lr", "sp",
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 10a1b08..8ffa8f6 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -7180,15 +7180,6 @@ mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     };
 }
 
-/* This function implements gdbarch_breakpoint_from_pc.  It uses the
-   program counter value to determine whether a 16- or 32-bit breakpoint
-   should be used.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pc (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (mips)
-
 /* Return non-zero if the standard MIPS instruction INST has a branch
    delay slot (i.e. it is a jump or branch instruction).  This function
    is based on mips32_next_pc.  */
diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
index ffc03fb..a34023f 100644
--- a/gdb/mt-tdep.c
+++ b/gdb/mt-tdep.c
@@ -478,8 +478,6 @@ mt_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
   return ms1_breakpoint;
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (mt)
-
 /* Select the correct coprocessor register bank.  Return the pseudo
    regnum we really want to read.  */
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 8d879d7..81b8dad 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1771,10 +1771,6 @@ nios2_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-/* Implement the breakpoint_from_pc gdbarch hook.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (nios2)
-
 /* Implement the print_insn gdbarch method.  */
 
 static int
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index 715a092..1bba20b 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -368,8 +368,6 @@ score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (score7)
-
 /* Implement the breakpoint_kind_from_pc gdbarch method.  */
 
 static int
@@ -406,8 +404,6 @@ score3_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
   return score_break_insns[index];
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (score3)
-
 static CORE_ADDR
 score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
 {
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 4ab29f0..4dac56b 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -453,8 +453,6 @@ sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (sh)
-
 /* Prologue looks like
    mov.l	r14,@-r15
    sts.l	pr,@-r15
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index 4f97223..b6c2cce 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -305,8 +305,6 @@ sh64_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (sh64)
-
 /* Prologue looks like
    [mov.l       <regs>,@-r15]...
    [sts.l       pr,@-r15]
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index b4ca757..e4d4749 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -345,10 +345,6 @@ tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     return tdep->breakpoint;
 }
 
-/* This is the implementation of gdbarch method breakpiont_from_pc.  */
-
-GDBARCH_BREAKPOINT_FROM_PC (tic6x)
-
 /* This is the implementation of gdbarch method print_insn.  */
 
 static int
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 85392a2..27e67a4 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -1208,8 +1208,6 @@ v850_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (v850)
-
 static struct v850_frame_cache *
 v850_alloc_frame_cache (struct frame_info *this_frame)
 {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index ed0664b..3652bef 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -2008,8 +2008,6 @@ xtensa_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-GDBARCH_BREAKPOINT_FROM_PC (xtensa)
-
 /* Call0 ABI support routines.  */
 
 /* Return true, if PC points to "ret" or "ret.n".  */ 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 02/13] Rename 'arch' by 'gdbarch' in m32c_gdbarch_init
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (7 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch renames local 'arch' by 'gdbarch' in m32c_gdbarch_init, so
that I can use macros in the following patch.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* m32c-tdep.c (m32c_gdbarch_init): Rename local 'arch' by
	'gdbarch'.
---
 gdb/m32c-tdep.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 1e98f73..8737880 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -2630,7 +2630,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
 static struct gdbarch *
 m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 {
-  struct gdbarch *arch;
+  struct gdbarch *gdbarch;
   struct gdbarch_tdep *tdep;
   unsigned long mach = info.bfd_arch_info->mach;
 
@@ -2642,51 +2642,51 @@ m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     return arches->gdbarch;
 
   tdep = XCNEW (struct gdbarch_tdep);
-  arch = gdbarch_alloc (&info, tdep);
+  gdbarch = gdbarch_alloc (&info, tdep);
 
   /* Essential types.  */
-  make_types (arch);
+  make_types (gdbarch);
 
   /* Address/pointer conversions.  */
   if (mach == bfd_mach_m16c)
     {
-      set_gdbarch_address_to_pointer (arch, m32c_m16c_address_to_pointer);
-      set_gdbarch_pointer_to_address (arch, m32c_m16c_pointer_to_address);
+      set_gdbarch_address_to_pointer (gdbarch, m32c_m16c_address_to_pointer);
+      set_gdbarch_pointer_to_address (gdbarch, m32c_m16c_pointer_to_address);
     }
 
   /* Register set.  */
-  make_regs (arch);
+  make_regs (gdbarch);
 
   /* Disassembly.  */
-  set_gdbarch_print_insn (arch, print_insn_m32c);
+  set_gdbarch_print_insn (gdbarch, print_insn_m32c);
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (arch, m32c_breakpoint_from_pc);
+  set_gdbarch_breakpoint_from_pc (gdbarch, m32c_breakpoint_from_pc);
 
   /* Prologue analysis and unwinding.  */
-  set_gdbarch_inner_than (arch, core_addr_lessthan);
-  set_gdbarch_skip_prologue (arch, m32c_skip_prologue);
-  set_gdbarch_unwind_pc (arch, m32c_unwind_pc);
-  set_gdbarch_unwind_sp (arch, m32c_unwind_sp);
+  set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
+  set_gdbarch_skip_prologue (gdbarch, m32c_skip_prologue);
+  set_gdbarch_unwind_pc (gdbarch, m32c_unwind_pc);
+  set_gdbarch_unwind_sp (gdbarch, m32c_unwind_sp);
 #if 0
   /* I'm dropping the dwarf2 sniffer because it has a few problems.
      They may be in the dwarf2 cfi code in GDB, or they may be in
      the debug info emitted by the upstream toolchain.  I don't 
      know which, but I do know that the prologue analyzer works better.
      MVS 04/13/06  */
-  dwarf2_append_sniffers (arch);
+  dwarf2_append_sniffers (gdbarch);
 #endif
-  frame_unwind_append_unwinder (arch, &m32c_unwind);
+  frame_unwind_append_unwinder (gdbarch, &m32c_unwind);
 
   /* Inferior calls.  */
-  set_gdbarch_push_dummy_call (arch, m32c_push_dummy_call);
-  set_gdbarch_return_value (arch, m32c_return_value);
-  set_gdbarch_dummy_id (arch, m32c_dummy_id);
+  set_gdbarch_push_dummy_call (gdbarch, m32c_push_dummy_call);
+  set_gdbarch_return_value (gdbarch, m32c_return_value);
+  set_gdbarch_dummy_id (gdbarch, m32c_dummy_id);
 
   /* Trampolines.  */
-  set_gdbarch_skip_trampoline_code (arch, m32c_skip_trampoline_code);
+  set_gdbarch_skip_trampoline_code (gdbarch, m32c_skip_trampoline_code);
 
-  set_gdbarch_virtual_frame_pointer (arch, m32c_virtual_frame_pointer);
+  set_gdbarch_virtual_frame_pointer (gdbarch, m32c_virtual_frame_pointer);
 
   /* m32c function boundary addresses are not necessarily even.
      Therefore, the `vbit', which indicates a pointer to a virtual
@@ -2696,9 +2696,9 @@ m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
      In order to verify this, see the definition of
      TARGET_PTRMEMFUNC_VBIT_LOCATION in gcc/defaults.h along with the
      definition of FUNCTION_BOUNDARY in gcc/config/m32c/m32c.h.  */
-  set_gdbarch_vbit_in_delta (arch, 1);
+  set_gdbarch_vbit_in_delta (gdbarch, 1);
 
-  return arch;
+  return gdbarch;
 }
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 04/13] GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (3 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 09/13] Rename placed_size to kind Yao Qi
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

Many archs have only one kind of breakpoint, so their breakpoint_from_pc
implementations are quite similar.  This patch uses macro
GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION
for breakpoint_from_pc, so that we can easily switch from
breakpoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
later.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_MANIPULATION): New macro.
	(SET_GDBARCH_BREAKPOINT_MANIPULATION): New macro.
	aarch64-tdep.c (aarch64_breakpoint_from_pc): Remove.  Use
	GDBARCH_BREAKPOINT_MANIPULATION.
	(aarch64_gdbarch_init): Replace set_gdbarch_breakpoint_from_pc
	with SET_GDBARCH_BREAKPOINT_MANIPULATION.
	* alpha-tdep.c: Likewise.
	* avr-tdep.c: Likewise.
	* frv-tdep.c: Likewise.
	* ft32-tdep.c: Likewise.
	* h8300-tdep.c: Likewise.
	* hppa-tdep.c: Likewise.
	* i386-tdep.c: Likewise.
	* lm32-tdep.c: Likewise.
	* m32c-tdep.c: Likewise.
	* m68hc11-tdep.c: Likewise.
	* m68k-tdep.c: Likewise.
	* m88k-tdep.c: Likewise.
	* mep-tdep.c: Likewise.
	* microblaze-tdep.c: Likewise.
	* mn10300-tdep.c: Likewise.
	* moxie-tdep.c: Likewise.
	* msp430-tdep.c: Likewise.
	* rl78-tdep.c: Likewise.
	* rx-tdep.c: Likewise.
	* s390-linux-tdep.c: Likewise.
	* sparc-tdep.c: Likewise.
	* spu-tdep.c: Likewise.
	* tilegx-tdep.c: Likewise.
	* vax-tdep.c: Likewise.
	* xstormy16-tdep.c: Likewise.
---
 gdb/aarch64-tdep.c    | 12 ++----------
 gdb/alpha-tdep.c      | 12 ++++--------
 gdb/arch-utils.h      | 13 +++++++++++++
 gdb/avr-tdep.c        | 13 ++++---------
 gdb/frv-tdep.c        | 12 ++++--------
 gdb/ft32-tdep.c       | 13 +++----------
 gdb/h8300-tdep.c      | 14 ++++----------
 gdb/hppa-tdep.c       | 12 ++++--------
 gdb/i386-tdep.c       | 11 +++--------
 gdb/lm32-tdep.c       | 12 +++---------
 gdb/m32c-tdep.c       | 13 +++----------
 gdb/m68hc11-tdep.c    | 13 +++----------
 gdb/m68k-tdep.c       | 13 ++++---------
 gdb/m88k-tdep.c       | 15 +++++----------
 gdb/mep-tdep.c        | 12 +++---------
 gdb/microblaze-tdep.c | 13 ++++---------
 gdb/mn10300-tdep.c    | 12 +++---------
 gdb/moxie-tdep.c      | 14 +++-----------
 gdb/msp430-tdep.c     | 14 +++-----------
 gdb/rl78-tdep.c       | 22 +++++++---------------
 gdb/rx-tdep.c         | 13 ++++---------
 gdb/s390-linux-tdep.c | 14 +++-----------
 gdb/sparc-tdep.c      | 12 +++---------
 gdb/spu-tdep.c        | 13 +++----------
 gdb/tilegx-tdep.c     | 18 +++++-------------
 gdb/vax-tdep.c        | 13 ++++---------
 gdb/xstormy16-tdep.c  | 13 ++++---------
 27 files changed, 108 insertions(+), 253 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 3b7e954..b998867 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1567,15 +1567,7 @@ aarch64_gdb_print_insn (bfd_vma memaddr, disassemble_info *info)
    1101.0100.0010.0000.0000.0000.0000.0000 = 0xd4200000.  */
 static const gdb_byte aarch64_default_breakpoint[] = {0x00, 0x00, 0x20, 0xd4};
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
-
-static const gdb_byte *
-aarch64_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			    int *lenptr)
-{
-  *lenptr = sizeof (aarch64_default_breakpoint);
-  return aarch64_default_breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (aarch64, aarch64_default_breakpoint)
 
 /* Extract from an array REGS containing the (raw) register state a
    function return value of type TYPE, and copy that, in virtual
@@ -2737,7 +2729,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   /* Breakpoint manipulation.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, aarch64_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (aarch64);
   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
   set_gdbarch_software_single_step (gdbarch, aarch64_software_single_step);
 
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index b89ea13..c6378c2 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -644,14 +644,10 @@ alpha_return_in_memory_always (struct type *type)
   return 1;
 }
 \f
-static const gdb_byte *
-alpha_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static const gdb_byte break_insn[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */
 
-  *len = sizeof(break_insn);
-  return break_insn;
-}
+static const gdb_byte break_insn[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */
+
+GDBARCH_BREAKPOINT_MANIPULATION (alpha, break_insn)
 
 \f
 /* This returns the PC of the first insn after the prologue.
@@ -1821,7 +1817,7 @@ alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (alpha);
   set_gdbarch_decr_pc_after_break (gdbarch, ALPHA_INSN_SIZE);
   set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
 
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index ad3f126..77d4fb5 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -26,6 +26,19 @@ struct minimal_symbol;
 struct type;
 struct gdbarch_info;
 
+#define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
+  static const gdb_byte *					      \
+  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		      \
+			     CORE_ADDR *pcptr,			      \
+			     int *lenptr)			      \
+  {								      \
+    *lenptr = sizeof (BREAK_INSN);				      \
+    return BREAK_INSN;						      \
+  }
+
+#define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)	\
+  set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc)
+
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
    single-stepping the displaced copy.
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index f6f43a0..d8e9a36 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -912,14 +912,9 @@ avr_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
    it as a NOP.  Thus, it should be ok.  Since the avr is currently a remote
    only target, this shouldn't be a problem (I hope).  TRoth/2003-05-14  */
 
-static const unsigned char *
-avr_breakpoint_from_pc (struct gdbarch *gdbarch,
-			CORE_ADDR *pcptr, int *lenptr)
-{
-    static const unsigned char avr_break_insn [] = { 0x98, 0x95 };
-    *lenptr = sizeof (avr_break_insn);
-    return avr_break_insn;
-}
+static const unsigned char avr_break_insn [] = { 0x98, 0x95 };
+
+GDBARCH_BREAKPOINT_MANIPULATION (avr, avr_break_insn)
 
 /* Determine, for architecture GDBARCH, how a return value of TYPE
    should be returned.  If it is supposed to be returned in registers,
@@ -1514,7 +1509,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_prologue (gdbarch, avr_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, avr_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (avr);
 
   frame_unwind_append_unwinder (gdbarch, &avr_frame_unwind);
   frame_base_set_default (gdbarch, &avr_frame_base);
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 7ce08c0..89d26d0 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -424,13 +424,9 @@ frv_register_sim_regno (struct gdbarch *gdbarch, int reg)
   internal_error (__FILE__, __LINE__, _("Bad register number %d"), reg);
 }
 
-static const unsigned char *
-frv_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenp)
-{
-  static unsigned char breakpoint[] = {0xc0, 0x70, 0x00, 0x01};
-  *lenp = sizeof (breakpoint);
-  return breakpoint;
-}
+static const unsigned char breakpoint[] = {0xc0, 0x70, 0x00, 0x01};
+
+GDBARCH_BREAKPOINT_MANIPULATION (frv, breakpoint)
 
 /* Define the maximum number of instructions which may be packed into a
    bundle (VLIW instruction).  */
@@ -1537,7 +1533,7 @@ frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, frv_skip_prologue);
   set_gdbarch_skip_main_prologue (gdbarch, frv_skip_main_prologue);
-  set_gdbarch_breakpoint_from_pc (gdbarch, frv_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (frv);
   set_gdbarch_adjust_breakpoint_address
     (gdbarch, frv_adjust_breakpoint_address);
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 5eaa682..95b84fc 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -77,17 +77,10 @@ ft32_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
   return sp & ~1;
 }
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
 
-static const unsigned char *
-ft32_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
-{
-  static const gdb_byte breakpoint[] = { 0x02, 0x00, 0x34, 0x00 };
+static const gdb_byte breakpoint[] = { 0x02, 0x00, 0x34, 0x00 };
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (ft32, breakpoint)
 
 /* FT32 register names.  */
 
@@ -631,7 +624,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, ft32_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, ft32_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (ft32);
   set_gdbarch_frame_align (gdbarch, ft32_frame_align);
 
   frame_base_set_default (gdbarch, &ft32_frame_base);
diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c
index 951f005..5e757a9 100644
--- a/gdb/h8300-tdep.c
+++ b/gdb/h8300-tdep.c
@@ -1242,16 +1242,10 @@ h8300s_dbg_reg_to_regnum (struct gdbarch *gdbarch, int regno)
   return regno;
 }
 
-static const unsigned char *
-h8300_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			  int *lenptr)
-{
-  /*static unsigned char breakpoint[] = { 0x7A, 0xFF }; *//* ??? */
-  static unsigned char breakpoint[] = { 0x01, 0x80 };	/* Sleep */
+/*static unsigned char breakpoint[] = { 0x7A, 0xFF }; *//* ??? */
+static const unsigned char breakpoint[] = { 0x01, 0x80 };	/* Sleep */
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (h8300, breakpoint)
 
 static struct gdbarch *
 h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
@@ -1377,7 +1371,7 @@ h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Stack grows up.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, h8300_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (h8300);
   set_gdbarch_push_dummy_call (gdbarch, h8300_push_dummy_call);
 
   set_gdbarch_char_signed (gdbarch, 0);
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index f879a25..be91bdc 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -603,13 +603,9 @@ hppa_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
   return 0;
 }
 
-static const unsigned char *
-hppa_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
-  (*len) = sizeof (breakpoint);
-  return breakpoint;
-}
+static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
+
+GDBARCH_BREAKPOINT_MANIPULATION (hppa, breakpoint)
 
 /* Return the name of a register.  */
 
@@ -3185,7 +3181,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       internal_error (__FILE__, __LINE__, _("bad switch"));
     }
       
-  set_gdbarch_breakpoint_from_pc (gdbarch, hppa_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (hppa);
   set_gdbarch_pseudo_register_read (gdbarch, hppa_pseudo_register_read);
 
   /* Frame unwind methods.  */
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 92987af..6c2c261 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -587,14 +587,9 @@ static const char *disassembly_flavor = att_flavor;
 
    This function is 64-bit safe.  */
 
-static const gdb_byte *
-i386_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static gdb_byte break_insn[] = { 0xcc }; /* int 3 */
+static const gdb_byte break_insn[] = { 0xcc }; /* int 3 */
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (i386, break_insn)
 \f
 /* Displaced instruction handling.  */
 
@@ -8437,7 +8432,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, i386_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (i386);
   set_gdbarch_decr_pc_after_break (gdbarch, 1);
   set_gdbarch_max_insn_length (gdbarch, I386_MAX_INSN_LEN);
 
diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c
index ea83892..f9f3b0b 100644
--- a/gdb/lm32-tdep.c
+++ b/gdb/lm32-tdep.c
@@ -215,16 +215,10 @@ lm32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 }
 
 /* Create a breakpoint instruction.  */
+static const gdb_byte breakpoint[4] = { OP_RAISE << 2, 0, 0, 2 };
 
-static const gdb_byte *
-lm32_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			 int *lenptr)
-{
-  static const gdb_byte breakpoint[4] = { OP_RAISE << 2, 0, 0, 2 };
+GDBARCH_BREAKPOINT_MANIPULATION (lm32, breakpoint)
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
 
 /* Setup registers and stack for faking a call to a function in the 
    inferior.  */
@@ -562,7 +556,7 @@ lm32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   frame_unwind_append_unwinder (gdbarch, &lm32_frame_unwind);
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, lm32_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (lm32);
   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
 
   /* Calling functions in the inferior.  */
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 8737880..470406e 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -999,16 +999,9 @@ make_regs (struct gdbarch *arch)
 
 \f
 /* Breakpoints.  */
+static const unsigned char break_insn[] = { 0x00 };	/* brk */
 
-static const unsigned char *
-m32c_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static unsigned char break_insn[] = { 0x00 };	/* brk */
-
-  *len = sizeof (break_insn);
-  return break_insn;
-}
-
+GDBARCH_BREAKPOINT_MANIPULATION (m32c, break_insn)
 
 \f
 /* Prologue analysis.  */
@@ -2661,7 +2654,7 @@ m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_print_insn (gdbarch, print_insn_m32c);
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, m32c_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m32c);
 
   /* Prologue analysis and unwinding.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index c30e682..620d1fb 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -390,16 +390,9 @@ m68hc11_register_name (struct gdbarch *gdbarch, int reg_nr)
   return m68hc11_register_names[reg_nr];
 }
 
-static const unsigned char *
-m68hc11_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			    int *lenptr)
-{
-  static unsigned char breakpoint[] = {0x0};
-
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+static unsigned char breakpoint[] = {0x0};
 
+GDBARCH_BREAKPOINT_MANIPULATION (m68hc11, breakpoint)
 \f
 /* 68HC11 & 68HC12 prologue analysis.  */
 
@@ -1528,7 +1521,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
   set_gdbarch_return_value (gdbarch, m68hc11_return_value);
   set_gdbarch_skip_prologue (gdbarch, m68hc11_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m68hc11_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m68hc11);
   set_gdbarch_print_insn (gdbarch, gdb_print_insn_m68hc11);
 
   m68hc11_add_reggroups (gdbarch);
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 5d7b65d..cea2f01 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -57,14 +57,9 @@
 #define BPT_VECTOR 0xf
 #endif
 
-static const gdb_byte *
-m68k_local_breakpoint_from_pc (struct gdbarch *gdbarch,
-			       CORE_ADDR *pcptr, int *lenptr)
-{
-  static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
-  *lenptr = sizeof (break_insn);
-  return break_insn;
-}
+static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
+
+GDBARCH_BREAKPOINT_MANIPULATION (m68k, break_insn)
 \f
 
 /* Construct types for ISA-specific registers.  */
@@ -1196,7 +1191,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);
 
   set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m68k);
 
   /* Stack grows down.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
diff --git a/gdb/m88k-tdep.c b/gdb/m88k-tdep.c
index 1a3c2cd..65f755c 100644
--- a/gdb/m88k-tdep.c
+++ b/gdb/m88k-tdep.c
@@ -96,16 +96,11 @@ m88k_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
    encode a breakpoint instruction, store the length of the string in
    *LEN and optionally adjust *PC to point to the correct memory
    location for inserting the breakpoint.  */
-   
-static const gdb_byte *
-m88k_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  /* tb 0,r0,511 */
-  static gdb_byte break_insn[] = { 0xf0, 0x00, 0xd1, 0xff };
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
+/* tb 0,r0,511 */
+static gdb_byte break_insn[] = { 0xf0, 0x00, 0xd1, 0xff };
+
+GDBARCH_BREAKPOINT_MANIPULATION (m88k, break_insn)
 
 static CORE_ADDR
 m88k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
@@ -856,7 +851,7 @@ m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_return_value (gdbarch, m88k_return_value);
 
   set_gdbarch_addr_bits_remove (gdbarch, m88k_addr_bits_remove);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m88k_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m88k);
   set_gdbarch_unwind_pc (gdbarch, m88k_unwind_pc);
   set_gdbarch_write_pc (gdbarch, m88k_write_pc);
 
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index a110b04..a8900f1 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -1918,15 +1918,9 @@ mep_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 
 \f
 /* Breakpoints.  */
+static unsigned char breakpoint[] = { 0x70, 0x32 };
 
-static const unsigned char *
-mep_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR * pcptr, int *lenptr)
-{
-  static unsigned char breakpoint[] = { 0x70, 0x32 };
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
-
+GDBARCH_BREAKPOINT_MANIPULATION (mep, breakpoint)
 
 \f
 /* Frames and frame unwinding.  */
@@ -2490,7 +2484,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_print_insn (gdbarch, mep_gdb_print_insn); 
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, mep_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mep);
   set_gdbarch_decr_pc_after_break (gdbarch, 0);
   set_gdbarch_skip_prologue (gdbarch, mep_skip_prologue);
 
diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
index 665ec0c..ea33ae7 100644
--- a/gdb/microblaze-tdep.c
+++ b/gdb/microblaze-tdep.c
@@ -134,15 +134,10 @@ microblaze_fetch_instruction (CORE_ADDR pc)
   return extract_unsigned_integer (buf, 4, byte_order);
 }
 \f
-static const gdb_byte *
-microblaze_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, 
-			       int *len)
-{
-  static gdb_byte break_insn[] = MICROBLAZE_BREAKPOINT;
+static gdb_byte break_insn[] = MICROBLAZE_BREAKPOINT;
+
+GDBARCH_BREAKPOINT_MANIPULATION (microblaze, break_insn)
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
 \f
 /* Allocate and initialize a frame cache.  */
 
@@ -736,7 +731,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, microblaze_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (microblaze);
 
   set_gdbarch_frame_args_skip (gdbarch, 8);
 
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 9ef88a8..16c0b39 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -322,15 +322,9 @@ mn10300_write_pc (struct regcache *regcache, CORE_ADDR val)
    The Matsushita mn10x00 processors have single byte instructions
    so we need a single byte breakpoint.  Matsushita hasn't defined
    one, so we defined it ourselves.  */
+static gdb_byte breakpoint[] = {0xff};
 
-static const unsigned char *
-mn10300_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			    int *bp_size)
-{
-  static gdb_byte breakpoint[] = {0xff};
-  *bp_size = 1;
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (mn10300, breakpoint)
 
 /* Model the semantics of pushing a register onto the stack.  This
    is a helper function for mn10300_analyze_prologue, below.  */
@@ -1444,7 +1438,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
   /* Stack unwinding.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, mn10300_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mn10300);
   /* decr_pc_after_break?  */
   /* Disassembly.  */
   set_gdbarch_print_insn (gdbarch, print_insn_mn10300);
diff --git a/gdb/moxie-tdep.c b/gdb/moxie-tdep.c
index 714734d..56989fd 100644
--- a/gdb/moxie-tdep.c
+++ b/gdb/moxie-tdep.c
@@ -67,17 +67,9 @@ moxie_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
   return sp & ~1;
 }
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
+static unsigned char breakpoint[] = { 0x35, 0x00 };
 
-static const unsigned char *
-moxie_breakpoint_from_pc (struct gdbarch *gdbarch,
-			  CORE_ADDR *pcptr, int *lenptr)
-{
-  static unsigned char breakpoint[] = { 0x35, 0x00 };
-
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (moxie, breakpoint)
 
 /* Moxie register names.  */
 
@@ -1138,7 +1130,7 @@ moxie_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, moxie_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, moxie_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (moxie);
   set_gdbarch_frame_align (gdbarch, moxie_frame_align);
 
   frame_base_set_default (gdbarch, &moxie_frame_base);
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 84189dc..8043155 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -277,17 +277,9 @@ msp430_register_sim_regno (struct gdbarch *gdbarch, int regnum)
   return regnum;
 }
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
+static gdb_byte breakpoint[] = { 0x43, 0x43 };
 
-static const gdb_byte *
-msp430_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
-{
-  static gdb_byte breakpoint[] = { 0x43, 0x43 };
-
-  *lenptr = sizeof breakpoint;
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (msp430, breakpoint)
 
 /* Define a "handle" struct for fetching the next opcode.  */
 
@@ -1001,7 +993,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, msp430_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (msp430);
   set_gdbarch_decr_pc_after_break (gdbarch, 1);
 
   /* Disassembly.  */
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 420ee86..58e6642 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -768,21 +768,13 @@ rl78_pseudo_register_write (struct gdbarch *gdbarch,
     gdb_assert_not_reached ("invalid pseudo register number");
 }
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
+/* The documented BRK instruction is actually a two byte sequence,
+   {0x61, 0xcc}, but instructions may be as short as one byte.
+   Correspondence with Renesas revealed that the one byte sequence
+   0xff is used when a one byte breakpoint instruction is required.  */
+static gdb_byte breakpoint[] = { 0xff };
 
-static const gdb_byte *
-rl78_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-                         int *lenptr)
-{
-  /* The documented BRK instruction is actually a two byte sequence,
-     {0x61, 0xcc}, but instructions may be as short as one byte.
-     Correspondence with Renesas revealed that the one byte sequence
-     0xff is used when a one byte breakpoint instruction is required.  */
-  static gdb_byte breakpoint[] = { 0xff };
-
-  *lenptr = sizeof breakpoint;
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (rl78, breakpoint)
 
 /* Define a "handle" struct for fetching the next opcode.  */
 
@@ -1467,7 +1459,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_addr_bits_remove (gdbarch, rl78_addr_bits_remove);
 
   /* Breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, rl78_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (rl78);
   set_gdbarch_decr_pc_after_break (gdbarch, 1);
 
   /* Disassembly.  */
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 904aebd..ddd340d 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -991,14 +991,9 @@ rx_return_value (struct gdbarch *gdbarch,
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
 
-/* Implement the "breakpoint_from_pc" gdbarch method.  */
-static const gdb_byte *
-rx_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
-{
-  static gdb_byte breakpoint[] = { 0x00 };
-  *lenptr = sizeof breakpoint;
-  return breakpoint;
-}
+static gdb_byte breakpoint[] = { 0x00 };
+
+GDBARCH_BREAKPOINT_MANIPULATION (rx, breakpoint)
 
 /* Implement the dwarf_reg_to_regnum" gdbarch method.  */
 
@@ -1096,7 +1091,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_sp_regnum (gdbarch, RX_SP_REGNUM);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   set_gdbarch_decr_pc_after_break (gdbarch, 1);
-  set_gdbarch_breakpoint_from_pc (gdbarch, rx_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (rx);
   set_gdbarch_skip_prologue (gdbarch, rx_skip_prologue);
 
   set_gdbarch_print_insn (gdbarch, print_insn_rx);
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 70364b4..7ae1716 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -3549,17 +3549,9 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
 
 
 /* Breakpoints.  */
+static const gdb_byte breakpoint[] = { 0x0, 0x1 };
 
-static const gdb_byte *
-s390_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
-{
-  static const gdb_byte breakpoint[] = { 0x0, 0x1 };
-
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
-
+GDBARCH_BREAKPOINT_MANIPULATION (s390, breakpoint)
 
 /* Address handling.  */
 
@@ -7982,7 +7974,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_decr_pc_after_break (gdbarch, 2);
   /* Stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (s390);
   set_gdbarch_software_single_step (gdbarch, s390_software_single_step);
   set_gdbarch_displaced_step_hw_singlestep (gdbarch, s390_displaced_step_hw_singlestep);
   set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 5a8acce..ac1504f 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -640,15 +640,9 @@ sparc32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
    encode a breakpoint instruction, store the length of the string in
    *LEN and optionally adjust *PC to point to the correct memory
    location for inserting the breakpoint.  */
-   
-static const gdb_byte *
-sparc_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static const gdb_byte break_insn[] = { 0x91, 0xd0, 0x20, 0x01 };
+static const gdb_byte break_insn[] = { 0x91, 0xd0, 0x20, 0x01 };
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (sparc, break_insn)
 \f
 
 /* Allocate and initialize a frame cache.  */
@@ -1708,7 +1702,7 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sparc_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sparc);
 
   set_gdbarch_frame_args_skip (gdbarch, 8);
 
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index f62e8e7..1863da1 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1570,16 +1570,9 @@ spu_return_value (struct gdbarch *gdbarch, struct value *function,
 
 
 /* Breakpoints.  */
+static const gdb_byte breakpoint[] = { 0x00, 0x00, 0x3f, 0xff };
 
-static const gdb_byte *
-spu_breakpoint_from_pc (struct gdbarch *gdbarch,
-			CORE_ADDR * pcptr, int *lenptr)
-{
-  static const gdb_byte breakpoint[] = { 0x00, 0x00, 0x3f, 0xff };
-
-  *lenptr = sizeof breakpoint;
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (spu, breakpoint)
 
 static int
 spu_memory_remove_breakpoint (struct gdbarch *gdbarch,
@@ -2797,7 +2790,7 @@ spu_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Breakpoints.  */
   set_gdbarch_decr_pc_after_break (gdbarch, 4);
-  set_gdbarch_breakpoint_from_pc (gdbarch, spu_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (spu);
   set_gdbarch_memory_remove_breakpoint (gdbarch, spu_memory_remove_breakpoint);
   set_gdbarch_software_single_step (gdbarch, spu_software_single_step);
   set_gdbarch_get_longjmp_target (gdbarch, spu_get_longjmp_target);
diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c
index 550be4c..a8113cb 100644
--- a/gdb/tilegx-tdep.c
+++ b/gdb/tilegx-tdep.c
@@ -840,19 +840,11 @@ tilegx_write_pc (struct regcache *regcache, CORE_ADDR pc)
                                   INT_SWINT_1_SIGRETURN);
 }
 
-/* This is the implementation of gdbarch method breakpoint_from_pc.  */
+/* 64-bit pattern for a { bpt ; nop } bundle.  */
+static const unsigned char breakpoint[] =
+  { 0x00, 0x50, 0x48, 0x51, 0xae, 0x44, 0x6a, 0x28 };
 
-static const unsigned char *
-tilegx_breakpoint_from_pc (struct gdbarch *gdbarch,
-			   CORE_ADDR *pcptr, int *lenptr)
-{
-  /* 64-bit pattern for a { bpt ; nop } bundle.  */
-  static const unsigned char breakpoint[] =
-    { 0x00, 0x50, 0x48, 0x51, 0xae, 0x44, 0x6a, 0x28 };
-
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+GDBARCH_BREAKPOINT_MANIPULATION (tilegx, breakpoint)
 
 /* Normal frames.  */
 
@@ -1055,7 +1047,7 @@ tilegx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_push_dummy_call (gdbarch, tilegx_push_dummy_call);
   set_gdbarch_get_longjmp_target (gdbarch, tilegx_get_longjmp_target);
   set_gdbarch_write_pc (gdbarch, tilegx_write_pc);
-  set_gdbarch_breakpoint_from_pc (gdbarch, tilegx_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (tilegx);
   set_gdbarch_return_value (gdbarch, tilegx_return_value);
 
   set_gdbarch_print_insn (gdbarch, print_insn_tilegx);
diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c
index b7f4185..861f807 100644
--- a/gdb/vax-tdep.c
+++ b/gdb/vax-tdep.c
@@ -251,15 +251,10 @@ vax_return_value (struct gdbarch *gdbarch, struct value *function,
    encode a breakpoint instruction, store the length of the string in
    *LEN and optionally adjust *PC to point to the correct memory
    location for inserting the breakpoint.  */
-   
-static const gdb_byte *
-vax_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
-{
-  static gdb_byte break_insn[] = { 3 };
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
+static gdb_byte break_insn[] = { 3 };
+
+GDBARCH_BREAKPOINT_MANIPULATION (vax, break_insn)
 \f
 /* Advance PC across any function entry prologue instructions
    to reach some "real" code.  */
@@ -500,7 +495,7 @@ vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_dummy_id (gdbarch, vax_dummy_id);
 
   /* Breakpoint info */
-  set_gdbarch_breakpoint_from_pc (gdbarch, vax_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (vax);
 
   /* Misc info */
   set_gdbarch_deprecated_function_start_offset (gdbarch, 2);
diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
index af1551f..b2f0c5e 100644
--- a/gdb/xstormy16-tdep.c
+++ b/gdb/xstormy16-tdep.c
@@ -506,14 +506,9 @@ xstormy16_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
   return 0;
 }
 
-static const unsigned char *
-xstormy16_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			      int *lenptr)
-{
-  static unsigned char breakpoint[] = { 0x06, 0x0 };
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+static unsigned char breakpoint[] = { 0x06, 0x0 };
+
+GDBARCH_BREAKPOINT_MANIPULATION (xstormy16, breakpoint)
 
 /* Given a pointer to a jump table entry, return the address
    of the function it jumps to.  Return 0 if not found.  */
@@ -843,7 +838,7 @@ xstormy16_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* These values and methods are used when gdb calls a target function.  */
   set_gdbarch_push_dummy_call (gdbarch, xstormy16_push_dummy_call);
-  set_gdbarch_breakpoint_from_pc (gdbarch, xstormy16_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (xstormy16);
   set_gdbarch_return_value (gdbarch, xstormy16_return_value);
 
   set_gdbarch_skip_trampoline_code (gdbarch, xstormy16_skip_trampoline_code);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/13] Remove v850_dbtrap_breakpoint_from_pc
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
  2016-08-31 15:06 ` [PATCH 05/13] Share enum arm_breakpoint_kinds Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-08-31 15:06 ` [PATCH 11/13] Add default_breakpoint_from_pc Yao Qi
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

v850 has two functions to install to gdbarch_breakpoint_from_pc,
and it selects one according to info.bfd_arch_info->mach.  However,
we can select the kind/length of breakpoint instruction inside
v850_breakpoint_from_pc by gdbarch_bfd_arch_info (gdbarch)->mach.
This patch is to do that, and remove v850_dbtrap_breakpoint_from_pc.

gdb:

2016-08-30  Yao Qi  <yao.qi@linaro.org>

	* v850-tdep.c (v850_breakpoint_from_pc): Use the right
	breakpoint instruction.
	(v850_dbtrap_breakpoint_from_pc): Remove.
	(v850_gdbarch_init): Update.
---
 gdb/v850-tdep.c | 49 +++++++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 26 deletions(-)

diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 0b50580..d03334e 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -1170,26 +1170,33 @@ v850_return_value (struct gdbarch *gdbarch, struct value *function,
 
 static const unsigned char *
 v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-                         int *lenptr)
+			 int *lenptr)
 {
-  static unsigned char breakpoint[] = { 0x85, 0x05 };
+  *lenptr = 2;
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
-}
+  switch (gdbarch_bfd_arch_info (gdbarch)->mach)
+    {
+    case bfd_mach_v850e2:
+    case bfd_mach_v850e2v3:
+    case bfd_mach_v850e3v5:
+      {
+	/* Implement software breakpoints by using the dbtrap instruction.
+	   Older architectures had no such instruction.  For those, an
+	   unconditional branch to self instruction is used.  */
 
-/* Implement software breakpoints by using the dbtrap instruction. 
-   Older architectures had no such instruction.  For those, an
-   unconditional branch to self instruction is used.  */
+	static unsigned char dbtrap_breakpoint[] = { 0x40, 0xf8 };
 
-static const unsigned char *
-v850_dbtrap_breakpoint_from_pc (struct gdbarch *gdbarch,
-                                CORE_ADDR *pcptr, int *lenptr)
-{
-  static unsigned char breakpoint[] = { 0x40, 0xf8 };
+	return dbtrap_breakpoint;
+      }
+      break;
+    default:
+      {
+	static unsigned char breakpoint[] = { 0x85, 0x05 };
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
+	return breakpoint;
+      }
+      break;
+    }
 }
 
 static struct v850_frame_cache *
@@ -1440,18 +1447,8 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  switch (info.bfd_arch_info->mach)
-    {
-    case bfd_mach_v850e2:
-    case bfd_mach_v850e2v3:
-    case bfd_mach_v850e3v5:
-      set_gdbarch_breakpoint_from_pc (gdbarch, v850_dbtrap_breakpoint_from_pc);
-      break;
-    default:
-      set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
-      break;
-    }
 
+  set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
   set_gdbarch_return_value (gdbarch, v850_return_value);
   set_gdbarch_push_dummy_call (gdbarch, v850_push_dummy_call);
   set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 12/13] Determine the kind of single step breakpoint
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (10 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 08/13] New gdbarch methods " Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-10-27 14:55   ` Pedro Alves
  2016-08-31 15:06 ` [PATCH 06/13] Add enum for mips breakpoint kinds Yao Qi
  2016-10-10 10:17 ` [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch adds a new gdbarch method breakpoint_kind_from_current_state
for single step breakpoint, and uses it in breakpoint_kind.

gdb:

2016-07-20  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.c (default_breakpoint_kind_from_current_state):
	New function.
	* arch-utils.h (default_breakpoint_kind_from_current_state):
	Declare.
	* arm-tdep.c (arm_breakpoint_kind_from_current_state): New
	function.
	(arm_gdbarch_init): Call
	set_gdbarch_breakpoint_kind_from_current_state.
	* breakpoint.c (breakpoint_kind): Call
	gdbarch_breakpoint_kind_from_current_state for single step
	breakpoint.
	* gdbarch.sh (breakpoint_kind_from_current_state): New.
	* gdbarch.c, gdbarch.h: Regenerate.
---
 gdb/arch-utils.c |  8 ++++++++
 gdb/arch-utils.h |  4 ++++
 gdb/arm-tdep.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/breakpoint.c | 13 ++++++++++++-
 gdb/gdbarch.c    | 23 +++++++++++++++++++++++
 gdb/gdbarch.h    |  8 ++++++++
 gdb/gdbarch.sh   |  5 +++++
 7 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index e236877..ad2787a 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -820,6 +820,14 @@ default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
 
   return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
 }
+int
+default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
+					    struct regcache *regcache,
+					    CORE_ADDR *pcptr)
+{
+  return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
+}
+
 
 void
 default_gen_return_address (struct gdbarch *gdbarch,
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 4af8b9f..2db5ce7 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -213,6 +213,10 @@ extern const gdb_byte *default_breakpoint_from_pc (struct gdbarch *gdbarch,
 						   CORE_ADDR *pcptr,
 						   int *lenptr);
 
+extern int default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
+						       struct regcache *regcache,
+						       CORE_ADDR *pcptr);
+
 extern void default_gen_return_address (struct gdbarch *gdbarch,
 					struct agent_expr *ax,
 					struct axs_value *value,
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index f03897c..37b68ed 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7853,6 +7853,59 @@ arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
+/* Implement the breakpoint_kind_from_current_state gdbarch method.  */
+
+static int
+arm_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
+					struct regcache *regcache,
+					CORE_ADDR *pcptr)
+{
+  gdb_byte buf[4];
+
+  /* Check the memory pointed by PC is readable.  */
+  if (target_read_memory (regcache_read_pc (regcache), buf, 4) == 0)
+    {
+      struct arm_get_next_pcs next_pcs_ctx;
+      CORE_ADDR pc;
+      int i;
+      VEC (CORE_ADDR) *next_pcs = NULL;
+      struct cleanup *old_chain
+	= make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs);
+
+      arm_get_next_pcs_ctor (&next_pcs_ctx,
+			     &arm_get_next_pcs_ops,
+			     gdbarch_byte_order (gdbarch),
+			     gdbarch_byte_order_for_code (gdbarch),
+			     0,
+			     regcache);
+
+      next_pcs = arm_get_next_pcs (&next_pcs_ctx);
+
+      /* If MEMADDR is the next instruction of current pc, do the
+	 software single step computation, and get the thumb mode by
+	 the destination address.  */
+      for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++)
+	{
+	  if (UNMAKE_THUMB_ADDR (pc) == *pcptr)
+	    {
+	      do_cleanups (old_chain);
+
+	      if (IS_THUMB_ADDR (pc))
+		{
+		  *pcptr = MAKE_THUMB_ADDR (*pcptr);
+		  return arm_breakpoint_kind_from_pc (gdbarch, pcptr);
+		}
+	      else
+		return ARM_BP_KIND_ARM;
+	    }
+	}
+
+      do_cleanups (old_chain);
+    }
+
+  return arm_breakpoint_kind_from_pc (gdbarch, pcptr);
+}
+
 /* Extract from an array REGBUF containing the (raw) register state a
    function return value of type TYPE, and copy that, in virtual
    format, into VALBUF.  */
@@ -9361,6 +9414,8 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Breakpoint manipulation.  */
   SET_GDBARCH_BREAKPOINT_MANIPULATION (arm);
+  set_gdbarch_breakpoint_kind_from_current_state (gdbarch,
+						  arm_breakpoint_kind_from_current_state);
 
   /* Information about registers, etc.  */
   set_gdbarch_sp_regnum (gdbarch, ARM_SP_REGNUM);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index cc672f7..2b6976e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2607,7 +2607,18 @@ build_target_command_list (struct bp_location *bl)
 static int
 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
 {
-  return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
+  if (bl->owner->type == bp_single_step)
+    {
+      struct thread_info *thr = find_thread_global_id (bl->owner->thread);
+      struct regcache *regcache;
+
+      regcache = get_thread_regcache (thr->ptid);
+
+      return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
+							 regcache, addr);
+    }
+  else
+    return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
 }
 
 /* Insert a low-level "breakpoint" of some type.  BL is the breakpoint
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index ca430a9..e480023 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -231,6 +231,7 @@ struct gdbarch
   gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc;
   gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc;
   gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind;
+  gdbarch_breakpoint_kind_from_current_state_ftype *breakpoint_kind_from_current_state;
   gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address;
   gdbarch_memory_insert_breakpoint_ftype *memory_insert_breakpoint;
   gdbarch_memory_remove_breakpoint_ftype *memory_remove_breakpoint;
@@ -404,6 +405,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->return_in_first_hidden_param_p = default_return_in_first_hidden_param_p;
   gdbarch->breakpoint_from_pc = default_breakpoint_from_pc;
   gdbarch->sw_breakpoint_from_kind = NULL;
+  gdbarch->breakpoint_kind_from_current_state = default_breakpoint_kind_from_current_state;
   gdbarch->memory_insert_breakpoint = default_memory_insert_breakpoint;
   gdbarch->memory_remove_breakpoint = default_memory_remove_breakpoint;
   gdbarch->remote_register_number = default_remote_register_number;
@@ -584,6 +586,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   if (gdbarch->breakpoint_kind_from_pc == 0)
     fprintf_unfiltered (log, "\n\tbreakpoint_kind_from_pc");
   /* Skip verify of sw_breakpoint_from_kind, invalid_p == 0 */
+  /* Skip verify of breakpoint_kind_from_current_state, invalid_p == 0 */
   /* Skip verify of adjust_breakpoint_address, has predicate.  */
   /* Skip verify of memory_insert_breakpoint, invalid_p == 0 */
   /* Skip verify of memory_remove_breakpoint, invalid_p == 0 */
@@ -793,6 +796,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: breakpoint_from_pc = <%s>\n",
                       host_address_to_string (gdbarch->breakpoint_from_pc));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: breakpoint_kind_from_current_state = <%s>\n",
+                      host_address_to_string (gdbarch->breakpoint_kind_from_current_state));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: breakpoint_kind_from_pc = <%s>\n",
                       host_address_to_string (gdbarch->breakpoint_kind_from_pc));
   fprintf_unfiltered (file,
@@ -2800,6 +2806,23 @@ set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch,
 }
 
 int
+gdbarch_breakpoint_kind_from_current_state (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR *pcptr)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->breakpoint_kind_from_current_state != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_breakpoint_kind_from_current_state called\n");
+  return gdbarch->breakpoint_kind_from_current_state (gdbarch, regcache, pcptr);
+}
+
+void
+set_gdbarch_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
+                                                gdbarch_breakpoint_kind_from_current_state_ftype breakpoint_kind_from_current_state)
+{
+  gdbarch->breakpoint_kind_from_current_state = breakpoint_kind_from_current_state;
+}
+
+int
 gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 65a6a6e..0df6dc8 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -556,6 +556,14 @@ typedef const gdb_byte * (gdbarch_sw_breakpoint_from_kind_ftype) (struct gdbarch
 extern const gdb_byte * gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size);
 extern void set_gdbarch_sw_breakpoint_from_kind (struct gdbarch *gdbarch, gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind);
 
+/* Return the breakpoint kind for this target based on the current
+   processor state (e.g. the current instruction mode on ARM) and the
+   *PCPTR.  In default, it is gdbarch->breakpoint_kind_from_pc. */
+
+typedef int (gdbarch_breakpoint_kind_from_current_state_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR *pcptr);
+extern int gdbarch_breakpoint_kind_from_current_state (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR *pcptr);
+extern void set_gdbarch_breakpoint_kind_from_current_state (struct gdbarch *gdbarch, gdbarch_breakpoint_kind_from_current_state_ftype *breakpoint_kind_from_current_state);
+
 extern int gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_adjust_breakpoint_address_ftype) (struct gdbarch *gdbarch, CORE_ADDR bpaddr);
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index c999f30..82d2c71 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -564,6 +564,11 @@ m:int:breakpoint_kind_from_pc:CORE_ADDR *pcptr:pcptr::0:
 # SIZE is set to the software breakpoint's length in memory.
 m:const gdb_byte *:sw_breakpoint_from_kind:int kind, int *size:kind, size::NULL::0
 
+# Return the breakpoint kind for this target based on the current
+# processor state (e.g. the current instruction mode on ARM) and the
+# *PCPTR.  In default, it is gdbarch->breakpoint_kind_from_pc.
+m:int:breakpoint_kind_from_current_state:struct regcache *regcache, CORE_ADDR *pcptr:regcache, pcptr:0:default_breakpoint_kind_from_current_state::0
+
 M:CORE_ADDR:adjust_breakpoint_address:CORE_ADDR bpaddr:bpaddr
 m:int:memory_insert_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_insert_breakpoint::0
 m:int:memory_remove_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_remove_breakpoint::0
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 06/13] Add enum for mips breakpoint kinds
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (11 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 12/13] Determine the kind of single step breakpoint Yao Qi
@ 2016-08-31 15:06 ` Yao Qi
  2016-10-27 14:54   ` Pedro Alves
  2016-10-10 10:17 ` [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-08-31 15:06 UTC (permalink / raw)
  To: gdb-patches

This patch adds an enum mips_breakpoint_kinds to avoid using magic
numbers as much as possible.

gdb:

2016-08-31  Yao Qi  <yao.qi@linaro.org>

	* mips-tdep.c (mips_breakpoint_kinds): New enum.
	(mips_breakpoint_from_pc): Use it.
	(mips_remote_breakpoint_from_pc): Likewise.
---
 gdb/mips-tdep.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 4e4d79e..34df8d0 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -107,6 +107,20 @@ static const char *const mips_abi_strings[] = {
   NULL
 };
 
+/* Enum describing the different kinds of breakpoints.  */
+
+enum mips_breakpoint_kinds
+{
+  /* 16-bit MIPS16 mode breakpoint */
+  MIPS_BP_KIND_16BIT_MIPS16 = 2,
+  /* 16-bit microMIPS mode breakpoint */
+  MIPS_BP_KIND_16BIT_MICROMIPS = 3,
+  /* 32-bit standard MIPS mode breakpoint */
+  MIPS_BP_KIND_32BIT = 4,
+  /* 32-bit microMIPS mode breakpoint */
+  MIPS_BP_KIND_32BIT_MICROMIPS = 5,
+};
+
 /* For backwards compatibility we default to MIPS16.  This flag is
    overridden as soon as unambiguous ELF file flags tell us the
    compressed ISA encoding used.  */
@@ -7143,16 +7157,7 @@ mips_breakpoint_from_pc (struct gdbarch *gdbarch,
     }
 }
 
-/* Determine the remote breakpoint kind suitable for the PC.  The following
-   kinds are used:
-
-   * 2 -- 16-bit MIPS16 mode breakpoint,
-
-   * 3 -- 16-bit microMIPS mode breakpoint,
-
-   * 4 -- 32-bit standard MIPS mode breakpoint,
-
-   * 5 -- 32-bit microMIPS mode breakpoint.  */
+/* Determine the remote breakpoint kind suitable for the PC.  */
 
 static void
 mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
@@ -7163,21 +7168,23 @@ mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
   if (mips_pc_is_mips16 (gdbarch, pc))
     {
       *pcptr = unmake_compact_addr (pc);
-      *kindptr = 2;
+      *kindptr = MIPS_BP_KIND_16BIT_MIPS16;
     }
   else if (mips_pc_is_micromips (gdbarch, pc))
     {
       ULONGEST insn;
       int status;
-      int size;
 
       insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status);
-      size = status ? 2 : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4;
+      if (status || (mips_insn_size (ISA_MICROMIPS, insn) == 2))
+	*kindptr = MIPS_BP_KIND_16BIT_MICROMIPS;
+      else
+	*kindptr = MIPS_BP_KIND_32BIT_MICROMIPS;
+
       *pcptr = unmake_compact_addr (pc);
-      *kindptr = size | 1;
     }
   else
-    *kindptr = 4;
+    *kindptr = MIPS_BP_KIND_32BIT;
 }
 
 /* Return non-zero if the standard MIPS instruction INST has a branch
-- 
1.9.1

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL
  2016-08-31 15:06 ` [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL Yao Qi
@ 2016-09-28 15:23   ` Michael Eager
  0 siblings, 0 replies; 28+ messages in thread
From: Michael Eager @ 2016-09-28 15:23 UTC (permalink / raw)
  To: gdb-patches

On 08/31/2016 08:05 AM, Yao Qi wrote:
> gdbarch_breakpoint_from_pc doesn't return NULL except for
> ia64_breakpoint_from_pc, and we checked its return value in three
> places. In microblaze_linux_memory_remove_breakpoint and
> ppc_linux_memory_remove_breakpoint, gdbarch_breakpoint_from_pc never
> returns NULL, so we can remove the NULL checking.  In
> default_memory_insert_breakpoint, gdbarch_breakpoint_from_pc can't
> returns NULL too because ia64 defines its own memory_insert_breakpoint.
>
> gdb:
>
> 2016-08-30  Yao Qi  <yao.qi@linaro.org>
>
> 	* mem-break.c (default_memory_insert_breakpoint): Don't check
> 	'bp' against NULL.
> 	* microblaze-linux-tdep.c (microblaze_linux_memory_remove_breakpoint):
> 	Likewise.
> 	* ppc-linux-tdep.c (ppc_linux_memory_remove_breakpoint): Likewise.

Microblaze change OK.

-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-08-31 15:06 ` [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
@ 2016-10-10 10:05   ` Yao Qi
  2016-10-27 14:55   ` Pedro Alves
  1 sibling, 0 replies; 28+ messages in thread
From: Yao Qi @ 2016-10-10 10:05 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> We convert each ARCH_brekapoint_from_pc to ARCH_breakpoint_kind_from_pc
> and ARCH_sw_breakpoint_from_kind.  Note that gdbarch doesn't have methods
> breakpoint_kind_from_pc and sw_breakpoint_from_kind so far.

The new port arc was added since these patches were posted.  Update this
patch for arc.

-- 
Yao (齐尧)

From: Yao Qi <yao.qi@linaro.org>
Subject: [PATCH] Split brekapoint_from_pc to breakpoint_kind_from_pc and
 sw_breakpoint_from_kind

We convert each ARCH_brekapoint_from_pc to ARCH_breakpoint_kind_from_pc
and ARCH_sw_breakpoint_from_kind.  Note that gdbarch doesn't have methods
breakpoint_kind_from_pc and sw_breakpoint_from_kind so far.

gdb:

2016-10-10  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_FROM_PC): New macro.
	(GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): New macro.
	* arm-tdep.c (arm_breakpoint_from_pc): Remove.
	(arm_breakpoint_kind_from_pc): New function.
	(arm_sw_breakpoint_from_kind): New function.
	(arm_breakpoint_from_pc): Call arm_breakpoint_kind_from_pc
	and arm_sw_breakpoint_from_kind.
	Use GDBARCH_BREAKPOINT_FROM_PC.
	(arm_remote_breakpoint_from_pc): Call
	arm_breakpoint_kind_from_pc.
	(arm_gdbarch_init): Replace set_gdbarch_breakpoint_from_pc
	with SET_GDBARCH_BREAKPOINT_MANIPULATION.
	* arc-tdep.c: Likewise.
	* bfin-tdep.c: Likewise.
	* cris-tdep.c: Likewise.
	* iq2000-tdep.c: Likewise.
	* m32r-tdep.c: Likewise.
	* mips-tdep.c: Likewise.
	* mt-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* rs6000-tdep.c: Likewise.
	* score-tdep.c: Likewise.
	* sh-tdep.c: Likewise.
	* sh64-tdep.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* v850-tdep.c: Likewise.
	* xtensa-tdep.c: Likewise.

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 60a4e04..e7405e7 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -693,9 +693,7 @@ static const gdb_byte arc_brk_s_le[] = { 0xff, 0x7f };
 static const gdb_byte arc_brk_be[] = { 0x25, 0x6f, 0x00, 0x3f };
 static const gdb_byte arc_brk_le[] = { 0x6f, 0x25, 0x3f, 0x00 };
 
-/* Implement the "breakpoint_from_pc" gdbarch method.
-
-   For ARC ELF, breakpoint uses the 16-bit BRK_S instruction, which is 0x7fff
+/* For ARC ELF, breakpoint uses the 16-bit BRK_S instruction, which is 0x7fff
    (little endian) or 0xff7f (big endian).  We used to insert BRK_S even
    instead of 32-bit instructions, which works mostly ok, unless breakpoint is
    inserted into delay slot instruction.  In this case if branch is taken
@@ -712,15 +710,12 @@ static const gdb_byte arc_brk_le[] = { 0x6f, 0x25, 0x3f, 0x00 };
    NB: Baremetal GDB uses BRK[_S], while user-space GDB uses TRAP_S.  BRK[_S]
    is much better because it doesn't commit unlike TRAP_S, so it can be set in
    delay slots; however it cannot be used in user-mode, hence usage of TRAP_S
-   in GDB for user-space.
+   in GDB for user-space.  */
 
-   PCPTR is a pointer to the PC where we want to place a breakpoint.  LENPTR
-   is a number of bytes used by the breakpoint.  Returns the byte sequence of
-   a breakpoint instruction.  */
+/* Implement the "breakpoint_kind_from_pc" gdbarch method.  */
 
-static const gdb_byte *
-arc_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			int *lenptr)
+static int
+arc_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   size_t length_with_limm = gdb_insn_length (gdbarch, *pcptr);
 
@@ -729,15 +724,26 @@ arc_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
      bytes for 32-bit instructions.  */
   if ((length_with_limm == 4 || length_with_limm == 8)
       && !arc_mach_is_arc600 (gdbarch))
+    return sizeof (arc_brk_le);
+  else
+    return sizeof (arc_brk_s_le);
+}
+
+/* Implement the "sw_breakpoint_from_kind" gdbarch method.  */
+
+static const gdb_byte *
+arc_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+  if (kind == sizeof (arc_brk_le))
     {
-      *lenptr = sizeof (arc_brk_le);
       return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
 	      ? arc_brk_be
 	      : arc_brk_le);
     }
   else
     {
-      *lenptr = sizeof (arc_brk_s_le);
       return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
 	      ? arc_brk_s_be
 	      : arc_brk_s_le);
@@ -1203,7 +1209,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_prologue (gdbarch, arc_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, arc_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (arc);
 
   /* On ARC 600 BRK_S instruction advances PC, unlike other ARC cores.  */
   if (!arc_mach_is_arc600 (gdbarch))
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 5bf6da5..2ccf191 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -26,6 +26,17 @@ struct minimal_symbol;
 struct type;
 struct gdbarch_info;
 
+#define GDBARCH_BREAKPOINT_FROM_PC(ARCH)			       \
+  static const gdb_byte *					       \
+  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		       \
+			     CORE_ADDR *pcptr,				\
+			     int *lenptr)				\
+  {									\
+    int kind = ARCH##_breakpoint_kind_from_pc (gdbarch, pcptr);	\
+								     \
+    return ARCH##_sw_breakpoint_from_kind (gdbarch, kind, lenptr);   \
+  }
+
 #define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
   static const gdb_byte *					      \
   ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,		      \
@@ -39,6 +50,23 @@ struct gdbarch_info;
 #define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)	\
   set_gdbarch_breakpoint_from_pc (gdbarch, ARCH##_breakpoint_from_pc)
 
+#define GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN(ARCH, \
+					       LITTLE_BREAK_INSN,	\
+					       BIG_BREAK_INSN)		\
+  static const gdb_byte *						\
+  ARCH##_breakpoint_from_pc (struct gdbarch *gdbarch,			\
+			     CORE_ADDR *pcptr,				\
+			     int *lenptr)				\
+  {									\
+    gdb_static_assert (ARRAY_SIZE (LITTLE_BREAK_INSN)			\
+		       == ARRAY_SIZE (BIG_BREAK_INSN));		\
+    *lenptr = sizeof (LITTLE_BREAK_INSN);				\
+    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)		\
+      return BIG_BREAK_INSN;						\
+    else								\
+      return LITTLE_BREAK_INSN;					\
+  }
+
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
    single-stepping the displaced copy.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 27a3ebe..372c495 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7846,16 +7846,8 @@ static const gdb_byte arm_default_arm_be_breakpoint[] = ARM_BE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_le_breakpoint[] = THUMB_LE_BREAKPOINT;
 static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 
-/* Determine the type and size of breakpoint to insert at PCPTR.  Uses
-   the program counter value to determine whether a 16-bit or 32-bit
-   breakpoint should be used.  It returns a pointer to a string of
-   bytes that encode a breakpoint instruction, stores the length of
-   the string to *lenptr, and adjusts the program counter (if
-   necessary) to point to the actual memory location where the
-   breakpoint should be inserted.  */
-
-static const unsigned char *
-arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
+static int
+arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
@@ -7869,38 +7861,61 @@ arm_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
       if (tdep->thumb2_breakpoint != NULL)
 	{
 	  gdb_byte buf[2];
+
 	  if (target_read_memory (*pcptr, buf, 2) == 0)
 	    {
 	      unsigned short inst1;
+
 	      inst1 = extract_unsigned_integer (buf, 2, byte_order_for_code);
 	      if (thumb_insn_size (inst1) == 4)
-		{
-		  *lenptr = tdep->thumb2_breakpoint_size;
-		  return tdep->thumb2_breakpoint;
-		}
+		return ARM_BP_KIND_THUMB2;
 	    }
 	}
 
-      *lenptr = tdep->thumb_breakpoint_size;
-      return tdep->thumb_breakpoint;
+      return ARM_BP_KIND_THUMB;
     }
   else
+    return ARM_BP_KIND_ARM;
+
+}
+
+static const gdb_byte *
+arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  switch (kind)
     {
-      *lenptr = tdep->arm_breakpoint_size;
+    case ARM_BP_KIND_ARM:
+      *size = tdep->arm_breakpoint_size;
       return tdep->arm_breakpoint;
+    case ARM_BP_KIND_THUMB:
+      *size = tdep->thumb_breakpoint_size;
+      return tdep->thumb_breakpoint;
+    case ARM_BP_KIND_THUMB2:
+      *size = tdep->thumb2_breakpoint_size;
+      return tdep->thumb2_breakpoint;
+    default:
+      gdb_assert_not_reached ("unexpected arm breakpoint kind");
     }
 }
 
+/* Determine the type and size of breakpoint to insert at PCPTR.  Uses
+   the program counter value to determine whether a 16-bit or 32-bit
+   breakpoint should be used.  It returns a pointer to a string of
+   bytes that encode a breakpoint instruction, stores the length of
+   the string to *lenptr, and adjusts the program counter (if
+   necessary) to point to the actual memory location where the
+   breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (arm)
+
 static void
 arm_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
 			       int *kindptr)
 {
-  arm_breakpoint_from_pc (gdbarch, pcptr, kindptr);
 
-  if (arm_pc_is_thumb (gdbarch, *pcptr) && *kindptr == 4)
-    /* The documented magic value for a 32-bit Thumb-2 breakpoint, so
-       that this is not confused with a 32-bit ARM breakpoint.  */
-    *kindptr = ARM_BP_KIND_THUMB2;
+  *kindptr = arm_breakpoint_kind_from_pc (gdbarch, pcptr);
 }
 
 /* Extract from an array REGBUF containing the (raw) register state a
@@ -9410,7 +9425,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   /* Breakpoint manipulation.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, arm_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (arm);
   set_gdbarch_remote_breakpoint_from_pc (gdbarch,
 					 arm_remote_breakpoint_from_pc);
 
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index d07bf6e..d895997 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -568,28 +568,28 @@ bfin_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   return map_gcc_gdb[reg];
 }
 
-/* This function implements the 'breakpoint_from_pc' gdbarch method.
-   It returns a pointer to a string of bytes that encode a breakpoint
-   instruction, stores the length of the string to *lenptr, and
-   adjusts the program counter (if necessary) to point to the actual
-   memory location where the breakpoint should be inserted.  */
-
-static const unsigned char *
-bfin_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static int
+bfin_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned short iw;
-  static unsigned char bfin_breakpoint[] = {0xa1, 0x00, 0x00, 0x00};
-  static unsigned char bfin_sim_breakpoint[] = {0x25, 0x00, 0x00, 0x00};
 
   iw = read_memory_unsigned_integer (*pcptr, 2, byte_order);
 
   if ((iw & 0xf000) >= 0xc000)
     /* 32-bit instruction.  */
-    *lenptr = 4;
+    return 4;
   else
-    *lenptr = 2;
+    return 2;
+}
+
+static const gdb_byte *
+bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  static unsigned char bfin_breakpoint[] = {0xa1, 0x00, 0x00, 0x00};
+  static unsigned char bfin_sim_breakpoint[] = {0x25, 0x00, 0x00, 0x00};
+
+  *size = kind;
 
   if (strcmp (target_shortname, "sim") == 0)
     return bfin_sim_breakpoint;
@@ -597,6 +597,14 @@ bfin_breakpoint_from_pc (struct gdbarch *gdbarch,
     return bfin_breakpoint;
 }
 
+/* This function implements the 'breakpoint_from_pc' gdbarch method.
+   It returns a pointer to a string of bytes that encode a breakpoint
+   instruction, stores the length of the string to *lenptr, and
+   adjusts the program counter (if necessary) to point to the actual
+   memory location where the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (bfin)
+
 static void
 bfin_extract_return_value (struct type *type,
 			   struct regcache *regs,
@@ -826,7 +834,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_return_value (gdbarch, bfin_return_value);
   set_gdbarch_skip_prologue (gdbarch, bfin_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, bfin_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (bfin);
   set_gdbarch_decr_pc_after_break (gdbarch, 2);
   set_gdbarch_frame_args_skip (gdbarch, 8);
   set_gdbarch_unwind_pc (gdbarch, bfin_unwind_pc);
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 1d29524..bee95cf 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -1391,20 +1391,20 @@ cris_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
   return sp;
 }
 
-/* Use the program counter to determine the contents and size of a breakpoint
-   instruction.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pcptr (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
+static int
+cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 2;
+}
 
-static const unsigned char *
-cris_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static const gdb_byte *
+cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
-  *lenptr = 2;
+
+  *size = kind;
 
   if (tdep->cris_mode == cris_mode_guru)
     return break15_insn;
@@ -1412,6 +1412,14 @@ cris_breakpoint_from_pc (struct gdbarch *gdbarch,
     return break8_insn;
 }
 
+/* Use the program counter to determine the contents and size of a breakpoint
+   instruction.  It returns a pointer to a string of bytes that encode a
+   breakpoint instruction, stores the length of the string to *lenptr, and
+   adjusts pcptr (if necessary) to point to the actual memory location where
+   the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (cris)
+
 /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
    0 otherwise.  */
 
@@ -4123,7 +4131,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* The stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (cris);
   
   set_gdbarch_unwind_pc (gdbarch, cris_unwind_pc);
   set_gdbarch_unwind_sp (gdbarch, cris_unwind_sp);
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 600d70a..ecd9074 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -469,22 +469,29 @@ static const struct frame_base iq2000_frame_base = {
   iq2000_frame_base_address
 };
 
-static const unsigned char *
-iq2000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static int
+iq2000_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
-  static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
-
   if ((*pcptr & 3) != 0)
     error (_("breakpoint_from_pc: invalid breakpoint address 0x%lx"),
 	   (long) *pcptr);
 
-  *lenptr = 4;
+  return 4;
+}
+
+static const gdb_byte *
+iq2000_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
+  static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
+  *size = kind;
+
   return (gdbarch_byte_order (gdbarch)
 	  == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (iq2000)
+
 /* Target function return value methods: */
 
 /* Function: store_return_value
@@ -826,7 +833,7 @@ iq2000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_double_format        (gdbarch, floatformats_ieee_double);
   set_gdbarch_long_double_format   (gdbarch, floatformats_ieee_double);
   set_gdbarch_return_value	   (gdbarch, iq2000_return_value);
-  set_gdbarch_breakpoint_from_pc   (gdbarch, iq2000_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (iq2000);
   set_gdbarch_frame_args_skip      (gdbarch, 0);
   set_gdbarch_skip_prologue        (gdbarch, iq2000_skip_prologue);
   set_gdbarch_inner_than           (gdbarch, core_addr_lessthan);
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 8e1d79e..2ca8940 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -165,9 +165,17 @@ m32r_memory_remove_breakpoint (struct gdbarch *gdbarch,
   return val;
 }
 
+static int
+m32r_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  if ((*pcptr & 3) == 0)
+    return 4;
+  else
+    return 2;
+}
+
 static const gdb_byte *
-m32r_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   static gdb_byte be_bp_entry[] = {
     0x10, 0xf1, 0x70, 0x00
@@ -175,39 +183,22 @@ m32r_breakpoint_from_pc (struct gdbarch *gdbarch,
   static gdb_byte le_bp_entry[] = {
     0x00, 0x70, 0xf1, 0x10
   };	/* dpt -> nop */
-  gdb_byte *bp;
+
+  *size = kind;
 
   /* Determine appropriate breakpoint.  */
   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    {
-      if ((*pcptr & 3) == 0)
-	{
-	  bp = be_bp_entry;
-	  *lenptr = 4;
-	}
-      else
-	{
-	  bp = be_bp_entry;
-	  *lenptr = 2;
-	}
-    }
+    return be_bp_entry;
   else
     {
-      if ((*pcptr & 3) == 0)
-	{
-	  bp = le_bp_entry;
-	  *lenptr = 4;
-	}
+      if (kind == 4)
+	return le_bp_entry;
       else
-	{
-	  bp = le_bp_entry + 2;
-	  *lenptr = 2;
-	}
+	return le_bp_entry + 2;
     }
-
-  return bp;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (m32r)
 
 char *m32r_register_names[] = {
   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
@@ -929,7 +920,7 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, m32r_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m32r_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (m32r);
   set_gdbarch_memory_insert_breakpoint (gdbarch,
 					m32r_memory_insert_breakpoint);
   set_gdbarch_memory_remove_breakpoint (gdbarch,
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index eb8fbc6..d79c49d 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -7056,141 +7056,137 @@ gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
   return gdb_print_insn_mips (memaddr, info);
 }
 
-/* This function implements gdbarch_breakpoint_from_pc.  It uses the
-   program counter value to determine whether a 16- or 32-bit breakpoint
-   should be used.  It returns a pointer to a string of bytes that encode a
-   breakpoint instruction, stores the length of the string to *lenptr, and
-   adjusts pc (if necessary) to point to the actual memory location where
-   the breakpoint should be inserted.  */
-
-static const gdb_byte *
-mips_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
-{
-  CORE_ADDR pc = *pcptr;
-
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    {
-      if (mips_pc_is_mips16 (gdbarch, pc))
-	{
-	  static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = sizeof (mips16_big_breakpoint);
-	  return mips16_big_breakpoint;
-	}
-      else if (mips_pc_is_micromips (gdbarch, pc))
-	{
-	  static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
-	  static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
-	  ULONGEST insn;
-	  int err;
-	  int size;
-
-	  insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &err);
-	  size = err ? 2 : mips_insn_size (ISA_MICROMIPS, insn);
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = size;
-	  return (size == 2) ? micromips16_big_breakpoint
-			     : micromips32_big_breakpoint;
-	}
-      else
-	{
-	  /* The IDT board uses an unusual breakpoint value, and
-	     sometimes gets confused when it sees the usual MIPS
-	     breakpoint instruction.  */
-	  static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
-	  static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
-	  static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
-	  /* Likewise, IRIX appears to expect a different breakpoint,
-	     although this is not apparent until you try to use pthreads.  */
-	  static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
-
-	  *lenptr = sizeof (big_breakpoint);
-
-	  if (strcmp (target_shortname, "mips") == 0)
-	    return idt_big_breakpoint;
-	  else if (strcmp (target_shortname, "ddb") == 0
-		   || strcmp (target_shortname, "pmon") == 0
-		   || strcmp (target_shortname, "lsi") == 0)
-	    return pmon_big_breakpoint;
-	  else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
-	    return irix_big_breakpoint;
-	  else
-	    return big_breakpoint;
-	}
-    }
-  else
-    {
-      if (mips_pc_is_mips16 (gdbarch, pc))
-	{
-	  static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = sizeof (mips16_little_breakpoint);
-	  return mips16_little_breakpoint;
-	}
-      else if (mips_pc_is_micromips (gdbarch, pc))
-	{
-	  static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 };
-	  static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 };
-	  ULONGEST insn;
-	  int err;
-	  int size;
-
-	  insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &err);
-	  size = err ? 2 : mips_insn_size (ISA_MICROMIPS, insn);
-	  *pcptr = unmake_compact_addr (pc);
-	  *lenptr = size;
-	  return (size == 2) ? micromips16_little_breakpoint
-			     : micromips32_little_breakpoint;
-	}
-      else
-	{
-	  static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
-	  static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
-	  static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
-
-	  *lenptr = sizeof (little_breakpoint);
-
-	  if (strcmp (target_shortname, "mips") == 0)
-	    return idt_little_breakpoint;
-	  else if (strcmp (target_shortname, "ddb") == 0
-		   || strcmp (target_shortname, "pmon") == 0
-		   || strcmp (target_shortname, "lsi") == 0)
-	    return pmon_little_breakpoint;
-	  else
-	    return little_breakpoint;
-	}
-    }
-}
-
-/* Determine the remote breakpoint kind suitable for the PC.  */
-
-static void
-mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-				int *kindptr)
+static int
+mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   CORE_ADDR pc = *pcptr;
 
   if (mips_pc_is_mips16 (gdbarch, pc))
     {
       *pcptr = unmake_compact_addr (pc);
-      *kindptr = MIPS_BP_KIND_16BIT_MIPS16;
+      return MIPS_BP_KIND_16BIT_MIPS16;
     }
   else if (mips_pc_is_micromips (gdbarch, pc))
     {
       ULONGEST insn;
       int status;
 
+      *pcptr = unmake_compact_addr (pc);
       insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status);
       if (status || (mips_insn_size (ISA_MICROMIPS, insn) == 2))
-	*kindptr = MIPS_BP_KIND_16BIT_MICROMIPS;
+	return MIPS_BP_KIND_16BIT_MICROMIPS;
       else
-	*kindptr = MIPS_BP_KIND_32BIT_MICROMIPS;
-
-      *pcptr = unmake_compact_addr (pc);
+	return MIPS_BP_KIND_32BIT_MICROMIPS;
     }
   else
-    *kindptr = MIPS_BP_KIND_32BIT;
+    return MIPS_BP_KIND_32BIT;
+}
+
+static const gdb_byte *
+mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
+
+  switch (kind)
+    {
+    case MIPS_BP_KIND_16BIT_MIPS16:
+      {
+	static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
+	static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
+
+	*size = 2;
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return mips16_big_breakpoint;
+	else
+	  return mips16_little_breakpoint;
+      }
+    case MIPS_BP_KIND_16BIT_MICROMIPS:
+      {
+	static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
+	static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 };
+
+	*size = 2;
+
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return micromips16_big_breakpoint;
+	else
+	  return micromips16_little_breakpoint;
+      }
+    case MIPS_BP_KIND_32BIT_MICROMIPS:
+      {
+	static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
+	static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 };
+
+	*size = 4;
+	if (byte_order_for_code == BFD_ENDIAN_BIG)
+	  return micromips32_big_breakpoint;
+	else
+	  return micromips32_little_breakpoint;
+      }
+    case MIPS_BP_KIND_32BIT:
+      {
+	/* The IDT board uses an unusual breakpoint value, and
+	   sometimes gets confused when it sees the usual MIPS
+	   breakpoint instruction.  */
+	static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
+	static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
+	static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
+	static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
+	static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
+	static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
+	/* Likewise, IRIX appears to expect a different breakpoint,
+	   although this is not apparent until you try to use pthreads.  */
+	static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
+
+	*size = 4;
+
+	if (strcmp (target_shortname, "mips") == 0)
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return idt_big_breakpoint;
+	    else
+	      return idt_little_breakpoint;
+	  }
+	else if (strcmp (target_shortname, "ddb") == 0
+		 || strcmp (target_shortname, "pmon") == 0
+		 || strcmp (target_shortname, "lsi") == 0)
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return pmon_big_breakpoint;
+	    else
+	      return pmon_little_breakpoint;
+	  }
+	else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
+	  return irix_big_breakpoint;
+	else
+	  {
+	    if (byte_order_for_code == BFD_ENDIAN_BIG)
+	      return big_breakpoint;
+	    else
+	      return little_breakpoint;
+	  }
+      }
+    default:
+      gdb_assert_not_reached ("unexpected mips breakpoint kind");
+    };
+}
+
+/* This function implements gdbarch_breakpoint_from_pc.  It uses the
+   program counter value to determine whether a 16- or 32-bit breakpoint
+   should be used.  It returns a pointer to a string of bytes that encode a
+   breakpoint instruction, stores the length of the string to *lenptr, and
+   adjusts pc (if necessary) to point to the actual memory location where
+   the breakpoint should be inserted.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (mips)
+
+/* Determine the remote breakpoint kind suitable for the PC.  */
+
+static void
+mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
+				int *kindptr)
+{
+  *kindptr = mips_breakpoint_kind_from_pc (gdbarch, pcptr);
 }
 
 /* Return non-zero if the standard MIPS instruction INST has a branch
@@ -8803,7 +8799,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mips);
   set_gdbarch_remote_breakpoint_from_pc (gdbarch,
 					 mips_remote_breakpoint_from_pc);
   set_gdbarch_adjust_breakpoint_address (gdbarch,
diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
index 5d7f31c..0adf413 100644
--- a/gdb/mt-tdep.c
+++ b/gdb/mt-tdep.c
@@ -449,26 +449,33 @@ mt_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   return pc;
 }
 
-/* The breakpoint instruction must be the same size as the smallest
-   instruction in the instruction set.
-
-   The BP for ms1 is defined as 0x68000000 (BREAK).
-   The BP for ms2 is defined as 0x69000000 (illegal).  */
+static int
+mt_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 4;
+}
 
 static const gdb_byte *
-mt_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-		       int *bp_size)
+mt_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
+  /* The breakpoint instruction must be the same size as the smallest
+     instruction in the instruction set.
+
+     The BP for ms1 is defined as 0x68000000 (BREAK).
+     The BP for ms2 is defined as 0x69000000 (illegal).  */
   static gdb_byte ms1_breakpoint[] = { 0x68, 0, 0, 0 };
   static gdb_byte ms2_breakpoint[] = { 0x69, 0, 0, 0 };
 
-  *bp_size = 4;
+  *size = kind;
+
   if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_ms2)
     return ms2_breakpoint;
-  
+
   return ms1_breakpoint;
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (mt)
+
 /* Select the correct coprocessor register bank.  Return the pseudo
    regnum we really want to read.  */
 
@@ -1162,7 +1169,7 @@ mt_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pseudo_register_write (gdbarch, mt_pseudo_register_write);
   set_gdbarch_skip_prologue (gdbarch, mt_skip_prologue);
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, mt_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (mt);
   set_gdbarch_decr_pc_after_break (gdbarch, 0);
   set_gdbarch_frame_args_skip (gdbarch, 0);
   set_gdbarch_print_insn (gdbarch, print_insn_mt);
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 3ff325fe0..57fd331 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1694,9 +1694,30 @@ nios2_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   return nios2_analyze_prologue (gdbarch, start_pc, start_pc, &cache, NULL);
 }
 
-/* Implement the breakpoint_from_pc gdbarch hook.
+static int
+nios2_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+
+  if (mach == bfd_mach_nios2r2)
+    {
+      unsigned int insn;
+      const struct nios2_opcode *op
+	= nios2_fetch_insn (gdbarch, *pcptr, &insn);
+
+      if (op && op->size == NIOS2_CDX_OPCODE_SIZE)
+	return NIOS2_CDX_OPCODE_SIZE;
+      else
+	return NIOS2_OPCODE_SIZE;
+    }
+  else
+    return NIOS2_OPCODE_SIZE;
+}
 
-   The Nios II ABI for Linux says: "Userspace programs should not use
+static const gdb_byte *
+nios2_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+/* The Nios II ABI for Linux says: "Userspace programs should not use
    the break instruction and userspace debuggers should not insert
    one." and "Userspace breakpoints are accomplished using the trap
    instruction with immediate operand 31 (all ones)."
@@ -1704,54 +1725,53 @@ nios2_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
    So, we use "trap 31" consistently as the breakpoint on bare-metal
    as well as Linux targets.  */
 
-static const gdb_byte*
-nios2_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			  int *bp_size)
-{
-  enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
-  unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+  /* R2 trap encoding:
+     ((0x2d << 26) | (0x1f << 21) | (0x1d << 16) | (0x20 << 0))
+     0xb7fd0020
+     CDX trap.n encoding:
+     ((0xd << 12) | (0x1f << 6) | (0x9 << 0))
+     0xd7c9
+     Note that code is always little-endian on R2.  */
+  *size = kind;
 
-  if (mach == bfd_mach_nios2r2)
+  if (kind == NIOS2_CDX_OPCODE_SIZE)
     {
-      /* R2 trap encoding:
-	   ((0x2d << 26) | (0x1f << 21) | (0x1d << 16) | (0x20 << 0))
-	   0xb7fd0020
-	 CDX trap.n encoding:
-	   ((0xd << 12) | (0x1f << 6) | (0x9 << 0))
-	   0xd7c9
-         Note that code is always little-endian on R2.  */
-      static const gdb_byte r2_breakpoint_le[] = {0x20, 0x00, 0xfd, 0xb7};
       static const gdb_byte cdx_breakpoint_le[] = {0xc9, 0xd7};
-      unsigned int insn;
-      const struct nios2_opcode *op
-	= nios2_fetch_insn (gdbarch, *bp_addr, &insn);
 
-      if (op && op->size == NIOS2_CDX_OPCODE_SIZE)
+      return cdx_breakpoint_le;
+    }
+  else
+    {
+      unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
+
+      if (mach == bfd_mach_nios2r2)
 	{
-	  *bp_size = NIOS2_CDX_OPCODE_SIZE;
-	  return cdx_breakpoint_le;
+	  static const gdb_byte r2_breakpoint_le[] = {0x20, 0x00, 0xfd, 0xb7};
+
+	  return r2_breakpoint_le;
 	}
       else
 	{
-	  *bp_size = NIOS2_OPCODE_SIZE;
-	  return r2_breakpoint_le;
+	  enum bfd_endian byte_order_for_code
+	    = gdbarch_byte_order_for_code (gdbarch);
+	  /* R1 trap encoding:
+	     ((0x1d << 17) | (0x2d << 11) | (0x1f << 6) | (0x3a << 0))
+	     0x003b6ffa */
+	  static const gdb_byte r1_breakpoint_le[] = {0xfa, 0x6f, 0x3b, 0x0};
+	  static const gdb_byte r1_breakpoint_be[] = {0x0, 0x3b, 0x6f, 0xfa};
+
+	  if (byte_order_for_code == BFD_ENDIAN_BIG)
+	    return r1_breakpoint_be;
+	  else
+	    return r1_breakpoint_le;
 	}
     }
-  else
-    {
-      /* R1 trap encoding:
-	 ((0x1d << 17) | (0x2d << 11) | (0x1f << 6) | (0x3a << 0))
-	 0x003b6ffa */
-      static const gdb_byte r1_breakpoint_le[] = {0xfa, 0x6f, 0x3b, 0x0};
-      static const gdb_byte r1_breakpoint_be[] = {0x0, 0x3b, 0x6f, 0xfa};
-      *bp_size = NIOS2_OPCODE_SIZE;
-      if (byte_order_for_code == BFD_ENDIAN_BIG)
-	return r1_breakpoint_be;
-      else
-	return r1_breakpoint_le;
-    }
 }
 
+/* Implement the breakpoint_from_pc gdbarch hook.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (nios2)
+
 /* Implement the print_insn gdbarch method.  */
 
 static int
@@ -2316,7 +2336,7 @@ nios2_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_skip_prologue (gdbarch, nios2_skip_prologue);
   set_gdbarch_stack_frame_destroyed_p (gdbarch, nios2_stack_frame_destroyed_p);
-  set_gdbarch_breakpoint_from_pc (gdbarch, nios2_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (nios2);
 
   set_gdbarch_dummy_id (gdbarch, nios2_dummy_id);
   set_gdbarch_unwind_pc (gdbarch, nios2_unwind_pc);
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index ca4d668..7cb7a9e 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -967,18 +967,11 @@ rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
 
 /* Sequence of bytes for breakpoint instruction.  */
 
-static const unsigned char *
-rs6000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			   int *bp_size)
-{
-  static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
-  static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
-  *bp_size = 4;
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    return big_breakpoint;
-  else
-    return little_breakpoint;
-}
+static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
+static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
+
+GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN (rs6000, little_breakpoint,
+					big_breakpoint)
 
 /* Instruction masks for displaced stepping.  */
 #define BRANCH_MASK 0xfc000000
@@ -6486,7 +6479,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (rs6000);
 
   /* The value of symbols of type N_SO and N_FUN maybe null when
      it shouldn't be.  */
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index 8e08d05..c325d48 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -306,69 +306,82 @@ score3_adjust_pc_and_fetch_inst (CORE_ADDR *pcptr, int *lenptr,
   return &inst;
 }
 
-static const gdb_byte *
-score7_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static int
+score7_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  gdb_byte buf[SCORE_INSTLEN] = { 0 };
   int ret;
   unsigned int raw;
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  gdb_byte buf[SCORE_INSTLEN] = { 0 };
 
   if ((ret = target_read_memory (*pcptr & ~0x3, buf, SCORE_INSTLEN)) != 0)
     {
       error (_("Error: target_read_memory in file:%s, line:%d!"),
-             __FILE__, __LINE__);
+	     __FILE__, __LINE__);
     }
   raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order);
 
-  if (byte_order == BFD_ENDIAN_BIG)
+  if (!(raw & 0x80008000))
     {
-      if (!(raw & 0x80008000))
-        {
-          /* 16bits instruction.  */
-          static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
-          *pcptr &= ~0x1;
-          *lenptr = sizeof (big_breakpoint16);
-          return big_breakpoint16;
-        }
+      /* 16bits instruction.  */
+      *pcptr &= ~0x1;
+      return 2;
+    }
+  else
+    {
+      /* 32bits instruction.  */
+      *pcptr &= ~0x3;
+      return 4;
+    }
+}
+
+static const gdb_byte *
+score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  *size = kind;
+
+  if (kind == 4)
+    {
+      static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
+      static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
+
+      if (byte_order == BFD_ENDIAN_BIG)
+	return big_breakpoint32;
       else
-        {
-          /* 32bits instruction.  */
-          static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
-          *pcptr &= ~0x3;
-          *lenptr = sizeof (big_breakpoint32);
-          return big_breakpoint32;
-        }
+	return little_breakpoint32;
     }
   else
     {
-      if (!(raw & 0x80008000))
-        {
-          /* 16bits instruction.  */
-          static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
-          *pcptr &= ~0x1;
-          *lenptr = sizeof (little_breakpoint16);
-          return little_breakpoint16;
-        }
+      static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
+      static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
+
+      if (byte_order == BFD_ENDIAN_BIG)
+	return big_breakpoint16;
       else
-        {
-          /* 32bits instruction.  */
-          static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
-          *pcptr &= ~0x3;
-          *lenptr = sizeof (little_breakpoint32);
-          return little_breakpoint32;
-        }
+	return little_breakpoint16;
     }
 }
 
-static const gdb_byte *
-score3_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+GDBARCH_BREAKPOINT_FROM_PC (score7)
+
+static int
+score3_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  CORE_ADDR adjust_pc = *pcptr; 
   int len;
+
+  score3_adjust_pc_and_fetch_inst (pcptr, &len, byte_order);
+
+  return len;
+}
+
+static const gdb_byte *
+score3_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  int index = 0;
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   static gdb_byte score_break_insns[6][6] = {
     /* The following three instructions are big endian.  */
     { 0x00, 0x20 },
@@ -379,20 +392,14 @@ score3_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
     { 0x00, 0x80, 0x06, 0x00 },
     { 0x00, 0x80, 0x00, 0x80, 0x00, 0x00 }};
 
-  gdb_byte *p = NULL;
-  int index = 0;
-
-  score3_adjust_pc_and_fetch_inst (&adjust_pc, &len, byte_order);
-
-  index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (len / 2 - 1);
-  p = score_break_insns[index];
+  *size = kind;
 
-  *pcptr = adjust_pc;
-  *lenptr = len;
-
-  return p;
+  index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (kind / 2 - 1);
+  return score_break_insns[index];
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (score3)
+
 static CORE_ADDR
 score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
 {
@@ -1485,7 +1492,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   switch (target_mach)
     {
     case bfd_mach_score7:
-      set_gdbarch_breakpoint_from_pc (gdbarch, score7_breakpoint_from_pc);
+      SET_GDBARCH_BREAKPOINT_MANIPULATION (score7);
       set_gdbarch_skip_prologue (gdbarch, score7_skip_prologue);
       set_gdbarch_stack_frame_destroyed_p (gdbarch,
 					   score7_stack_frame_destroyed_p);
@@ -1497,7 +1504,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       break;
 
     case bfd_mach_score3:
-      set_gdbarch_breakpoint_from_pc (gdbarch, score3_breakpoint_from_pc);
+      SET_GDBARCH_BREAKPOINT_MANIPULATION (score3);
       set_gdbarch_skip_prologue (gdbarch, score3_skip_prologue);
       set_gdbarch_stack_frame_destroyed_p (gdbarch,
 					   score3_stack_frame_destroyed_p);
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 12aedbb..6100d92 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -418,11 +418,16 @@ sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
   return register_names[reg_nr];
 }
 
-static const unsigned char *
-sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
+static int
+sh_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  /* 0xc3c3 is trapa #c3, and it works in big and little endian modes.  */
-  static unsigned char breakpoint[] = { 0xc3, 0xc3 };
+  return 2;
+}
+
+static const gdb_byte *
+sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
 
   /* For remote stub targets, trapa #20 is used.  */
   if (strcmp (target_shortname, "remote") == 0)
@@ -431,21 +436,22 @@ sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
 
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (big_remote_breakpoint);
-	  return big_remote_breakpoint;
-	}
+	return big_remote_breakpoint;
       else
-	{
-	  *lenptr = sizeof (little_remote_breakpoint);
-	  return little_remote_breakpoint;
-	}
+	return little_remote_breakpoint;
     }
+  else
+    {
+      /* 0xc3c3 is trapa #c3, and it works in big and little endian
+	 modes.  */
+      static unsigned char breakpoint[] = { 0xc3, 0xc3 };
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
+      return breakpoint;
+    }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (sh)
+
 /* Prologue looks like
    mov.l	r14,@-r15
    sts.l	pr,@-r15
@@ -2274,7 +2280,7 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_register_type (gdbarch, sh_default_register_type);
   set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sh);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index f51186a..97e5a58 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -253,11 +253,24 @@ pc_is_isa32 (bfd_vma memaddr)
     return 0;
 }
 
-static const unsigned char *
-sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
-			 CORE_ADDR *pcptr, int *lenptr)
+static int
+sh64_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  /* The BRK instruction for shmedia is 
+  if (pc_is_isa32 (*pcptr))
+    {
+      *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
+      return 4;
+    }
+  else
+    return 2;
+}
+
+static const gdb_byte *
+sh64_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+  /* The BRK instruction for shmedia is
      01101111 11110101 11111111 11110000
      which translates in big endian mode to 0x6f, 0xf5, 0xff, 0xf0
      and in little endian mode to 0xf0, 0xff, 0xf5, 0x6f */
@@ -267,44 +280,34 @@ sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
      which translates in big endian mode to 0x0, 0x3b
      and in little endian mode to 0x3b, 0x0 */
 
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+  if (kind == 4)
     {
-      if (pc_is_isa32 (*pcptr))
-	{
-	  static unsigned char big_breakpoint_media[] = {
-	    0x6f, 0xf5, 0xff, 0xf0
-	  };
-	  *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-	  *lenptr = sizeof (big_breakpoint_media);
-	  return big_breakpoint_media;
-	}
+      static unsigned char big_breakpoint_media[] = {
+	0x6f, 0xf5, 0xff, 0xf0
+      };
+      static unsigned char little_breakpoint_media[] = {
+	0xf0, 0xff, 0xf5, 0x6f
+      };
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	return big_breakpoint_media;
       else
-	{
-	  static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
-	  *lenptr = sizeof (big_breakpoint_compact);
-	  return big_breakpoint_compact;
-	}
+	return little_breakpoint_media;
     }
   else
     {
-      if (pc_is_isa32 (*pcptr))
-	{
-	  static unsigned char little_breakpoint_media[] = {
-	    0xf0, 0xff, 0xf5, 0x6f
-	  };
-	  *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-	  *lenptr = sizeof (little_breakpoint_media);
-	  return little_breakpoint_media;
-	}
+      static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
+      static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	return big_breakpoint_compact;
       else
-	{
-	  static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
-	  *lenptr = sizeof (little_breakpoint_compact);
-	  return little_breakpoint_compact;
-	}
+	return little_breakpoint_compact;
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (sh64)
+
 /* Prologue looks like
    [mov.l       <regs>,@-r15]...
    [sts.l       pr,@-r15]
@@ -2410,7 +2413,7 @@ sh64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
   set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh64_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sh64);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index adb7f50..9957947 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -318,15 +318,18 @@ tic6x_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 				 NULL);
 }
 
-/* This is the implementation of gdbarch method breakpiont_from_pc.  */
+static int
+tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 4;
+}
 
 static const gdb_byte *
-tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
-			  int *bp_size)
+tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  *bp_size = 4;
+  *size = kind;
 
   if (tdep == NULL || tdep->breakpoint == NULL)
     {
@@ -339,6 +342,10 @@ tic6x_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
     return tdep->breakpoint;
 }
 
+/* This is the implementation of gdbarch method breakpiont_from_pc.  */
+
+GDBARCH_BREAKPOINT_FROM_PC (tic6x)
+
 /* This is the implementation of gdbarch method print_insn.  */
 
 static int
@@ -1295,7 +1302,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   set_gdbarch_skip_prologue (gdbarch, tic6x_skip_prologue);
-  set_gdbarch_breakpoint_from_pc (gdbarch, tic6x_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (tic6x);
 
   set_gdbarch_unwind_pc (gdbarch, tic6x_unwind_pc);
   set_gdbarch_unwind_sp (gdbarch, tic6x_unwind_sp);
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index d03334e..9cc1b8b 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -1168,13 +1168,18 @@ v850_return_value (struct gdbarch *gdbarch, struct value *function,
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
 
-static const unsigned char *
-v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			 int *lenptr)
+static int
+v850_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  *lenptr = 2;
+  return 2;
+}
 
-  switch (gdbarch_bfd_arch_info (gdbarch)->mach)
+static const gdb_byte *
+v850_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+    switch (gdbarch_bfd_arch_info (gdbarch)->mach)
     {
     case bfd_mach_v850e2:
     case bfd_mach_v850e2v3:
@@ -1199,6 +1204,8 @@ v850_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (v850)
+
 static struct v850_frame_cache *
 v850_alloc_frame_cache (struct frame_info *this_frame)
 {
@@ -1448,7 +1455,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (v850);
   set_gdbarch_return_value (gdbarch, v850_return_value);
   set_gdbarch_push_dummy_call (gdbarch, v850_push_dummy_call);
   set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index aafb175..90da611 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1959,6 +1959,14 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
   return sp + SP_ALIGNMENT;
 }
 
+static int
+xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  if (gdbarch_tdep (gdbarch)->isa_use_density_instructions)
+    return 2;
+  else
+    return 4;
+}
 
 /* Return a breakpoint for the current location of PC.  We always use
    the density version if we have density instructions (regardless of the
@@ -1969,45 +1977,36 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 #define DENSITY_BIG_BREAKPOINT { 0xd2, 0x0f }
 #define DENSITY_LITTLE_BREAKPOINT { 0x2d, 0xf0 }
 
-static const unsigned char *
-xtensa_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
-			   int *lenptr)
+static const gdb_byte *
+xtensa_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
-  static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
-  static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
-  static unsigned char density_little_breakpoint[] = DENSITY_LITTLE_BREAKPOINT;
+  *size = kind;
 
-  DEBUGTRACE ("xtensa_breakpoint_from_pc (pc = 0x%08x)\n", (int) *pcptr);
-
-  if (gdbarch_tdep (gdbarch)->isa_use_density_instructions)
+  if (kind == 4)
     {
+      static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
+      static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
+
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (density_big_breakpoint);
-	  return density_big_breakpoint;
-	}
+	return big_breakpoint;
       else
-	{
-	  *lenptr = sizeof (density_little_breakpoint);
-	  return density_little_breakpoint;
-	}
+	return little_breakpoint;
     }
   else
     {
+      static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
+      static unsigned char density_little_breakpoint[]
+	= DENSITY_LITTLE_BREAKPOINT;
+
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-	{
-	  *lenptr = sizeof (big_breakpoint);
-	  return big_breakpoint;
-	}
+	return density_big_breakpoint;
       else
-	{
-	  *lenptr = sizeof (little_breakpoint);
-	  return little_breakpoint;
-	}
+	return density_little_breakpoint;
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (xtensa)
+
 /* Call0 ABI support routines.  */
 
 /* Return true, if PC points to "ret" or "ret.n".  */ 
@@ -3239,7 +3238,7 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
   /* Set breakpoints.  */
-  set_gdbarch_breakpoint_from_pc (gdbarch, xtensa_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (xtensa);
 
   /* After breakpoint instruction or illegal instruction, pc still
      points at break instruction, so don't decrement.  */

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
                   ` (12 preceding siblings ...)
  2016-08-31 15:06 ` [PATCH 06/13] Add enum for mips breakpoint kinds Yao Qi
@ 2016-10-10 10:17 ` Yao Qi
  2016-10-26 15:43   ` Yao Qi
  13 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-10-10 10:17 UTC (permalink / raw)
  To: gdb-patches

On Wed, Aug 31, 2016 at 4:05 PM, Yao Qi <qiyaoltc@gmail.com> wrote:
> This patch series is to split gdbarch method brekapoint_from_pc to
> methods breakpoint_kind_from_pc and sw_breakpoint_from_kind.  After
> these changes, new gdbarch methods breakpoint_kind_from_pc and
> sw_breakpoint_from_kind are more preferred than brekapoint_from_pc.
>
> In this patch https://sourceware.org/ml/gdb-patches/2016-05/msg00201.html,
> I wanted to remove a global variable arm_override_mode, and the
> discussion leads to a design here
> https://sourceware.org/ml/gdb-patches/2016-07/msg00211.html  In short,
> we reuse bp_target_info.placed_size as the "kind" of a breakpoint,
> which can be got by gdbarch breakpoint_kind_from_pc or
> breakpoint_kind_from_current_state.
>
> I choose a way that I can change the code incrementally, and make the
> review easier.  Patch #1, #2, #5, and #8 are obvious, IMO.  Patch #7
> and #12 do the major work, and the rest are code refactor.
>
> Regression tested on arm-linux and x86_64-linux.  Tests on other
> architectures are welcome!
>

I've pushed patches 1#, #2, and #5 in, because they are obvious.
Update patch 7 to cover arc.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-10-10 10:17 ` [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
@ 2016-10-26 15:43   ` Yao Qi
  2016-10-27 14:58     ` Pedro Alves
  0 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-10-26 15:43 UTC (permalink / raw)
  To: gdb-patches

On Mon, Oct 10, 2016 at 11:17 AM, Yao Qi <qiyaoltc@gmail.com> wrote:
> On Wed, Aug 31, 2016 at 4:05 PM, Yao Qi <qiyaoltc@gmail.com> wrote:
>> This patch series is to split gdbarch method brekapoint_from_pc to
>> methods breakpoint_kind_from_pc and sw_breakpoint_from_kind.  After
>> these changes, new gdbarch methods breakpoint_kind_from_pc and
>> sw_breakpoint_from_kind are more preferred than brekapoint_from_pc.
>>
>> In this patch https://sourceware.org/ml/gdb-patches/2016-05/msg00201.html,
>> I wanted to remove a global variable arm_override_mode, and the
>> discussion leads to a design here
>> https://sourceware.org/ml/gdb-patches/2016-07/msg00211.html  In short,
>> we reuse bp_target_info.placed_size as the "kind" of a breakpoint,
>> which can be got by gdbarch breakpoint_kind_from_pc or
>> breakpoint_kind_from_current_state.
>>
>> I choose a way that I can change the code incrementally, and make the
>> review easier.  Patch #1, #2, #5, and #8 are obvious, IMO.  Patch #7
>> and #12 do the major work, and the rest are code refactor.
>>
>> Regression tested on arm-linux and x86_64-linux.  Tests on other
>> architectures are welcome!
>>
>
> I've pushed patches 1#, #2, and #5 in, because they are obvious.
> Update patch 7 to cover arc.
>

Ping.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/13] Add enum for mips breakpoint kinds
  2016-08-31 15:06 ` [PATCH 06/13] Add enum for mips breakpoint kinds Yao Qi
@ 2016-10-27 14:54   ` Pedro Alves
  2016-10-28 19:39     ` Maciej W. Rozycki
  0 siblings, 1 reply; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:54 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 08/31/2016 04:05 PM, Yao Qi wrote:
> This patch adds an enum mips_breakpoint_kinds to avoid using magic
> numbers as much as possible.
> 
> gdb:
> 
> 2016-08-31  Yao Qi  <yao.qi@linaro.org>
> 
> 	* mips-tdep.c (mips_breakpoint_kinds): New enum.
> 	(mips_breakpoint_from_pc): Use it.
> 	(mips_remote_breakpoint_from_pc): Likewise.
> ---
>  gdb/mips-tdep.c | 37 ++++++++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
> index 4e4d79e..34df8d0 100644
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -107,6 +107,20 @@ static const char *const mips_abi_strings[] = {
>    NULL
>  };
>  
> +/* Enum describing the different kinds of breakpoints.  */
> +
> +enum mips_breakpoint_kinds

IMO that should be singular.  Imagine you put one of these
in a variable.  Like:

  enum mips_breakpoint_kinds kind;

This would be more natural, IMO:

  enum mips_breakpoint_kind kind;

> +{
> +  /* 16-bit MIPS16 mode breakpoint */
> +  MIPS_BP_KIND_16BIT_MIPS16 = 2,
> +  /* 16-bit microMIPS mode breakpoint */
> +  MIPS_BP_KIND_16BIT_MICROMIPS = 3,
> +  /* 32-bit standard MIPS mode breakpoint */
> +  MIPS_BP_KIND_32BIT = 4,
> +  /* 32-bit microMIPS mode breakpoint */
> +  MIPS_BP_KIND_32BIT_MICROMIPS = 5,

IMO a line break between these makes it much more readable.

  /* 16-bit MIPS16 mode breakpoint */
  MIPS_BP_KIND_16BIT_MIPS16 = 2,

  /* 16-bit microMIPS mode breakpoint */
  MIPS_BP_KIND_16BIT_MICROMIPS = 3,

etc.

> +};
> +
>  /* For backwards compatibility we default to MIPS16.  This flag is
>     overridden as soon as unambiguous ELF file flags tell us the
>     compressed ISA encoding used.  */
> @@ -7143,16 +7157,7 @@ mips_breakpoint_from_pc (struct gdbarch *gdbarch,
>      }
>  }
>  
> -/* Determine the remote breakpoint kind suitable for the PC.  The following
> -   kinds are used:
> -
> -   * 2 -- 16-bit MIPS16 mode breakpoint,
> -
> -   * 3 -- 16-bit microMIPS mode breakpoint,
> -
> -   * 4 -- 32-bit standard MIPS mode breakpoint,
> -
> -   * 5 -- 32-bit microMIPS mode breakpoint.  */

In a latter patch you seem to read this comment.

> +/* Determine the remote breakpoint kind suitable for the PC.  */

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc
  2016-08-31 15:06 ` [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc Yao Qi
@ 2016-10-27 14:55   ` Pedro Alves
  0 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:55 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 08/31/2016 04:06 PM, Yao Qi wrote:
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -7050,7 +7050,18 @@ gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
>    return gdb_print_insn_mips (memaddr, info);
>  }
>  
> -/* Implement the breakpoint_kind_from_pc gdbarch method.  */
> +/* Implement the breakpoint_kind_from_pc gdbarch method.
> +
> +   Determine the remote breakpoint kind suitable for the PC.  The following
> +   kinds are used:
> +
> +   * 2 -- 16-bit MIPS16 mode breakpoint,
> +
> +   * 3 -- 16-bit microMIPS mode breakpoint,
> +
> +   * 4 -- 32-bit standard MIPS mode breakpoint,
> +
> +   * 5 -- 32-bit microMIPS mode breakpoint.  */
>  

Isn't this duplicating info that's now on the enum?
I was surprised to find this in this mostly unrelated patch.

>  static int
>  mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
> @@ -7178,15 +7189,6 @@ mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind,

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 12/13] Determine the kind of single step breakpoint
  2016-08-31 15:06 ` [PATCH 12/13] Determine the kind of single step breakpoint Yao Qi
@ 2016-10-27 14:55   ` Pedro Alves
  0 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:55 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 08/31/2016 04:06 PM, Yao Qi wrote:
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -2607,7 +2607,18 @@ build_target_command_list (struct bp_location *bl)
>  static int
>  breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
>  {
> -  return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
> +  if (bl->owner->type == bp_single_step)
> +    {
> +      struct thread_info *thr = find_thread_global_id (bl->owner->thread);
> +      struct regcache *regcache;
> +
> +      regcache = get_thread_regcache (thr->ptid);
> +
> +      return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
> +							 regcache, addr);
> +    }
> +  else
> +    return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
>  }

This deserves a function intro comment update, I think.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-08-31 15:06 ` [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
  2016-10-10 10:05   ` Yao Qi
@ 2016-10-27 14:55   ` Pedro Alves
  2016-10-28 19:44     ` Maciej W. Rozycki
  1 sibling, 1 reply; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:55 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

Note the "brekapoint" typo -- it appears through the series
several times, both in code and in email subjects.  I suggest
using git format-patch, and grep the patches to find them all.

On 08/31/2016 04:05 PM, Yao Qi wrote:

> +static const gdb_byte *
> +mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
> +{



> +    case MIPS_BP_KIND_32BIT:
> +      {
> +	/* The IDT board uses an unusual breakpoint value, and
> +	   sometimes gets confused when it sees the usual MIPS
> +	   breakpoint instruction.  */
> +	static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
> +	static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
> +	static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
> +	static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
> +	static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
> +	static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
> +	/* Likewise, IRIX appears to expect a different breakpoint,
> +	   although this is not apparent until you try to use pthreads.  */
> +	static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
> +
> +	*size = 4;
> +
> +	if (strcmp (target_shortname, "mips") == 0)
> +	  {
> +	    if (byte_order_for_code == BFD_ENDIAN_BIG)
> +	      return idt_big_breakpoint;
> +	    else
> +	      return idt_little_breakpoint;
> +	  }
> +	else if (strcmp (target_shortname, "ddb") == 0
> +		 || strcmp (target_shortname, "pmon") == 0
> +		 || strcmp (target_shortname, "lsi") == 0)
> +	  {
> +	    if (byte_order_for_code == BFD_ENDIAN_BIG)
> +	      return pmon_big_breakpoint;
> +	    else
> +	      return pmon_little_breakpoint;
> +	  }
> +	else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
> +	  return irix_big_breakpoint;

FYI, I think all of these above could be removed. 
target mips/ddb/pmon/etc. are all gone, and we don't support IRIX any
longer either:

*** Changes in GDB 7.12*** Changes in GDB 7.12

* Support for various remote target protocols and ROM monitors has
  been removed:

  target m32rsdi        Remote M32R debugging over SDI
  target mips           MIPS remote debugging protocol
  target pmon           PMON ROM monitor
  target ddb            NEC's DDB variant of PMON for Vr4300
  target rockhopper     NEC RockHopper variant of PMON
  target lsi            LSI variant of PMO

*** Changes in GDB 7.10

Support for these obsolete configurations has been removed.

SGI Irix-5.x                            mips-*-irix5*
SGI Irix-6.x                            mips-*-irix6*

> +	else
> +	  {
> +	    if (byte_order_for_code == BFD_ENDIAN_BIG)
> +	      return big_breakpoint;
> +	    else
> +	      return little_breakpoint;
> +	  }
> +      }
> +    default:
> +      gdb_assert_not_reached ("unexpected mips breakpoint kind");
> +    };
> +}
> +
> +/* This function implements gdbarch_breakpoint_from_pc.  It uses the
> +   program counter value to determine whether a 16- or 32-bit breakpoint
> +   should be used.  It returns a pointer to a string of bytes that encode a
> +   breakpoint instruction, stores the length of the string to *lenptr, and
> +   adjusts pc (if necessary) to point to the actual memory location where
> +   the breakpoint should be inserted.  */

I see this comment repeated in several places.  Shouldn't we replace it
with some "implement foo" comment ?

/me reads rest of series...

Oh, this is all eliminated in the end.  So nevermind.

> +
> +GDBARCH_BREAKPOINT_FROM_PC (mips)
> +


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 13/13] Remove arm_override_mode
  2016-08-31 15:06 ` [PATCH 13/13] Remove arm_override_mode Yao Qi
@ 2016-10-27 14:56   ` Pedro Alves
  0 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:56 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 08/31/2016 04:06 PM, Yao Qi wrote:
> GDB can determine the kind of single step breakpoint by gdbarch
> breakpoint_kind_from_current_state, so global variable
> arm_override_mode is no longer needed.  This patch removes it.

Hurray!

Thanks so much for following through with this.

Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-10-26 15:43   ` Yao Qi
@ 2016-10-27 14:58     ` Pedro Alves
  2016-10-27 15:41       ` Yao Qi
  0 siblings, 1 reply; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 14:58 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 10/26/2016 04:43 PM, Yao Qi wrote:
> On Mon, Oct 10, 2016 at 11:17 AM, Yao Qi <qiyaoltc@gmail.com> wrote:
>> On Wed, Aug 31, 2016 at 4:05 PM, Yao Qi <qiyaoltc@gmail.com> wrote:
>>> This patch series is to split gdbarch method brekapoint_from_pc to
>>> methods breakpoint_kind_from_pc and sw_breakpoint_from_kind.  After
>>> these changes, new gdbarch methods breakpoint_kind_from_pc and
>>> sw_breakpoint_from_kind are more preferred than brekapoint_from_pc.
>>>
>>> In this patch https://sourceware.org/ml/gdb-patches/2016-05/msg00201.html,
>>> I wanted to remove a global variable arm_override_mode, and the
>>> discussion leads to a design here
>>> https://sourceware.org/ml/gdb-patches/2016-07/msg00211.html  In short,
>>> we reuse bp_target_info.placed_size as the "kind" of a breakpoint,
>>> which can be got by gdbarch breakpoint_kind_from_pc or
>>> breakpoint_kind_from_current_state.
>>>
>>> I choose a way that I can change the code incrementally, and make the
>>> review easier.  Patch #1, #2, #5, and #8 are obvious, IMO.  Patch #7
>>> and #12 do the major work, and the rest are code refactor.
>>>
>>> Regression tested on arm-linux and x86_64-linux.  Tests on other
>>> architectures are welcome!
>>>
>>
>> I've pushed patches 1#, #2, and #5 in, because they are obvious.
>> Update patch 7 to cover arc.
>>

So I like this a lot.  Thanks again for going through with this
all.  And thanks for the patience.

My only question is what happens to the GDBARCH_BREAKPOINT_MANIPULATION
/ SET_GDBARCH_BREAKPOINT_MANIPULATION macros?  I was hoping they'd
disappear in the end, but looks like not?  (I find the "manipulation"
name to be very opaque here, btw.)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-10-27 14:58     ` Pedro Alves
@ 2016-10-27 15:41       ` Yao Qi
  2016-10-27 17:55         ` Pedro Alves
  0 siblings, 1 reply; 28+ messages in thread
From: Yao Qi @ 2016-10-27 15:41 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Hi Pedro,
Thanks for the review,

On Thu, Oct 27, 2016 at 3:58 PM, Pedro Alves <palves@redhat.com> wrote:
>
> My only question is what happens to the GDBARCH_BREAKPOINT_MANIPULATION
> / SET_GDBARCH_BREAKPOINT_MANIPULATION macros?  I was hoping they'd
> disappear in the end, but looks like not?  (I find the "manipulation"
> name to be very opaque here, btw.)

Both are the intermediate structure during the the process of conversion.
I didn't remove them as I think they two can "simplify" the code, because
a lot of gdbarch have one breakpoint instruction.  Their
breakpoint_kind_from_pc and sw_breakpoint_from_kind look quite similar.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-10-27 15:41       ` Yao Qi
@ 2016-10-27 17:55         ` Pedro Alves
  0 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2016-10-27 17:55 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 10/27/2016 04:41 PM, Yao Qi wrote:
> Hi Pedro,
> Thanks for the review,
> 
> On Thu, Oct 27, 2016 at 3:58 PM, Pedro Alves <palves@redhat.com> wrote:
>>
>> My only question is what happens to the GDBARCH_BREAKPOINT_MANIPULATION
>> / SET_GDBARCH_BREAKPOINT_MANIPULATION macros?  I was hoping they'd
>> disappear in the end, but looks like not?  (I find the "manipulation"
>> name to be very opaque here, btw.)
> 
> Both are the intermediate structure during the the process of conversion.
> I didn't remove them as I think they two can "simplify" the code, because
> a lot of gdbarch have one breakpoint instruction.  Their
> breakpoint_kind_from_pc and sw_breakpoint_from_kind look quite similar.
> 

I see.  Guess we can proceed with what you have, and then maybe replace
the macros with templates?  Here's how it might look like.  I confirmed that
i386-tdep.o and rs6000-tdep.o build with this, and confirmed that the
x86 version works at least with a version of the patch that kept
the template inside i386-tdep.c only.

Without C++11, we have to remove the "constexpr", and we can't
make the arrays static nor const -- only extern arrays can be
used as non-type parameters.  So with C++03 that'd be a little
regression compared to the macros.  C++11 wins here too.  :-)

Another option would be to replace the two gdbarch methods with
a single one that returns an object that itself has the two
conversion methods.  Those methods in the new object would have
to be virtual, so it'd end up being more hops at run time.

From 51cc27113394b07ad1b3cec429973412d88baa7f Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 27 Oct 2016 18:21:44 +0100
Subject: [PATCH] BREAKPOINT_MANIPULATION: macro -> template

---
 gdb/arch-utils.h  | 80 ++++++++++++++++++++++++++++---------------------------
 gdb/i386-tdep.c   |  9 ++++---
 gdb/rs6000-tdep.c | 12 +++++----
 3 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 9592580..4b0848f 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -26,48 +26,50 @@ struct minimal_symbol;
 struct type;
 struct gdbarch_info;
 
-#define GDBARCH_BREAKPOINT_MANIPULATION(ARCH,BREAK_INSN)	      \
-  static int							      \
-  ARCH##_breakpoint_kind_from_pc (struct gdbarch *gdbarch,	      \
-				  CORE_ADDR *pcptr)		      \
-  {								      \
-    return sizeof (BREAK_INSN);				      \
-  }								      \
-  static const gdb_byte *					      \
-  ARCH##_sw_breakpoint_from_kind (struct gdbarch *gdbarch,	      \
-				  int kind, int *size)		      \
-  {								      \
-    *size = kind;						      \
-    return BREAK_INSN;						      \
+template <size_t bp_size, const gdb_byte *break_insn>
+struct bp_manipulation
+{
+  static int
+  kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+  {
+    return bp_size;
   }
 
-#define SET_GDBARCH_BREAKPOINT_MANIPULATION(ARCH)			\
-  set_gdbarch_breakpoint_kind_from_pc (gdbarch,			\
-				       ARCH##_breakpoint_kind_from_pc); \
-  set_gdbarch_sw_breakpoint_from_kind (gdbarch,			\
-				       ARCH##_sw_breakpoint_from_kind)
-
-#define GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN(ARCH, \
-					       LITTLE_BREAK_INSN,	\
-					       BIG_BREAK_INSN)		\
-  static int								\
-  ARCH##_breakpoint_kind_from_pc (struct gdbarch *gdbarch,		\
-				  CORE_ADDR *pcptr)			\
-  {									\
-    gdb_static_assert (ARRAY_SIZE (LITTLE_BREAK_INSN)			\
-		       == ARRAY_SIZE (BIG_BREAK_INSN));		\
-    return sizeof (BIG_BREAK_INSN);					\
-  }									\
-  static const gdb_byte *					      \
-  ARCH##_sw_breakpoint_from_kind (struct gdbarch *gdbarch,	      \
-				  int kind, int *size)		      \
-  {								      \
-    *size = kind;						      \
-    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)	      \
-      return BIG_BREAK_INSN;					      \
-    else							      \
-      return LITTLE_BREAK_INSN;				      \
+  static const gdb_byte *
+  bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+  {
+    *size = kind;
+    return break_insn;
   }
+};
+
+template <size_t bp_size,
+	  const gdb_byte *break_insn_little,
+	  const gdb_byte *break_insn_big>
+struct bp_manipulation_endian
+{
+  static int
+  kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+  {
+    return bp_size;
+  }
+
+  static const gdb_byte *
+  bp_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+  {
+    *size = kind;
+    if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+      return break_insn_big;
+    else
+      return break_insn_little;
+  }
+};
+
+#define BP_MANIPULATION(BREAK_INSN) \
+  bp_manipulation<sizeof (BREAK_INSN), BREAK_INSN>
+
+#define BP_MANIPULATION_ENDIAN(BREAK_INSN_LITTLE, BREAK_INSN_BIG) \
+  bp_manipulation_endian<sizeof (BREAK_INSN_LITTLE), BREAK_INSN_LITTLE, BREAK_INSN_BIG>
 
 /* An implementation of gdbarch_displaced_step_copy_insn for
    processors that don't need to modify the instruction before
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 697edc6..a1e078b 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -588,9 +588,10 @@ static const char *disassembly_flavor = att_flavor;
 
    This function is 64-bit safe.  */
 
-static const gdb_byte break_insn[] = { 0xcc }; /* int 3 */
+constexpr gdb_byte i386_break_insn[] = { 0xcc }; /* int 3 */
+
+typedef BP_MANIPULATION (i386_break_insn) i386_breakpoint;
 
-GDBARCH_BREAKPOINT_MANIPULATION (i386, break_insn)
 \f
 /* Displaced instruction handling.  */
 
@@ -8453,7 +8454,9 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Stack grows downward.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  SET_GDBARCH_BREAKPOINT_MANIPULATION (i386);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch, i386_breakpoint::kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch, i386_breakpoint::bp_from_kind);
+
   set_gdbarch_decr_pc_after_break (gdbarch, 1);
   set_gdbarch_max_insn_length (gdbarch, I386_MAX_INSN_LEN);
 
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 7cb7a9e..5578b33 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -967,11 +967,11 @@ rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
 
 /* Sequence of bytes for breakpoint instruction.  */
 
-static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
-static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
+constexpr gdb_byte big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
+constexpr gdb_byte little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
 
-GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN (rs6000, little_breakpoint,
-					big_breakpoint)
+typedef BP_MANIPULATION_ENDIAN (little_breakpoint, big_breakpoint)
+  rs6000_breakpoint;
 
 /* Instruction masks for displaced stepping.  */
 #define BRANCH_MASK 0xfc000000
@@ -6479,7 +6479,9 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);
 
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-  SET_GDBARCH_BREAKPOINT_MANIPULATION (rs6000);
+
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch, rs6000_breakpoint::kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch, rs6000_breakpoint::bp_from_kind);
 
   /* The value of symbols of type N_SO and N_FUN maybe null when
      it shouldn't be.  */
-- 
2.5.5


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/13] Add enum for mips breakpoint kinds
  2016-10-27 14:54   ` Pedro Alves
@ 2016-10-28 19:39     ` Maciej W. Rozycki
  0 siblings, 0 replies; 28+ messages in thread
From: Maciej W. Rozycki @ 2016-10-28 19:39 UTC (permalink / raw)
  To: Pedro Alves, Yao Qi; +Cc: gdb-patches

Pedro, Yao --

 I missed the MIPS parts previously, sorry.

On Thu, 27 Oct 2016, Pedro Alves wrote:

> > +/* Enum describing the different kinds of breakpoints.  */
> > +
> > +enum mips_breakpoint_kinds
> 
> IMO that should be singular.  Imagine you put one of these
> in a variable.  Like:
> 
>   enum mips_breakpoint_kinds kind;
> 
> This would be more natural, IMO:
> 
>   enum mips_breakpoint_kind kind;

 Agreed.

> > +{
> > +  /* 16-bit MIPS16 mode breakpoint */
> > +  MIPS_BP_KIND_16BIT_MIPS16 = 2,
> > +  /* 16-bit microMIPS mode breakpoint */
> > +  MIPS_BP_KIND_16BIT_MICROMIPS = 3,
> > +  /* 32-bit standard MIPS mode breakpoint */
> > +  MIPS_BP_KIND_32BIT = 4,
> > +  /* 32-bit microMIPS mode breakpoint */
> > +  MIPS_BP_KIND_32BIT_MICROMIPS = 5,
> 
> IMO a line break between these makes it much more readable.
> 
>   /* 16-bit MIPS16 mode breakpoint */
>   MIPS_BP_KIND_16BIT_MIPS16 = 2,
> 
>   /* 16-bit microMIPS mode breakpoint */
>   MIPS_BP_KIND_16BIT_MICROMIPS = 3,
> 
> etc.

 Indeed.  Also a full stop and two spaces at the end are due.

 Also how about calling them:

MIPS_BP_KIND_MIPS16
MIPS_BP_KIND_MICROMIPS16
MIPS_BP_KIND_MIPS32
MIPS_BP_KIND_MICROMIPS32

to make the names a bit shorter though still retaining the meaning?

  Maciej

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
  2016-10-27 14:55   ` Pedro Alves
@ 2016-10-28 19:44     ` Maciej W. Rozycki
  0 siblings, 0 replies; 28+ messages in thread
From: Maciej W. Rozycki @ 2016-10-28 19:44 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, gdb-patches

On Thu, 27 Oct 2016, Pedro Alves wrote:

> > +    case MIPS_BP_KIND_32BIT:
> > +      {
> > +	/* The IDT board uses an unusual breakpoint value, and
> > +	   sometimes gets confused when it sees the usual MIPS
> > +	   breakpoint instruction.  */
> > +	static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
> > +	static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
> > +	static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
> > +	static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
> > +	static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
> > +	static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
> > +	/* Likewise, IRIX appears to expect a different breakpoint,
> > +	   although this is not apparent until you try to use pthreads.  */
> > +	static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
> > +
> > +	*size = 4;
> > +
> > +	if (strcmp (target_shortname, "mips") == 0)
> > +	  {
> > +	    if (byte_order_for_code == BFD_ENDIAN_BIG)
> > +	      return idt_big_breakpoint;
> > +	    else
> > +	      return idt_little_breakpoint;
> > +	  }
> > +	else if (strcmp (target_shortname, "ddb") == 0
> > +		 || strcmp (target_shortname, "pmon") == 0
> > +		 || strcmp (target_shortname, "lsi") == 0)
> > +	  {
> > +	    if (byte_order_for_code == BFD_ENDIAN_BIG)
> > +	      return pmon_big_breakpoint;
> > +	    else
> > +	      return pmon_little_breakpoint;
> > +	  }
> > +	else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
> > +	  return irix_big_breakpoint;
> 
> FYI, I think all of these above could be removed. 
> target mips/ddb/pmon/etc. are all gone, and we don't support IRIX any
> longer either:
> 
> *** Changes in GDB 7.12*** Changes in GDB 7.12
> 
> * Support for various remote target protocols and ROM monitors has
>   been removed:
> 
>   target m32rsdi        Remote M32R debugging over SDI
>   target mips           MIPS remote debugging protocol
>   target pmon           PMON ROM monitor
>   target ddb            NEC's DDB variant of PMON for Vr4300
>   target rockhopper     NEC RockHopper variant of PMON
>   target lsi            LSI variant of PMO
> 
> *** Changes in GDB 7.10
> 
> Support for these obsolete configurations has been removed.
> 
> SGI Irix-5.x                            mips-*-irix5*
> SGI Irix-6.x                            mips-*-irix6*

 Agreed, all this can go.

 I'd prefer changes to be functionally self-contained though, so I'm 
working right now on a set of preparatory changes to remove the remains of 
MIPS target-side support for IRIX and legacy remote protocols.  I'll post 
the patches shortly.  Please rebase this change on top.

  Maciej

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2016-10-28 19:44 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-31 15:06 [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
2016-08-31 15:06 ` [PATCH 05/13] Share enum arm_breakpoint_kinds Yao Qi
2016-08-31 15:06 ` [PATCH 01/13] Remove v850_dbtrap_breakpoint_from_pc Yao Qi
2016-08-31 15:06 ` [PATCH 11/13] Add default_breakpoint_from_pc Yao Qi
2016-08-31 15:06 ` [PATCH 03/13] gdbarch_breakpoint_from_pc doesn't return NULL Yao Qi
2016-09-28 15:23   ` Michael Eager
2016-08-31 15:06 ` [PATCH 04/13] GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION Yao Qi
2016-08-31 15:06 ` [PATCH 09/13] Rename placed_size to kind Yao Qi
2016-08-31 15:06 ` [PATCH 13/13] Remove arm_override_mode Yao Qi
2016-10-27 14:56   ` Pedro Alves
2016-08-31 15:06 ` [PATCH 10/13] Remove gdbarch_remote_breakpoint_from_pc Yao Qi
2016-10-27 14:55   ` Pedro Alves
2016-08-31 15:06 ` [PATCH 02/13] Rename 'arch' by 'gdbarch' in m32c_gdbarch_init Yao Qi
2016-08-31 15:06 ` [PATCH 07/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
2016-10-10 10:05   ` Yao Qi
2016-10-27 14:55   ` Pedro Alves
2016-10-28 19:44     ` Maciej W. Rozycki
2016-08-31 15:06 ` [PATCH 08/13] New gdbarch methods " Yao Qi
2016-08-31 15:06 ` [PATCH 12/13] Determine the kind of single step breakpoint Yao Qi
2016-10-27 14:55   ` Pedro Alves
2016-08-31 15:06 ` [PATCH 06/13] Add enum for mips breakpoint kinds Yao Qi
2016-10-27 14:54   ` Pedro Alves
2016-10-28 19:39     ` Maciej W. Rozycki
2016-10-10 10:17 ` [PATCH 00/13] Split brekapoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind Yao Qi
2016-10-26 15:43   ` Yao Qi
2016-10-27 14:58     ` Pedro Alves
2016-10-27 15:41       ` Yao Qi
2016-10-27 17:55         ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).