This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] Get rid of VEC(probe_p)


From: Simon Marchi <simon.marchi@ericsson.com>

Replace the remaining usages of VEC(probe_p) with std::vector.

Regtested on the buildbot.

gdb/ChangeLog:

	* probe.h: Don't include gdb_vecs.h.
	(DEF_VEC_P (probe_p)): Remove.
	(find_probes_in_objfile): Return an std::vector.
	* probe.c (find_probes_in_objfile): Likewise.
	* breakpoint.c (breakpoint_objfile_data)
	<longjmp_probes>: Change type to std::vector.
	<exception_probes>: Likewise.
	(free_breakpoint_probes): Don't manually free vectors.
	(create_longjmp_master_breakpoint): Adjust.
	(create_exception_master_breakpoint): Adjust.
	* solib-svr4.c (svr4_create_probe_breakpoints): Change
	parameter type, adjust.
	(svr4_create_solib_event_breakpoints): Adjust.
---
 gdb/breakpoint.c | 64 ++++++++++++++++++++------------------------------------
 gdb/probe.c      |  8 +++----
 gdb/probe.h      | 14 +++----------
 gdb/solib-svr4.c | 29 ++++++++-----------------
 4 files changed, 39 insertions(+), 76 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 301d7aabff..246507a1f1 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3191,8 +3191,9 @@ struct breakpoint_objfile_data
   /* True if we have looked for longjmp probes.  */
   int longjmp_searched = 0;
 
-  /* SystemTap probe points for longjmp (if any).  */
-  VEC (probe_p) *longjmp_probes = NULL;
+  /* SystemTap probe points for longjmp (if any).  These are non-owning
+     references.  */
+  std::vector<probe *> longjmp_probes;
 
   /* Minimal symbol for "std::terminate()" (if any).  */
   struct bound_minimal_symbol terminate_msym {};
@@ -3203,8 +3204,9 @@ struct breakpoint_objfile_data
   /* True if we have looked for exception probes.  */
   int exception_searched = 0;
 
-  /* SystemTap probe points for unwinding (if any).  */
-  VEC (probe_p) *exception_probes = NULL;
+  /* SystemTap probe points for unwinding (if any).  These are non-owning
+     references.  */
+  std::vector<probe *> exception_probes;
 };
 
 static const struct objfile_data *breakpoint_objfile_key;
@@ -3244,9 +3246,6 @@ free_breakpoint_objfile_data (struct objfile *obj, void *data)
   struct breakpoint_objfile_data *bp_objfile_data
     = (struct breakpoint_objfile_data *) data;
 
-  VEC_free (probe_p, bp_objfile_data->longjmp_probes);
-  VEC_free (probe_p, bp_objfile_data->exception_probes);
-
   delete bp_objfile_data;
 }
 
@@ -3328,43 +3327,35 @@ create_longjmp_master_breakpoint (void)
 
       if (!bp_objfile_data->longjmp_searched)
 	{
-	  VEC (probe_p) *ret;
+	  std::vector<probe *> ret
+	    = find_probes_in_objfile (objfile, "libc", "longjmp");
 
-	  ret = find_probes_in_objfile (objfile, "libc", "longjmp");
-	  if (ret != NULL)
+	  if (!ret.empty ())
 	    {
 	      /* We are only interested in checking one element.  */
-	      struct probe *p = VEC_index (probe_p, ret, 0);
+	      probe *p = ret[0];
 
 	      if (!can_evaluate_probe_arguments (p))
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
-		  VEC_free (probe_p, ret);
-		  ret = NULL;
+		  ret.clear ();
 		}
 	    }
 	  bp_objfile_data->longjmp_probes = ret;
 	  bp_objfile_data->longjmp_searched = 1;
 	}
 
