Replace SYMBOL_SET_LINKAGE_NAME with a member function

Message ID 20191126204351.83076-1-cbiesinger@google.com
State New, archived
Headers

Commit Message

Terekhov, Mikhail via Gdb-patches Nov. 26, 2019, 8:43 p.m. UTC
  Easier to read, shorter, and will later make it possible to make the
name field private.

gdb/ChangeLog:

2019-11-26  Christian Biesinger  <cbiesinger@google.com>

	* ada-exp.y (write_ambiguous_var): Replace SYMBOL_SET_LINKAGE_NAME
	with sym->set_linkage_name.
	* coffread.c (coff_read_enum_type): Likewise.
	* mdebugread.c (parse_symbol): Likewise.
	* stabsread.c (patch_block_stabs): Likewise.
	(define_symbol): Likewise.
	(read_enum_type): Likewise.
	(common_block_end): Likewise.
	* symtab.h (struct general_symbol_info) <set_linkage_name>: New
	function.
	(SYMBOL_SET_LINKAGE_NAME): Remove.
	* xcoffread.c (process_xcoff_symbol): Replace SYMBOL_SET_LINKAGE_NAME
	with sym->set_linkage_name.

Change-Id: I174a0542c014f1b035070068076308bb8ae79abb
---
 gdb/ada-exp.y    |  3 +--
 gdb/coffread.c   |  2 +-
 gdb/mdebugread.c |  5 ++---
 gdb/stabsread.c  | 20 +++++++++-----------
 gdb/symtab.h     | 19 +++++++++----------
 gdb/xcoffread.c  |  2 +-
 6 files changed, 23 insertions(+), 28 deletions(-)
  

Comments

Simon Marchi Nov. 27, 2019, 3:54 a.m. UTC | #1
On 2019-11-26 3:43 p.m., Christian Biesinger via gdb-patches wrote:
> Easier to read, shorter, and will later make it possible to make the
> name field private.

Thanks, LGTM, with the nits below fixed.

