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

Message ID 20190930194621.168116-1-cbiesinger@google.com
State Superseded
Headers show
Series
  • [v3] Change some arguments to gdb::string_view instead of name+len
Related show

Commit Message

Christian Biesinger via gdb-patches Sept. 30, 2019, 7:46 p.m.
[Oops, this version also does the substr (1) change]

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.
---
 gdb/coffread.c   |  5 ++-
 gdb/dbxread.c    | 24 +++++++--------
 gdb/dwarf2read.c | 29 +++++++++---------
 gdb/elfread.c    |  4 +--
 gdb/mdebugread.c | 80 ++++++++++++++++++++++++++----------------------
 gdb/minsyms.c    | 18 +++++------
 gdb/minsyms.h    | 10 +++---
 gdb/psympriv.h   | 16 +++++-----
 gdb/psymtab.c    |  8 ++---
 gdb/stabsread.c  |  5 +--
 gdb/symtab.c     | 26 ++++++++--------
 gdb/symtab.h     |  7 +++--
 gdb/xcoffread.c  | 42 +++++++++++++++----------
 13 files changed, 143 insertions(+), 131 deletions(-)

-- 
2.23.0.444.g18eeb5a265-goog

Patch

diff --git a/gdb/coffread.c b/gdb/coffread.c
index c44b69069e..52b9c57b9c 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -462,8 +462,7 @@  record_minimal_symbol (minimal_symbol_reader &reader,
       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 @@  process_coff_symbol (struct coff_symbol *cs,
   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/dbxread.c b/gdb/dbxread.c
index 564c5d3a41..16727ef108 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -1464,7 +1464,7 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	    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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  || (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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	    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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 			;
 		      /* 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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 
 	    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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  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 @@  read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  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 1052501c35..ff0fc7a06a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8922,7 +8922,7 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
              of the global scope.  But in Ada, we want to be able to access
              nested procedures globally.  So all Ada 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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	}
       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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	     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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	      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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
       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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 
       /* 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 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 
       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
@@ -9888,8 +9888,7 @@  fixup_go_packaging (struct dwarf2_cu *cu)
 
       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;
@@ -18533,7 +18532,7 @@  load_partial_dies (const struct die_reader_specs *reader,
 	      || 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);
@@ -18567,7 +18566,7 @@  load_partial_dies (const struct die_reader_specs *reader,
 	  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
@@ -21551,7 +21550,7 @@  new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       /* 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 a3d17e54a2..04b36d3dba 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -203,8 +203,8 @@  record_minimal_symbol (minimal_symbol_reader &reader,
       || ms_type == mst_text_gnu_ifunc)
     address = gdbarch_addr_bits_remove (gdbarch, address);
 
-  return reader.record_full (name, name_len, copy_name, address,
-			     ms_type,
+  return reader.record_full (gdb::string_view (name, name_len), copy_name,
+			     address, ms_type,
 			     gdb_bfd_section_index (objfile->obfd,
 						    bfd_section));
 }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 0956fbdb67..5921251f65 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3048,8 +3048,9 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			  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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			/* 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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			    || (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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 				/* 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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			    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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 			    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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 		     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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 		      && 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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 		  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 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 		  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 @@  handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
 
       /* 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 @@  new_symbol (const char *name)
 
   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 83f5d89577..06825d4dc7 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1063,7 +1063,7 @@  mst_str (minimal_symbol_type t)
 /* 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)
@@ -1077,24 +1077,24 @@  minimal_symbol_reader::record_full (const char *name, int name_len,
      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))
+      && (strcmp (name.data (), GCC_COMPILED_FLAG_SYMBOL) == 0
+	  || strcmp (name.data (), GCC2_COMPILED_FLAG_SYMBOL) == 0))
     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"))
+  if (ms_type == mst_file_text && startswith (name.data (), "__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)
     {
@@ -1106,7 +1106,7 @@  minimal_symbol_reader::record_full (const char *name, int name_len,
   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 ce4b83d544..f62a2b9914 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -88,7 +88,6 @@  class minimal_symbol_reader
      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 @@  class minimal_symbol_reader
      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 @@  class minimal_symbol_reader
 	       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 @@  class minimal_symbol_reader
 			 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 3e89742d8d..9404c46837 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 @@  enum class psymbol_placement
    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 31b6d59777..b30d29e6ef 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1568,7 +1568,7 @@  psymbol_compare (const void *addr1, const void *addr2, int length)
    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 @@  add_psymbol_to_bcache (const char *name, int namelength, bool copy_name,
   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 @@  append_psymbol_to_list (std::vector<partial_symbol *> *list,
 /* 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 @@  add_psymbol_to_list (const char *name, int namelength, bool copy_name,
   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 48c88ded55..d8cb4a5264 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -751,11 +751,12 @@  define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       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 6ea9fc6971..16cb5b7c94 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -811,7 +811,7 @@  symbol_find_demangled_name (struct general_symbol_info *gsymbol,
 
 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 @@  symbol_set_names (struct general_symbol_info *gsymbol,
       /* 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,18 @@  symbol_set_names (struct general_symbol_info *gsymbol,
   if (per_bfd->demangled_names_hash == NULL)
     create_demangled_names_hash (per_bfd);
 
-  if (linkage_name[len] != '\0')
+  if (linkage_name[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 +881,14 @@  symbol_set_names (struct general_symbol_info *gsymbol,
 	 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 +901,7 @@  symbol_set_names (struct general_symbol_info *gsymbol,
 	    = ((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 1f0fc62a65..1546d83029 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"
 
@@ -493,11 +494,11 @@  extern void symbol_set_language (struct general_symbol_info *symbol,
 
 /* 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 2fa2706653..52a700215d 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2644,8 +2644,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 		  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,
@@ -2655,8 +2656,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 	      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,
@@ -2674,15 +2676,17 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 		    || (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;
@@ -2693,8 +2697,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 	      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);
 		  }
@@ -2755,7 +2760,7 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 			  ;
 			/* 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);
@@ -2773,8 +2778,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 
 	      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;
@@ -2790,8 +2796,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 		    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,
@@ -2820,8 +2827,9 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 		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,