RFC: Use the ARM CPSR as a fallback to determine ARM/Thumb

Daniel Jacobowitz drow@false.org
Thu Mar 2 22:23:00 GMT 2006


On Tue, Feb 21, 2006 at 10:36:01AM -0500, Daniel Jacobowitz wrote:
> What I had in mind for this was:
> 
> set arm fallback-mode [arm|thumb|auto]
> 
> That is, continue to honor symbol information, but change the fallback
> when we don't have symbols to arm, thumb, or current cpsr.
> 
> And maybe augment that with:
> 
> set arm force-mode [arm|thumb|auto]
> 
> This would also override symbol information.
> 
> This is basically the same as your first option, but spread out over
> two variables.  How does that sound?

Something like the attached; look OK?

For correctness this needs the massive remove_breakpoint patch
I'm posting next.

-- 
Daniel Jacobowitz
CodeSourcery

2006-03-02  Daniel Jacobowitz  <dan@codesourcery.com>

	* arm-tdep.c (arm_mode_strings, arm_fallback_mode_string)
	(arm_force_mode_string, arm_show_fallback_mode)
	(arm_show_force_mode): New.
	(arm_pc_is_thumb): Honor fallback-mode and force-mode.
	Fall back to the CPSR.
	(_initialize_arm_tdep): Add "set arm fallback-mode"
	and "set arm force-mode".

2006-03-02  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.texinfo (ARM): Document set/show arm fallback-mode
	and set/show arm force-mode.

Index: src/gdb/arm-tdep.c
===================================================================
--- src.orig/gdb/arm-tdep.c	2006-03-02 15:58:19.000000000 -0500
+++ src/gdb/arm-tdep.c	2006-03-02 17:13:17.000000000 -0500
@@ -99,6 +99,17 @@ static const char *arm_abi_strings[] =
 static enum arm_abi_kind arm_abi_global = ARM_ABI_AUTO;
 static const char *arm_abi_string = "auto";
 
+/* The execution mode to assume.  */
+static const char *arm_mode_strings[] =
+  {
+    "auto",
+    "arm",
+    "thumb"
+  };
+
+static const char *arm_fallback_mode_string = "auto";
+static const char *arm_force_mode_string = "auto";
+
 /* Number of different reg name sets (options).  */
 static int num_disassembly_options;
 
@@ -181,16 +192,30 @@ arm_pc_is_thumb (CORE_ADDR memaddr)
   if (IS_THUMB_ADDR (memaddr))
     return 1;
 
+  /* If the user wants to override the symbol table, let him.  */
+  if (strcmp (arm_force_mode_string, "arm") == 0)
+    return 0;
+  if (strcmp (arm_force_mode_string, "thumb") == 0)
+    return 1;
+
   /* Thumb functions have a "special" bit set in minimal symbols.  */
   sym = lookup_minimal_symbol_by_pc (memaddr);
   if (sym)
-    {
-      return (MSYMBOL_IS_SPECIAL (sym));
-    }
-  else
-    {
-      return 0;
-    }
+    return (MSYMBOL_IS_SPECIAL (sym));
+
+  /* If the user wants to override the fallback mode, let them.  */
+  if (strcmp (arm_fallback_mode_string, "arm") == 0)
+    return 0;
+  if (strcmp (arm_fallback_mode_string, "thumb") == 0)
+    return 1;
+
+  /* If we couldn't find any symbol, but we're talking to a running
+     target, then trust the current value of $cpsr.  */
+  if (target_has_registers)
+    return (read_register (ARM_PS_REGNUM) & 0x20) != 0;
+
+  /* Otherwise we're out of luck; we assume ARM.  */
+  return 0;
 }
 
 /* Remove useless bits from addresses in a running program.  */
@@ -2458,6 +2483,28 @@ The current ARM ABI is \"auto\" (current
 		      arm_abi_string);
 }
 
+static void
+arm_show_fallback_mode (struct ui_file *file, int from_tty,
+			struct cmd_list_element *c, const char *value)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+
+  fprintf_filtered (file, _("\
+The current execution mode assumed (when symbols are unavailable) is \"%s\".\n"),
+		    arm_fallback_mode_string);
+}
+
+static void
+arm_show_force_mode (struct ui_file *file, int from_tty,
+		     struct cmd_list_element *c, const char *value)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+
+  fprintf_filtered (file, _("\
+The current execution mode assumed (even when symbols are available) is \"%s\".\n"),
+		    arm_force_mode_string);
+}
+
 /* If the user changes the register disassembly style used for info
    register and other commands, we have to also switch the style used
    in opcodes for disassembly output.  This function is run in the "set
@@ -2970,6 +3017,21 @@ vfp - VFP co-processor."),
 			NULL, arm_set_abi, arm_show_abi,
 			&setarmcmdlist, &showarmcmdlist);
 
+  /* Add two commands to allow the user to force the assumed
+     execution mode.  */
+  add_setshow_enum_cmd ("fallback-mode", class_support,
+			arm_mode_strings, &arm_fallback_mode_string,
+			_("Set the mode assumed when symbols are unavailable."),
+			_("Show the mode assumed when symbols are unavailable."),
+			NULL, NULL, arm_show_fallback_mode,
+			&setarmcmdlist, &showarmcmdlist);
+  add_setshow_enum_cmd ("force-mode", class_support,
+			arm_mode_strings, &arm_force_mode_string,
+			_("Set the mode assumed even when symbols are available."),
+			_("Show the mode assumed even when symbols are available."),
+			NULL, NULL, arm_show_force_mode,
+			&setarmcmdlist, &showarmcmdlist);
+
   /* Debugging flag.  */
   add_setshow_boolean_cmd ("arm", class_maintenance, &arm_debug,
 			   _("Set ARM debugging."),
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo	2006-02-22 15:02:33.000000000 -0500
+++ src/gdb/doc/gdb.texinfo	2006-03-02 17:11:02.000000000 -0500
@@ -14010,6 +14010,24 @@ This command forces @value{GDBN} to use 
 @item show arm abi
 Show the currently used ABI.
 
+@item set arm fallback-mode
+This command sets the mode (ARM versus Thumb) which @value{GDBN} will
+assume for code without a symbol table.  The default is @samp{auto},
+which causes @value{GDBN} to use the mode associated with the current
+CPSR.
+
+@item show arm fallback-mode
+Show the current fallback execution mode.
+
+@item set arm force-mode
+This command sets the mode (ARM versus Thumb) which @value{GDBN} will
+assume for all code, even when a symbol table is present.  The default
+is @samp{auto}, which causes @value{GDBN} to use the symbol table
+and fall back to the value of @samp{set arm fallback-mode}.
+
+@item show arm force-mode
+Show the currently forced execution mode.
+
 @item set debug arm
 Toggle whether to display ARM-specific debugging messages from the ARM
 target support subsystem.



More information about the Gdb-patches mailing list