From patchwork Fri Aug 10 23:25:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 28859 Received: (qmail 59875 invoked by alias); 10 Aug 2018 23:32:41 -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 59749 invoked by uid 89); 10 Aug 2018 23:32:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_STOCKGEN, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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:32: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 79B04333B9 for ; Fri, 10 Aug 2018 23:25:36 +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 45C0E5429B for ; Fri, 10 Aug 2018 23:25:36 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 4/9] Change `minimal_symbols' to std::vector in linespec.c structures Date: Fri, 10 Aug 2018 16:25:29 -0700 Message-Id: <20180810232534.481-5-keiths@redhat.com> In-Reply-To: <20180810232534.481-1-keiths@redhat.com> References: <20180810232534.481-1-keiths@redhat.com> X-IsSubscribed: yes This patch converts linespec.c's linespec.label_symbols member 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): Change `minsyms' parameter to std::vector. Update all callers. --- gdb/ChangeLog | 8 +++++ gdb/linespec.c | 104 +++++++++++++++++++++++---------------------------------- 2 files changed, 49 insertions(+), 63 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b3f5a5d039..f762196cbc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 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): Change + `minsyms' parameter to std::vector. Update all callers. + +YYYY-MM-DD Keith Seitz + * linespec.c (struct linespec) : Change type to std::vector. Update all users. (find_label_symbols_in_block): Change `result' parameter to diff --git a/gdb/linespec.c b/gdb/linespec.c index 4e7f9b08b0..bc20001df9 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -116,7 +116,7 @@ struct linespec /* A list of matching function symbols and minimal symbols. Both lists may be NULL (or empty) if no matching symbols were found. */ std::vector *function_symbols; - VEC (bound_minimal_symbol_d) *minimal_symbols; + std::vector *minimal_symbols; /* A structure of matching label symbols and the corresponding function symbol in which the label was found. Both may be NULL @@ -202,7 +202,7 @@ struct collect_info struct { std::vector *symbols; - VEC (bound_minimal_symbol_d) *minimal_symbols; + std::vector *minimal_symbols; } result; /* Possibly add a symbol to the results. */ @@ -362,7 +362,7 @@ static void find_linespec_symbols (struct linespec_state *self, const char *name, symbol_name_match_type name_match_type, std::vector *symbols, - VEC (bound_minimal_symbol_d) **minsyms); + std::vector *minsyms); static struct line_offset linespec_parse_variable (struct linespec_state *self, @@ -1768,7 +1768,7 @@ linespec_parse_basic (linespec_parser *parser) linespec_token token; std::vector symbols; std::vector *labels; - VEC (bound_minimal_symbol_d) *minimal_symbols; + std::vector minimal_symbols; /* Get the next token. */ token = linespec_lexer_lex_one (parser); @@ -1871,11 +1871,13 @@ linespec_parse_basic (linespec_parser *parser) PARSER_EXPLICIT (parser)->func_name_match_type, &symbols, &minimal_symbols); - if (!symbols.empty () || minimal_symbols != NULL) + if (!symbols.empty () || !minimal_symbols.empty ()) { PARSER_RESULT (parser)->function_symbols = new std::vector (std::move (symbols)); - PARSER_RESULT (parser)->minimal_symbols = minimal_symbols; + PARSER_RESULT (parser)->minimal_symbols + = new std::vector + (std::move (minimal_symbols)); PARSER_EXPLICIT (parser)->function_name = name.release (); } else @@ -2280,20 +2282,16 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) const CORE_ADDR addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); - bound_minimal_symbol_d *elem; - for (int m = 0; - VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols, - m, elem); - ++m) + for (const auto &elem : *ls->minimal_symbols) { - if (MSYMBOL_TYPE (elem->minsym) == mst_text_gnu_ifunc - || MSYMBOL_TYPE (elem->minsym) == mst_data_gnu_ifunc) + if (MSYMBOL_TYPE (elem.minsym) == mst_text_gnu_ifunc + || MSYMBOL_TYPE (elem.minsym) == mst_data_gnu_ifunc) { - CORE_ADDR msym_addr = BMSYMBOL_VALUE_ADDRESS (*elem); - if (MSYMBOL_TYPE (elem->minsym) == mst_data_gnu_ifunc) + CORE_ADDR msym_addr = BMSYMBOL_VALUE_ADDRESS (elem); + if (MSYMBOL_TYPE (elem.minsym) == mst_data_gnu_ifunc) { struct gdbarch *gdbarch - = get_objfile_arch (elem->objfile); + = get_objfile_arch (elem.objfile); msym_addr = (gdbarch_convert_from_func_ptr_addr (gdbarch, @@ -2324,20 +2322,14 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) if (ls->minimal_symbols != NULL) { /* Sort minimal symbols by program space, too */ - qsort (VEC_address (bound_minimal_symbol_d, ls->minimal_symbols), - VEC_length (bound_minimal_symbol_d, ls->minimal_symbols), - sizeof (bound_minimal_symbol_d), compare_msymbols); + qsort (ls->minimal_symbols->data (), ls->minimal_symbols->size (), + sizeof (bound_minimal_symbol), compare_msymbols); - bound_minimal_symbol_d *elem; - - for (int i = 0; - VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols, - i, elem); - ++i) + for (const auto &elem : *ls->minimal_symbols) { - program_space *pspace = elem->objfile->pspace; + program_space *pspace = elem.objfile->pspace; set_current_program_space (pspace); - minsym_found (state, elem->objfile, elem->minsym, &sals); + minsym_found (state, elem.objfile, elem.minsym, &sals); } } } @@ -2386,7 +2378,7 @@ convert_explicit_location_to_linespec (struct linespec_state *self, { std::vector symbols; std::vector *labels; - VEC (bound_minimal_symbol_d) *minimal_symbols; + std::vector minimal_symbols; result->explicit_loc.func_name_match_type = fname_match_type; @@ -2416,14 +2408,15 @@ convert_explicit_location_to_linespec (struct linespec_state *self, function_name, fname_match_type, &symbols, &minimal_symbols); - if (symbols.empty () && minimal_symbols == NULL) + if (symbols.empty () && minimal_symbols.empty ()) symbol_not_found_error (function_name, result->explicit_loc.source_filename); result->explicit_loc.function_name = xstrdup (function_name); result->function_symbols = new std::vector (std::move (symbols)); - result->minimal_symbols = minimal_symbols; + result->minimal_symbols + = new std::vector (std::move (minimal_symbols)); } if (label_name != NULL) @@ -2773,10 +2766,7 @@ linespec_parser_delete (void *arg) delete PARSER_RESULT (parser)->file_symtabs; delete PARSER_RESULT (parser)->function_symbols; - - if (PARSER_RESULT (parser)->minimal_symbols != NULL) - VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols); - + delete PARSER_RESULT (parser)->minimal_symbols; delete PARSER_RESULT (parser)->labels.label_symbols; delete PARSER_RESULT (parser)->labels.function_symbols; @@ -3036,7 +3026,7 @@ linespec_complete (completion_tracker &tracker, const char *text, const char *func_name = PARSER_EXPLICIT (&parser)->function_name; std::vector function_symbols; - VEC (bound_minimal_symbol_d) *minimal_symbols; + std::vector minimal_symbols; find_linespec_symbols (PARSER_STATE (&parser), PARSER_RESULT (&parser)->file_symtabs, func_name, match_type, @@ -3044,7 +3034,8 @@ linespec_complete (completion_tracker &tracker, const char *text, PARSER_RESULT (&parser)->function_symbols = new std::vector (std::move (function_symbols)); - PARSER_RESULT (&parser)->minimal_symbols = minimal_symbols; + PARSER_RESULT (&parser)->minimal_symbols + = new std::vector (std::move (minimal_symbols)); complete_label (tracker, &parser, parser.completion_word); } @@ -3444,7 +3435,8 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) std::vector symbols; info.result.symbols = &symbols; - info.result.minimal_symbols = NULL; + std::vector minimal_symbols; + info.result.minimal_symbols = &minimal_symbols; new_argptr = find_imps (arg, &symbol_names); if (symbol_names.empty ()) @@ -3454,8 +3446,7 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) FUNCTIONS_DOMAIN); std::vector values; - if (!symbols.empty () - || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) + if (!symbols.empty () || !minimal_symbols.empty ()) { char *saved_arg; @@ -3465,7 +3456,8 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) ls->explicit_loc.function_name = xstrdup (saved_arg); ls->function_symbols = new std::vector (std::move (symbols)); - ls->minimal_symbols = info.result.minimal_symbols; + ls->minimal_symbols + = new std::vector (std::move (minimal_symbols)); values = convert_linespec_to_sals (self, ls); if (self->canonical) @@ -3705,7 +3697,7 @@ static void find_method (struct linespec_state *self, std::vector *file_symtabs, const char *class_name, const char *method_name, VEC (symbolp) *sym_classes, std::vector *symbols, - VEC (bound_minimal_symbol_d) **minsyms) + std::vector *minsyms) { struct symbol *sym; int ix; @@ -3724,7 +3716,7 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, info.state = self; info.file_symtabs = file_symtabs; info.result.symbols = symbols; - info.result.minimal_symbols = NULL; + info.result.minimal_symbols = minsyms; /* Iterate over all the types, looking for the names of existing methods matching METHOD_NAME. If we cannot find a direct method in a @@ -3774,12 +3766,8 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, } } - if (!symbols->empty () - || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) - { - *minsyms = info.result.minimal_symbols; - return; - } + if (!symbols->empty () || !minsyms->empty ()) + return; /* Throw an NOT_FOUND_ERROR. This will be caught by the caller and other attempts to locate the symbol will be made. */ @@ -3910,14 +3898,14 @@ find_function_symbols (struct linespec_state *state, std::vector *file_symtabs, const char *name, symbol_name_match_type name_match_type, std::vector *symbols, - VEC (bound_minimal_symbol_d) **minsyms) + std::vector *minsyms) { struct collect_info info; std::vector symbol_names; info.state = state; info.result.symbols = symbols; - info.result.minimal_symbols = NULL; + info.result.minimal_symbols = minsyms; info.file_symtabs = file_symtabs; /* Try NAME as an Objective-C selector. */ @@ -3928,14 +3916,6 @@ find_function_symbols (struct linespec_state *state, else add_matching_symbols_to_info (name, name_match_type, FUNCTIONS_DOMAIN, &info, state->search_pspace); - - if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) - { - VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols); - *minsyms = NULL; - } - else - *minsyms = info.result.minimal_symbols; } /* Find all symbols named NAME in FILE_SYMTABS, returning debug symbols @@ -3947,7 +3927,7 @@ find_linespec_symbols (struct linespec_state *state, const char *lookup_name, symbol_name_match_type name_match_type, std::vector *symbols, - VEC (bound_minimal_symbol_d) **minsyms) + std::vector *minsyms) { std::string canon = cp_canonicalize_string_no_typedefs (lookup_name); if (!canon.empty ()) @@ -3968,8 +3948,7 @@ find_linespec_symbols (struct linespec_state *state, /* 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 (symbols->empty () - && VEC_empty (bound_minimal_symbol_d, *minsyms)) + if (symbols->empty () && minsyms->empty ()) { std::string klass, method; const char *last, *p, *scope_op; @@ -4444,8 +4423,7 @@ search_minsyms_for_name (struct collect_info *info, if (classify_mtype (MSYMBOL_TYPE (item.minsym)) != classification) break; - VEC_safe_push (bound_minimal_symbol_d, - info->result.minimal_symbols, &item); + info->result.minimal_symbols->push_back (item); } } }