This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[review] Change some arguments to gdb::string_view instead of name+len


Christian Biesinger has uploaded a new patch set version (#2).

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/125
......................................................................

Change some arguments to gdb::string_view instead of name+len

Just some code cleanup. This change has a few benefits:
- Shorter argument list in the functions
- If the caller needs to calculate the string, they no longer
  need to explicitly call strlen
- It is easy to pass std::string to this (done in one place
  currently)

This also updates a couple of places that were passing 0/1 to
a bool parameter.

gdb/ChangeLog:

2019-09-29  Christian Biesinger  <cbiesinger@google.com>

	* coffread.c (record_minimal_symbol): Update.
	(process_coff_symbol): Update.
	* dbxread.c (read_dbx_symtab): Update.
	* dwarf2read.c (add_partial_symbol): Update.
	(fixup_go_packaging): Update.
	(load_partial_dies): Update.
	(new_symbol): Update.
	* elfread.c (record_minimal_symbol): Update.
	* mdebugread.c (parse_partial_symbols): Update.
	(handle_psymbol_enumerators): Update.
	(new_symbol): Update.
	* minsyms.c (minimal_symbol_reader::record_full): Change signature
	to use gdb::string_view instead of name+len.
	* minsyms.h (class minimal_symbol_reader) <record_full>: Likewise.
	* psympriv.h (add_psymbol_to_list): Likewise.
	* psymtab.c (add_psymbol_to_bcache): Likewise.
	(add_psymbol_to_list): Likewise.
	* stabsread.c (define_symbol): Update.
	* symtab.c (symbol_set_names): Change signature to use gdb::string_view.
	* symtab.h (SYMBOL_SET_NAMES): Likewise.
	(symbol_set_names): Likewise.
	* xcoffread.c (scan_xcoff_symtab): Update.

Change-Id: I2675c6865e0368f9c755a1081088a53aa54dda4c
---
M gdb/coffread.c
M gdb/ctfread.c
M gdb/dbxread.c
M gdb/dwarf2read.c
M gdb/elfread.c
M gdb/mdebugread.c
M gdb/minsyms.c
M gdb/minsyms.h
M gdb/psympriv.h
M gdb/psymtab.c
M gdb/stabsread.c
M gdb/symtab.c
M gdb/symtab.h
M gdb/xcoffread.c
14 files changed, 151 insertions(+), 139 deletions(-)



diff --git a/gdb/coffread.c b/gdb/coffread.c
index 869a32b..3fed056 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -462,8 +462,7 @@
       return NULL;
     }
 
-  return reader.record_full (cs->c_name, strlen (cs->c_name), true, address,
-			     type, section);
+  return reader.record_full (cs->c_name, true, address, type, section);
 }
 
 /* coff_symfile_init ()
@@ -1569,7 +1568,7 @@
   name = EXTERNAL_NAME (name, objfile->obfd);
   SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language,
 		       &objfile->objfile_obstack);
-  SYMBOL_SET_NAMES (sym, name, strlen (name), 1, objfile);
+  SYMBOL_SET_NAMES (sym, name, true, objfile);
 
   /* default assumptions */
   SYMBOL_VALUE (sym) = cs->c_value;
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 44ccff6..0e80150 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -380,7 +380,7 @@
       OBJSTAT (ccp->of, n_syms++);
 
       SYMBOL_SET_LANGUAGE (sym, language_c, &ccp->of->objfile_obstack);
-      SYMBOL_SET_NAMES (sym, name, strlen (name), 0, ccp->of);
+      SYMBOL_SET_NAMES (sym, name, false, ccp->of);
       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       SYMBOL_TYPE (sym) = fip->ptype;
@@ -409,7 +409,7 @@
       OBJSTAT (objfile, n_syms++);
 
       SYMBOL_SET_LANGUAGE (sym, language_c, &objfile->objfile_obstack);
-      SYMBOL_SET_NAMES (sym, name.get (), strlen (name.get ()), 1, objfile);
+      SYMBOL_SET_NAMES (sym, name.get (), true, objfile);
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
 
@@ -1029,7 +1029,7 @@
 	if (type)
 	  {
 	    sym = new_symbol (ccp, type, id);
-	    SYMBOL_SET_NAMES (sym, name, strlen (name), 0, ccp->of);
+	    SYMBOL_SET_NAMES (sym, name, false, ccp->of);
 	  }
 	break;
       case CTF_K_STRUCT:
@@ -1045,7 +1045,7 @@
 	SYMBOL_TYPE (sym) = type;
 	SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 	SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
-	SYMBOL_SET_NAMES (sym, name, strlen (name), 0, ccp->of);
+	SYMBOL_SET_NAMES (sym, name, false, ccp->of);
 	add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
 	break;
       default:
