gdb: Convert language la_watch_location_expression field to a method
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 1 Jun 2020 14:06:43 +0000 (15:06 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 17 Jun 2020 08:25:11 +0000 (09:25 +0100)
This commit changes the language_data::la_watch_location_expression
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_watch_location_expression): Rename to
ada_language::watch_location_expression.
(ada_language_data): Delete la_watch_location_expression
initializer.
(ada_language::watch_location_expression): New member function,
implementation from ada_watch_location_expression.
* breakpoint.c (watch_command_1): Update call to
watch_location_expression.
* c-lang.c (c_watch_location_expression): Rename to
language_defn::watch_location_expression.
(c_language_data): Delete la_watch_location_expression
initializer.
(cplus_language_data): Likewise.
(asm_language_data): Likewise.
(minimal_language_data): Likewise.
* c-lang.h (c_watch_location_expression): Delete declaration.
* d-lang.c (d_language_data): Delete la_watch_location_expression
initializer.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (language_defn::watch_location_expression): Member
function implementation from c_watch_location_expression.
(unknown_language_data): Delete la_watch_location_expression
initializer.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_watch_location_expression
field.
(language_defn::watch_location_expression): Declare new member
function.
* m2-lang.c (m2_language_data): Delete
la_watch_location_expression initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_watch_location_expression): Rename to
rust_language::watch_location_expression.
(rust_language_data): Delete la_watch_location_expression
initializer.
(rust_language::watch_location_expression): New member function,
implementation from rust_watch_location_expression.

15 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/breakpoint.c
gdb/c-lang.c
gdb/c-lang.h
gdb/d-lang.c
gdb/f-lang.c
gdb/go-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/rust-lang.c

index 52cfc4ccc176dc6b3e95ee2096b1636d30170e51..2b8ea9617f3b97553f7f0dcaed55192fa5e3da08 100644 (file)
@@ -1,3 +1,46 @@
+2020-06-17  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * ada-lang.c (ada_watch_location_expression): Rename to
+       ada_language::watch_location_expression.
+       (ada_language_data): Delete la_watch_location_expression
+       initializer.
+       (ada_language::watch_location_expression): New member function,
+       implementation from ada_watch_location_expression.
+       * breakpoint.c (watch_command_1): Update call to
+       watch_location_expression.
+       * c-lang.c (c_watch_location_expression): Rename to
+       language_defn::watch_location_expression.
+       (c_language_data): Delete la_watch_location_expression
+       initializer.
+       (cplus_language_data): Likewise.
+       (asm_language_data): Likewise.
+       (minimal_language_data): Likewise.
+       * c-lang.h (c_watch_location_expression): Delete declaration.
+       * d-lang.c (d_language_data): Delete la_watch_location_expression
+       initializer.
+       * f-lang.c (f_language_data): Likewise.
+       * go-lang.c (go_language_data): Likewise.
+       * language.c (language_defn::watch_location_expression): Member
+       function implementation from c_watch_location_expression.
+       (unknown_language_data): Delete la_watch_location_expression
+       initializer.
+       (auto_language_data): Likewise.
+       * language.h (language_data): Delete la_watch_location_expression
+       field.
+       (language_defn::watch_location_expression): Declare new member
+       function.
+       * m2-lang.c (m2_language_data): Delete
+       la_watch_location_expression initializer.
+       * objc-lang.c (objc_language_data): Likewise.
+       * opencl-lang.c (opencl_language_data): Likewise.
+       * p-lang.c (pascal_language_data): Likewise.
+       * rust-lang.c (rust_watch_location_expression): Rename to
+       rust_language::watch_location_expression.
+       (rust_language_data): Delete la_watch_location_expression
+       initializer.
+       (rust_language::watch_location_expression): New member function,
+       implementation from rust_watch_location_expression.
+
 2020-06-17  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * ada-lang.c (ada_collect_symbol_completion_matches): Rename to
index 306cf3acafc5d99ec81a5115e9759815a31dc953..392b1a679c57b9175cbaccf4f5f30d5a243db666 100644 (file)
@@ -488,17 +488,6 @@ add_angle_brackets (const char *str)
   return string_printf ("<%s>", str);
 }
 
-/* la_watch_location_expression for Ada.  */
-
-static gdb::unique_xmalloc_ptr<char>
-ada_watch_location_expression (struct type *type, CORE_ADDR addr)
-{
-  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
-  std::string name = type_to_string (type);
-  return gdb::unique_xmalloc_ptr<char>
-    (xstrprintf ("{%s} %s", name.c_str (), core_addr_to_string (addr)));
-}
-
 /* Assuming V points to an array of S objects,  make sure that it contains at
    least M objects, updating V and S as necessary.  */
 
