From patchwork Fri Aug 10 23:25:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 28852 Received: (qmail 50273 invoked by alias); 10 Aug 2018 23:25:39 -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 50209 invoked by uid 89); 10 Aug 2018 23:25:38 -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=vec 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 2ED36308403A 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 040A652FD4 for ; Fri, 10 Aug 2018 23:25:35 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 3/9] Change `label_symbols' to std::vector in linespec.c structures Date: Fri, 10 Aug 2018 16:25:28 -0700 Message-Id: <20180810232534.481-4-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. (find_label_symbols_in_block): Change `result' parameter to std::vector. Update all callers. (find_label_symbols): Return std::vector. Update all callers. --- gdb/ChangeLog | 8 ++++++++ gdb/linespec.c | 54 +++++++++++++++++++++++++++--------------------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5a71381262..b3f5a5d039 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. + (find_label_symbols_in_block): Change `result' parameter to + std::vector. Update all callers. + (find_label_symbols): Return std::vector. Update all callers. + +YYYY-MM-DD Keith Seitz + * linespec.c (struct linespec) : Change type to std::vector. Update all users. (struct collect_info) : Likewise. diff --git a/gdb/linespec.c b/gdb/linespec.c index 8070db68ec..4e7f9b08b0 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -123,7 +123,7 @@ struct linespec or both must be non-NULL. */ struct { - VEC (symbolp) *label_symbols; + std::vector *label_symbols; std::vector *function_symbols; } labels; }; @@ -352,7 +352,7 @@ 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 +static std::vector *find_label_symbols (struct linespec_state *self, std::vector *function_symbols, std::vector *label_funcs_ret, const char *name, bool completion_mode = false); @@ -1767,7 +1767,7 @@ linespec_parse_basic (linespec_parser *parser) gdb::unique_xmalloc_ptr name; linespec_token token; std::vector symbols; - VEC (symbolp) *labels; + std::vector *labels; VEC (bound_minimal_symbol_d) *minimal_symbols; /* Get the next token. */ @@ -2241,12 +2241,9 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) if (ls->labels.label_symbols != NULL) { /* We have just a bunch of functions/methods or labels. */ - int i; - struct symtab_and_line sal; - struct symbol *sym; - - for (i = 0; VEC_iterate (symbolp, ls->labels.label_symbols, i, sym); ++i) + for (const auto &sym : *ls->labels.label_symbols) { + struct symtab_and_line sal; struct program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym)); if (symbol_to_sal (&sal, state->funfirstline, sym) @@ -2388,7 +2385,7 @@ convert_explicit_location_to_linespec (struct linespec_state *self, struct line_offset line_offset) { std::vector symbols; - VEC (symbolp) *labels; + std::vector *labels; VEC (bound_minimal_symbol_d) *minimal_symbols; result->explicit_loc.func_name_match_type = fname_match_type; @@ -2780,9 +2777,7 @@ linespec_parser_delete (void *arg) if (PARSER_RESULT (parser)->minimal_symbols != NULL) VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols); - if (PARSER_RESULT (parser)->labels.label_symbols != NULL) - VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols); - + delete PARSER_RESULT (parser)->labels.label_symbols; delete PARSER_RESULT (parser)->labels.function_symbols; linespec_state_destructor (PARSER_STATE (parser)); @@ -2917,20 +2912,21 @@ complete_label (completion_tracker &tracker, const char *label_name) { std::vector label_function_symbols; - VEC (symbolp) *labels + std::vector *labels = find_label_symbols (PARSER_STATE (parser), PARSER_RESULT (parser)->function_symbols, &label_function_symbols, label_name, true); - symbol *label; - for (int ix = 0; - VEC_iterate (symbolp, labels, ix, label); ++ix) + if (labels != nullptr) { - char *match = xstrdup (SYMBOL_SEARCH_NAME (label)); - tracker.add_completion (gdb::unique_xmalloc_ptr (match)); + for (const auto &label : *labels) + { + char *match = xstrdup (SYMBOL_SEARCH_NAME (label)); + tracker.add_completion (gdb::unique_xmalloc_ptr (match)); + } + delete labels; } - VEC_free (symbolp, labels); } /* See linespec.h. */ @@ -4045,7 +4041,7 @@ static void find_label_symbols_in_block (const struct block *block, const char *name, struct symbol *fn_sym, bool completion_mode, - VEC (symbolp) **result, + std::vector *result, std::vector *label_funcs_ret) { if (completion_mode) @@ -4063,7 +4059,7 @@ find_label_symbols_in_block (const struct block *block, SYMBOL_DOMAIN (sym), LABEL_DOMAIN) && cmp (SYMBOL_SEARCH_NAME (sym), name, name_len) == 0) { - VEC_safe_push (symbolp, *result, sym); + result->push_back (sym); label_funcs_ret->push_back (fn_sym); } } @@ -4074,19 +4070,21 @@ find_label_symbols_in_block (const struct block *block, if (sym != NULL) { - VEC_safe_push (symbolp, *result, sym); + result->push_back (sym); label_funcs_ret->push_back (fn_sym); } } } -/* Return all labels that match name NAME in FUNCTION_SYMBOLS. Return - the actual function symbol in which the label was found in +/* Return all labels that match name NAME in FUNCTION_SYMBOLS or NULL + if no matches were found. + + Return the actual function symbol in which the label was found in LABEL_FUNC_RET. If COMPLETION_MODE is true, then NAME is interpreted as a label name prefix. Otherwise, only labels named exactly NAME match. */ -static VEC (symbolp) * +static std::vector * find_label_symbols (struct linespec_state *self, std::vector *function_symbols, std::vector *label_funcs_ret, const char *name, @@ -4094,7 +4092,7 @@ find_label_symbols (struct linespec_state *self, { const struct block *block; struct symbol *fn_sym; - VEC (symbolp) *result = NULL; + std::vector result; if (function_symbols == NULL) { @@ -4124,7 +4122,9 @@ find_label_symbols (struct linespec_state *self, } } - return result; + if (!result.empty ()) + return new std::vector (std::move (result)); + return nullptr; }