[binutils-gdb] gdb/gdbtypes: replace TYPE_SAFE_NAME macro with method

Simon Marchi via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7662807a0bc61d46a60dddaa9a7a9ee9608107f4

commit 7662807a0bc61d46a60dddaa9a7a9ee9608107f4
Author: Simon Marchi <[email protected]>
Date:   Tue Feb 17 14:13:56 2026 -0500

    gdb/gdbtypes: replace TYPE_SAFE_NAME macro with method
    
    Replace the TYPE_SAFE_NAME macro with the method type::safe_name.
    
    Change-Id: I7ecaa6e5f88383821d2f227474c1c146ff731ff6
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/c-exp.y      | 12 ++++++------
 gdb/d-exp.y      |  4 ++--
 gdb/f-exp.y      |  6 +++---
 gdb/f-lang.c     |  6 +++---
 gdb/gdbtypes.h   | 13 +++++++------
 gdb/gnu-v3-abi.c |  4 ++--
 gdb/riscv-tdep.c |  2 +-
 gdb/typeprint.h  |  2 +-
 gdb/valops.c     |  8 ++++----
 9 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 63e98bfb596..a4a910df712 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1119,7 +1119,7 @@ qualified_name:	TYPENAME COLONCOLON name
 			  type = check_typedef (type);
 			  if (!type_aggregate_p (type))
 			    error (_("`%s' is not defined as an aggregate type."),
-				   TYPE_SAFE_NAME (type));
+				   type->safe_name ());
 
 			  pstate->push_new<scope_operation> (type,
 							     copy_name ($3));
@@ -1131,7 +1131,7 @@ qualified_name:	TYPENAME COLONCOLON name
 			  type = check_typedef (type);
 			  if (!type_aggregate_p (type))
 			    error (_("`%s' is not defined as an aggregate type."),
-				   TYPE_SAFE_NAME (type));
+				   type->safe_name ());
 			  std::string name = "~" + std::string ($4.ptr,
 								$4.length);
 
@@ -1145,7 +1145,7 @@ qualified_name:	TYPENAME COLONCOLON name
 			  std::string copy = copy_name ($3);
 			  error (_("No type \"%s\" within class "
 				   "or namespace \"%s\"."),
-				 copy.c_str (), TYPE_SAFE_NAME ($1.type));
+				 copy.c_str (), $1.type->safe_name ());
 			}
 	;
 
@@ -3341,7 +3341,7 @@ handle_qualified_field_name (qualified_name_token token)
   type = check_typedef (type);
   if (!type_aggregate_p (type))
     error (_("`%s' is not defined as an aggregate type."),
-	   TYPE_SAFE_NAME (type));
+	   type->safe_name ());
   if (token.name[0] == '~')
     destructor_name_p (token.name, type);
   pstate->push_new<scope_operation> (type, token.name);
@@ -3574,7 +3574,7 @@ c_print_token (FILE *file, int type, YYSTYPE value)
     {
     case INT:
       parser_fprintf (file, "typed_val_int<%s, %s>",
-		      TYPE_SAFE_NAME (value.typed_val_int.type),
+		      value.typed_val_int.type->safe_name (),
 		      pulongest (value.typed_val_int.val));
       break;
 
@@ -3592,7 +3592,7 @@ c_print_token (FILE *file, int type, YYSTYPE value)
 
     case TYPENAME:
       parser_fprintf (file, "tsym<type=%s, name=%s>",
-		      TYPE_SAFE_NAME (value.tsym.type),
+		      value.tsym.type->safe_name (),
 		      copy_name (value.tsym.stoken).c_str ());
       break;
 
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 963a853023c..a3b1b507ef9 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -483,7 +483,7 @@ PrimaryExpression:
 			  if (type->code () == TYPE_CODE_MODULE)
 			    {
 			      struct block_symbol sym;
-			      const char *type_name = TYPE_SAFE_NAME (type);
+			      const char *type_name = type->safe_name ();
 			      int type_name_len = strlen (type_name);
 			      std::string name
 				= string_printf ("%.*s.%.*s",
@@ -502,7 +502,7 @@ PrimaryExpression:
 				 of an aggregate or an enum type.  */
 			      if (!type_aggregate_p (type))
 				error (_("`%s' is not defined as an aggregate type."),
-				       TYPE_SAFE_NAME (type));
+				       type->safe_name ());
 
 			      pstate->push_new<scope_operation>
 				(type, copy_name ($3));
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index de4b7d473cf..278e2091403 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -756,7 +756,7 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			{ $$ = parse_f_type (pstate)->builtin_real_s16;
 			  if ($$->code () == TYPE_CODE_ERROR)
 			    error (_("unsupported type %s"),
-				   TYPE_SAFE_NAME ($$));
+				   $$->safe_name ());
 			}
 	|	COMPLEX_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_complex; }
@@ -768,7 +768,7 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			{ $$ = parse_f_type (pstate)->builtin_complex_s16;
 			  if ($$->code () == TYPE_CODE_ERROR)
 			    error (_("unsupported type %s"),
-				   TYPE_SAFE_NAME ($$));
+				   $$->safe_name ());
 			}
 	|	SINGLE PRECISION
 			{ $$ = parse_f_type (pstate)->builtin_real;}
@@ -1228,7 +1228,7 @@ convert_to_kind_type (struct type *basetype, int kind)
 
   if (res == nullptr || res->code () == TYPE_CODE_ERROR)
     error (_("unsupported kind %d for type %s"),
-	   kind, TYPE_SAFE_NAME (basetype));
+	   kind, basetype->safe_name ());
 
   return res;
 }
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 2cebe14ecb3..e2a34b22ba3 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -772,7 +772,7 @@ eval_op_f_abs (struct type *expect_type, struct expression *exp,
 	return value_from_longest (type, l);
       }
     }