@@ -13783,7 +13772,6 @@ extern const struct language_data ada_language_data =
   ada_op_print_tab,             /* expression operators for printing */
   0,                            /* c-style arrays */
   1,                            /* String lower bound */
-  ada_watch_location_expression,
   &ada_varobj_ops,
   ada_is_string_type,
   "(...)"                      /* la_struct_too_deep_ellipsis */
@@ -14102,6 +14090,17 @@ public:
       }
   }
 
+  /* See language.h.  */
+
+  gdb::unique_xmalloc_ptr<char> watch_location_expression
+       (struct type *type, CORE_ADDR addr) const override
+  {
+    type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
+    std::string name = type_to_string (type);
+    return gdb::unique_xmalloc_ptr<char>
+      (xstrprintf ("{%s} %s", name.c_str (), core_addr_to_string (addr)));
+  }
+
 protected:
   /* See language.h.  */
 
index aead882acd885b13694af3f90e5a6fe525b6c46c..6d81323dd921fd3699757c32b2a6ab33894e9b09 100644 (file)
@@ -10738,7 +10738,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
       CORE_ADDR addr = value_as_address (val.get ());
 
       w->exp_string_reparse
-       = current_language->la_watch_location_expression (t, addr).release ();
+       = current_language->watch_location_expression (t, addr).release ();
 
       w->exp_string = xstrprintf ("-location %.*s",
                                  (int) (exp_end - exp_start), exp_start);
index 3d1116b5b50aa78e02a109bdaf1a21848939c32d..42141e28dd4cb255b40d4b5a20d3111ce165720d 100644 (file)
@@ -727,17 +727,6 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
   return evaluate_subexp_standard (expect_type, exp, pos, noside);
 }
 \f
-/* la_watch_location_expression for C.  */
-
-gdb::unique_xmalloc_ptr<char>
-c_watch_location_expression (struct type *type, CORE_ADDR addr)
-{
-  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
-  std::string name = type_to_string (type);
-  return gdb::unique_xmalloc_ptr<char>
-    (xstrprintf ("* (%s *) %s", name.c_str (), core_addr_to_string (addr)));
-}
-
 /* See c-lang.h.  */
 
 bool
