Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 03/14] Change find_pcs_for_symtab_line to return a std::vector
Date: Sat, 08 Apr 2017 20:12:00 -0000	[thread overview]
Message-ID: <20170408201208.2672-4-tom@tromey.com> (raw)
In-Reply-To: <20170408201208.2672-1-tom@tromey.com>

This changes find_pcs_for_symtab_line to return a std::vector.  This
allows the removal of some cleanups.

2017-04-07  Tom Tromey  <tom@tromey.com>

	* 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 | 20 ++++++++------------
 gdb/symtab.c              | 11 +++++------
 gdb/symtab.h              |  6 +++---
 5 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 30de15b..9451af1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
 2017-04-07  Tom Tromey  <tom@tromey.com>
 
+	* 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-07  Tom Tromey  <tom@tromey.com>
+
 	* 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<CORE_ADDR> 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..6c9350a 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -122,23 +122,23 @@ build_linetable_entry (int line, CORE_ADDR address)
    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<CORE_ADDR> &vec)
 {
-  int vec_len = 0;
-  CORE_ADDR pc;
+  int vec_len;
   int i;
 
-  vec_len = VEC_length (CORE_ADDR, vec);
+  vec_len = vec.size ();
   if (vec_len < 1)
     Py_RETURN_NONE;
 
-  gdbpy_ref<> tuple (PyTuple_New (vec_len));
+  gdbpy_ref<> tuple (PyTuple_New (vec.size ()));
 
   if (tuple == NULL)
     return NULL;
 
-  for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i)
+  for (i = 0; i < vec_len; ++i)
     {
+      CORE_ADDR pc = vec[i];
       gdbpy_ref<> obj (build_linetable_entry (line, pc));
 
       if (obj == NULL)
@@ -160,8 +160,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<CORE_ADDR> pcs;
 
   LTPY_REQUIRE_VALID (self, symtab);
 
@@ -178,10 +177,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<CORE_ADDR>
 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<CORE_ADDR> 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 <vector>
 #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<bool (symtab *)> callback);
 
 
-VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line,
-					   struct linetable_entry **best_entry);
+std::vector<CORE_ADDR> 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


  parent reply	other threads:[~2017-04-08 20:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 20:12 [RFA 00/14] miscellaneous C++-ificiation Tom Tromey
2017-04-08 20:12 ` [RFA 08/14] Remove some cleanups from gnu-v3-abi.c Tom Tromey
2017-04-10  4:09   ` Simon Marchi
2017-04-10 13:57     ` Tom Tromey
2017-04-08 20:12 ` [RFA 11/14] Use scoped_restore in more places Tom Tromey
2017-04-11  1:48   ` Simon Marchi
2017-04-08 20:12 ` [RFA 06/14] Remove cleanup_iconv Tom Tromey
2017-04-10  3:56   ` Simon Marchi
2017-04-10 23:20     ` Tom Tromey
2017-04-08 20:12 ` [RFA 01/14] Introduce event_location_up Tom Tromey
2017-04-10  1:33   ` Simon Marchi
2017-04-10 23:19     ` Tom Tromey
2017-04-08 20:12 ` [RFA 02/14] Introduce command_line_up Tom Tromey
2017-04-10  2:36   ` Simon Marchi
2017-04-10 23:21     ` Tom Tromey
2017-04-08 20:12 ` [RFA 14/14] Use std::vector in compile-loc2c.c Tom Tromey
2017-04-08 20:12 ` [RFA 09/14] Remove some cleanups from location.c Tom Tromey
2017-04-10  4:43   ` Simon Marchi
2017-04-08 20:12 ` [RFA 10/14] C++ify mi_parse Tom Tromey
2017-04-11  1:12   ` Simon Marchi
2017-04-08 20:12 ` Tom Tromey [this message]
2017-04-10  2:49   ` [RFA 03/14] Change find_pcs_for_symtab_line to return a std::vector Simon Marchi
2017-04-08 20:13 ` [RFA 13/14] Use std::vector in find_instruction_backward Tom Tromey
2017-04-08 20:13 ` [RFA 12/14] Use std::vector in reread_symbols Tom Tromey
2017-04-11  1:59   ` Simon Marchi
2017-04-08 20:13 ` [RFA 04/14] Introduce gdb_dlopen_up Tom Tromey
2017-04-10  3:13   ` Simon Marchi
2017-04-10  9:26   ` Pedro Alves
2017-04-10 23:31     ` Tom Tromey
2017-04-08 20:22 ` [RFA 07/14] Fix up wchar_iterator comment Tom Tromey
2017-04-10  4:05   ` Simon Marchi
2017-04-10 23:29     ` Tom Tromey
2017-04-08 20:23 ` [RFA 05/14] Change increment_reading_symtab to return a scoped_restore Tom Tromey
2017-04-10  3:27   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170408201208.2672-4-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox