From 31edb802957b0073c571f48b9262e66b817fd360 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Sun, 13 Oct 2019 06:57:14 -0500 Subject: [PATCH] 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-10-29 Christian Biesinger * 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): Change signature to use gdb::string_view instead of name+len. (elf_symtab_read): Update. (elf_rel_plt_read): 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) : 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 --- gdb/ChangeLog | 28 +++++++++++++++++ gdb/coffread.c | 5 ++- gdb/ctfread.c | 14 ++++----- gdb/dbxread.c | 24 +++++++-------- gdb/dwarf2read.c | 29 +++++++++--------- gdb/elfread.c | 25 +++++++-------- gdb/mdebugread.c | 80 ++++++++++++++++++++++++++---------------------- gdb/minsyms.c | 18 +++++------ gdb/minsyms.h | 10 +++--- gdb/psympriv.h | 3 +- gdb/psymtab.c | 8 ++--- gdb/stabsread.c | 5 +-- gdb/symtab.c | 37 +++++++++++----------- gdb/symtab.h | 7 +++-- gdb/xcoffread.c | 42 +++++++++++++++---------- 15 files changed, 188 insertions(+), 147 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1c4e47c78b5..fee6332e8fc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,31 @@ +2019-10-29 Christian Biesinger + + * 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): Change signature to use + gdb::string_view instead of name+len. + (elf_symtab_read): Update. + (elf_rel_plt_read): 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) : 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. + 2019-10-29 Christian Biesinger * symtab.h (symbol_set_names): Document that copy_name must be diff --git a/gdb/coffread.c b/gdb/coffread.c index 12f36b7917b..2ec48d60d56 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/ctfread.c b/gdb/ctfread.c index 44ccff62ae3..0e80150394a 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -380,7 +380,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg) 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 @@ new_symbol (ctf_context_t *ccp, struct type *type, ctf_id_t tid) 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 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) 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 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) 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 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg) 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_psymtab_var_cb (const char *name, ctf_id_t id, void *arg) { 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 @@ scan_partial_symbols (ctf_file_t *cfp, struct objfile *of) 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 bbef3726700..462f7f0ddae 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 4372a47c6d6..cac719a9c6a 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -8952,7 +8952,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) 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), @@ -8962,7 +8962,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), @@ -8974,7 +8974,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 @@ -9010,7 +9010,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), @@ -9029,7 +9029,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), @@ -9041,7 +9041,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, @@ -9049,7 +9049,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, @@ -9060,7 +9060,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, @@ -9084,7 +9084,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 @@ -9094,7 +9094,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 @@ -9924,8 +9924,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; @@ -18566,7 +18565,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); @@ -18600,7 +18599,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 @@ -21606,7 +21605,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 1b5b4e0aa80..226e3f09d38 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -48,6 +48,7 @@ #include "auxv.h" #include "mdebugread.h" #include "ctfread.h" +#include "gdbsupport/gdb_string_view.h" /* Forward declarations. */ extern const struct sym_fns elf_sym_fns_gdb_index; @@ -198,7 +199,7 @@ elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip) static struct minimal_symbol * record_minimal_symbol (minimal_symbol_reader &reader, - const char *name, int name_len, bool copy_name, + gdb::string_view name, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile) @@ -210,7 +211,7 @@ record_minimal_symbol (minimal_symbol_reader &reader, address = gdbarch_addr_bits_remove (gdbarch, address); struct minimal_symbol *result - = reader.record_full (name, name_len, copy_name, address, + = reader.record_full (name, copy_name, address, ms_type, gdb_bfd_section_index (objfile->obfd, bfd_section)); @@ -330,7 +331,7 @@ elf_symtab_read (minimal_symbol_reader &reader, continue; msym = record_minimal_symbol - (reader, sym->name, strlen (sym->name), copy_names, + (reader, sym->name, copy_names, symaddr, mst_solib_trampoline, sect, objfile); if (msym != NULL) { @@ -474,7 +475,7 @@ elf_symtab_read (minimal_symbol_reader &reader, continue; /* Skip this symbol. */ } msym = record_minimal_symbol - (reader, sym->name, strlen (sym->name), copy_names, symaddr, + (reader, sym->name, copy_names, symaddr, ms_type, sym->section, objfile); if (msym) @@ -503,8 +504,10 @@ elf_symtab_read (minimal_symbol_reader &reader, { int len = atsign - sym->name; - record_minimal_symbol (reader, sym->name, len, true, symaddr, - ms_type, sym->section, objfile); + record_minimal_symbol (reader, + gdb::string_view (sym->name, len), + true, symaddr, ms_type, sym->section, + objfile); } } @@ -520,10 +523,9 @@ elf_symtab_read (minimal_symbol_reader &reader, { struct minimal_symbol *mtramp; - mtramp = record_minimal_symbol (reader, sym->name, len - 4, - true, symaddr, - mst_solib_trampoline, - sym->section, objfile); + mtramp = record_minimal_symbol + (reader, gdb::string_view (sym->name, len - 4), true, + symaddr, mst_solib_trampoline, sym->section, objfile); if (mtramp) { SET_MSYMBOL_SIZE (mtramp, MSYMBOL_SIZE (msym)); @@ -639,8 +641,7 @@ elf_rel_plt_read (minimal_symbol_reader &reader, string_buffer.assign (name); string_buffer.append (got_suffix, got_suffix + got_suffix_len); - msym = record_minimal_symbol (reader, string_buffer.c_str (), - string_buffer.size (), + msym = record_minimal_symbol (reader, string_buffer, true, address, mst_slot_got_plt, msym_section, objfile); if (msym) diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index d53d57f1367..454929381d9 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -3050,8 +3050,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, @@ -3061,8 +3062,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, @@ -3080,21 +3082,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; } } @@ -3103,11 +3104,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 @@ -3168,9 +3170,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); @@ -3187,8 +3190,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; @@ -3200,8 +3204,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, @@ -3219,8 +3224,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, @@ -3454,13 +3460,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, @@ -3527,7 +3533,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); @@ -3567,7 +3573,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); @@ -3646,7 +3652,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, @@ -3809,7 +3815,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 0267472e5de..db3e546ae1a 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1086,7 +1086,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) @@ -1100,24 +1100,22 @@ 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)) + && (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 @@ 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 0a19f0b0962..deaecb4df61 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 3e89742d8d5..19d692bd230 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,7 +305,7 @@ 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, +extern void add_psymbol_to_list (gdb::string_view name, bool copy_name, domain_enum domain, enum address_class theclass, short section, diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 31b6d597773..b30d29e6efa 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 *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 b99ac201f84..ef4aa47345c 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -752,11 +752,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 a6a9dc9c6eb..060e676bbb6 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -828,7 +828,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; @@ -838,14 +838,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); @@ -856,7 +856,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, if (per_bfd->demangled_names_hash == NULL) create_demangled_names_hash (per_bfd); - struct demangled_name_entry entry (gdb::string_view (linkage_name, len)); + struct demangled_name_entry entry (linkage_name); slot = ((struct demangled_name_entry **) htab_find_slot (per_bfd->demangled_names_hash.get (), &entry, INSERT)); @@ -870,20 +870,21 @@ symbol_set_names (struct general_symbol_info *gsymbol, /* A 0-terminated copy of the linkage name. Callers must set COPY_NAME to true if the string might not be nullterminated. We have to make this copy because demangling needs a nullterminated string. */ - const char *linkage_name_copy; + gdb::string_view linkage_name_copy; if (copy_name) { - char *alloc_name = (char *) alloca (len + 1); - memcpy (alloc_name, linkage_name, len); - alloc_name[len] = '\0'; + char *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; + linkage_name_copy = gdb::string_view (alloc_name, + linkage_name.length ()); } else linkage_name_copy = linkage_name; gdb::unique_xmalloc_ptr demangled_name_ptr - (symbol_find_demangled_name (gsymbol, linkage_name_copy)); + (symbol_find_demangled_name (gsymbol, linkage_name_copy.data ())); /* Suppose we have demangled_name==NULL, copy_name==0, and linkage_name_copy==linkage_name. In this case, we already have the @@ -900,8 +901,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, sizeof (demangled_name_entry))); - new (*slot) demangled_name_entry - (gdb::string_view (linkage_name, len)); + new (*slot) demangled_name_entry (linkage_name); } else { @@ -910,12 +910,13 @@ symbol_set_names (struct general_symbol_info *gsymbol, *slot = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, - sizeof (demangled_name_entry) + len + 1)); + sizeof (demangled_name_entry) + + linkage_name.length () + 1)); char *mangled_ptr = reinterpret_cast (*slot + 1); - memcpy (mangled_ptr, linkage_name, len); - mangled_ptr [len] = '\0'; + memcpy (mangled_ptr, linkage_name.data (), linkage_name.length ()); + mangled_ptr [linkage_name.length ()] = '\0'; new (*slot) demangled_name_entry - (gdb::string_view (mangled_ptr, len)); + (gdb::string_view (mangled_ptr, linkage_name.length ())); } (*slot)->demangled = std::move (demangled_name_ptr); (*slot)->language = gsymbol->language; diff --git a/gdb/symtab.h b/gdb/symtab.h index 131a74d4bae..20c11d16cf8 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" @@ -506,11 +507,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. If linkage_name may not be nullterminated, copy_name must be set to true. */ -#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 bc4877389b0..20a21872d1c 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -2634,8 +2634,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, @@ -2645,8 +2646,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, @@ -2664,15 +2666,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; @@ -2683,8 +2687,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); } @@ -2745,7 +2750,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); @@ -2763,8 +2768,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; @@ -2780,8 +2786,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, @@ -2810,8 +2817,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, -- 2.30.2