> diff --git a/gdb/stabsread.c b/gdb/stabsread.c
> index 6ec9f971e1..3f3f0a624f 100644
> --- a/gdb/stabsread.c
> +++ b/gdb/stabsread.c
> @@ -399,8 +399,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
>        /* for all the stab entries, find their corresponding symbols and 
>           patch their types!  */
>  
> -      for (ii = 0; ii < stabs->count; ++ii)
> -	{
> +      for (ii = 0; ii < stabs->count; ++ii) {

Unrelated change.

> diff --git a/gdb/symtab.h b/gdb/symtab.h
> index 897ffda76e..ff51069b6c 100644
> --- a/gdb/symtab.h
> +++ b/gdb/symtab.h
> @@ -407,8 +407,7 @@ struct general_symbol_info
>  
>    /* Return the demangled name for a symbol based on the language for
>       that symbol.  If no demangled name exists, return NULL.  */
> -  const char *demangled_name () const;
> -
> +  const char *demangled_name () const; 

Unrelated change.

Simon
  
Terekhov, Mikhail via Gdb-patches Nov. 27, 2019, 5:10 p.m. UTC | #2
On Tue, Nov 26, 2019 at 9:54 PM Simon Marchi <simark@simark.ca> wrote:
>
> On 2019-11-26 3:43 p.m., Christian Biesinger via gdb-patches wrote:
> > Easier to read, shorter, and will later make it possible to make the
> > name field private.
>
> Thanks, LGTM, with the nits below fixed.

Thanks for catching those, not sure how that happened. Fixed and pushed:

To ssh://sourceware.org/git/binutils-gdb.git
   db5960b4d2..43678b0afe  HEAD -> master

> > diff --git a/gdb/stabsread.c b/gdb/stabsread.c
> > index 6ec9f971e1..3f3f0a624f 100644
> > --- a/gdb/stabsread.c
> > +++ b/gdb/stabsread.c
> > @@ -399,8 +399,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
> >        /* for all the stab entries, find their corresponding symbols and
> >           patch their types!  */
> >
> > -      for (ii = 0; ii < stabs->count; ++ii)
> > -     {
> > +      for (ii = 0; ii < stabs->count; ++ii) {
>
> Unrelated change.

Done.

> > diff --git a/gdb/symtab.h b/gdb/symtab.h
> > index 897ffda76e..ff51069b6c 100644
> > --- a/gdb/symtab.h
> > +++ b/gdb/symtab.h
> > @@ -407,8 +407,7 @@ struct general_symbol_info
> >
> >    /* Return the demangled name for a symbol based on the language for
> >       that symbol.  If no demangled name exists, return NULL.  */
> > -  const char *demangled_name () const;
> > -
> > +  const char *demangled_name () const;
>
> Unrelated change.

Done.

Christian
  

Patch

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 5e9d3e70b9..00020cd067 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1105,8 +1105,7 @@  write_ambiguous_var (struct parser_state *par_state,
   struct symbol *sym = new (&temp_parse_space) symbol ();
 
   SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
-  SYMBOL_SET_LINKAGE_NAME (sym,
-			   obstack_strndup (&temp_parse_space, name, len));
+  sym->set_linkage_name (obstack_strndup (&temp_parse_space, name, len));
   SYMBOL_LANGUAGE (sym) = language_ada;
 
   write_exp_elt_opcode (par_state, OP_VAR_VALUE);
diff --git a/gdb/coffread.c b/gdb/coffread.c
index ac00e1c1e3..d0a9233de7 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2106,7 +2106,7 @@  coff_read_enum_type (int index, int length, int lastsym,
 	  sym = allocate_symbol (objfile);
 
 	  name = obstack_strdup (&objfile->objfile_obstack, name);
-	  SYMBOL_SET_LINKAGE_NAME (sym, name);
+	  sym->set_linkage_name (name);
 	  SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
 	  SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 	  SYMBOL_VALUE (sym) = ms->c_value;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index c58e40c94a..f279f13171 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1066,9 +1066,8 @@  parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		FIELD_BITSIZE (*f) = 0;
 
 		enum_sym = allocate_symbol (mdebugread_objfile);
-		SYMBOL_SET_LINKAGE_NAME
-		  (enum_sym,
-		   obstack_strdup (&mdebugread_objfile->objfile_obstack,
+		enum_sym->set_linkage_name
+		  (obstack_strdup (&mdebugread_objfile->objfile_obstack,
 				   f->name));
 		SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
 		SYMBOL_TYPE (enum_sym) = t;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 6ec9f971e1..3f3f0a624f 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -399,8 +399,7 @@  patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
       /* for all the stab entries, find their corresponding symbols and 
          patch their types!  */
 
-      for (ii = 0; ii < stabs->count; ++ii)
-	{
+      for (ii = 0; ii < stabs->count; ++ii) {
 	  name = stabs->stab[ii];
 	  pp = (char *) strchr (name, ':');
 	  gdb_assert (pp);	/* Must find a ':' or game's over.  */
@@ -426,9 +425,8 @@  patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
 	      sym = allocate_symbol (objfile);
 	      SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 	      SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
-	      SYMBOL_SET_LINKAGE_NAME
-		(sym, obstack_strndup (&objfile->objfile_obstack,
-				       name, pp - name));
+	      sym->set_linkage_name
+		(obstack_strndup (&objfile->objfile_obstack, name, pp - name));
 	      pp += 2;
 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
 		{
@@ -710,14 +708,14 @@  define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       switch (string[1])
 	{
 	case 't':
-	  SYMBOL_SET_LINKAGE_NAME (sym, "this");
+	  sym->set_linkage_name ("this");
 	  break;
 
 	case 'v':		/* $vtbl_ptr_type */
 	  goto normal;
 
 	case 'e':
-	  SYMBOL_SET_LINKAGE_NAME (sym, "eh_throw");
+	  sym->set_linkage_name ("eh_throw");
 	  break;
 
 	case '_':
@@ -1202,7 +1200,7 @@  define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	      const char *new_name = gdbarch_static_transform_name
 		(gdbarch, sym->linkage_name ());
 
-	      SYMBOL_SET_LINKAGE_NAME (sym, new_name);
+	      sym->set_linkage_name (new_name);
 	      SET_SYMBOL_VALUE_ADDRESS (sym,
 					BMSYMBOL_VALUE_ADDRESS (msym));
 	    }
@@ -1385,7 +1383,7 @@  define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	      const char *new_name = gdbarch_static_transform_name
 		(gdbarch, sym->linkage_name ());
 
-	      SYMBOL_SET_LINKAGE_NAME (sym, new_name);
+	      sym->set_linkage_name (new_name);
 	      SET_SYMBOL_VALUE_ADDRESS (sym, BMSYMBOL_VALUE_ADDRESS (msym));
 	    }
 	}
@@ -3638,7 +3636,7 @@  read_enum_type (const char **pp, struct type *type,
 	return error_type (pp, objfile);
 
       sym = allocate_symbol (objfile);
-      SYMBOL_SET_LINKAGE_NAME (sym, name);
+      sym->set_linkage_name (name);
       SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language,
 			   &objfile->objfile_obstack);
       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
@@ -4306,7 +4304,7 @@  common_block_end (struct objfile *objfile)
 
   sym = allocate_symbol (objfile);
   /* Note: common_block_name already saved on objfile_obstack.  */
-  SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
+  sym->set_linkage_name (common_block_name);
   SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
 
   /* Now we copy all the symbols which have been defined since the BCOMM.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 897ffda76e..ff51069b6c 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -407,8 +407,7 @@  struct general_symbol_info
 
   /* Return the demangled name for a symbol based on the language for
      that symbol.  If no demangled name exists, return NULL.  */
-  const char *demangled_name () const;
-
+  const char *demangled_name () const; 
   /* Returns the name to be used when sorting and searching symbols.
      In C++, we search for the demangled form of a name,
      and so sort symbols accordingly.  In Ada, however, we search by mangled
@@ -416,6 +415,14 @@  struct general_symbol_info
      returns the same value (same pointer) as linkage_name ().  */
   const char *search_name () const;
 
+  /* Set just the linkage name of a symbol; do not try to demangle
+     it.  Used for constructs which do not have a mangled name,
+     e.g. struct tags.  Unlike SYMBOL_SET_NAMES, linkage_name must
+     be terminated and either already on the objfile's obstack or
+     permanently allocated.  */
+  void set_linkage_name (const char *linkage_name)
+  { name = linkage_name; }
+
   /* Name of the symbol.  This is a required field.  Storage for the
      name is allocated on the objfile_obstack for the associated
      objfile.  For languages like C++ that make a distinction between
@@ -528,14 +535,6 @@  extern void symbol_set_language (struct general_symbol_info *symbol,
                                  enum language language,
 				 struct obstack *obstack);
 
-/* Set just the linkage name of a symbol; do not try to demangle
-   it.  Used for constructs which do not have a mangled name,
-   e.g. struct tags.  Unlike SYMBOL_SET_NAMES, linkage_name must
-   be terminated and either already on the objfile's obstack or
-   permanently allocated.  */
-#define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
-  (symbol)->name = (linkage_name)
-
 /* Set the linkage and natural names of a symbol, by demangling
    the linkage name.  If linkage_name may not be nullterminated,
    copy_name must be set to true.  */
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 4ea9b0b5bd..eaa77fd491 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1574,7 +1574,7 @@  process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
          will be patched with the type from its stab entry later on in
          patch_block_stabs (), unless the file was compiled without -g.  */
 
-      SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
+      sym->set_linkage_name (SYMNAME_ALLOC (name, symname_alloced));
       SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
 
       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;