gdb: Remove a non-const reference parameter
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 2 Jul 2019 11:06:06 +0000 (12:06 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 17 Jul 2019 15:24:32 +0000 (16:24 +0100)
Non-const reference parameter should be avoided according to the GDB
coding standard:

  https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Avoid_non-const_reference_parameters.2C_use_pointers_instead

This commit updates the gdbarch method gdbarch_stap_adjust_register,
and the one implementation i386_stap_adjust_register to avoid using a
non-const reference parameter.

I've also removed the kfail from the testsuite for bug 24541, as this
issue is now resolved.

gdb/ChangeLog:

PR breakpoints/24541
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh: Adjust return type and parameter types for
'stap_adjust_register'.
(i386_stap_adjust_register): Adjust signature and return new
register name.
* stap-probe.c (stap_parse_register_operand): Adjust use of
'gdbarch_stap_adjust_register'.

gdb/testsuite/ChangeLog:

PR breakpoints/24541
* gdb.mi/mi-catch-cpp-exceptions.exp: Remove kfail due to 24541.

gdb/ChangeLog
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/i386-tdep.c
gdb/stap-probe.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.exp

index 611a10e43e2bcf969965a9a7215f7bcbdf3cdbf1..16d09dc9d405ef9dc5e20b02f9fd544310b1359c 100644 (file)
@@ -1,3 +1,15 @@
+2019-07-17  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       PR breakpoints/24541
+       * gdbarch.c: Regenerate.
+       * gdbarch.h: Regenerate.
+       * gdbarch.sh: Adjust return type and parameter types for
+       'stap_adjust_register'.
+       (i386_stap_adjust_register): Adjust signature and return new
+       register name.
+       * stap-probe.c (stap_parse_register_operand): Adjust use of
+       'gdbarch_stap_adjust_register'.
+
 2019-07-17  Tom Tromey  <tromey@adacore.com>
 
        * s390-linux-nat.c (s390_watch_area): Remove typedef.  Don't
index cc7d0ace66c5f8b04d4a1f2344b386b9f8774df2..725b98fcd9f293afc912dca25c6eb2cb743ad0f7 100644 (file)
@@ -4530,14 +4530,14 @@ gdbarch_stap_adjust_register_p (struct gdbarch *gdbarch)
   return gdbarch->stap_adjust_register != NULL;
 }
 
-void
-gdbarch_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p, std::string &regname, int regnum)
+std::string
+gdbarch_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p, const std::string &regname, int regnum)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->stap_adjust_register != NULL);
   if (gdbarch_debug >= 2)
     fprintf_unfiltered (gdb_stdlog, "gdbarch_stap_adjust_register called\n");
-  gdbarch->stap_adjust_register (gdbarch, p, regname, regnum);
+  return gdbarch->stap_adjust_register (gdbarch, p, regname, regnum);
 }
 
 void
index 0857d2f30279480ddb93199364f5796b51ca5119..c3556d3841973fa5b5590375940f346d78ee5442 100644 (file)
@@ -1376,8 +1376,8 @@ extern void set_gdbarch_stap_parse_special_token (struct gdbarch *gdbarch, gdbar
 
 extern int gdbarch_stap_adjust_register_p (struct gdbarch *gdbarch);
 
-typedef void (gdbarch_stap_adjust_register_ftype) (struct gdbarch *gdbarch, struct stap_parse_info *p, std::string &regname, int regnum);
-extern void gdbarch_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p, std::string &regname, int regnum);
+typedef std::string (gdbarch_stap_adjust_register_ftype) (struct gdbarch *gdbarch, struct stap_parse_info *p, const std::string &regname, int regnum);
+extern std::string gdbarch_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p, const std::string &regname, int regnum);
 extern void set_gdbarch_stap_adjust_register (struct gdbarch *gdbarch, gdbarch_stap_adjust_register_ftype *stap_adjust_register);
 
 /* DTrace related functions.
index f3d1bf489acaf91c01e68986d1cdaaa9b2edd2de..2f9fbbc56cd78cbc5600a9a310454646dc08b07a 100755 (executable)
@@ -1053,7 +1053,7 @@ M;int;stap_parse_special_token;struct stap_parse_info *p;p
 # replace the register name from %ax to %eax.
 #
 # The rationale for this can be found at PR breakpoints/24541.
-M;void;stap_adjust_register;struct stap_parse_info *p, std::string \&regname, int regnum;p, regname, regnum
+M;std::string;stap_adjust_register;struct stap_parse_info *p, const std::string \&regname, int regnum;p, regname, regnum
 
 # DTrace related functions.
 
index aac9baa0aacebc95925b99eab932a1ddc873df7b..ccec6d171b71afef6d4a01674e3e3a4020643a7a 100644 (file)
@@ -4389,27 +4389,24 @@ i386_stap_parse_special_token (struct gdbarch *gdbarch,
 /* Implementation of 'gdbarch_stap_adjust_register', as defined in
    gdbarch.h.  */
 
