]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Add guess_tracepoint_registers hook to gdbarch.
authorMarcin Kościelnicki <koriakin@0x04.net>
Thu, 18 Feb 2016 08:21:38 +0000 (09:21 +0100)
committerMarcin Kościelnicki <koriakin@0x04.net>
Thu, 18 Feb 2016 16:21:22 +0000 (17:21 +0100)
When we're looking at a tracefile trace frame where registers are not
available, and the tracepoint has only one location, we supply
the location's address as the PC register.  However, this only works
if PC is not a pseudo register, and individual architectures may want
to guess more registers.  Add a gdbarch hook that will handle that.

gdb/ChangeLog:

* arch-utils.c (default_guess_tracepoint_registers): New function.
* arch-utils.h (default_guess_tracepoint_registers): New prototype.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh: Add guess_tracepoint_registers hook.
* tracefile.c (tracefile_fetch_registers): Use the new gdbarch hook.

gdb/ChangeLog
gdb/arch-utils.c
gdb/arch-utils.h
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/tracefile.c

index e507dd181c6f16a05ae5663342cdbd6039f667b2..c8832c90862e9f942cc6047655057944b9fd8dbb 100644 (file)
@@ -1,3 +1,12 @@
+2016-02-18  Marcin Kościelnicki  <koriakin@0x04.net>
+
+       * arch-utils.c (default_guess_tracepoint_registers): New function.
+       * arch-utils.h (default_guess_tracepoint_registers): New prototype.
+       * gdbarch.c: Regenerate.
+       * gdbarch.h: Regenerate.
+       * gdbarch.sh: Add guess_tracepoint_registers hook.
+       * tracefile.c (tracefile_fetch_registers): Use the new gdbarch hook.
+
 2016-02-17  Gary Benson  <gbenson@redhat.com>
 
        * exec.c (exec_file_locate_attach): Add missing cleanup.
index fe64627825389a985a327043c7b006dcfd65e476..c3d78024131235e7a8b6ac2fd3983852089c4203 100644 (file)
@@ -897,6 +897,29 @@ default_addressable_memory_unit_size (struct gdbarch *gdbarch)
   return 1;
 }
 
+void
+default_guess_tracepoint_registers (struct gdbarch *gdbarch,
+                                   struct regcache *regcache,
+                                   CORE_ADDR addr)
+{
+  int pc_regno = gdbarch_pc_regnum (gdbarch);
+  gdb_byte *regs;
+
+  /* This guessing code below only works if the PC register isn't
+     a pseudo-register.  The value of a pseudo-register isn't stored
+     in the (non-readonly) regcache -- instead it's recomputed
+     (probably from some other cached raw register) whenever the
+     register is read.  In this case, a custom method implementation
+     should be used by the architecture.  */
+  if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
+    return;
+
+  regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
+  store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
+                         gdbarch_byte_order (gdbarch), addr);
+  regcache_raw_supply (regcache, pc_regno, regs);
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_gdbarch_utils;
 
index 3fad2c36340d0ab15232aa92d66464eb53a7f620..9e1e70ea5e7cabc9268cbf71f595b6529ca91524 100644 (file)
@@ -204,4 +204,8 @@ extern char *default_gcc_target_options (struct gdbarch *gdbarch);
 extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
 extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch);
 
+extern void default_guess_tracepoint_registers (struct gdbarch *gdbarch,
+                                               struct regcache *regcache,
+                                               CORE_ADDR addr);
+
 #endif
index 41437447af7375d4dfa75b0534cfd3b74a05f71c..0136c75c2b79e863945b6bafe03ffcf289177760 100644 (file)
@@ -312,6 +312,7 @@ struct gdbarch
   int has_global_breakpoints;
   gdbarch_has_shared_address_space_ftype *has_shared_address_space;
   gdbarch_fast_tracepoint_valid_at_ftype *fast_tracepoint_valid_at;
+  gdbarch_guess_tracepoint_registers_ftype *guess_tracepoint_registers;
   gdbarch_auto_charset_ftype *auto_charset;
   gdbarch_auto_wide_charset_ftype *auto_wide_charset;
   const char * solib_symbols_extension;
@@ -419,6 +420,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->relocate_instruction = NULL;
   gdbarch->has_shared_address_space = default_has_shared_address_space;
   gdbarch->fast_tracepoint_valid_at = default_fast_tracepoint_valid_at;
+  gdbarch->guess_tracepoint_registers = default_guess_tracepoint_registers;
   gdbarch->auto_charset = default_auto_charset;
   gdbarch->auto_wide_charset = default_auto_wide_charset;
   gdbarch->gen_return_address = default_gen_return_address;
@@ -658,6 +660,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of has_global_breakpoints, invalid_p == 0 */
   /* Skip verify of has_shared_address_space, invalid_p == 0 */
   /* Skip verify of fast_tracepoint_valid_at, invalid_p == 0 */
+  /* Skip verify of guess_tracepoint_registers, invalid_p == 0 */
   /* Skip verify of auto_charset, invalid_p == 0 */
   /* Skip verify of auto_wide_charset, invalid_p == 0 */
   /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
@@ -1023,6 +1026,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   fprintf_unfiltered (file,
                       "gdbarch_dump: gnu_triplet_regexp = <%s>\n",
                       host_address_to_string (gdbarch->gnu_triplet_regexp));
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: guess_tracepoint_registers = <%s>\n",
+                      host_address_to_string (gdbarch->guess_tracepoint_registers));
   fprintf_unfiltered (file,
                       "gdbarch_dump: half_bit = %s\n",
                       plongest (gdbarch->half_bit));
@@ -4450,6 +4456,23 @@ set_gdbarch_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
   gdbarch->fast_tracepoint_valid_at = fast_tracepoint_valid_at;
 }
 
