[PATCHv2 12/13] gdb: Convert language la_demangle field to a method

Andrew Burgess andrew.burgess@embecosm.com
Fri May 15 15:06:51 GMT 2020


This commit changes the language_data::la_demangle function pointer
member variable into a member function of language_defn.

The only slightly "weird" change in this commit is in f-lang.c, where
I have given the Fortran language a demangle method that is identical
to the default language_defn::demangle.  The only reason for this is
to give me somewhere to copy the comment that was previously embedded
within the f_language_data structure.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_demangle initializer.
	(ada_language::demangle): New member function.
	* c-lang.c (c_language_data): Delete la_demangle initializer.
	(cplus_language_data): Delete la_demangle initializer.
	(cplus_language::demangle): New member function.
	(asm_language_data): Delete la_demangle initializer.
	(minimal_language_data): Delete la_demangle initializer.
	* d-lang.c (d_language_data): Delete la_demangle initializer.
	(d_language::demangle): New member function.
	* f-lang.c (f_language_data): Delete la_demangle initializer.
	(f_language::demangle): New member function.
	* go-lang.c (go_language_data): Delete la_demangle initializer.
	(go_language::demangle): New member function.
	* language.c (language_demangle): Update.
	(unk_lang_demangle): Delete.
	(unknown_language_data): Delete la_demangle initializer.
	(unknown_language::demangle): New member function.
	(auto_language_data): Delete la_demangle initializer.
	(auto_language::demangle): New member function.
	* language.h (language_data): Delete la_demangle field.
	(language_defn::demangle): New function.
	* m2-lang.c (m2_language_data): Delete la_demangle initializer.
	* objc-lang.c (objc_language_data): Delete la_demangle
	initializer.
	(objc_language::demangle): New member function.
	* opencl-lang.c (opencl_language_data): Delete la_demangle
	initializer.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	(rust_language::demangle): New member functi
---
 gdb/ChangeLog     | 33 +++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  8 +++++++-
 gdb/c-lang.c      | 11 +++++++----
 gdb/d-lang.c      |  8 +++++++-
 gdb/f-lang.c      | 19 ++++++++++++-------
 gdb/go-lang.c     |  8 +++++++-
 gdb/language.c    | 28 ++++++++++++++++++----------
 gdb/language.h    |  9 ++++++---
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  8 +++++++-
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  8 +++++++-
 13 files changed, 111 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 10b4c97b801..3c151588ecb 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13923,7 +13923,6 @@ extern const struct language_data ada_language_data =
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
-  ada_la_decode,                /* Language specific symbol demangler */
   NULL,                         /* Language specific
 				   class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */
