From patchwork Fri Aug 10 23:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 28854 Received: (qmail 50473 invoked by alias); 10 Aug 2018 23:25:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 50322 invoked by uid 89); 10 Aug 2018 23:25:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, SPF_HELO_PASS, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy=canon, vec, 29227, sk:infofi X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Aug 2018 23:25:37 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E34C5308A957 for ; Fri, 10 Aug 2018 23:25:35 +0000 (UTC) Received: from theo.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A61EB52FD4 for ; Fri, 10 Aug 2018 23:25:35 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 2/9] Change `function_symbols' to std::vector Date: Fri, 10 Aug 2018 16:25:27 -0700 Message-Id: <20180810232534.481-3-keiths@redhat.com> In-Reply-To: <20180810232534.481-1-keiths@redhat.com> References: <20180810232534.481-1-keiths@redhat.com> X-IsSubscribed: yes This patch changes the `function_symbols' members in linespec.c structures from a VEC to a std::vector. gdb/ChangeLog: * linespec.c (struct linespec) : Change type to std::vector. Update all users. (struct collect_info) : Likewise. (find_method, find_function_symbols, find_linespec_symbols) (find_label_symbols_in_block): Change `symbols' parameter to std::vector. Update all callers. (find_label_symbols): Likewise for `function_symbols' and `label_funcs_ret'. --- gdb/ChangeLog | 11 +++++ gdb/linespec.c | 139 +++++++++++++++++++++++++-------------------------------- 2 files changed, 73 insertions(+), 77 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 07a4531a4d..5a71381262 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ YYYY-MM-DD Keith Seitz + * linespec.c (struct linespec) : Change type to + std::vector. Update all users. + (struct collect_info) : Likewise. + (find_method, find_function_symbols, find_linespec_symbols) + (find_label_symbols_in_block): Change `symbols' parameter to + std::vector. Update all callers. + (find_label_symbols): Likewise for `function_symbols' and + `label_funcs_ret'. + +YYYY-MM-DD Keith Seitz + * linespec.c (symtab_vector_up): Define. (struct linespec) : Change type to std::vector. Update all uses. diff --git a/gdb/linespec.c b/gdb/linespec.c index 418e5f8ba2..8070db68ec 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -114,8 +114,8 @@ struct linespec std::vector *file_symtabs; /* A list of matching function symbols and minimal symbols. Both lists - may be NULL if no matching symbols were found. */ - VEC (symbolp) *function_symbols; + may be NULL (or empty) if no matching symbols were found. */ + std::vector *function_symbols; VEC (bound_minimal_symbol_d) *minimal_symbols; /* A structure of matching label symbols and the corresponding @@ -124,7 +124,7 @@ struct linespec struct { VEC (symbolp) *label_symbols; - VEC (symbolp) *function_symbols; + std::vector *function_symbols; } labels; }; typedef struct linespec *linespec_p; @@ -201,7 +201,7 @@ struct collect_info /* The result being accumulated. */ struct { - VEC (symbolp) *symbols; + std::vector *symbols; VEC (bound_minimal_symbol_d) *minimal_symbols; } result; @@ -215,7 +215,7 @@ collect_info::add_symbol (symbol *sym) /* In list mode, add all matching symbols, regardless of class. This allows the user to type "list a_global_variable". */ if (SYMBOL_CLASS (sym) == LOC_BLOCK || this->state->list_mode) - VEC_safe_push (symbolp, this->result.symbols, sym); + this->result.symbols->push_back (sym); /* Continue iterating. */ return true; @@ -352,17 +352,16 @@ static std::vector decode_objc (struct linespec_state *self, static std::vector *symtabs_from_filename (const char *, struct program_space *pspace); -static VEC (symbolp) *find_label_symbols (struct linespec_state *self, - VEC (symbolp) *function_symbols, - VEC (symbolp) **label_funcs_ret, - const char *name, - bool completion_mode = false); +static VEC (symbolp) *find_label_symbols + (struct linespec_state *self, std::vector *function_symbols, + std::vector *label_funcs_ret, const char *name, + bool completion_mode = false); static void find_linespec_symbols (struct linespec_state *self, std::vector *file_symtabs, const char *name, symbol_name_match_type name_match_type, - VEC (symbolp) **symbols, + std::vector *symbols, VEC (bound_minimal_symbol_d) **minsyms); static struct line_offset @@ -1767,7 +1766,8 @@ linespec_parse_basic (linespec_parser *parser) { gdb::unique_xmalloc_ptr name; linespec_token token; - VEC (symbolp) *symbols, *labels; + std::vector symbols; + VEC (symbolp) *labels; VEC (bound_minimal_symbol_d) *minimal_symbols; /* Get the next token. */ @@ -1871,12 +1871,12 @@ linespec_parse_basic (linespec_parser *parser) PARSER_EXPLICIT (parser)->func_name_match_type, &symbols, &minimal_symbols); - if (symbols != NULL || minimal_symbols != NULL) + if (!symbols.empty () || minimal_symbols != NULL) { - PARSER_RESULT (parser)->function_symbols = symbols; + PARSER_RESULT (parser)->function_symbols + = new std::vector (std::move (symbols)); PARSER_RESULT (parser)->minimal_symbols = minimal_symbols; PARSER_EXPLICIT (parser)->function_name = name.release (); - symbols = NULL; } else { @@ -1887,9 +1887,9 @@ linespec_parse_basic (linespec_parser *parser) if (labels != NULL) { PARSER_RESULT (parser)->labels.label_symbols = labels; - PARSER_RESULT (parser)->labels.function_symbols = symbols; + PARSER_RESULT (parser)->labels.function_symbols + = new std::vector (std::move (symbols)); PARSER_EXPLICIT (parser)->label_name = name.release (); - symbols = NULL; } else if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$') @@ -1993,9 +1993,9 @@ linespec_parse_basic (linespec_parser *parser) if (labels != NULL) { PARSER_RESULT (parser)->labels.label_symbols = labels; - PARSER_RESULT (parser)->labels.function_symbols = symbols; + PARSER_RESULT (parser)->labels.function_symbols + = new std::vector (std::move (symbols)); PARSER_EXPLICIT (parser)->label_name = name.release (); - symbols = NULL; } else { @@ -2061,13 +2061,10 @@ canonicalize_linespec (struct linespec_state *state, const linespec_p ls) if (explicit_loc->function_name == NULL) { - struct symbol *s; - /* No function was specified, so add the symbol name. */ - gdb_assert (ls->labels.function_symbols != NULL - && (VEC_length (symbolp, ls->labels.function_symbols) - == 1)); - s = VEC_index (symbolp, ls->labels.function_symbols, 0); + gdb_assert (!ls->labels.function_symbols->empty () + && (ls->labels.function_symbols->size () == 1)); + struct symbol *s = ls->labels.function_symbols->front (); explicit_loc->function_name = xstrdup (SYMBOL_NATURAL_NAME (s)); } } @@ -2265,12 +2262,10 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) { /* Sort symbols so that symbols with the same program space are next to each other. */ - qsort (VEC_address (symbolp, ls->function_symbols), - VEC_length (symbolp, ls->function_symbols), - sizeof (symbolp), compare_symbols); + qsort (ls->function_symbols->data (), ls->function_symbols->size (), + sizeof (symbol *), compare_symbols); - struct symbol *sym; - for (int i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i) + for (const auto &sym : *ls->function_symbols) { program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym)); set_current_program_space (pspace); @@ -2392,7 +2387,8 @@ convert_explicit_location_to_linespec (struct linespec_state *self, const char *label_name, struct line_offset line_offset) { - VEC (symbolp) *symbols, *labels; + std::vector symbols; + VEC (symbolp) *labels; VEC (bound_minimal_symbol_d) *minimal_symbols; result->explicit_loc.func_name_match_type = fname_match_type; @@ -2423,18 +2419,18 @@ convert_explicit_location_to_linespec (struct linespec_state *self, function_name, fname_match_type, &symbols, &minimal_symbols); - if (symbols == NULL && minimal_symbols == NULL) + if (symbols.empty () && minimal_symbols == NULL) symbol_not_found_error (function_name, result->explicit_loc.source_filename); result->explicit_loc.function_name = xstrdup (function_name); - result->function_symbols = symbols; + result->function_symbols + = new std::vector (std::move (symbols)); result->minimal_symbols = minimal_symbols; } if (label_name != NULL) { - symbols = NULL; labels = find_label_symbols (self, result->function_symbols, &symbols, label_name); @@ -2444,7 +2440,8 @@ convert_explicit_location_to_linespec (struct linespec_state *self, result->explicit_loc.label_name = xstrdup (label_name); result->labels.label_symbols = labels; - result->labels.function_symbols = symbols; + result->labels.function_symbols + = new std::vector (std::move (symbols)); } if (line_offset.sign != LINE_OFFSET_UNKNOWN) @@ -2778,9 +2775,7 @@ linespec_parser_delete (void *arg) xfree (PARSER_EXPLICIT (parser)->function_name); delete PARSER_RESULT (parser)->file_symtabs; - - if (PARSER_RESULT (parser)->function_symbols != NULL) - VEC_free (symbolp, PARSER_RESULT (parser)->function_symbols); + delete PARSER_RESULT (parser)->function_symbols; if (PARSER_RESULT (parser)->minimal_symbols != NULL) VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols); @@ -2788,8 +2783,7 @@ linespec_parser_delete (void *arg) if (PARSER_RESULT (parser)->labels.label_symbols != NULL) VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols); - if (PARSER_RESULT (parser)->labels.function_symbols != NULL) - VEC_free (symbolp, PARSER_RESULT (parser)->labels.function_symbols); + delete PARSER_RESULT (parser)->labels.function_symbols; linespec_state_destructor (PARSER_STATE (parser)); } @@ -2922,7 +2916,7 @@ complete_label (completion_tracker &tracker, linespec_parser *parser, const char *label_name) { - VEC (symbolp) *label_function_symbols = NULL; + std::vector label_function_symbols; VEC (symbolp) *labels = find_label_symbols (PARSER_STATE (parser), PARSER_RESULT (parser)->function_symbols, @@ -3045,14 +3039,15 @@ linespec_complete (completion_tracker &tracker, const char *text, const char *func_name = PARSER_EXPLICIT (&parser)->function_name; - VEC (symbolp) *function_symbols; + std::vector function_symbols; VEC (bound_minimal_symbol_d) *minimal_symbols; find_linespec_symbols (PARSER_STATE (&parser), PARSER_RESULT (&parser)->file_symtabs, func_name, match_type, &function_symbols, &minimal_symbols); - PARSER_RESULT (&parser)->function_symbols = function_symbols; + PARSER_RESULT (&parser)->function_symbols + = new std::vector (std::move (function_symbols)); PARSER_RESULT (&parser)->minimal_symbols = minimal_symbols; complete_label (tracker, &parser, parser.completion_word); @@ -3450,7 +3445,9 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) symtabs.push_back (nullptr); info.file_symtabs = &symtabs; - info.result.symbols = NULL; + + std::vector symbols; + info.result.symbols = &symbols; info.result.minimal_symbols = NULL; new_argptr = find_imps (arg, &symbol_names); @@ -3461,7 +3458,7 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) FUNCTIONS_DOMAIN); std::vector values; - if (!VEC_empty (symbolp, info.result.symbols) + if (!symbols.empty () || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) { char *saved_arg; @@ -3471,7 +3468,7 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) saved_arg[new_argptr - arg] = '\0'; ls->explicit_loc.function_name = xstrdup (saved_arg); - ls->function_symbols = info.result.symbols; + ls->function_symbols = new std::vector (std::move (symbols)); ls->minimal_symbols = info.result.minimal_symbols; values = convert_linespec_to_sals (self, ls); @@ -3711,7 +3708,7 @@ find_superclass_methods (std::vector &&superclasses, static void find_method (struct linespec_state *self, std::vector *file_symtabs, const char *class_name, const char *method_name, - VEC (symbolp) *sym_classes, VEC (symbolp) **symbols, + VEC (symbolp) *sym_classes, std::vector *symbols, VEC (bound_minimal_symbol_d) **minsyms) { struct symbol *sym; @@ -3730,7 +3727,7 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, info.state = self; info.file_symtabs = file_symtabs; - info.result.symbols = NULL; + info.result.symbols = symbols; info.result.minimal_symbols = NULL; /* Iterate over all the types, looking for the names of existing @@ -3781,10 +3778,9 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, } } - if (!VEC_empty (symbolp, info.result.symbols) + if (!symbols->empty () || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) { - *symbols = info.result.symbols; *minsyms = info.result.minimal_symbols; return; } @@ -3917,14 +3913,14 @@ static void find_function_symbols (struct linespec_state *state, std::vector *file_symtabs, const char *name, symbol_name_match_type name_match_type, - VEC (symbolp) **symbols, + std::vector *symbols, VEC (bound_minimal_symbol_d) **minsyms) { struct collect_info info; std::vector symbol_names; info.state = state; - info.result.symbols = NULL; + info.result.symbols = symbols; info.result.minimal_symbols = NULL; info.file_symtabs = file_symtabs; @@ -3937,14 +3933,6 @@ find_function_symbols (struct linespec_state *state, add_matching_symbols_to_info (name, name_match_type, FUNCTIONS_DOMAIN, &info, state->search_pspace); - if (VEC_empty (symbolp, info.result.symbols)) - { - VEC_free (symbolp, info.result.symbols); - *symbols = NULL; - } - else - *symbols = info.result.symbols; - if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) { VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols); @@ -3962,7 +3950,7 @@ find_linespec_symbols (struct linespec_state *state, std::vector *file_symtabs, const char *lookup_name, symbol_name_match_type name_match_type, - VEC (symbolp) **symbols, + std::vector *symbols, VEC (bound_minimal_symbol_d) **minsyms) { std::string canon = cp_canonicalize_string_no_typedefs (lookup_name); @@ -3979,13 +3967,12 @@ find_linespec_symbols (struct linespec_state *state, 2) break class::method where method is in class (and not a baseclass) */ find_function_symbols (state, file_symtabs, lookup_name, - name_match_type, - symbols, minsyms); + name_match_type, symbols, minsyms); /* If we were unable to locate a symbol of the same name, try dividing the name into class and method names and searching the class and its baseclasses. */ - if (VEC_empty (symbolp, *symbols) + if (symbols->empty () && VEC_empty (bound_minimal_symbol_d, *minsyms)) { std::string klass, method; @@ -4059,7 +4046,7 @@ find_label_symbols_in_block (const struct block *block, const char *name, struct symbol *fn_sym, bool completion_mode, VEC (symbolp) **result, - VEC (symbolp) **label_funcs_ret) + std::vector *label_funcs_ret) { if (completion_mode) { @@ -4077,7 +4064,7 @@ find_label_symbols_in_block (const struct block *block, && cmp (SYMBOL_SEARCH_NAME (sym), name, name_len) == 0) { VEC_safe_push (symbolp, *result, sym); - VEC_safe_push (symbolp, *label_funcs_ret, fn_sym); + label_funcs_ret->push_back (fn_sym); } } } @@ -4088,7 +4075,7 @@ find_label_symbols_in_block (const struct block *block, if (sym != NULL) { VEC_safe_push (symbolp, *result, sym); - VEC_safe_push (symbolp, *label_funcs_ret, fn_sym); + label_funcs_ret->push_back (fn_sym); } } } @@ -4101,11 +4088,10 @@ find_label_symbols_in_block (const struct block *block, static VEC (symbolp) * find_label_symbols (struct linespec_state *self, - VEC (symbolp) *function_symbols, - VEC (symbolp) **label_funcs_ret, const char *name, + std::vector *function_symbols, + std::vector *label_funcs_ret, const char *name, bool completion_mode) { - int ix; const struct block *block; struct symbol *fn_sym; VEC (symbolp) *result = NULL; @@ -4128,13 +4114,12 @@ find_label_symbols (struct linespec_state *self, } else { - for (ix = 0; - VEC_iterate (symbolp, function_symbols, ix, fn_sym); ++ix) + for (const auto &elt : *function_symbols) { - set_current_program_space (SYMTAB_PSPACE (symbol_symtab (fn_sym))); - block = SYMBOL_BLOCK_VALUE (fn_sym); + set_current_program_space (SYMTAB_PSPACE (symbol_symtab (elt))); + block = SYMBOL_BLOCK_VALUE (elt); - find_label_symbols_in_block (block, name, fn_sym, completion_mode, + find_label_symbols_in_block (block, name, elt, completion_mode, &result, label_funcs_ret); } } @@ -4490,7 +4475,7 @@ add_matching_symbols_to_info (const char *name, } else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt)) { - int prev_len = VEC_length (symbolp, info->result.symbols); + int prev_len = info->result.symbols->size (); /* Program spaces that are executing startup should have been filtered out earlier. */ @@ -4504,7 +4489,7 @@ add_matching_symbols_to_info (const char *name, is in assembler, we might actually be looking for a label for which we don't have debug info. Check for a minimal symbol in this case. */ - if (prev_len == VEC_length (symbolp, info->result.symbols) + if (prev_len == info->result.symbols->size () && elt->language == language_asm) search_minsyms_for_name (info, lookup_name, pspace, elt); }