From: Simon Marchi Date: Fri, 19 Dec 2025 18:43:44 +0000 (-0500) Subject: gdb/buildsym: replace struct pending with std::vector X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1819e42280cc89754db92a3416392b82794989a2;p=thirdparty%2Fbinutils-gdb.git gdb/buildsym: replace struct pending with std::vector Replace `struct pending`, a home-made linked list of chunks of symbols, with `std::vector`. This removes manual memory management and simplifies the code. The change starts by switching m_local_symbols, m_file_symbols and m_global_symbols in buildsym_compunit to be vectors, and propagates from there. ~buildsym_compunit no longer needs to manually free the lists (it did not free m_local_symbols, was it on purpose?). add_symbol_to_list just appends the symbol to the vector. Obviously, this sometimes causes a vector reallocation, but it is amortized O(1) and I did not find that it causes a performance degradation (more details later). We could try to reserve some space in the vectors up front if we had an estimate of how many entries we'll have, but I am not sure we really can have a good idea up front. collate_pending_symbols_by_language iterates the vector backwards to keep the existing behavior. I am not sure if this is actually needed. buildsym_compunit::push_context std::moves m_local_symbols, to avoid copying the contents of the vector. I don't think buildsym_compunit::pop_context needs to change, everything should be efficient thanks to NRVO. Users of buildsym_compunit::pop_context use std::move to move context_stack::locals back to m_local_symbols. There is a non-trivial change in coff_read_enum_type, which I can't test easily. I did the following test to see if this change would have a performance impact: - I added a scoped_time_it in maintenance_expand_symtabs, to measure just that step - I use a build of blender compiled with "-O2 -g" - I run: $ ./gdb -q -nx --data-directory=data-directory -iex 'maint set dwarf sync on' -iex "maint set per-command time on" -ex "file /data1/smarchi/blender/build-RelWithDebInfo-gcc/bin/blender" -ex "maint expand windowmanager" -batch - I record the time taken by maintenance_expand_symtabs Before looks like: Time for "maintenance_expand_symtabs": wall 34.311, user 32.335, sys 1.829, user+sys 34.164, 99.6 % CPU Time for "maintenance_expand_symtabs": wall 34.208, user 32.265, sys 1.800, user+sys 34.065, 99.6 % CPU Time for "maintenance_expand_symtabs": wall 34.420, user 32.378, sys 1.894, user+sys 34.272, 99.6 % CPU After looks like: Time for "maintenance_expand_symtabs": wall 34.316, user 32.342, sys 1.838, user+sys 34.180, 99.6 % CPU Time for "maintenance_expand_symtabs": wall 34.318, user 32.347, sys 1.831, user+sys 34.178, 99.6 % CPU Time for "maintenance_expand_symtabs": wall 34.357, user 32.272, sys 1.943, user+sys 34.215, 99.6 % CPU I also measured the execution of the whole command (with "maint set per-command time off" this time). Before looks like: 116.12user 12.61system 1:30.68elapsed 141%CPU (0avgtext+0avgdata 10707780maxresident)k 116.69user 12.33system 1:31.42elapsed 141%CPU (0avgtext+0avgdata 10709132maxresident)k 116.51user 12.57system 1:30.83elapsed 142%CPU (0avgtext+0avgdata 10729880maxresident)k After looks like: 115.75user 12.03system 1:29.35elapsed 143%CPU (0avgtext+0avgdata 10712348maxresident)k 116.41user 12.58system 1:30.94elapsed 141%CPU (0avgtext+0avgdata 10727488maxresident)k 115.91user 11.90system 1:29.36elapsed 143%CPU (0avgtext+0avgdata 10770412maxresident)k Change-Id: I984fdaf47b9bddd840c033a6c6052b007bdcd13d Approved-By: Tom Tromey --- diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c index 68a2e1ebafc..794d29978d4 100644 --- a/gdb/buildsym-legacy.c +++ b/gdb/buildsym-legacy.c @@ -96,7 +96,7 @@ get_current_subfile () /* See buildsym.h. */ -struct pending ** +std::vector & get_local_symbols () { gdb_assert (buildsym_compunit != nullptr); @@ -105,7 +105,7 @@ get_local_symbols () /* See buildsym.h. */ -struct pending ** +std::vector & get_file_symbols () { gdb_assert (buildsym_compunit != nullptr); @@ -114,7 +114,7 @@ get_file_symbols () /* See buildsym.h. */ -struct pending ** +std::vector & get_global_symbols () { gdb_assert (buildsym_compunit != nullptr); diff --git a/gdb/buildsym-legacy.h b/gdb/buildsym-legacy.h index e13a0673fa9..c7e4e313339 100644 --- a/gdb/buildsym-legacy.h +++ b/gdb/buildsym-legacy.h @@ -136,15 +136,15 @@ extern struct subfile *get_current_subfile (); /* Return the local symbol list. */ -extern struct pending **get_local_symbols (); +extern std::vector &get_local_symbols (); /* Return the file symbol list. */ -extern struct pending **get_file_symbols (); +extern std::vector &get_file_symbols (); /* Return the global symbol list. */ -extern struct pending **get_global_symbols (); +extern std::vector &get_global_symbols (); /* Return the current buildsym_compunit. */ diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 2ac6cf1ba70..0e1b6292bf9 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -83,20 +83,6 @@ buildsym_compunit::~buildsym_compunit () nextsub = subfile->next; delete subfile; } - - struct pending *next, *next1; - - for (next = m_file_symbols; next != NULL; next = next1) - { - next1 = next->next; - xfree ((void *) next); - } - - for (next = m_global_symbols; next != NULL; next = next1) - { - next1 = next->next; - xfree ((void *) next); - } } struct macro_table * @@ -114,25 +100,13 @@ buildsym_compunit::get_macro_table () /* Add a symbol to one of the lists of symbols. */ void -add_symbol_to_list (struct symbol *symbol, struct pending **listhead) +add_symbol_to_list (symbol *symbol, std::vector &list) { - struct pending *link; - /* If this is an alias for another symbol, don't add it. */ if (symbol->linkage_name () && symbol->linkage_name ()[0] == '#') return; - /* We keep PENDINGSIZE symbols in each link of the list. If we - don't have a link with room in it, add a new link. */ - if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE) - { - link = XNEW (struct pending); - link->next = *listhead; - *listhead = link; - link->nsyms = 0; - } - - (*listhead)->symbol[(*listhead)->nsyms++] = symbol; + list.push_back (symbol); } /* Record BLOCK on the list of all blocks in the file. Put it after @@ -166,14 +140,13 @@ buildsym_compunit::record_pending_block (struct block *block, struct block * buildsym_compunit::finish_block_internal (struct symbol *symbol, - struct pending **listhead, + std::vector &symbol_list, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end, bool is_global, bool expandable) { struct gdbarch *gdbarch = m_objfile->arch (); - struct pending *next, *next1; struct block *block; struct pending_block *pblock; struct pending_block *opblock; @@ -186,7 +159,7 @@ buildsym_compunit::finish_block_internal if (symbol) { block->set_multidict - (mdict_create_linear (&m_objfile->objfile_obstack, *listhead)); + (mdict_create_linear (&m_objfile->objfile_obstack, symbol_list)); } else { @@ -194,12 +167,12 @@ buildsym_compunit::finish_block_internal { block->set_multidict (mdict_create_hashed_expandable (m_language)); - mdict_add_pending (block->multidict (), *listhead); + mdict_add_pending (block->multidict (), symbol_list); } else { block->set_multidict - (mdict_create_hashed (&m_objfile->objfile_obstack, *listhead)); + (mdict_create_hashed (&m_objfile->objfile_obstack, symbol_list)); } } @@ -257,14 +230,8 @@ buildsym_compunit::finish_block_internal if (static_link != NULL) objfile_register_static_link (m_objfile, block, static_link); - /* Now free the links of the list, and empty the list. */ - - for (next = *listhead; next; next = next1) - { - next1 = next->next; - xfree (next); - } - *listhead = NULL; + /* Now empty the list. */ + symbol_list.clear (); /* Check to be sure that the blocks have an end address that is greater than starting address. */ @@ -355,7 +322,7 @@ buildsym_compunit::finish_block (struct symbol *symbol, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end) { - return finish_block_internal (symbol, &m_local_symbols, + return finish_block_internal (symbol, m_local_symbols, old_blocks, static_link, start, end, false, false); } @@ -776,8 +743,8 @@ buildsym_compunit::end_compunit_symtab_get_static_block (CORE_ADDR end_addr, if (!required && m_pending_blocks == NULL - && m_file_symbols == NULL - && m_global_symbols == NULL + && m_file_symbols.empty () + && m_global_symbols.empty () && !m_have_line_numbers && m_pending_macros == NULL && m_global_using_directives == NULL) @@ -788,7 +755,7 @@ buildsym_compunit::end_compunit_symtab_get_static_block (CORE_ADDR end_addr, else { /* Define the STATIC_BLOCK. */ - return finish_block_internal (NULL, get_file_symbols (), NULL, NULL, + return finish_block_internal (NULL, m_file_symbols, NULL, NULL, m_last_source_start_addr, end_addr, false, expandable); } @@ -827,7 +794,7 @@ buildsym_compunit::end_compunit_symtab_from_static_block end_addr = static_block->end (); /* Create the GLOBAL_BLOCK and build the blockvector. */ - finish_block_internal (NULL, get_global_symbols (), NULL, NULL, + finish_block_internal (NULL, m_global_symbols, NULL, NULL, m_last_source_start_addr, end_addr, true, expandable); blockvector_up blockvector = make_blockvector (); @@ -999,20 +966,11 @@ buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr) don't have one. */ static void -set_missing_symtab (struct pending *pending_list, - struct compunit_symtab *cu) +set_missing_symtab (const std::vector &symbols, compunit_symtab *cu) { - struct pending *pending; - int i; - - for (pending = pending_list; pending != NULL; pending = pending->next) - { - for (i = 0; i < pending->nsyms; ++i) - { - if (pending->symbol[i]->symtab () == NULL) - pending->symbol[i]->set_symtab (cu->primary_filetab ()); - } - } + for (symbol *sym : symbols) + if (sym->symtab () == nullptr) + sym->set_symtab (cu->primary_filetab ()); } /* Same as end_compunit_symtab, but for the case where we're adding more symbols @@ -1034,7 +992,7 @@ buildsym_compunit::augment_type_symtab () if (m_have_line_numbers) complaint (_("Line numbers recorded in a type symtab")); - if (m_file_symbols != NULL) + if (!m_file_symbols.empty ()) { struct block *block = blockvector->static_block (); @@ -1045,7 +1003,7 @@ buildsym_compunit::augment_type_symtab () mdict_add_pending (block->multidict (), m_file_symbols); } - if (m_global_symbols != NULL) + if (!m_global_symbols.empty ()) { struct block *block = blockvector->global_block (); @@ -1065,10 +1023,10 @@ context_stack & buildsym_compunit::push_context (int desc, CORE_ADDR valu) { context_stack &ctx - = m_context_stack.emplace_back (m_local_symbols, m_local_using_directives, + = m_context_stack.emplace_back (std::move (m_local_symbols), + m_local_using_directives, m_pending_blocks, valu, desc); - m_local_symbols = nullptr; m_local_using_directives = nullptr; return ctx; diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 99971826889..ff1c2a075fc 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -68,27 +68,14 @@ struct subfile using subfile_up = std::unique_ptr; -/* Record the symbols defined for each context in a list. We don't - create a struct block for the context until we know how long to - make it. */ - -#define PENDINGSIZE 100 - -struct pending - { - struct pending *next; - int nsyms; - struct symbol *symbol[PENDINGSIZE]; - }; - /* Stack representing unclosed lexical contexts (that will become blocks, eventually). */ struct context_stack { - context_stack (pending *locals, using_direct *local_using_directives, + context_stack (std::vector locals, using_direct *local_using_directives, pending_block *old_blocks, CORE_ADDR start_addr, int depth) - : locals (locals), + : locals (std::move (locals)), local_using_directives (local_using_directives), old_blocks (old_blocks), start_addr (start_addr), @@ -96,7 +83,7 @@ struct context_stack {} /* Outer locals at the time we entered. */ - pending *locals; + std::vector locals; /* Pending using directives at the time we entered. */ using_direct *local_using_directives; @@ -290,19 +277,19 @@ struct buildsym_compunit return m_current_subfile; } - struct pending **get_local_symbols () + std::vector &get_local_symbols () { - return &m_local_symbols; + return m_local_symbols; } - struct pending **get_file_symbols () + std::vector &get_file_symbols () { - return &m_file_symbols; + return m_file_symbols; } - struct pending **get_global_symbols () + std::vector &get_global_symbols () { - return &m_global_symbols; + return m_global_symbols; } void record_debugformat (const char *format) @@ -336,7 +323,7 @@ private: void record_pending_block (struct block *block, struct pending_block *opblock); struct block *finish_block_internal (struct symbol *symbol, - struct pending **listhead, + std::vector &symbol_list, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end, @@ -432,18 +419,18 @@ private: struct pending_block *m_pending_blocks = nullptr; /* Pending static symbols and types at the top level. */ - struct pending *m_file_symbols = nullptr; + std::vector m_file_symbols; /* Pending global functions and variables. */ - struct pending *m_global_symbols = nullptr; + std::vector m_global_symbols; /* Pending symbols that are local to the lexical context. */ - struct pending *m_local_symbols = nullptr; + std::vector m_local_symbols; }; using buildsym_compunit_up = std::unique_ptr; -extern void add_symbol_to_list (struct symbol *symbol, - struct pending **listhead); +extern void add_symbol_to_list (symbol *symbol, + std::vector &list); #endif /* GDB_BUILDSYM_H */ diff --git a/gdb/coffread.c b/gdb/coffread.c index d88fdd09262..82849146164 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1122,7 +1122,7 @@ coff_symtab_read (minimal_symbol_reader &reader, symnum); break; } - if (*get_local_symbols () && !outermost_context_p ()) + if (!get_local_symbols ().empty () && !outermost_context_p ()) { tmpaddr = cs->c_value + objfile->text_section_offset (); /* Make a block for the local symbols within. */ @@ -1130,7 +1130,7 @@ coff_symtab_read (minimal_symbol_reader &reader, cstk.start_addr, tmpaddr); } /* Now pop locals of block just finished. */ - *get_local_symbols () = cstk.locals; + get_local_symbols () = std::move (cstk.locals); } break; @@ -2022,24 +2022,21 @@ coff_read_enum_type (int index, int length, int lastsym, struct type *type; int nsyms = 0; int done = 0; - struct pending **symlist; + std::vector *symlist; struct coff_symbol member_sym; struct coff_symbol *ms = &member_sym; struct internal_syment sub_sym; union internal_auxent sub_aux; - struct pending *osyms, *syms; - int o_nsyms; - int n; char *name; int unsigned_enum = 1; type = coff_alloc_type (index); if (within_function) - symlist = get_local_symbols (); + symlist = &get_local_symbols (); else - symlist = get_file_symbols (); - osyms = *symlist; - o_nsyms = osyms ? osyms->nsyms : 0; + symlist = &get_file_symbols (); + + size_t o_nsyms = symlist->size (); while (!done && symnum < lastsym && symnum < nlist_nsyms_global) { @@ -2057,7 +2054,7 @@ coff_read_enum_type (int index, int length, int lastsym, sym->set_loc_class_index (LOC_CONST); sym->set_domain (VAR_DOMAIN); sym->set_value_longest (ms->c_value); - add_symbol_to_list (sym, symlist); + add_symbol_to_list (sym, *symlist); nsyms++; break; @@ -2081,31 +2078,22 @@ coff_read_enum_type (int index, int length, int lastsym, /* Find the symbols for the values and put them into the type. The symbols can be found in the symlist that we put them on - to cause them to be defined. osyms contains the old value - of that symlist; everything up to there was defined by us. */ + to cause them to be defined. o_nsyms is the original size of + that symlist; everything from there to the end was defined by us. */ /* Note that we preserve the order of the enum constants, so that in something like "enum {FOO, LAST_THING=FOO}" we print FOO, not LAST_THING. */ - for (syms = *symlist, n = 0; syms; syms = syms->next) + for (size_t i = o_nsyms, n = 0; i < symlist->size (); i++, n++) { - int j = 0; - - if (syms == osyms) - j = o_nsyms; - for (; j < syms->nsyms; j++, n++) - { - struct symbol *xsym = syms->symbol[j]; - - xsym->set_type (type); - type->field (n).set_name (xsym->linkage_name ()); - type->field (n).set_loc_enumval (xsym->value_longest ()); - if (xsym->value_longest () < 0) - unsigned_enum = 0; - type->field (n).set_bitsize (0); - } - if (syms == osyms) - break; + symbol *xsym = (*symlist)[i]; + + xsym->set_type (type); + type->field (n).set_name (xsym->linkage_name ()); + type->field (n).set_loc_enumval (xsym->value_longest ()); + if (xsym->value_longest () < 0) + unsigned_enum = 0; + type->field (n).set_bitsize (0); } if (unsigned_enum) diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 252dfe67ce4..e3ff053504e 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -919,19 +919,12 @@ struct multidictionary /* A helper function to collate symbols on the pending list by language. */ static gdb::unordered_map> -collate_pending_symbols_by_language (const struct pending *symbol_list) +collate_pending_symbols_by_language (const std::vector &symbol_list) { gdb::unordered_map> nsyms; - for (const pending *list_counter = symbol_list; - list_counter != nullptr; list_counter = list_counter->next) - { - for (int i = list_counter->nsyms - 1; i >= 0; --i) - { - enum language language = list_counter->symbol[i]->language (); - nsyms[language].push_back (list_counter->symbol[i]); - } - } + for (auto it = symbol_list.rbegin (); it != symbol_list.rend (); ++it) + nsyms[(*it)->language ()].push_back (*it); return nsyms; } @@ -940,7 +933,7 @@ collate_pending_symbols_by_language (const struct pending *symbol_list) struct multidictionary * mdict_create_hashed (struct obstack *obstack, - const struct pending *symbol_list) + const std::vector &symbol_list) { struct multidictionary *retval = XOBNEW (obstack, struct multidictionary); @@ -982,7 +975,7 @@ mdict_create_hashed_expandable (enum language language) struct multidictionary * mdict_create_linear (struct obstack *obstack, - const struct pending *symbol_list) + const std::vector &symbol_list) { struct multidictionary *retval = XOBNEW (obstack, struct multidictionary); @@ -1120,7 +1113,7 @@ mdict_add_symbol (struct multidictionary *mdict, struct symbol *sym) void mdict_add_pending (struct multidictionary *mdict, - const struct pending *symbol_list) + const std::vector &symbol_list) { gdb::unordered_map> nsyms = collate_pending_symbols_by_language (symbol_list); diff --git a/gdb/dictionary.h b/gdb/dictionary.h index 05a57e0e7c0..d4ed8ae744d 100644 --- a/gdb/dictionary.h +++ b/gdb/dictionary.h @@ -34,7 +34,6 @@ struct multidictionary; struct symbol; struct obstack; -struct pending; struct language_defn; /* The creation functions for various implementations of @@ -46,7 +45,7 @@ struct language_defn; extern struct multidictionary * mdict_create_hashed (struct obstack *obstack, - const struct pending *symbol_list); + const std::vector &symbol_list); /* Create a multi-language dictionary of symbols, implemented via a hashtable that grows as necessary. The initial dictionary of @@ -64,7 +63,7 @@ extern struct multidictionary * extern struct multidictionary * mdict_create_linear (struct obstack *obstack, - const struct pending *symbol_list); + const std::vector &symbol_list); /* Create a multi-language dictionary of symbols, implemented via an array that grows as necessary. The multidictionary initially @@ -91,7 +90,7 @@ extern void mdict_add_symbol (struct multidictionary *mdict, /* Utility to add a list of symbols to a multidictionary. */ extern void mdict_add_pending (struct multidictionary *mdict, - const struct pending *symbol_list); + const std::vector &symbol_list); /* A type containing data that is used when iterating over all symbols in a dictionary. Don't ever look at its innards; this type would diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index cb910fbaff7..d2e63006935 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -94,7 +94,7 @@ dwarf2_cu::start_compunit_symtab (const char *name, const char *comp_dir, lang (), low_pc); - list_in_scope = get_builder ()->get_file_symbols (); + list_in_scope = &get_builder ()->get_file_symbols (); /* DWARF versions are restricted to [2, 5], thanks to the check in read_comp_unit_head. */ diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index a354bdced84..af444cfeb96 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -296,7 +296,7 @@ public: first local scope, and all other local scopes as nested local scopes, and worked fine. Check to see if we really need to distinguish these in buildsym.c. */ - struct pending **list_in_scope = nullptr; + std::vector *list_in_scope = nullptr; /* Storage for things with the same lifetime as this read-in compilation unit. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4f7e1c889f4..4b706f654e0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4333,41 +4333,31 @@ static void fixup_go_packaging (struct dwarf2_cu *cu) { gdb::unique_xmalloc_ptr package_name; - struct pending *list; - int i; - for (list = *cu->get_builder ()->get_global_symbols (); - list != NULL; - list = list->next) - { - for (i = 0; i < list->nsyms; ++i) - { - struct symbol *sym = list->symbol[i]; + for (symbol *sym : cu->get_builder ()->get_global_symbols ()) + if (sym->language () == language_go && sym->loc_class () == LOC_BLOCK) + { + gdb::unique_xmalloc_ptr this_package_name + = go_symbol_package_name (sym); - if (sym->language () == language_go - && sym->loc_class () == LOC_BLOCK) - { - gdb::unique_xmalloc_ptr this_package_name - = go_symbol_package_name (sym); + if (this_package_name == nullptr) + continue; - if (this_package_name == NULL) - continue; - if (package_name == NULL) - package_name = std::move (this_package_name); - else - { - struct objfile *objfile = cu->per_objfile->objfile; - if (strcmp (package_name.get (), this_package_name.get ()) != 0) - complaint (_("Symtab %s has objects from two different Go packages: %s and %s"), - (sym->symtab () != NULL - ? symtab_to_filename_for_display - (sym->symtab ()) - : objfile_name (objfile)), - this_package_name.get (), package_name.get ()); - } - } - } - } + if (package_name == nullptr) + package_name = std::move (this_package_name); + else + { + objfile *objfile = cu->per_objfile->objfile; + + if (strcmp (package_name.get (), this_package_name.get ()) != 0) + complaint (_("Symtab %s has objects from two different Go " + "packages: %s and %s"), + (sym->symtab () != NULL + ? symtab_to_filename_for_display (sym->symtab ()) + : objfile_name (objfile)), + this_package_name.get (), package_name.get ()); + } + } if (package_name != NULL) { @@ -6250,7 +6240,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) cust->dirname (), cust->language (), 0, cust); - list_in_scope = get_builder ()->get_file_symbols (); + list_in_scope = &get_builder ()->get_file_symbols (); } return; } @@ -6304,7 +6294,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) cust->dirname (), cust->language (), 0, cust); - list_in_scope = get_builder ()->get_file_symbols (); + list_in_scope = &get_builder ()->get_file_symbols (); auto &file_names = line_header->file_names (); for (i = 0; i < file_names.size (); ++i) @@ -8270,7 +8260,8 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) /* We're inheriting ORIGIN's children into the scope we'd put DIE's symbols in. */ - struct pending **origin_previous_list_in_scope = origin_cu->list_in_scope; + std::vector *origin_previous_list_in_scope + = origin_cu->list_in_scope; origin_cu->list_in_scope = cu->list_in_scope; if (die->tag != origin_die->tag @@ -8619,7 +8610,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) cu->addr_type ()); } - cu->list_in_scope = cu->get_builder ()->get_local_symbols (); + cu->list_in_scope = &cu->get_builder ()->get_local_symbols (); for (die_info *child_die : die->children ()) { @@ -8702,13 +8693,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) a function declares a class that has methods). This means that when we finish processing a function scope, we may need to go back to building a containing block's symbol lists. */ - *cu->get_builder ()->get_local_symbols () = cstk.locals; + cu->get_builder ()->get_local_symbols () = std::move (cstk.locals); cu->get_builder ()->set_local_using_directives (cstk.local_using_directives); /* If we've finished processing a top-level function, subsequent symbols go in the file symbol list. */ if (cu->get_builder ()->outermost_context_p ()) - cu->list_in_scope = cu->get_builder ()->get_file_symbols (); + cu->list_in_scope = &cu->get_builder ()->get_file_symbols (); } /* Process all the DIES contained within a lexical block scope. Start @@ -8758,7 +8749,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) inherit_abstract_dies (die, cu); struct context_stack cstk = cu->get_builder ()->pop_context (); - if (*cu->get_builder ()->get_local_symbols () != NULL + if (!cu->get_builder ()->get_local_symbols ().empty () || (*cu->get_builder ()->get_local_using_directives ()) != NULL) { struct block *block @@ -8777,7 +8768,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) to do. */ dwarf2_record_block_ranges (die, block, cu); } - *cu->get_builder ()->get_local_symbols () = cstk.locals; + cu->get_builder ()->get_local_symbols () = std::move (cstk.locals); cu->get_builder ()->set_local_using_directives (cstk.local_using_directives); } @@ -16098,7 +16089,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym, static void add_ada_export_symbol (struct symbol *orig, const char *new_name, const char *orig_name, struct dwarf2_cu *cu, - struct pending **list_to_add) + std::vector &list_to_add) { struct symbol *copy = new (&cu->per_objfile->objfile->objfile_obstack) symbol (*orig); @@ -16152,7 +16143,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, const char *name; struct attribute *attr = NULL; struct attribute *attr2 = NULL; - struct pending **list_to_add = NULL; + std::vector *list_to_add = nullptr; int inlined_func = (die->tag == DW_TAG_inlined_subroutine); @@ -16278,7 +16269,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, belongs to. */ attr2 = dwarf2_attr (die->parent, DW_AT_external, cu); if (attr2 != nullptr && attr2->as_boolean ()) - list_to_add = cu->get_builder ()->get_global_symbols (); + list_to_add = &cu->get_builder ()->get_global_symbols (); else list_to_add = cu->list_in_scope; break; @@ -16298,7 +16289,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, to be able to access them globally. For instance, we want to be able to break on a nested subprogram without having to specify the context. */ - list_to_add = cu->get_builder ()->get_global_symbols (); + list_to_add = &cu->get_builder ()->get_global_symbols (); } else { @@ -16323,7 +16314,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, name, then create a second symbol that refers back to it. */ add_ada_export_symbol (sym, linkagename, physname, cu, - list_to_add); + *list_to_add); } } break; @@ -16370,7 +16361,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, if (!suppress_add) { if (attr2 != nullptr && attr2->as_boolean ()) - list_to_add = cu->get_builder ()->get_global_symbols (); + list_to_add = &cu->get_builder ()->get_global_symbols (); else list_to_add = cu->list_in_scope; } @@ -16419,8 +16410,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, but it may be block-scoped. */ list_to_add = ((cu->list_in_scope - == cu->get_builder ()->get_file_symbols ()) - ? cu->get_builder ()->get_global_symbols () + == &cu->get_builder ()->get_file_symbols ()) + ? &cu->get_builder ()->get_global_symbols () : cu->list_in_scope); } else @@ -16433,7 +16424,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, be seen here, because it will not have a location and so will be handled below. */ add_ada_export_symbol (sym, physname, linkagename, cu, - list_to_add); + *list_to_add); } } else @@ -16464,8 +16455,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, sym->set_linkage_name (physname); list_to_add = ((cu->list_in_scope - == cu->get_builder ()->get_file_symbols ()) - ? cu->get_builder ()->get_global_symbols () + == &cu->get_builder ()->get_file_symbols ()) + ? &cu->get_builder ()->get_global_symbols () : cu->list_in_scope); SYMBOL_LOCATION_BATON (sym) = (void *) linkagename; sym->set_loc_class_index (ada_imported_index); @@ -16477,8 +16468,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, may be block-scoped. */ list_to_add = ((cu->list_in_scope - == cu->get_builder ()->get_file_symbols ()) - ? cu->get_builder ()->get_global_symbols () + == &cu->get_builder ()->get_file_symbols ()) + ? &cu->get_builder ()->get_global_symbols () : cu->list_in_scope); sym->set_loc_class_index (LOC_UNRESOLVED); @@ -16564,9 +16555,9 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, { buildsym_compunit *builder = cu->get_builder (); list_to_add - = (cu->list_in_scope == builder->get_file_symbols () - && cu->lang () == language_cplus - ? builder->get_global_symbols () + = ((cu->list_in_scope == &builder->get_file_symbols () + && cu->lang () == language_cplus) + ? &builder->get_global_symbols () : cu->list_in_scope); /* The semantics of C++ state that "struct foo { @@ -16609,21 +16600,21 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, DW_TAG_class_type, etc. block. */ list_to_add - = (cu->list_in_scope == cu->get_builder ()->get_file_symbols () - && cu->lang () == language_cplus - ? cu->get_builder ()->get_global_symbols () + = ((cu->list_in_scope == &cu->get_builder ()->get_file_symbols () + && cu->lang () == language_cplus) + ? &cu->get_builder ()->get_global_symbols () : cu->list_in_scope); break; case DW_TAG_imported_declaration: case DW_TAG_namespace: sym->set_domain (TYPE_DOMAIN); sym->set_loc_class_index (LOC_TYPEDEF); - list_to_add = cu->get_builder ()->get_global_symbols (); + list_to_add = &cu->get_builder ()->get_global_symbols (); break; case DW_TAG_module: sym->set_loc_class_index (LOC_TYPEDEF); sym->set_domain (MODULE_DOMAIN); - list_to_add = cu->get_builder ()->get_global_symbols (); + list_to_add = &cu->get_builder ()->get_global_symbols (); break; case DW_TAG_common_block: sym->set_loc_class_index (LOC_COMMON_BLOCK); @@ -16653,7 +16644,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, } if (list_to_add != NULL) - add_symbol_to_list (sym, list_to_add); + add_symbol_to_list (sym, *list_to_add); /* For the benefit of old versions of GCC, check for anonymous namespaces based on the demangled name. */ diff --git a/gdb/jit.c b/gdb/jit.c index 3512665a19e..1d3b0f417a6 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -570,7 +570,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) struct type *block_type = builtin_type (objfile->arch ())->builtin_void; new_block->set_multidict - (mdict_create_linear (&objfile->objfile_obstack, NULL)); + (mdict_create_linear (&objfile->objfile_obstack, {})); /* The address range. */ new_block->set_start (gdb_block_iter.begin); new_block->set_end (gdb_block_iter.end); @@ -610,7 +610,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) new_block = new (&objfile->objfile_obstack) block; new_block->set_multidict - (mdict_create_linear (&objfile->objfile_obstack, NULL)); + (mdict_create_linear (&objfile->objfile_obstack, {})); new_block->set_superblock (block_iter); block_iter = new_block;