@@ -1365,7 +1365,7 @@
 	return 0;
     }
 
-    add_psymbol_to_list (name.get (), strlen (name.get ()), true,
+    add_psymbol_to_list (name.get (), true,
 			 domain, aclass, section,
 			 psymbol_placement::GLOBAL,
 			 0, language_c, ccp->of);
@@ -1380,7 +1380,7 @@
 {
   ctf_context_t *ccp = (ctf_context_t *) arg;
 
-  add_psymbol_to_list (name, strlen (name), true,
+  add_psymbol_to_list (name, true,
 		       VAR_DOMAIN, LOC_STATIC, -1,
 		       psymbol_placement::GLOBAL,
 		       0, language_c, ccp->of);
@@ -1445,7 +1445,7 @@
       else
 	aclass = LOC_TYPEDEF;
 
-      add_psymbol_to_list (tname.get (), strlen (tname.get ()), true,
+      add_psymbol_to_list (tname.get (), true,
 			   tdomain, aclass, -1,
 			   psymbol_placement::STATIC,
 			   0, language_c, of);
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 564c5d3..16727ef 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -1464,7 +1464,7 @@
 	      if (gdbarch_static_transform_name_p (gdbarch))
 		gdbarch_static_transform_name (gdbarch, namestring);
 
-	      add_psymbol_to_list (sym_name, sym_len, true,
+	      add_psymbol_to_list (gdb::string_view (sym_name, sym_len), true,
 				   VAR_DOMAIN, LOC_STATIC,
 				   data_sect_index,
 				   psymbol_placement::STATIC,
@@ -1474,7 +1474,7 @@
 	    case 'G':
 	      /* The addresses in these entries are reported to be
 		 wrong.  See the code that reads 'G's for symtabs.  */
-	      add_psymbol_to_list (sym_name, sym_len, true,
+	      add_psymbol_to_list (gdb::string_view (sym_name, sym_len), true,
 				   VAR_DOMAIN, LOC_STATIC,
 				   data_sect_index,
 				   psymbol_placement::GLOBAL,
@@ -1492,15 +1492,15 @@
 		  || (p == namestring + 1
 		      && namestring[0] != ' '))
 		{
-		  add_psymbol_to_list (sym_name, sym_len, true,
-				       STRUCT_DOMAIN, LOC_TYPEDEF, -1,
+		  add_psymbol_to_list (gdb::string_view (sym_name, sym_len),
+				       true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				       psymbol_placement::STATIC,
 				       0, psymtab_language, objfile);
 		  if (p[2] == 't')
 		    {
 		      /* Also a typedef with the same name.  */
-		      add_psymbol_to_list (sym_name, sym_len, true,
-					   VAR_DOMAIN, LOC_TYPEDEF, -1,
+		      add_psymbol_to_list (gdb::string_view (sym_name, sym_len),
+					   true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					   psymbol_placement::STATIC,
 					   0, psymtab_language, objfile);
 		      p += 1;
@@ -1511,8 +1511,8 @@
 	    case 't':
 	      if (p != namestring)	/* a name is there, not just :T...  */
 		{
-		  add_psymbol_to_list (sym_name, sym_len, true,
-				       VAR_DOMAIN, LOC_TYPEDEF, -1,
+		  add_psymbol_to_list (gdb::string_view (sym_name, sym_len),
+				       true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				       psymbol_placement::STATIC,
 				       0, psymtab_language, objfile);
 		}
@@ -1572,7 +1572,7 @@
 			;
 		      /* Note that the value doesn't matter for
 			 enum constants in psymtabs, just in symtabs.  */
-		      add_psymbol_to_list (p, q - p, true,
+		      add_psymbol_to_list (gdb::string_view (p, q - p), true,
 					   VAR_DOMAIN, LOC_CONST, -1,
 					   psymbol_placement::STATIC, 0,
 					   psymtab_language, objfile);
@@ -1590,7 +1590,7 @@
 
 	    case 'c':
 	      /* Constant, e.g. from "const" in Pascal.  */
-	      add_psymbol_to_list (sym_name, sym_len, true,
+	      add_psymbol_to_list (gdb::string_view (sym_name, sym_len), true,
 				   VAR_DOMAIN, LOC_CONST, -1,
 				   psymbol_placement::STATIC, 0,
 				   psymtab_language, objfile);
@@ -1645,7 +1645,7 @@
 		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
-	      add_psymbol_to_list (sym_name, sym_len, true,
+	      add_psymbol_to_list (gdb::string_view (sym_name, sym_len), true,
 				   VAR_DOMAIN, LOC_BLOCK,
 				   SECT_OFF_TEXT (objfile),
 				   psymbol_placement::STATIC,
@@ -1704,7 +1704,7 @@
 		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
-	      add_psymbol_to_list (sym_name, sym_len, true,
+	      add_psymbol_to_list (gdb::string_view (sym_name, sym_len), true,
 				   VAR_DOMAIN, LOC_BLOCK,
 				   SECT_OFF_TEXT (objfile),
 				   psymbol_placement::GLOBAL,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0443b55..f842f50 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8922,7 +8922,7 @@
              But in Ada and Fortran, we want to be able to access nested
              procedures globally.  So all Ada and Fortran subprograms are
              stored in the global scope.  */
-	  add_psymbol_to_list (actual_name, strlen (actual_name),
+	  add_psymbol_to_list (actual_name,
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_BLOCK,
 			       SECT_OFF_TEXT (objfile),
@@ -8932,7 +8932,7 @@
 	}
       else
 	{
-	  add_psymbol_to_list (actual_name, strlen (actual_name),
+	  add_psymbol_to_list (actual_name,
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_BLOCK,
 			       SECT_OFF_TEXT (objfile),
@@ -8944,7 +8944,7 @@
 	set_objfile_main_name (objfile, actual_name, cu->language);
       break;
     case DW_TAG_constant:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
 			   built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
 			   -1, (pdi->is_external
 				? psymbol_placement::GLOBAL
@@ -8980,7 +8980,7 @@
 	     table building.  */
 
 	  if (pdi->d.locdesc || pdi->has_type)
-	    add_psymbol_to_list (actual_name, strlen (actual_name),
+	    add_psymbol_to_list (actual_name,
 				 built_actual_name != NULL,
 				 VAR_DOMAIN, LOC_STATIC,
 				 SECT_OFF_TEXT (objfile),
@@ -8999,7 +8999,7 @@
 	      return;
 	    }
 
-	  add_psymbol_to_list (actual_name, strlen (actual_name),
+	  add_psymbol_to_list (actual_name,
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_STATIC,
 			       SECT_OFF_TEXT (objfile),
@@ -9011,7 +9011,7 @@
     case DW_TAG_typedef:
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
 			   built_actual_name != NULL,
 			   VAR_DOMAIN, LOC_TYPEDEF, -1,
 			   psymbol_placement::STATIC,
@@ -9019,7 +9019,7 @@
       break;
     case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
 			   built_actual_name != NULL,
 			   VAR_DOMAIN, LOC_TYPEDEF, -1,
 			   psymbol_placement::GLOBAL,
@@ -9030,7 +9030,7 @@
          available without any name.  If so, we skip the module as it
          doesn't bring any value.  */
       if (actual_name != nullptr)
-	add_psymbol_to_list (actual_name, strlen (actual_name),
+	add_psymbol_to_list (actual_name,
 			     built_actual_name != NULL,
 			     MODULE_DOMAIN, LOC_TYPEDEF, -1,
 			     psymbol_placement::GLOBAL,
@@ -9054,7 +9054,7 @@
 
       /* NOTE: carlton/2003-10-07: See comment in new_symbol about
 	 static vs. global.  */
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
 			   built_actual_name != NULL,
 			   STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 			   cu->language == language_cplus
@@ -9064,7 +9064,7 @@
 
       break;
     case DW_TAG_enumerator:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
 			   built_actual_name != NULL,
 			   VAR_DOMAIN, LOC_CONST, -1,
 			   cu->language == language_cplus
@@ -9894,8 +9894,7 @@
 
       sym = allocate_symbol (objfile);
       SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack);
-      SYMBOL_SET_NAMES (sym, saved_package_name,
-			strlen (saved_package_name), 0, objfile);
+      SYMBOL_SET_NAMES (sym, saved_package_name, false, objfile);
       /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
 	 e.g., "main" finds the "main" module and not C's main().  */
       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
@@ -18536,7 +18535,7 @@
 	      || pdi.tag == DW_TAG_subrange_type))
 	{
 	  if (building_psymtab && pdi.name != NULL)
-	    add_psymbol_to_list (pdi.name, strlen (pdi.name), false,
+	    add_psymbol_to_list (pdi.name, false,
 				 VAR_DOMAIN, LOC_TYPEDEF, -1,
 				 psymbol_placement::STATIC,
 				 0, cu->language, objfile);
@@ -18570,7 +18569,7 @@
 	  if (pdi.name == NULL)
 	    complaint (_("malformed enumerator DIE ignored"));
 	  else if (building_psymtab)
-	    add_psymbol_to_list (pdi.name, strlen (pdi.name), false,
+	    add_psymbol_to_list (pdi.name, false,
 				 VAR_DOMAIN, LOC_CONST, -1,
 				 cu->language == language_cplus
 				 ? psymbol_placement::GLOBAL
@@ -21564,7 +21563,7 @@
       /* Cache this symbol's name and the name's demangled form (if any).  */
       SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
       linkagename = dwarf2_physname (name, die, cu);
-      SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
+      SYMBOL_SET_NAMES (sym, linkagename, false, objfile);
 
       /* Fortran does not have mangling standard and the mangling does differ
 	 between gfortran, iFort etc.  */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 53bdd35..6440d12 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -210,8 +210,8 @@
     address = gdbarch_addr_bits_remove (gdbarch, address);
 
   struct minimal_symbol *result
-    = reader.record_full (name, name_len, copy_name, address,
-			  ms_type,
+    = reader.record_full (gdb::string_view (name, name_len), copy_name,
+			  address, ms_type,
 			  gdb_bfd_section_index (objfile->obfd,
 						 bfd_section));
   if ((objfile->flags & OBJF_MAINLINE) == 0
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index eed7146..11e2a22 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3048,8 +3048,9 @@
 			  namestring = gdbarch_static_transform_name
 					 (gdbarch, namestring);
 
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_STATIC,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_STATIC,
 					     SECT_OFF_DATA (objfile),
 					     psymbol_placement::STATIC,
 					     sh.value,
@@ -3059,8 +3060,9 @@
 			/* The addresses in these entries are reported
 			   to be wrong.  See the code that reads 'G's
 			   for symtabs.  */
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_STATIC,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_STATIC,
 					     SECT_OFF_DATA (objfile),
 					     psymbol_placement::GLOBAL,
 					     sh.value,
@@ -3078,21 +3080,20 @@
 			    || (p == namestring + 1
 				&& namestring[0] != ' '))
 			  {
-			    add_psymbol_to_list (namestring, p - namestring, true,
-						 STRUCT_DOMAIN, LOC_TYPEDEF,
-						 -1,
-						 psymbol_placement::STATIC,
-						 0, psymtab_language, objfile);
+			    add_psymbol_to_list
+			      (gdb::string_view (namestring, p - namestring),
+			       true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
+			       psymbol_placement::STATIC, 0, psymtab_language,
+			       objfile);
 			    if (p[2] == 't')
 			      {
 				/* Also a typedef with the same name.  */
-				add_psymbol_to_list (namestring,
-						     p - namestring, true,
-						     VAR_DOMAIN, LOC_TYPEDEF,
-						     -1,
-						     psymbol_placement::STATIC,
-						     0, psymtab_language,
-						     objfile);
+				add_psymbol_to_list
+				  (gdb::string_view (namestring,
+						     p - namestring),
+				   true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+				   psymbol_placement::STATIC, 0,
+				   psymtab_language, objfile);
 				p += 1;
 			      }
 			  }
@@ -3101,11 +3102,12 @@
 			if (p != namestring)	/* a name is there, not
 						   just :T...  */
 			  {
-			    add_psymbol_to_list (namestring, p - namestring,
-						 true, VAR_DOMAIN, LOC_TYPEDEF,
-						 -1,
-						 psymbol_placement::STATIC,
-						 0, psymtab_language, objfile);
+			    add_psymbol_to_list
+			      (gdb::string_view (namestring,
+						 p - namestring),
+			       true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+			       psymbol_placement::STATIC, 0, psymtab_language,
+			       objfile);
 			  }
 		      check_enum:
 			/* If this is an enumerated type, we need to add
@@ -3166,9 +3168,10 @@
 				/* Note that the value doesn't matter for
 				   enum constants in psymtabs, just in
 				   symtabs.  */
-				add_psymbol_to_list (p, q - p, true,
-						     VAR_DOMAIN, LOC_CONST,
-						     -1,
+				add_psymbol_to_list (gdb::string_view (p,
+								       q - p),
+						     true, VAR_DOMAIN,
+						     LOC_CONST, -1,
 						     psymbol_placement::STATIC,
 						     0, psymtab_language,
 						     objfile);
@@ -3185,8 +3188,9 @@
 			continue;
 		      case 'c':
 			/* Constant, e.g. from "const" in Pascal.  */
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_CONST, -1,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_CONST, -1,
 					     psymbol_placement::STATIC,
 					     0, psymtab_language, objfile);
 			continue;
@@ -3198,8 +3202,9 @@
 			    function_outside_compilation_unit_complaint
 			      (copy.c_str ());
 			  }
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_BLOCK,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_BLOCK,
 					     SECT_OFF_TEXT (objfile),
 					     psymbol_placement::STATIC,
 					     sh.value,
@@ -3217,8 +3222,9 @@
 			    function_outside_compilation_unit_complaint
 			      (copy.c_str ());
 			  }
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_BLOCK,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_BLOCK,
 					     SECT_OFF_TEXT (objfile),
 					     psymbol_placement::GLOBAL,
 					     sh.value,
@@ -3452,13 +3458,13 @@
 		     symbol table, and the MAIN__ symbol via the minimal
 		     symbol table.  */
 		  if (sh.st == stProc)
-		    add_psymbol_to_list (sym_name, strlen (sym_name), true,
+		    add_psymbol_to_list (sym_name, true,
 					 VAR_DOMAIN, LOC_BLOCK,
 					 section,
 					 psymbol_placement::GLOBAL,
 					 sh.value, psymtab_language, objfile);
 		  else
-		    add_psymbol_to_list (sym_name, strlen (sym_name), true,
+		    add_psymbol_to_list (sym_name, true,
 					 VAR_DOMAIN, LOC_BLOCK,
 					 section,
 					 psymbol_placement::STATIC,
@@ -3525,7 +3531,7 @@
 		      && sh.iss != 0
 		      && sh.index != cur_sdx + 2)
 		    {
-		      add_psymbol_to_list (sym_name, strlen (sym_name), true,
+		      add_psymbol_to_list (sym_name, true,
 					   STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					   psymbol_placement::STATIC,
 					   0, psymtab_language, objfile);
@@ -3565,7 +3571,7 @@
 		  continue;
 		}
 	      /* Use this gdb symbol.  */
-	      add_psymbol_to_list (sym_name, strlen (sym_name), true,
+	      add_psymbol_to_list (sym_name, true,
 				   VAR_DOMAIN, theclass, section,
 				   psymbol_placement::STATIC,
 				   sh.value, psymtab_language, objfile);
@@ -3644,7 +3650,7 @@
 		  break;
 		}
 	      char *sym_name = debug_info->ssext + psh->iss;
-	      add_psymbol_to_list (sym_name, strlen (sym_name), true,
+	      add_psymbol_to_list (sym_name, true,
 				   VAR_DOMAIN, theclass,
 				   section,
 				   psymbol_placement::GLOBAL,
@@ -3807,7 +3813,7 @@
 
       /* Note that the value doesn't matter for enum constants
          in psymtabs, just in symtabs.  */
-      add_psymbol_to_list (name, strlen (name), true,
+      add_psymbol_to_list (name, true,
 			   VAR_DOMAIN, LOC_CONST, -1,
 			   psymbol_placement::STATIC, 0,
 			   psymtab_language, objfile);
@@ -4758,7 +4764,7 @@
 
   SYMBOL_SET_LANGUAGE (s, psymtab_language,
 		       &mdebugread_objfile->objfile_obstack);
-  SYMBOL_SET_NAMES (s, name, strlen (name), 1, mdebugread_objfile);
+  SYMBOL_SET_NAMES (s, name, true, mdebugread_objfile);
   return s;
 }
 
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index c41e5c3..1f123f7 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1086,7 +1086,7 @@
 /* See minsyms.h.  */
 
 struct minimal_symbol *
-minimal_symbol_reader::record_full (const char *name, int name_len,
+minimal_symbol_reader::record_full (gdb::string_view name,
 				    bool copy_name, CORE_ADDR address,
 				    enum minimal_symbol_type ms_type,
 				    int section)
@@ -1100,24 +1100,22 @@
      lookup_minimal_symbol_by_pc would have no way of getting the
      right one.  */
   if (ms_type == mst_file_text && name[0] == 'g'
-      && (strcmp (name, GCC_COMPILED_FLAG_SYMBOL) == 0
-	  || strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0))
+      && (name == GCC_COMPILED_FLAG_SYMBOL
+	  || name == GCC2_COMPILED_FLAG_SYMBOL))
     return (NULL);
 
   /* It's safe to strip the leading char here once, since the name
      is also stored stripped in the minimal symbol table.  */
   if (name[0] == get_symbol_leading_char (m_objfile->obfd))
-    {
-      ++name;
-      --name_len;
-    }
+    name = name.substr (1);
 
   if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
     return (NULL);
 
   if (symtab_create_debug >= 2)
-    printf_unfiltered ("Recording minsym:  %-21s  %18s  %4d  %s\n",
-               mst_str (ms_type), hex_string (address), section, name);
+    printf_unfiltered ("Recording minsym:  %-21s  %18s  %4d  %.*s\n",
+               mst_str (ms_type), hex_string (address), section,
+	       (int) name.size (), name.data ());
 
   if (m_msym_bunch_index == BUNCH_SIZE)
     {
@@ -1129,7 +1127,7 @@
   msymbol = &m_msym_bunch->contents[m_msym_bunch_index];
   symbol_set_language (msymbol, language_auto,
 		       &m_objfile->per_bfd->storage_obstack);
-  symbol_set_names (msymbol, name, name_len, copy_name, m_objfile->per_bfd);
+  symbol_set_names (msymbol, name, copy_name, m_objfile->per_bfd);
 
   SET_MSYMBOL_VALUE_ADDRESS (msymbol, address);
   MSYMBOL_SECTION (msymbol) = section;
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 0a19f0b..deaecb4 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -88,7 +88,6 @@
      Arguments are:
 
      NAME - the symbol's name
-     NAME_LEN - the length of the name
      COPY_NAME - if true, the minsym code must make a copy of NAME.  If
      false, then NAME must be NUL-terminated, and must have a lifetime
      that is at least as long as OBJFILE's lifetime.
@@ -97,15 +96,14 @@
      SECTION - the symbol's section
   */
 
-  struct minimal_symbol *record_full (const char *name,
-				      int name_len,
+  struct minimal_symbol *record_full (gdb::string_view name,
 				      bool copy_name,
 				      CORE_ADDR address,
 				      enum minimal_symbol_type ms_type,
 				      int section);
 
   /* Like record_full, but:
-     - uses strlen to compute NAME_LEN,
+     - computes the length of NAME
      - passes COPY_NAME = true,
      - and passes a default SECTION, depending on the type
 
@@ -115,7 +113,7 @@
 	       enum minimal_symbol_type ms_type);
 
   /* Like record_full, but:
-     - uses strlen to compute NAME_LEN,
+     - computes the length of NAME
      - passes COPY_NAME = true.
 
      This variant does not return the new symbol.  */
@@ -124,7 +122,7 @@
 			 enum minimal_symbol_type ms_type,
 			 int section)
   {
-    record_full (name, strlen (name), true, address, ms_type, section);
+    record_full (name, true, address, ms_type, section);
   }
 
  private:
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 3e89742..9404c46 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -22,6 +22,7 @@
 
 #include "psymtab.h"
 #include "objfiles.h"
+#include "gdbsupport/gdb_string_view.h"
 
 /* A partial_symbol records the name, domain, and address class of
    symbols whose types we have not parsed yet.  For functions, it also
@@ -304,14 +305,13 @@
    LANGUAGE is the language from which the symbol originates.  This will
    influence, amongst other things, how the symbol name is demangled. */
 
-extern void add_psymbol_to_list (const char *name, int namelength,
-				 bool copy_name, domain_enum domain,
-				 enum address_class theclass,
-				 short section,
-				 psymbol_placement where,
-				 CORE_ADDR coreaddr,
-				 enum language language,
-				 struct objfile *objfile);
+extern void add_psymbol_to_list (gdb::string_view,
+				 bool, domain_enum,
+				 enum address_class,
+				 short /* section */,
+				 enum psymbol_placement,
+				 CORE_ADDR,
+				 enum language, struct objfile *);
 
 /* Initialize storage for partial symbols.  If partial symbol storage
    has already been initialized, this does nothing.  TOTAL_SYMBOLS is
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 31b6d59..b30d29e 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1568,7 +1568,7 @@
    different domain (or address) is possible and correct.  */
 
 static struct partial_symbol *
-add_psymbol_to_bcache (const char *name, int namelength, bool copy_name,
+add_psymbol_to_bcache (gdb::string_view name, bool copy_name,
 		       domain_enum domain,
 		       enum address_class theclass,
 		       short section,
@@ -1585,7 +1585,7 @@
   psymbol.aclass = theclass;
   symbol_set_language (&psymbol.ginfo, language,
 		       objfile->partial_symtabs->obstack ());
-  symbol_set_names (&psymbol.ginfo, name, namelength, copy_name,
+  symbol_set_names (&psymbol.ginfo, name, copy_name,
 		    objfile->per_bfd);
 
   /* Stash the partial symbol away in the cache.  */
@@ -1608,7 +1608,7 @@
 /* See psympriv.h.  */
 
 void
-add_psymbol_to_list (const char *name, int namelength, bool copy_name,
+add_psymbol_to_list (gdb::string_view name, bool copy_name,
 		     domain_enum domain,
 		     enum address_class theclass,
 		     short section,
@@ -1621,7 +1621,7 @@
   int added;
 
   /* Stash the partial symbol away in the cache.  */
-  psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, theclass,
+  psym = add_psymbol_to_bcache (name, copy_name, domain, theclass,
 				section, coreaddr, language, objfile, &added);
 
   /* Do not duplicate global partial symbols.  */
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index fa2521f..7658072 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -752,11 +752,12 @@
       if (!new_name.empty ())
 	{
 	  SYMBOL_SET_NAMES (sym,
-			    new_name.c_str (), new_name.length (),
+			    new_name,
 			    1, objfile);
 	}
       else
-	SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
+	SYMBOL_SET_NAMES (sym, gdb::string_view (string, p - string), true,
+			  objfile);
 
       if (SYMBOL_LANGUAGE (sym) == language_cplus)
 	cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8a551f1..3078f87 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -811,7 +811,7 @@
 
 void
 symbol_set_names (struct general_symbol_info *gsymbol,
-		  const char *linkage_name, int len, bool copy_name,
+		  gdb::string_view linkage_name, bool copy_name,
 		  struct objfile_per_bfd_storage *per_bfd)
 {
   struct demangled_name_entry **slot;
@@ -824,14 +824,14 @@
       /* In Ada, we do the symbol lookups using the mangled name, so
          we can save some space by not storing the demangled name.  */
       if (!copy_name)
-	gsymbol->name = linkage_name;
+	gsymbol->name = linkage_name.data ();
       else
 	{
 	  char *name = (char *) obstack_alloc (&per_bfd->storage_obstack,
-					       len + 1);
+					       linkage_name.length () + 1);
 
-	  memcpy (name, linkage_name, len);
-	  name[len] = '\0';
+	  memcpy (name, linkage_name.data (), linkage_name.length ());
+	  name[linkage_name.length ()] = '\0';
 	  gsymbol->name = name;
 	}
       symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack);
@@ -842,18 +842,20 @@
   if (per_bfd->demangled_names_hash == NULL)
     create_demangled_names_hash (per_bfd);
 
-  if (linkage_name[len] != '\0')
+  /* Don't use string_view::operator[] because we are accessing beyond
+     the size of the string_view, which is technically unsupported.  */
+  if (linkage_name.data ()[linkage_name.length ()] != '\0')
     {
       char *alloc_name;
 
-      alloc_name = (char *) alloca (len + 1);
-      memcpy (alloc_name, linkage_name, len);
-      alloc_name[len] = '\0';
+      alloc_name = (char *) alloca (linkage_name.length () + 1);
+      memcpy (alloc_name, linkage_name.data (), linkage_name.length ());
+      alloc_name[linkage_name.length ()] = '\0';
 
       linkage_name_copy = alloc_name;
     }
   else
-    linkage_name_copy = linkage_name;
+    linkage_name_copy = linkage_name.data ();
 
   entry.mangled = linkage_name_copy;
   slot = ((struct demangled_name_entry **)
@@ -881,14 +883,14 @@
 	 It turns out that it is actually important to still save such
 	 an entry in the hash table, because storing this name gives
 	 us better bcache hit rates for partial symbols.  */
-      if (!copy_name && linkage_name_copy == linkage_name)
+      if (!copy_name && linkage_name_copy == linkage_name.data ())
 	{
 	  *slot
 	    = ((struct demangled_name_entry *)
 	       obstack_alloc (&per_bfd->storage_obstack,
 			      offsetof (struct demangled_name_entry, demangled)
 			      + demangled_len + 1));
-	  (*slot)->mangled = linkage_name;
+	  (*slot)->mangled = linkage_name.data ();
 	}
       else
 	{
@@ -901,7 +903,7 @@
 	    = ((struct demangled_name_entry *)
 	       obstack_alloc (&per_bfd->storage_obstack,
 			      offsetof (struct demangled_name_entry, demangled)
-			      + len + demangled_len + 2));
+			      + linkage_name.length () + demangled_len + 2));
 	  mangled_ptr = &((*slot)->demangled[demangled_len + 1]);
 	  strcpy (mangled_ptr, linkage_name_copy);
 	  (*slot)->mangled = mangled_ptr;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index dc65409..6646e7d 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -29,6 +29,7 @@
 #include "gdbsupport/enum-flags.h"
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/gdb_optional.h"
+#include "gdbsupport/gdb_string_view.h"
 #include "gdbsupport/next-iterator.h"
 #include "completer.h"
 
@@ -505,11 +506,11 @@
 
 /* Set the linkage and natural names of a symbol, by demangling
    the linkage name.  */
-#define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile)	\
-  symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, \
+#define SYMBOL_SET_NAMES(symbol,linkage_name,copy_name,objfile)	\
+  symbol_set_names (&(symbol)->ginfo, linkage_name, copy_name, \
 		    (objfile)->per_bfd)
 extern void symbol_set_names (struct general_symbol_info *symbol,
-			      const char *linkage_name, int len, bool copy_name,
+			      gdb::string_view linkage_name, bool copy_name,
 			      struct objfile_per_bfd_storage *per_bfd);
 
 /* Now come lots of name accessor macros.  Short version as to when to
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index aec1923..9deae88 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2646,8 +2646,9 @@
 		  namestring = gdbarch_static_transform_name
 				 (gdbarch, namestring);
 
-		add_psymbol_to_list (namestring, p - namestring, true,
-				     VAR_DOMAIN, LOC_STATIC,
+		add_psymbol_to_list (gdb::string_view (namestring,
+						       p - namestring),
+				     true, VAR_DOMAIN, LOC_STATIC,
 				     SECT_OFF_DATA (objfile),
 				     psymbol_placement::STATIC,
 				     symbol.n_value,
@@ -2657,8 +2658,9 @@
 	      case 'G':
 		/* The addresses in these entries are reported to be
 		   wrong.  See the code that reads 'G's for symtabs.  */
-		add_psymbol_to_list (namestring, p - namestring, true,
-				     VAR_DOMAIN, LOC_STATIC,
+		add_psymbol_to_list (gdb::string_view (namestring,
+						       p - namestring),
+				     true, VAR_DOMAIN, LOC_STATIC,
 				     SECT_OFF_DATA (objfile),
 				     psymbol_placement::GLOBAL,
 				     symbol.n_value,
@@ -2676,15 +2678,17 @@
 		    || (p == namestring + 1
 			&& namestring[0] != ' '))
 		  {
-		    add_psymbol_to_list (namestring, p - namestring, true,
-					 STRUCT_DOMAIN, LOC_TYPEDEF, -1,
+		    add_psymbol_to_list (gdb::string_view (namestring,
+							   p - namestring),
+					 true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					 psymbol_placement::STATIC,
 					 0, psymtab_language, objfile);
 		    if (p[2] == 't')
 		      {
 			/* Also a typedef with the same name.  */
-			add_psymbol_to_list (namestring, p - namestring, true,
-					     VAR_DOMAIN, LOC_TYPEDEF, -1,
+			add_psymbol_to_list (gdb::string_view (namestring,
+							       p - namestring),
+					     true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					     psymbol_placement::STATIC,
 					     0, psymtab_language, objfile);
 			p += 1;
@@ -2695,8 +2699,9 @@
 	      case 't':
 		if (p != namestring)	/* a name is there, not just :T...  */
 		  {
-		    add_psymbol_to_list (namestring, p - namestring, true,
-					 VAR_DOMAIN, LOC_TYPEDEF, -1,
+		    add_psymbol_to_list (gdb::string_view (namestring,
+							   p - namestring),
+					 true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					 psymbol_placement::STATIC,
 					 0, psymtab_language, objfile);
 		  }
@@ -2757,7 +2762,7 @@
 			  ;
 			/* Note that the value doesn't matter for
 			   enum constants in psymtabs, just in symtabs.  */
-			add_psymbol_to_list (p, q - p, true,
+			add_psymbol_to_list (gdb::string_view (p, q - p), true,
 					     VAR_DOMAIN, LOC_CONST, -1,
 					     psymbol_placement::STATIC,
 					     0, psymtab_language, objfile);
@@ -2775,8 +2780,9 @@
 
 	      case 'c':
 		/* Constant, e.g. from "const" in Pascal.  */
-		add_psymbol_to_list (namestring, p - namestring, true,
-				     VAR_DOMAIN, LOC_CONST, -1,
+		add_psymbol_to_list (gdb::string_view (namestring,
+						       p - namestring),
+				     true, VAR_DOMAIN, LOC_CONST, -1,
 				     psymbol_placement::STATIC,
 				     0, psymtab_language, objfile);
 		continue;
@@ -2792,8 +2798,9 @@
 		    function_outside_compilation_unit_complaint (name);
 		    xfree (name);
 		  }
-		add_psymbol_to_list (namestring, p - namestring, true,
-				     VAR_DOMAIN, LOC_BLOCK,
+		add_psymbol_to_list (gdb::string_view (namestring,
+						       p - namestring),
+				     true, VAR_DOMAIN, LOC_BLOCK,
 				     SECT_OFF_TEXT (objfile),
 				     psymbol_placement::STATIC,
 				     symbol.n_value,
@@ -2822,8 +2829,9 @@
 		if (startswith (namestring, "@FIX"))
 		  continue;
 
-		add_psymbol_to_list (namestring, p - namestring, true,
-				     VAR_DOMAIN, LOC_BLOCK,
+		add_psymbol_to_list (gdb::string_view (namestring,
+						       p - namestring),
+				     true, VAR_DOMAIN, LOC_BLOCK,
 				     SECT_OFF_TEXT (objfile),
 				     psymbol_placement::GLOBAL,
 				     symbol.n_value,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]