-      if (bp_objfile_data->longjmp_probes != NULL)
+      if (!bp_objfile_data->longjmp_probes.empty ())
 	{
-	  int i;
-	  struct probe *probe;
 	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
-	  for (i = 0;
-	       VEC_iterate (probe_p,
-			    bp_objfile_data->longjmp_probes,
-			    i, probe);
-	       ++i)
+	  for (probe *p : bp_objfile_data->longjmp_probes)
 	    {
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (probe,
-								 objfile),
+					      get_probe_address (p, objfile),
 					      bp_longjmp_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libc:longjmp");
@@ -3489,44 +3480,35 @@ create_exception_master_breakpoint (void)
       /* We prefer the SystemTap probe point if it exists.  */
       if (!bp_objfile_data->exception_searched)
 	{
-	  VEC (probe_p) *ret;
-
-	  ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
+	  std::vector<probe *> ret
+	    = find_probes_in_objfile (objfile, "libgcc", "unwind");
 
-	  if (ret != NULL)
+	  if (!ret.empty ())
 	    {
 	      /* We are only interested in checking one element.  */
-	      struct probe *p = VEC_index (probe_p, ret, 0);
+	      probe *p = ret[0];
 
 	      if (!can_evaluate_probe_arguments (p))
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
-		  VEC_free (probe_p, ret);
-		  ret = NULL;
+		  ret.clear ();
 		}
 	    }
 	  bp_objfile_data->exception_probes = ret;
 	  bp_objfile_data->exception_searched = 1;
 	}
 
-      if (bp_objfile_data->exception_probes != NULL)
+      if (!bp_objfile_data->exception_probes.empty ())
 	{
 	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-	  int i;
-	  struct probe *probe;
-
-	  for (i = 0;
-	       VEC_iterate (probe_p,
-			    bp_objfile_data->exception_probes,
-			    i, probe);
-	       ++i)
+
+	  for (probe *p : bp_objfile_data->exception_probes)
 	    {
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (probe,
-								 objfile),
+					      get_probe_address (p, objfile),
 					      bp_exception_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libgcc:unwind");
diff --git a/gdb/probe.c b/gdb/probe.c
index ba40959126..829f6d18d7 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -193,14 +193,14 @@ parse_probes (const struct event_location *location,
 
 /* See definition in probe.h.  */
 
-VEC (probe_p) *
+std::vector<probe *>
 find_probes_in_objfile (struct objfile *objfile, const char *provider,
 			const char *name)
 {
-  VEC (probe_p) *result = NULL;
+  std::vector<probe *> result;
 
   if (!objfile->sf || !objfile->sf->sym_probe_fns)
-    return NULL;
+    return result;
 
   const std::vector<probe *> &probes
     = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
@@ -212,7 +212,7 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider,
       if (strcmp (p->name, name) != 0)
 	continue;
 
-      VEC_safe_push (probe_p, result, p);
+      result.push_back (p);
     }
 
   return result;
diff --git a/gdb/probe.h b/gdb/probe.h
index 1b3916602a..c44a308d9b 100644
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -21,14 +21,6 @@
 #define PROBE_H 1
 
 struct event_location;
-
-#include "gdb_vecs.h"
-
-/* Definition of a vector of probes.  */
-
-typedef struct probe *probe_p;
-DEF_VEC_P (probe_p);
-
 struct linespec_result;
 
 /* Structure useful for passing the header names in the method
@@ -257,9 +249,9 @@ extern struct bound_probe find_probe_by_pc (CORE_ADDR pc);
    VEC of all probes that were found.  If no matching probe is found,
    return NULL.  The caller must free the VEC.  */
 
-extern VEC (probe_p) *find_probes_in_objfile (struct objfile *objfile,
-					      const char *provider,
-					      const char *name);
+extern std::vector<probe *> find_probes_in_objfile (struct objfile *objfile,
+						    const char *provider,
+						    const char *name);
 
 /* Generate a `info probes' command output for probe_ops represented by
    POPS.  If POPS is NULL it considers any probes types.  It is a helper
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index bf2577a433..5ec606de43 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -2075,25 +2075,19 @@ svr4_update_solib_event_breakpoints (void)
 
 static void
 svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
-			       VEC (probe_p) **probes,
+			       const std::vector<probe *> *probes,
 			       struct objfile *objfile)
 {
-  int i;
-
-  for (i = 0; i < NUM_PROBES; i++)
+  for (int i = 0; i < NUM_PROBES; i++)
     {
       enum probe_action action = probe_info[i].action;
-      struct probe *probe;
-      int ix;
 
-      for (ix = 0;
-	   VEC_iterate (probe_p, probes[i], ix, probe);
-	   ++ix)
+      for (probe *p : probes[i])
 	{
-	  CORE_ADDR address = get_probe_address (probe, objfile);
+	  CORE_ADDR address = get_probe_address (p, objfile);
 
 	  create_solib_event_breakpoint (gdbarch, address);
-	  register_solib_event_probe (probe, address, action);
+	  register_solib_event_probe (p, address, action);
 	}
     }
 
@@ -2125,13 +2119,11 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 
       for (with_prefix = 0; with_prefix <= 1; with_prefix++)
 	{
-	  VEC (probe_p) *probes[NUM_PROBES];
+	  std::vector<probe *> probes[NUM_PROBES];
 	  int all_probes_found = 1;
 	  int checked_can_use_probe_arguments = 0;
-	  int i;
 
-	  memset (probes, 0, sizeof (probes));
-	  for (i = 0; i < NUM_PROBES; i++)
+	  for (int i = 0; i < NUM_PROBES; i++)
 	    {
 	      const char *name = probe_info[i].name;
 	      struct probe *p;
@@ -2158,7 +2150,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	      if (strcmp (name, "rtld_map_failed") == 0)
 		continue;
 
-	      if (VEC_empty (probe_p, probes[i]))
+	      if (probes[i].empty ())
 		{
 		  all_probes_found = 0;
 		  break;
@@ -2167,7 +2159,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	      /* Ensure probe arguments can be evaluated.  */
 	      if (!checked_can_use_probe_arguments)
 		{
-		  p = VEC_index (probe_p, probes[i], 0);
+		  p = probes[i][0];
 		  if (!can_evaluate_probe_arguments (p))
 		    {
 		      all_probes_found = 0;
@@ -2180,9 +2172,6 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	  if (all_probes_found)
 	    svr4_create_probe_breakpoints (gdbarch, probes, os->objfile);
 
-	  for (i = 0; i < NUM_PROBES; i++)
-	    VEC_free (probe_p, probes[i]);
-
 	  if (all_probes_found)
 	    return;
 	}
-- 
2.14.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]