@@ -14102,6 +14101,13 @@ class ada_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return ada_la_decode (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 79e4494aa4d..75efb6ae592 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -912,7 +912,6 @@ extern const struct language_data c_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1022,7 +1021,6 @@ extern const struct language_data cplus_language_data =
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  gdb_demangle,			/* Language specific symbol demangler */
   cp_class_name_from_physname,  /* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1146,6 +1144,13 @@ class cplus_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return gdb_demangle (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
@@ -1188,7 +1193,6 @@ extern const struct language_data asm_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1263,7 +1267,6 @@ extern const struct language_data minimal_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 815b59734e0..fb56e1e9baf 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -155,7 +155,6 @@ extern const struct language_data d_language_data =
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
-  d_demangle,			/* Language specific symbol demangler.  */
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   d_op_print_tab,		/* Expression operators for printing.  */
@@ -254,6 +253,13 @@ class d_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return d_demangle (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1b0fec68c0e..bd5f78ccbef 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -615,13 +615,6 @@ extern const struct language_data f_language_data =
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-
-  /* We could support demangling here to provide module namespaces
-     also for inferiors with only minimal symbol table (ELF symbols).
-     Just the mangling standard is not standardized across compilers
-     and there is no DW_AT_producer available for inferiors with only
-     the ELF symbols to check the mangling kind.  */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   f_op_print_tab,		/* expression operators for printing */
@@ -692,6 +685,18 @@ class f_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+      /* We could support demangling here to provide module namespaces
+	 also for inferiors with only minimal symbol table (ELF symbols).
+	 Just the mangling standard is not standardized across compilers
+	 and there is no DW_AT_producer available for inferiors with only
+	 the ELF symbols to check the mangling kind.  */
+    return nullptr;
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 36a46a403e2..47a4abcc2fe 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -540,7 +540,6 @@ extern const struct language_data go_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
-  go_demangle,			/* Language specific symbol demangler.  */
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   go_op_print_tab,		/* Expression operators for printing.  */
@@ -628,6 +627,13 @@ class go_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return go_demangle (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
diff --git a/gdb/language.c b/gdb/language.c
index 7df47b3ddee..e6ca03f4916 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -590,8 +590,8 @@ char *
 language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options)
 {
-  if (current_language != NULL && current_language->la_demangle)
-    return current_language->la_demangle (mangled, options);
+  if (current_language != NULL)
+    return current_language->demangle (mangled, options);
   return NULL;
 }
 
@@ -748,12 +748,6 @@ static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
   return 0;
 }
 
-/* Unknown languages just use the cplus demangler.  */
-static char *unk_lang_demangle (const char *mangled, int options)
-{
-  return gdb_demangle (mangled, options);
-}
-
 static char *unk_lang_class_name (const char *mangled)
 {
   return NULL;
@@ -799,7 +793,6 @@ extern const struct language_data unknown_language_data =
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
-  unk_lang_demangle,		/* Language specific symbol demangler */
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
@@ -839,6 +832,14 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::print_type called"));
   }
+
+  /* See language.h.  */
+
+  char *demangle (const char *mangled, int options) const override
+  {
+    /* The unknown language just uses the C++ demangler.  */
+    return gdb_demangle (mangled, options);
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -870,7 +871,6 @@ extern const struct language_data auto_language_data =
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  unk_lang_demangle,		/* Language specific symbol demangler */
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
@@ -910,6 +910,14 @@ class auto_language : public language_defn
   {
     error (_("unimplemented auto_language::print_type called"));
   }
+
+  /* See language.h.  */
+
+  char *demangle (const char *mangled, int options) const override
+  {
+    /* The auto language just uses the C++ demangler.  */
+    return gdb_demangle (mangled, options);
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index dd415bbef85..bee479720ae 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -310,9 +310,6 @@ struct language_data
        const struct block *,
        const domain_enum);
 
-    /* Return demangled language symbol, or NULL.  */
-    char *(*la_demangle) (const char *mangled, int options);
-
     /* Return class name of a mangled method name or NULL.  */
     char *(*la_class_name_from_physname) (const char *physname);
 
@@ -511,6 +508,12 @@ struct language_defn : language_data
     return false;
   }
 
+  /* Return demangled language symbol version of MANGLED, or NULL.  */
+  virtual char *demangle (const char *mangled, int options) const
+  {
+    return nullptr;
+  }
+
   /* Print a type using syntax appropriate for this language.  */
 
   virtual void print_type (struct type *, const char *, struct ui_file *, int,
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 68aad7d7367..4bc25ce82fe 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -374,7 +374,6 @@ extern const struct language_data m2_language_data =
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   m2_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 0566ce8f188..1e3d1fd3616 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -380,7 +380,6 @@ extern const struct language_data objc_language_data =
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  objc_demangle,		/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   objc_op_print_tab,		/* Expression operators for printing */
@@ -422,6 +421,13 @@ class objc_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return objc_demangle (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 481fe1dba47..dc5d69873f6 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1028,7 +1028,6 @@ extern const struct language_data opencl_language_data =
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 82277739ec9..70f8e5af80a 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -405,7 +405,6 @@ extern const struct language_data pascal_language_data =
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific class_name_from_physname */
   pascal_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 53dd7761847..9afe0b1f16f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2060,7 +2060,6 @@ extern const struct language_data rust_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  gdb_demangle,			/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -2136,6 +2135,13 @@ class rust_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return gdb_demangle (mangled, options);
+  }
+
+  /* See language.h.  */
+
   void print_type (struct type *type, const char *varstring,
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
-- 
2.25.4



More information about the Gdb-patches mailing list