From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33941 invoked by alias); 11 Apr 2017 15:21:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32298 invoked by uid 89); 11 Apr 2017 15:21:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy10.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 15:21:08 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id D3C16141C86 for ; Tue, 11 Apr 2017 09:01:22 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id 731K1v01K2f2jeq0131NoD; Tue, 11 Apr 2017 09:01:22 -0600 X-Authority-Analysis: v=2.2 cv=QdwWhoTv c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=EI0tgHN0zcg_ZKZoWf4A:9 a=OHBTQvgDg_SUel9K:21 a=oy4snwOj0zuksFWq:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:50042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cxxIF-0007Ml-D9; Tue, 11 Apr 2017 09:01:19 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 03/17] Change find_pcs_for_symtab_line to return a std::vector Date: Tue, 11 Apr 2017 15:21:00 -0000 Message-Id: <20170411150112.23207-4-tom@tromey.com> In-Reply-To: <20170411150112.23207-1-tom@tromey.com> References: <20170411150112.23207-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cxxIF-0007Ml-D9 X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:50042 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2017-04/txt/msg00283.txt.bz2 This changes find_pcs_for_symtab_line to return a std::vector. This allows the removal of some cleanups. gdb/ChangeLog 2017-04-11 Tom Tromey * symtab.h (find_pcs_for_symtab_line): Change return type. * symtab.c (find_pcs_for_symtab_line): Change return type. * python/py-linetable.c (build_line_table_tuple_from_pcs): Change type of "vec". Update. (ltpy_get_pcs_for_line): Update. * linespec.c (decode_digits_ordinary): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/linespec.c | 8 ++------ gdb/python/py-linetable.c | 24 +++++++++--------------- gdb/symtab.c | 11 +++++------ gdb/symtab.h | 6 +++--- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7fa5099..a71de4a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-04-11 Tom Tromey + * symtab.h (find_pcs_for_symtab_line): Change return type. + * symtab.c (find_pcs_for_symtab_line): Change return type. + * python/py-linetable.c (build_line_table_tuple_from_pcs): Change + type of "vec". Update. + (ltpy_get_pcs_for_line): Update. + * linespec.c (decode_digits_ordinary): Update. + +2017-04-11 Tom Tromey + * tracepoint.c (actions_command): Update. * python/python.c (python_command, python_interactive_command): Update. diff --git a/gdb/linespec.c b/gdb/linespec.c index 41b82d7..bccabaf 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3469,9 +3469,7 @@ decode_digits_ordinary (struct linespec_state *self, for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix) { - int i; - VEC (CORE_ADDR) *pcs; - CORE_ADDR pc; + std::vector pcs; /* The logic above should ensure this. */ gdb_assert (elt != NULL); @@ -3479,7 +3477,7 @@ decode_digits_ordinary (struct linespec_state *self, set_current_program_space (SYMTAB_PSPACE (elt)); pcs = find_pcs_for_symtab_line (elt, line, best_entry); - for (i = 0; VEC_iterate (CORE_ADDR, pcs, i, pc); ++i) + for (CORE_ADDR pc : pcs) { struct symtab_and_line sal; @@ -3490,8 +3488,6 @@ decode_digits_ordinary (struct linespec_state *self, sal.pc = pc; add_sal_to_sals_basic (sals, &sal); } - - VEC_free (CORE_ADDR, pcs); } } diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index 8d17aab..13daa3d 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -115,30 +115,28 @@ build_linetable_entry (int line, CORE_ADDR address) return (PyObject *) obj; } -/* Internal helper function to build a Python Tuple from a GDB Vector. +/* Internal helper function to build a Python Tuple from a vector. A line table entry can have multiple PCs for a given source line. Construct a Tuple of all entries for the given source line, LINE - from the line table VEC. Construct one line table entry object per + from the line table PCS. Construct one line table entry object per address. */ static PyObject * -build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec) +build_line_table_tuple_from_pcs (int line, const std::vector &pcs) { - int vec_len = 0; - CORE_ADDR pc; int i; - vec_len = VEC_length (CORE_ADDR, vec); - if (vec_len < 1) + if (pcs.size () < 1) Py_RETURN_NONE; - gdbpy_ref<> tuple (PyTuple_New (vec_len)); + gdbpy_ref<> tuple (PyTuple_New (pcs.size ())); if (tuple == NULL) return NULL; - for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i) + for (i = 0; i < pcs.size (); ++i) { + CORE_ADDR pc = pcs[i]; gdbpy_ref<> obj (build_linetable_entry (line, pc)); if (obj == NULL) @@ -160,8 +158,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args) struct symtab *symtab; gdb_py_longest py_line; struct linetable_entry *best_entry = NULL; - VEC (CORE_ADDR) *pcs = NULL; - PyObject *tuple; + std::vector pcs; LTPY_REQUIRE_VALID (self, symtab); @@ -178,10 +175,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args) } END_CATCH - tuple = build_line_table_tuple_from_pcs (py_line, pcs); - VEC_free (CORE_ADDR, pcs); - - return tuple; + return build_line_table_tuple_from_pcs (py_line, pcs); } /* Implementation of gdb.LineTable.has_line (self, line) -> Boolean. diff --git a/gdb/symtab.c b/gdb/symtab.c index cc2f400..20ef76d 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3289,15 +3289,15 @@ done: } /* Given SYMTAB, returns all the PCs function in the symtab that - exactly match LINE. Returns NULL if there are no exact matches, - but updates BEST_ITEM in this case. */ + exactly match LINE. Returns an empty vector if there are no exact + matches, but updates BEST_ITEM in this case. */ -VEC (CORE_ADDR) * +std::vector find_pcs_for_symtab_line (struct symtab *symtab, int line, struct linetable_entry **best_item) { int start = 0; - VEC (CORE_ADDR) *result = NULL; + std::vector result; /* First, collect all the PCs that are at this line. */ while (1) @@ -3320,8 +3320,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line, break; } - VEC_safe_push (CORE_ADDR, result, - SYMTAB_LINETABLE (symtab)->item[idx].pc); + result.push_back (SYMTAB_LINETABLE (symtab)->item[idx].pc); start = idx + 1; } diff --git a/gdb/symtab.h b/gdb/symtab.h index d8c665c..341deca 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -20,7 +20,7 @@ #if !defined (SYMTAB_H) #define SYMTAB_H 1 -#include "vec.h" +#include #include "gdb_vecs.h" #include "gdbtypes.h" #include "common/enum-flags.h" @@ -1618,8 +1618,8 @@ void iterate_over_symtabs (const char *name, gdb::function_view callback); -VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line, - struct linetable_entry **best_entry); +std::vector find_pcs_for_symtab_line + (struct symtab *symtab, int line, struct linetable_entry **best_entry); /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback is called once per matching symbol SYM. The callback should return -- 2.9.3