@@ -914,7 +903,6 @@ extern const struct language_data c_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &c_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
@@ -1026,7 +1014,6 @@ extern const struct language_data cplus_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &cplus_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
@@ -1226,7 +1213,6 @@ extern const struct language_data asm_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
@@ -1293,7 +1279,6 @@ extern const struct language_data minimal_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index 31ec6f2cf74c41fb302e5c25be9131bf20f70831..6c5d0d814c4c2dc80c34c74dcbe15fa1f9431bf4 100644 (file)
@@ -116,9 +116,6 @@ extern void c_emit_char (int c, struct type *type,
 
 extern const struct op_print c_op_print_tab[];
 
-extern gdb::unique_xmalloc_ptr<char> c_watch_location_expression
-     (struct type *type, CORE_ADDR addr);
-
 /* These are in c-typeprint.c: */
 
 extern void c_type_print_base (struct type *, struct ui_file *,
index 67c82e4215e3951b8516fc60b83f57d451111b23..001af06a82af1fdfc1bcd583460bbea9dda97c39 100644 (file)
@@ -157,7 +157,6 @@ extern const struct language_data d_language_data =
   d_op_print_tab,              /* Expression operators for printing.  */
   1,                           /* C-style arrays.  */
   0,                           /* String lower bound.  */
-  c_watch_location_expression,
   &default_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index 0540ab233db252f1002446fea4cf6e9832350cb3..e421e5f96451298ebdc77e401ff6cd0ce9489ad7 100644 (file)
@@ -578,7 +578,6 @@ extern const struct language_data f_language_data =
   f_op_print_tab,              /* expression operators for printing */
   0,                           /* arrays are first-class (not c-style) */
   1,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   f_is_string_type_p,
   "(...)"                      /* la_struct_too_deep_ellipsis */
index c060ad56436cbba3b2304b26bd6615f8ed0c81ac..5e742d710945f012c75cab7be261b06ce83f16f2 100644 (file)
@@ -542,7 +542,6 @@ extern const struct language_data go_language_data =
   go_op_print_tab,             /* Expression operators for printing.  */
   1,                           /* C-style arrays.  */
   0,                           /* String lower bound.  */
-  c_watch_location_expression,
   &default_varobj_ops,
   go_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index f4e99fc392f6d46fd0ad279a43bd01d2edf6d22b..6320577addf84e6c5d5cea7f2c6defb1248b9291 100644 (file)
@@ -622,6 +622,19 @@ language_defn::print_array_index (struct type *index_type, LONGEST index,
   fprintf_filtered (stream, "] = ");
 }
 
+/* See language.h.  */
+
+gdb::unique_xmalloc_ptr<char>
+language_defn::watch_location_expression (struct type *type,
+                                         CORE_ADDR addr) const
+{
+  /* Generates an expression that assumes a C like syntax is valid.  */
+  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
+  std::string name = type_to_string (type);
+  return gdb::unique_xmalloc_ptr<char>
+    (xstrprintf ("* (%s *) %s", name.c_str (), core_addr_to_string (addr)));
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -779,7 +792,6 @@ extern const struct language_data unknown_language_data =
   unk_op_print_tab,            /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   default_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
@@ -850,7 +862,6 @@ extern const struct language_data auto_language_data =
   unk_op_print_tab,            /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   default_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index 5872db39dbb5869a68a9b7f2c26b52005b0de97d..1cd3785ab0b8e7270605bc648849f27d6d9ca6b7 100644 (file)
@@ -319,12 +319,6 @@ struct language_data
     /* Index to use for extracting the first element of a string.  */
     char string_lower_bound;
 
-    /* Return an expression that can be used for a location
-       watchpoint.  TYPE is a pointer type that points to the memory
-       to watch, and ADDR is the address of the watched memory.  */
-    gdb::unique_xmalloc_ptr<char> (*la_watch_location_expression)
-         (struct type *type, CORE_ADDR addr);
-
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
@@ -540,6 +534,12 @@ struct language_defn : language_data
       (tracker, mode, name_match_type, text, word, "", code);
   }
 
+  /* Return an expression that can be used for a location
+     watchpoint.  TYPE is a pointer type that points to the memory
+     to watch, and ADDR is the address of the watched memory.  */
+  virtual gdb::unique_xmalloc_ptr<char> watch_location_expression
+       (struct type *type, CORE_ADDR addr) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 
index d21a5c9705c87fcbec9f3126dc92d7a8d1307c47..6dbc48767dcb8018b3be913a4b27434fb30b6a86 100644 (file)
@@ -376,7 +376,6 @@ extern const struct language_data m2_language_data =
   m2_op_print_tab,             /* expression operators for printing */
   0,                           /* arrays are first-class (not c-style) */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   m2_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index 5f9e97103664eb671f82e7baa10f31e0b7e0ab99..fa5aa9bc06e4eaad13c82aa7add08f0ceaecdb6c 100644 (file)
@@ -351,7 +351,6 @@ extern const struct language_data objc_language_data =
   objc_op_print_tab,           /* Expression operators for printing */
   1,                           /* C-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index d93ce0bc478482aa05feac2c86d3dcc0de2708ed..4cdfc045e04df10149d3316a04d307a00b872fc0 100644 (file)
@@ -1030,7 +1030,6 @@ extern const struct language_data opencl_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   c_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index f94f4c531436e566d846c9c55d07ca007dc11800..808e9e51a2705517e88f79b02a4222b793b94a3c 100644 (file)
@@ -407,7 +407,6 @@ extern const struct language_data pascal_language_data =
   pascal_op_print_tab,         /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  c_watch_location_expression,
   &default_varobj_ops,
   pascal_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
index 47fc3dbc4af463575853db48c6f6385854efeaec..fec68e3819374e2593b93f897e16f5ba1185270b 100644 (file)
@@ -2006,20 +2006,6 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
 
 \f
 
-/* la_watch_location_expression for Rust.  */
-
-static gdb::unique_xmalloc_ptr<char>
-rust_watch_location_expression (struct type *type, CORE_ADDR addr)
-{
-  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
-  std::string name = type_to_string (type);
-  return gdb::unique_xmalloc_ptr<char>
-    (xstrprintf ("*(%s as *mut %s)", core_addr_to_string (addr),
-                name.c_str ()));
-}
-
-\f
-
 static const struct exp_descriptor exp_descriptor_rust = 
 {
   rust_print_subexp,
@@ -2062,7 +2048,6 @@ extern const struct language_data rust_language_data =
   c_op_print_tab,              /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  rust_watch_location_expression,
   &default_varobj_ops,
   rust_is_string_type_p,
   "{...}"                      /* la_struct_too_deep_ellipsis */
@@ -2143,6 +2128,18 @@ public:
     rust_internal_print_type (type, varstring, stream, show, level,
                              flags, false, &podata);
   }
+
+  /* See language.h.  */
+
+  gdb::unique_xmalloc_ptr<char> watch_location_expression
+       (struct type *type, CORE_ADDR addr) const override
+  {
+    type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
+    std::string name = type_to_string (type);
+    return gdb::unique_xmalloc_ptr<char>
+      (xstrprintf ("*(%s as *mut %s)", core_addr_to_string (addr),
+                  name.c_str ()));
+  }
 };
 
 /* Single instance of the Rust language class.  */