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

Daniel Jacobowitz
2008-05-01T18:38:28Z

On Thu, Mar 02, 2006 at 05:14:46PM -0500, Daniel Jacobowitz wrote:
> 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?

Here's the final version of this old patch, now that it is frame based
as Mark Kettenis suggested.

Eli, do the documentation and NEWS changes look OK?

--
Daniel Jacobowitz
CodeSourcery

2008-05-01 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. Use
arm_frame_is_thumb.
(_initialize_arm_tdep): Add "set arm fallback-mode"
and "set arm force-mode".
* NEWS: Document new commands.

2008-05-01 Daniel Jacobowitz <dan@codesourcery.com>

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

---
gdb/NEWS | 9 +++++
gdb/arm-tdep.c | 85 +++++++++++++++++++++++++++++++++++++++++++++-------
gdb/doc/gdb.texinfo | 18 +++++++++++
3 files changed, 101 insertions(+), 11 deletions(-)

Index: src/gdb/arm-tdep.c
===================================================================
--- src.orig/gdb/arm-tdep.c 2008-05-01 13:56:01.000000000 -0400
+++ src/gdb/arm-tdep.c 2008-05-01 13:56:33.000000000 -0400
@@ -101,6 +101,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;

@@ -240,16 +251,33 @@ 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. This lets
+ "display/i $pc" always show the correct mode (though if there is
+ a symbol table we will not reach here, so it still may not be
+ displayed in the mode it will be executed). */
+ if (target_has_registers)
+ return arm_frame_is_thumb (get_current_frame ());
+
+ /* Otherwise we're out of luck; we assume ARM. */
+ return 0;
}

/* Remove useless bits from addresses in a running program. */
@@ -2663,6 +2689,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
@@ -3286,6 +3334,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 2008-05-01 13:55:45.000000000 -0400
+++ src/gdb/doc/gdb.texinfo 2008-05-01 13:56:33.000000000 -0400
@@ -14894,6 +14894,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.
Index: src/gdb/NEWS
===================================================================
--- src.orig/gdb/NEWS 2008-05-01 13:57:29.000000000 -0400
+++ src/gdb/NEWS 2008-05-01 14:01:32.000000000 -0400
@@ -49,6 +49,15 @@ show breakpoint always-inserted
them when resuming the target, and removing them when the target stops.
This option can improve debugger performance on slow remote targets.

+set arm fallback-mode (arm|thumb|auto)
+show arm fallback-mode
+set arm force-mode (arm|thumb|auto)
+show arm force-mode
+ These variables control how ARM GDB determines whether instructions
+ are ARM or Thumb. The default for both settings is auto, which uses
+ the current CPSR value for instructions without symbols; previous
+ versions of GDB behaved as if "set arm fallback-mode arm".
+
*** Changes in GDB 6.8

* New native configurations