+void
+gdbarch_guess_tracepoint_registers (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->guess_tracepoint_registers != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_guess_tracepoint_registers called\n");
+  gdbarch->guess_tracepoint_registers (gdbarch, regcache, addr);
+}
+
+void
+set_gdbarch_guess_tracepoint_registers (struct gdbarch *gdbarch,
+                                        gdbarch_guess_tracepoint_registers_ftype guess_tracepoint_registers)
+{
+  gdbarch->guess_tracepoint_registers = guess_tracepoint_registers;
+}
+
 const char *
 gdbarch_auto_charset (struct gdbarch *gdbarch)
 {
index 3fadcd14ba01bbeada1b086a1d37247c6a2cdc1b..7ffbf1fd296ddec5f2ddc5a047c17664b050fb35 100644 (file)
@@ -1327,6 +1327,15 @@ typedef int (gdbarch_fast_tracepoint_valid_at_ftype) (struct gdbarch *gdbarch, C
 extern int gdbarch_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr, char **msg);
 extern void set_gdbarch_fast_tracepoint_valid_at (struct gdbarch *gdbarch, gdbarch_fast_tracepoint_valid_at_ftype *fast_tracepoint_valid_at);
 
+/* Guess register state based on tracepoint location.  Used for tracepoints
+   where no registers have been collected, but there's only one location,
+   allowing us to guess the PC value, and perhaps some other registers.
+   On entry, regcache has all registers marked as unavailable. */
+
+typedef void (gdbarch_guess_tracepoint_registers_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr);
+extern void gdbarch_guess_tracepoint_registers (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr);
+extern void set_gdbarch_guess_tracepoint_registers (struct gdbarch *gdbarch, gdbarch_guess_tracepoint_registers_ftype *guess_tracepoint_registers);
+
 /* Return the "auto" target charset. */
 
 typedef const char * (gdbarch_auto_charset_ftype) (void);
index 4ac6b90fd128214c42c0b0d24f1ef2f4b66d3dfc..61cb04a7194f4db8adcdd98f269011973e48e635 100755 (executable)
@@ -1028,6 +1028,12 @@ m:int:has_shared_address_space:void:::default_has_shared_address_space::0
 # True if a fast tracepoint can be set at an address.
 m:int:fast_tracepoint_valid_at:CORE_ADDR addr, char **msg:addr, msg::default_fast_tracepoint_valid_at::0
 
+# Guess register state based on tracepoint location.  Used for tracepoints
+# where no registers have been collected, but there's only one location,
+# allowing us to guess the PC value, and perhaps some other registers.
+# On entry, regcache has all registers marked as unavailable.
+m:void:guess_tracepoint_registers:struct regcache *regcache, CORE_ADDR addr:regcache, addr::default_guess_tracepoint_registers::0
+
 # Return the "auto" target charset.
 f:const char *:auto_charset:void::default_auto_charset:default_auto_charset::0
 # Return the "auto" target wide charset.
index de421650341c70a754c6a00d90b9c05ea6acb062..609b7e5a42a2522c7f52b8b62e026174b98bfc3d 100644 (file)
@@ -388,7 +388,8 @@ void
 tracefile_fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  int regn, pc_regno;
+  struct tracepoint *tp = get_tracepoint (get_tracepoint_number ());
+  int regn;
 
   /* We get here if no register data has been found.  Mark registers
      as unavailable.  */
@@ -397,48 +398,29 @@ tracefile_fetch_registers (struct regcache *regcache, int regno)
 
   /* We can often usefully guess that the PC is going to be the same
      as the address of the tracepoint.  */
-  pc_regno = gdbarch_pc_regnum (gdbarch);
-
-  /* XXX This guessing code below only works if the PC register isn't
-     a pseudo-register.  The value of a pseudo-register isn't stored
-     in the (non-readonly) regcache -- instead it's recomputed
-     (probably from some other cached raw register) whenever the
-     register is read.  This guesswork should probably move to some
-     higher layer.  */
-  if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
+  if (tp == NULL || tp->base.loc == NULL)
     return;
 
-  if (regno == -1 || regno == pc_regno)
+  /* But don't try to guess if tracepoint is multi-location...  */
+  if (tp->base.loc->next)
     {
-      struct tracepoint *tp = get_tracepoint (get_tracepoint_number ());
-      gdb_byte *regs;
-
-      if (tp && tp->base.loc)
-       {
-         /* But don't try to guess if tracepoint is multi-location...  */
-         if (tp->base.loc->next)
-           {
-             warning (_("Tracepoint %d has multiple "
-                        "locations, cannot infer $pc"),
-                      tp->base.number);
-             return;
-           }
-         /* ... or does while-stepping.  */
-         if (tp->step_count > 0)
-           {
-             warning (_("Tracepoint %d does while-stepping, "
-                        "cannot infer $pc"),
-                      tp->base.number);
-             return;
-           }
-
-         regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
-         store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
-                                 gdbarch_byte_order (gdbarch),
-                                 tp->base.loc->address);
-         regcache_raw_supply (regcache, pc_regno, regs);
-       }
+      warning (_("Tracepoint %d has multiple "
+                "locations, cannot infer $pc"),
+              tp->base.number);
+      return;
+    }
+  /* ... or does while-stepping.  */
+  else if (tp->step_count > 0)
+    {
+      warning (_("Tracepoint %d does while-stepping, "
+                "cannot infer $pc"),
+              tp->base.number);
+      return;
     }
+
+  /* Guess what we can from the tracepoint location.  */
+  gdbarch_guess_tracepoint_registers (gdbarch, regcache,
+                                     tp->base.loc->address);
 }
 
 /* This is the implementation of target_ops method to_has_all_memory.  */