-static void
+static std::string
 i386_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p,
-                          std::string &regname, int regnum)
+                          const std::string &regname, int regnum)
 {
   static const std::unordered_set<std::string> reg_assoc
     = { "ax", "bx", "cx", "dx",
        "si", "di", "bp", "sp" };
 
-  if (register_size (gdbarch, regnum) >= TYPE_LENGTH (p->arg_type))
-    {
-      /* If we're dealing with a register whose size is greater or
-        equal than the size specified by the "[-]N@" prefix, then we
-        don't need to do anything.  */
-      return;
-    }
+  /* If we are dealing with a register whose size is less than the size
+     specified by the "[-]N@" prefix, and it is one of the registers that
+     we know has an extended variant available, then use the extended
+     version of the register instead.  */
+  if (register_size (gdbarch, regnum) < TYPE_LENGTH (p->arg_type)
+      && reg_assoc.find (regname) != reg_assoc.end ())
+    return "e" + regname;
 
-  if (reg_assoc.find (regname) != reg_assoc.end ())
-    {
-      /* Use the extended version of the register.  */
-      regname = "e" + regname;
-    }
+  /* Otherwise, just use the requested register.  */
+  return regname;
 }
 
 \f
index 866b41e7f04e367c1d94c81cbd783e3eae30017a..b6de873d2c935a42e21c6b19bcb667a3b5959348 100644 (file)
@@ -774,23 +774,24 @@ stap_parse_register_operand (struct stap_parse_info *p)
      code would like to perform on the register name.  */
   if (gdbarch_stap_adjust_register_p (gdbarch))
     {
-      std::string oldregname = regname;
+      std::string newregname
+       = gdbarch_stap_adjust_register (gdbarch, p, regname, regnum);
 
-      gdbarch_stap_adjust_register (gdbarch, p, regname, regnum);
-
-      if (regname != oldregname)
+      if (regname != newregname)
        {
          /* This is just a check we perform to make sure that the
             arch-dependent code has provided us with a valid
             register name.  */
-         regnum = user_reg_map_name_to_regnum (gdbarch, regname.c_str (),
-                                               regname.size ());
+         regnum = user_reg_map_name_to_regnum (gdbarch, newregname.c_str (),
+                                               newregname.size ());
 
          if (regnum == -1)
            internal_error (__FILE__, __LINE__,
                            _("Invalid register name '%s' after replacing it"
                              " (previous name was '%s')"),
-                           regname.c_str (), oldregname.c_str ());
+                           newregname.c_str (), regname.c_str ());
+
+         regname = newregname;
        }
     }
 
index c24eed9114af53d823c1cfc4dc779462a2896451..4d7c4a7dffb5a6f777d93f7930aaf95e90afbd3f 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-17  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       PR breakpoints/24541
+       * gdb.mi/mi-catch-cpp-exceptions.exp: Remove kfail due to 24541.
+
 2019-07-14  Tom de Vries  <tdevries@suse.de>
 
        PR testsuite/24760
index 80ecabbe5553073139e5d315a2d0b2161bd80176..9b64fb14f2aa64513af6dcad44dbc56cf3d9f91d 100644 (file)
@@ -130,27 +130,7 @@ with_test_prefix "all with invalid regexp" {
     setup_catchpoint "throw" "-r blahblah"
     setup_catchpoint "rethrow" "-r woofwoof"
     setup_catchpoint "catch" "-r miowmiow"
-
-    # Would like to use 'continue_to_breakpoint_in_main' here, if
-    # there wasn't a bug that requires a use of kfail.
-
-    mi_send_resuming_command "exec-continue" \
-       "exec-continue"
-    set testname "run until breakpoint in main"
-    gdb_expect {
-       -re "could not find minimal symbol for typeinfo address.*$mi_gdb_prompt$" {
-           kfail "gdb/24541" "${testname}"
-       }
-       -re "\\*stopped,bkptno=\"$decimal\",reason=\"breakpoint-hit\",disp=\"keep\".*func=\"__cxa_throw\".*$mi_gdb_prompt$" {
-           kfail "gdb/24541" "${testname}"
-       }
-       -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"main\".*line=\"${main_lineno}\".*$mi_gdb_prompt$" {
-           pass "${testname}"
-       }
-       timeout {
-           fail "${testname} (timeout)"
-       }
-    }
+    continue_to_breakpoint_in_main
 }
 
 # Now check that all of the commands with a regexp that does match,
This page took 0.036613 seconds and 4 git commands to generate.