-  error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type));
+  error (_("ABS of type %s not supported"), type->safe_name ());
 }
 
 /* A helper function for BINOP_MOD.  */
@@ -809,7 +809,7 @@ eval_op_f_mod (struct type *expect_type, struct expression *exp,
 	return value_from_longest (arg1->type (), v3);
       }
     }
-  error (_("MOD of type %s not supported"), TYPE_SAFE_NAME (type));
+  error (_("MOD of type %s not supported"), type->safe_name ());
 }
 
 /* A helper function for the different FORTRAN_CEILING overloads.  Calculates
@@ -927,7 +927,7 @@ eval_op_f_modulo (struct type *expect_type, struct expression *exp,
 	return value_from_host_double (type, result);
       }
     }
-  error (_("MODULO of type %s not supported"), TYPE_SAFE_NAME (type));
+  error (_("MODULO of type %s not supported"), type->safe_name ());
 }
 
 /* A helper function for FORTRAN_CMPLX.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 2d1f9937b4e..80886e59f67 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1058,6 +1058,13 @@ struct type
     this->main_type->name = name;
   }
 
+  /* Return the name of this type, or "<unnamed type>" if it has no
+     name.  */
+  const char *safe_name () const
+  {
+    return this->name () != nullptr ? this->name () : _("<unnamed type>");
+  }
+
   /* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
      But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
      so you only have to call check_typedef once.  Since value::allocate
@@ -2043,12 +2050,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
        || TYPE_NFN_FIELDS (thistype) == 0) \
    && ((thistype)->is_stub () || !(thistype)->stub_is_supported ()))
 
-/* * A helper macro that returns the name of a type or "unnamed type"
-   if the type has no name.  */
-
-#define TYPE_SAFE_NAME(type) \
-  (type->name () != nullptr ? type->name () : _("<unnamed type>"))
-
 /* * A helper macro that returns the name of an error type.  If the
    type has a name, it is used; otherwise, a default is used.  */
 
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 1ea9d29c0b9..35910be0f06 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -348,7 +348,7 @@ gnuv3_rtti_type (struct value *value,
       || !startswith (vtable_symbol_name, "vtable for "))
     {
       warning (_("can't find linker symbol for virtual table for `%s' value"),
-	       TYPE_SAFE_NAME (values_type));
+	       values_type->safe_name ());
       if (vtable_symbol_name)
 	warning (_("  found `%s' instead"), vtable_symbol_name);
       return NULL;
@@ -885,7 +885,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
   vt_addr = vtable->field (vtable_field_virtual_functions)->address ();
 
   gdb_printf (_("vtable for '%s' @ %s (subobject @ %s):\n"),
-	      TYPE_SAFE_NAME (type),
+	      type->safe_name (),
 	      paddress (gdbarch, vt_addr),
 	      paddress (gdbarch, (value->address ()
 				  + value->embedded_offset ())));
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 0d2cbd8cbe9..8b06566582c 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -3320,7 +3320,7 @@ riscv_print_arg_location (ui_file *stream, struct gdbarch *gdbarch,
 			  CORE_ADDR sp_refs, CORE_ADDR sp_args)
 {
   gdb_printf (stream, "type: '%s', length: 0x%x, alignment: 0x%x",
-	      TYPE_SAFE_NAME (info->type), info->length, info->align);
+	      info->type->safe_name (), info->length, info->align);
   switch (info->argloc[0].loc_type)
     {
     case riscv_arg_info::location::in_reg:
diff --git a/gdb/typeprint.h b/gdb/typeprint.h
index 36bfbd28743..733baec614f 100644
--- a/gdb/typeprint.h
+++ b/gdb/typeprint.h
@@ -162,7 +162,7 @@ private:
     {
       /* Use check_typedef: the hash must agree with equals, and types_equal
 	 strips typedefs.  */
-      return htab_hash_string (TYPE_SAFE_NAME (check_typedef (t)));
+      return htab_hash_string (check_typedef (t)->safe_name ());
     }
 
     std::size_t operator() (const decl_field *f) const noexcept
diff --git a/gdb/valops.c b/gdb/valops.c
index 3743c8e0c82..7725a230ab2 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1936,7 +1936,7 @@ struct_field_searcher::update_result (struct value *v, LONGEST boffset)
 		 found occupy the same space.  */
 	      && m_last_boffset != boffset)
 	    error (_("base class '%s' is ambiguous in type '%s'"),
-		   m_name, TYPE_SAFE_NAME (m_outermost_type));
+		   m_name, m_outermost_type->safe_name ());
 
 	  m_baseclass = v;
 	  m_last_boffset = boffset;
@@ -2160,15 +2160,15 @@ search_struct_field (const char *name, struct value *arg1,
 		}
 
 	      candidates += string_printf ("\n  '%s %s::%s' (%s)",
-					   TYPE_SAFE_NAME (field_type),
-					   TYPE_SAFE_NAME (struct_type),
+					   field_type->safe_name (),
+					   struct_type->safe_name (),
 					   name,
 					   path.c_str ());
 	    }
 
 	  error (_("Request for member '%s' is ambiguous in type '%s'."
 		   " Candidates are:%s"),
-		 name, TYPE_SAFE_NAME (type),
+		 name, type->safe_name (),
 		 candidates.c_str ());
 	}
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.