public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
  2017-11-13 17:59 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
@ 2017-11-13 17:59 ` Sergio Durigan Junior
  2017-11-15  2:52   ` Simon Marchi
  2017-11-13 17:59 ` [PATCH 3/3] Convert DTrace " Sergio Durigan Junior
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  3 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:59 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch converts the generic probe interface (gdb/probe.[ch]) to
C++, and also performs some cleanups that were on my TODO list for a
while.

The main changes were the conversion of 'struct probe' to 'class
probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
former now contains all the "dynamic", generic methods that act on a
probe + the generic data related to it; the latter encapsulates a
bunch of "static" methods that relate to the probe type, but not to a
specific probe itself.

I've had to do a few renamings (e.g., on 'struct bound_probe' the
field is called 'probe *prob' now, instead of 'struct probe *probe')
because GCC was complaining about naming the field using the same name
as the class.  Nothing major, though.  Generally speaking, the logic
behind and the design behind the code are the same.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* break-catch-throw.c (fetch_probe_arguments): Use
	'probe.prob' instead of 'probe.probe'.
	* breakpoint.c (create_longjmp_master_breakpoint): Call
	'can_evaluate_arguments' and 'get_relocated_address' methods
	from probe.
	(create_exception_master_breakpoint): Likewise.
	(add_location_to_breakpoint): Use 'sal->prob' instead of
	'sal->probe'.
	(bkpt_probe_insert_location): Call 'set_semaphore' method from
	probe.
	(bkpt_probe_remove_location): Likewise, for 'clear_semaphore'.
	* elfread.c (elf_get_probes): Use 'static_probe_ops' instead
	of 'probe_ops'.
	(probe_key_free): Call 'delete' on probe.
	(check_exception_resume): Use 'probe.prob' instead of
	'probe.probe'.
	* location.c (string_to_event_location_basic): Call
	'probe_linespec_to_static_ops'.
	* probe.c (class any_static_probe_ops): New class.
	(any_static_probe_ops any_static_probe_ops): New variable.
	(parse_probes_in_pspace): Receive 'static_probe_ops' as
	argument.  Adjust code to reflect change.
	(parse_probes): Use 'static_probe_ops' instead of
	'probe_ops'.  Adjust code to reflect change.
	(find_probes_in_objfile): Call methods to get name and
	provider from probe.
	(find_probe_by_pc): Use 'result.prob' instead of
	'result.probe'.  Call 'get_relocated_address' method from
	probe.
	(collect_probes): Adjust comment and argument list to receive
	'static_probe_ops' instead of 'probe_ops'.  Adjust code to
	reflect change.  Call necessary methods from probe.
	(compare_probes): Call methods to get name and provider from
	probes.
	(gen_ui_out_table_header_info): Receive 'static_probe_ops'
	instead of 'probe_ops'.  Use 'std::vector' instead of VEC,
	adjust code accordingly.
	(print_ui_out_not_applicables): Likewise.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Receive 'static_probe_ops'
	as argument instead of 'probe_ops'.  Adjust code.  Call
	necessary methods from probe.
	(info_probes_command): Use 'info_probes_for_spops'.
	(enable_probes_command): Pass correct argument to
	'collect_probes'.  Call methods from probe.
	(disable_probes_command): Likewise.
	(get_probe_address): Move to 'any_static_probe_ops::get_address'.
	(get_probe_argument_count): Move to
	'any_static_probe_ops::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'any_static_probe_ops::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to
	'any_static_probe_ops::evaluate_argument'.
	(probe_safe_evaluate_at_pc): Use 'probe.prob' instead of
	'probe.probe'.
	(probe_linespec_to_ops): Rename to...
	(probe_linespec_to_static_ops): ...this.  Adjust code.
	(probe_any_is_linespec): Rename to...
	(any_static_probe_ops::is_linespec): ...this.
	(probe_any_get_probes): Rename to...
	(any_static_probe_ops::get_probes): ...this.
	(any_static_probe_ops::type_name): New method.
	(any_static_probe_ops::emit_info_probes_extra_fields): New
	method.
	(any_static_probe_ops::gen_info_probes_table_header): New
	method.
	(compute_probe_arg): Use 'pc_probe.prob' instead of
	'pc_probe.probe'.  Call methods from probe.
	(compile_probe_arg): Likewise.
	(std::vector<const probe_ops *> all_probe_ops): Delete.
	(std::vector<const static_probe_ops *> all_static_probe_ops):
	New variable.
	(_initialize_probe): Use 'all_static_probe_ops' instead of
	'all_probe_ops'.
	* probe.h (struct info_probe_column) <field_name>: Delete
	extraneous newline
	(info_probe_column_s): Delete type and VEC.
	(struct probe_ops): Delete.  Replace with...
	(class static_probe_ops): ...this and...
	(clas probe): ...this.
	(struct bound_probe) <bound_probe>: Delete extraneous
	newline.  Adjust constructor to receive 'probe' instead of
	'struct probe'.
	<probe>: Rename to...
	<prob>: ...this.  Delete extraneous newline.
	<objfile>: Delete extraneous newline.
	(register_probe_ops): Delete unused prototype.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Adjust comment.
	(get_probe_address): Move to 'probe::get_address'.
	(get_probe_argument_count): Move to
	'probe::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'probe::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to 'probe::evaluate_argument'.
	* solib-svr4.c (struct svr4_info): Adjust comment.
	(struct probe_and_action) <probe>: Rename to...
	<prob>: ...this.
	(register_solib_event_probe): Receive 'probe' instead of
	'struct probe' as argument.  Use 'prob' instead of 'probe'
	when applicable.
	(solib_event_probe_action): Call 'get_argument_count' method
	from probe.  Adjust comment.
	(svr4_handle_solib_event): Adjust comment.  Call
	'evaluate_argument' method from probe.
	(svr4_create_probe_breakpoints): Call 'get_relocated_address'
	from probe.
	(svr4_create_solib_event_breakpoints): Use 'probe' instead of
	'struct probe'.  Call 'can_evaluate_arguments' from probe.
	* symfile.h: Forward declare 'class probe' instead of 'struct
	probe'.
	* symtab.h: Likewise.
	(struct symtab_and_line) <probe>: Rename to...
	<prob>: ...this.
	* tracepoint.c (start_tracing): Use 'prob' when applicable.
	Call probe methods.
	(stop_tracing): Likewise.

Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
---
 gdb/break-catch-throw.c |  16 +-
 gdb/breakpoint.c        |  20 +--
 gdb/elfread.c           |   4 +-
 gdb/infrun.c            |   2 +-
 gdb/location.c          |   2 +-
 gdb/probe.c             | 435 ++++++++++++++++++++++--------------------------
 gdb/probe.h             | 363 ++++++++++++++++++++--------------------
 gdb/solib-svr4.c        |  36 ++--
 gdb/symfile.h           |   2 +-
 gdb/symtab.h            |   4 +-
 gdb/tracepoint.c        |  16 +-
 11 files changed, 427 insertions(+), 473 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index fd8a113803..ffc100bb24 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -106,20 +106,20 @@ fetch_probe_arguments (struct value **arg0, struct value **arg1)
   unsigned n_args;
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL
-      || strcmp (pc_probe.probe->provider, "libstdcxx") != 0
-      || (strcmp (pc_probe.probe->name, "catch") != 0
-	  && strcmp (pc_probe.probe->name, "throw") != 0
-	  && strcmp (pc_probe.probe->name, "rethrow") != 0))
+  if (pc_probe.prob == NULL
+      || strcmp (pc_probe.prob->get_provider (), "libstdcxx") != 0
+      || (strcmp (pc_probe.prob->get_name (), "catch") != 0
+	  && strcmp (pc_probe.prob->get_name (), "throw") != 0
+	  && strcmp (pc_probe.prob->get_name (), "rethrow") != 0))
     error (_("not stopped at a C++ exception catchpoint"));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
   if (n_args < 2)
     error (_("C++ exception catchpoint has too few arguments"));
 
   if (arg0 != NULL)
-    *arg0 = evaluate_probe_argument (pc_probe.probe, 0, frame);
-  *arg1 = evaluate_probe_argument (pc_probe.probe, 1, frame);
+    *arg0 = pc_probe.prob->evaluate_argument (0, frame);
+  *arg1 = pc_probe.prob->evaluate_argument (1, frame);
 
   if ((arg0 != NULL && *arg0 == NULL) || *arg1 == NULL)
     error (_("error computing probe argument at c++ exception catchpoint"));
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b170a14cb5..1728aee838 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3309,7 +3309,7 @@ create_longjmp_master_breakpoint (void)
 	      /* We are only interested in checking one element.  */
 	      probe *p = ret[0];
 
-	      if (!can_evaluate_probe_arguments (p))
+	      if (!p->can_evaluate_arguments ())
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
@@ -3329,7 +3329,7 @@ create_longjmp_master_breakpoint (void)
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (p, objfile),
+					      p->get_relocated_address (objfile),
 					      bp_longjmp_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libc:longjmp");
@@ -3462,7 +3462,7 @@ create_exception_master_breakpoint (void)
 	      /* We are only interested in checking one element.  */
 	      probe *p = ret[0];
 
-	      if (!can_evaluate_probe_arguments (p))
+	      if (!p->can_evaluate_arguments ())
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
@@ -3482,7 +3482,7 @@ create_exception_master_breakpoint (void)
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (p, objfile),
+					      p->get_relocated_address (objfile),
 					      bp_exception_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libgcc:unwind");
@@ -8694,7 +8694,7 @@ add_location_to_breakpoint (struct breakpoint *b,
   loc->requested_address = sal->pc;
   loc->address = adjusted_address;
   loc->pspace = sal->pspace;
-  loc->probe.probe = sal->probe;
+  loc->probe.prob = sal->prob;
   loc->probe.objfile = sal->objfile;
   gdb_assert (loc->pspace != NULL);
   loc->section = sal->section;
@@ -12879,10 +12879,7 @@ bkpt_probe_insert_location (struct bp_location *bl)
     {
       /* The insertion was successful, now let's set the probe's semaphore
 	 if needed.  */
-      if (bl->probe.probe->pops->set_semaphore != NULL)
-	bl->probe.probe->pops->set_semaphore (bl->probe.probe,
-					      bl->probe.objfile,
-					      bl->gdbarch);
+      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
     }
 
   return v;
@@ -12893,10 +12890,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
 			    enum remove_bp_reason reason)
 {
   /* Let's clear the semaphore before removing the location.  */
-  if (bl->probe.probe->pops->clear_semaphore != NULL)
-    bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
-					    bl->probe.objfile,
-					    bl->gdbarch);
+  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
 
   return bkpt_remove_location (bl, reason);
 }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index cdef5a8c59..f2483025ba 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1324,7 +1324,7 @@ elf_get_probes (struct objfile *objfile)
 
       /* Here we try to gather information about all types of probes from the
 	 objfile.  */
-      for (const probe_ops *ops : all_probe_ops)
+      for (const static_probe_ops *ops : all_static_probe_ops)
 	ops->get_probes (probes_per_bfd, objfile);
 
       set_bfd_data (objfile->obfd, probe_key, probes_per_bfd);
@@ -1342,7 +1342,7 @@ probe_key_free (bfd *abfd, void *d)
   std::vector<probe *> *probes = (std::vector<probe *> *) d;
 
   for (probe *p : *probes)
-    p->pops->destroy (p);
+    delete p;
 
   delete probes;
 }
diff --git a/gdb/infrun.c b/gdb/infrun.c
index e2d1248e75..4592100962 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7583,7 +7583,7 @@ check_exception_resume (struct execution_control_state *ecs,
      CFA and the HANDLER.  We ignore the CFA, extract the handler, and
      set a breakpoint there.  */
   probe = find_probe_by_pc (get_frame_pc (frame));
-  if (probe.probe)
+  if (probe.prob)
     {
       insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
       return;
diff --git a/gdb/location.c b/gdb/location.c
index c78778edc1..5ed3623f0a 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -844,7 +844,7 @@ string_to_event_location_basic (const char **stringp,
 
   /* Try the input as a probe spec.  */
   cs = *stringp;
-  if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
+  if (cs != NULL && probe_linespec_to_static_ops (&cs) != NULL)
     {
       location = new_probe_location (*stringp);
       *stringp += strlen (*stringp);
diff --git a/gdb/probe.c b/gdb/probe.c
index 829f6d18d7..0c47f904cb 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -38,11 +38,38 @@
 #include <algorithm>
 #include "common/gdb_optional.h"
 
+/* Class that implements the static probe methods for "any" probe.  */
+
+class any_static_probe_ops : public static_probe_ops
+{
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  bool emit_info_probes_extra_fields () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_header
+    (std::vector<struct info_probe_column> *heads) const override;
+};
+
+/* Static operations associated with a generic probe.  */
+
+const any_static_probe_ops any_static_probe_ops;
+
 /* A helper for parse_probes that decodes a probe specification in
    SEARCH_PSPACE.  It appends matching SALs to RESULT.  */
 
 static void
-parse_probes_in_pspace (const struct probe_ops *probe_ops,
+parse_probes_in_pspace (const static_probe_ops *spops,
 			struct program_space *search_pspace,
 			const char *objfile_namestr,
 			const char *provider,
@@ -67,21 +94,21 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops,
 
       for (probe *p : probes)
 	{
-	  if (probe_ops != &probe_ops_any && p->pops != probe_ops)
+	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
 	    continue;
 
-	  if (provider && strcmp (p->provider, provider) != 0)
+	  if (provider && strcmp (p->get_provider (), provider) != 0)
 	    continue;
 
-	  if (strcmp (p->name, name) != 0)
+	  if (strcmp (p->get_name (), name) != 0)
 	    continue;
 
 	  symtab_and_line sal;
-	  sal.pc = get_probe_address (p, objfile);
+	  sal.pc = p->get_relocated_address (objfile);
 	  sal.explicit_pc = 1;
 	  sal.section = find_pc_overlay (sal.pc);
 	  sal.pspace = search_pspace;
-	  sal.probe = p;
+	  sal.prob = p;
 	  sal.objfile = objfile;
 
 	  result->push_back (std::move (sal));
@@ -98,15 +125,14 @@ parse_probes (const struct event_location *location,
 {
   char *arg_end, *arg;
   char *objfile_namestr = NULL, *provider = NULL, *name, *p;
-  const struct probe_ops *probe_ops;
   const char *arg_start, *cs;
 
   gdb_assert (event_location_type (location) == PROBE_LOCATION);
   arg_start = get_probe_location (location);
 
   cs = arg_start;
-  probe_ops = probe_linespec_to_ops (&cs);
-  if (probe_ops == NULL)
+  const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
+  if (spops == NULL)
     error (_("'%s' is not a probe linespec"), arg_start);
 
   arg = (char *) cs;
@@ -159,7 +185,7 @@ parse_probes (const struct event_location *location,
   std::vector<symtab_and_line> result;
   if (search_pspace != NULL)
     {
-      parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
+      parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
 			      provider, name, &result);
     }
   else
@@ -167,7 +193,7 @@ parse_probes (const struct event_location *location,
       struct program_space *pspace;
 
       ALL_PSPACES (pspace)
-	parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
+	parse_probes_in_pspace (spops, pspace, objfile_namestr,
 				provider, name, &result);
     }
 
@@ -206,10 +232,10 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider,
     = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
   for (probe *p : probes)
     {
-      if (strcmp (p->provider, provider) != 0)
+      if (strcmp (p->get_provider (), provider) != 0)
 	continue;
 
-      if (strcmp (p->name, name) != 0)
+      if (strcmp (p->get_name (), name) != 0)
 	continue;
 
       result.push_back (p);
@@ -227,7 +253,7 @@ find_probe_by_pc (CORE_ADDR pc)
   struct bound_probe result;
 
   result.objfile = NULL;
-  result.probe = NULL;
+  result.prob = NULL;
 
   ALL_OBJFILES (objfile)
   {
@@ -239,10 +265,10 @@ find_probe_by_pc (CORE_ADDR pc)
     const std::vector<probe *> &probes
       = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
     for (probe *p : probes)
-      if (get_probe_address (p, objfile) == pc)
+      if (p->get_relocated_address (objfile) == pc)
 	{
 	  result.objfile = objfile;
-	  result.probe = p;
+	  result.prob = p;
 	  return result;
 	}
   }
@@ -253,12 +279,13 @@ find_probe_by_pc (CORE_ADDR pc)
 \f
 
 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
-   If POPS is not NULL, only probes of this certain probe_ops will match.
-   Each argument is a regexp, or NULL, which matches anything.  */
+   If SPOPS is not &any_static_probe_ops, only probes related to this
+   specific static probe ops will match.  Each argument is a regexp,
+   or NULL, which matches anything.  */
 
 static std::vector<bound_probe>
 collect_probes (const std::string &objname, const std::string &provider,
-		const std::string &probe_name, const struct probe_ops *pops)
+		const std::string &probe_name, const static_probe_ops *spops)
 {
   struct objfile *objfile;
   std::vector<bound_probe> result;
@@ -290,15 +317,15 @@ collect_probes (const std::string &objname, const std::string &provider,
 
       for (probe *p : probes)
 	{
-	  if (pops != NULL && p->pops != pops)
+	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
 	    continue;
 
 	  if (prov_pat
-	      && prov_pat->exec (p->provider, 0, NULL, 0) != 0)
+	      && prov_pat->exec (p->get_provider (), 0, NULL, 0) != 0)
 	    continue;
 
 	  if (probe_pat
-	      && probe_pat->exec (p->name, 0, NULL, 0) != 0)
+	      && probe_pat->exec (p->get_name (), 0, NULL, 0) != 0)
 	    continue;
 
 	  result.emplace_back (p, objfile);
@@ -315,16 +342,16 @@ compare_probes (const bound_probe &a, const bound_probe &b)
 {
   int v;
 
-  v = strcmp (a.probe->provider, b.probe->provider);
+  v = strcmp (a.prob->get_provider (), b.prob->get_provider ());
   if (v != 0)
     return v < 0;
 
-  v = strcmp (a.probe->name, b.probe->name);
+  v = strcmp (a.prob->get_name (), b.prob->get_name ());
   if (v != 0)
     return v < 0;
 
-  if (a.probe->address != b.probe->address)
-    return a.probe->address < b.probe->address;
+  if (a.prob->get_address () != b.prob->get_address ())
+    return a.prob->get_address () < b.prob->get_address ();
 
   return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
 }
@@ -334,56 +361,37 @@ compare_probes (const bound_probe &a, const bound_probe &b)
 
 static void
 gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
-			      const struct probe_ops *p)
+			      const static_probe_ops *spops)
 {
   /* `headings' refers to the names of the columns when printing `info
      probes'.  */
-  VEC (info_probe_column_s) *headings = NULL;
-  struct cleanup *c;
-  info_probe_column_s *column;
-  size_t headings_size;
-  int ix;
+  std::vector<struct info_probe_column> headings;
 
-  gdb_assert (p != NULL);
+  gdb_assert (spops != NULL);
 
-  if (p->gen_info_probes_table_header == NULL
-      && p->gen_info_probes_table_values == NULL)
+  if (!spops->emit_info_probes_extra_fields ())
     return;
 
-  gdb_assert (p->gen_info_probes_table_header != NULL
-	      && p->gen_info_probes_table_values != NULL);
-
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  p->gen_info_probes_table_header (&headings);
-
-  headings_size = VEC_length (info_probe_column_s, headings);
+  spops->gen_info_probes_table_header (&headings);
 
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
+  for (struct info_probe_column column : headings)
     {
-      size_t size_max = strlen (column->print_name);
+      size_t size_max = strlen (column.print_name);
 
       for (const bound_probe &probe : probes)
 	{
 	  /* `probe_fields' refers to the values of each new field that this
 	     probe will display.  */
-	  VEC (const_char_ptr) *probe_fields = NULL;
-	  struct cleanup *c2;
-	  const char *val;
-	  int kx;
+	  std::vector<const char *> probe_fields;
 
-	  if (probe.probe->pops != p)
+	  if (probe.prob->get_static_ops () != spops)
 	    continue;
 
-	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
-	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
+	  probe.prob->gen_info_probes_table_values (&probe_fields);
 
-	  gdb_assert (VEC_length (const_char_ptr, probe_fields)
-		      == headings_size);
+	  gdb_assert (probe_fields.size () == headings.size ());
 
-	  for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
-	       ++kx)
+	  for (const char *val : probe_fields)
 	    {
 	      /* It is valid to have a NULL value here, which means that the
 		 backend does not have something to write and this particular
@@ -393,128 +401,92 @@ gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
 
 	      size_max = std::max (strlen (val), size_max);
 	    }
-	  do_cleanups (c2);
 	}
 
       current_uiout->table_header (size_max, ui_left,
-				   column->field_name, column->print_name);
+				   column.field_name, column.print_name);
     }
-
-  do_cleanups (c);
 }
 
 /* Helper function to print not-applicable strings for all the extra
-   columns defined in a probe_ops.  */
+   columns defined in a static_probe_ops.  */
 
 static void
-print_ui_out_not_applicables (const struct probe_ops *pops)
+print_ui_out_not_applicables (const static_probe_ops *spops)
 {
   struct cleanup *c;
-  VEC (info_probe_column_s) *headings = NULL;
-  info_probe_column_s *column;
-  int ix;
+  std::vector<struct info_probe_column> headings;
 
-  if (pops->gen_info_probes_table_header == NULL)
+  if (!spops->emit_info_probes_extra_fields ())
     return;
 
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  pops->gen_info_probes_table_header (&headings);
-
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
-    current_uiout->field_string (column->field_name, _("n/a"));
+  spops->gen_info_probes_table_header (&headings);
 
-  do_cleanups (c);
+  for (struct info_probe_column column : headings)
+    current_uiout->field_string (column.field_name, _("n/a"));
 }
 
 /* Helper function to print extra information about a probe and an objfile
    represented by PROBE.  */
 
 static void
-print_ui_out_info (struct probe *probe)
+print_ui_out_info (probe *probe)
 {
-  int ix;
-  int j = 0;
   /* `values' refers to the actual values of each new field in the output
      of `info probe'.  `headings' refers to the names of each new field.  */
-  VEC (const_char_ptr) *values = NULL;
-  VEC (info_probe_column_s) *headings = NULL;
-  info_probe_column_s *column;
-  struct cleanup *c;
+  std::vector<struct info_probe_column> headings;
+  std::vector<const char *> values;
+  struct info_probe_column *column;
 
   gdb_assert (probe != NULL);
-  gdb_assert (probe->pops != NULL);
 
-  if (probe->pops->gen_info_probes_table_header == NULL
-      && probe->pops->gen_info_probes_table_values == NULL)
-    return;
+  probe->get_static_ops ()->gen_info_probes_table_header (&headings);
+  probe->gen_info_probes_table_values (&values);
 
-  gdb_assert (probe->pops->gen_info_probes_table_header != NULL
-	      && probe->pops->gen_info_probes_table_values != NULL);
+  gdb_assert (headings.size () == values.size ());
 
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  make_cleanup (VEC_cleanup (const_char_ptr), &values);
-
-  probe->pops->gen_info_probes_table_header (&headings);
-  probe->pops->gen_info_probes_table_values (probe, &values);
-
-  gdb_assert (VEC_length (info_probe_column_s, headings)
-	      == VEC_length (const_char_ptr, values));
-
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
+  for (int ix = 0; ix < headings.size (); ++ix)
     {
-      const char *val = VEC_index (const_char_ptr, values, j++);
+      struct info_probe_column column = headings[ix];
+      const char *val = values[ix];
 
       if (val == NULL)
-	current_uiout->field_skip (column->field_name);
+	current_uiout->field_skip (column.field_name);
       else
-	current_uiout->field_string (column->field_name, val);
+	current_uiout->field_string (column.field_name, val);
     }
-
-  do_cleanups (c);
 }
 
 /* Helper function that returns the number of extra fields which POPS will
    need.  */
 
 static int
-get_number_extra_fields (const struct probe_ops *pops)
+get_number_extra_fields (const static_probe_ops *spops)
 {
-  VEC (info_probe_column_s) *headings = NULL;
-  struct cleanup *c;
-  int n;
+  std::vector<info_probe_column> headings;
 
-  if (pops->gen_info_probes_table_header == NULL)
+  if (!spops->emit_info_probes_extra_fields ())
     return 0;
 
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  pops->gen_info_probes_table_header (&headings);
-
-  n = VEC_length (info_probe_column_s, headings);
+  spops->gen_info_probes_table_header (&headings);
 
-  do_cleanups (c);
-
-  return n;
+  return headings.size ();
 }
 
-/* Helper function that returns 1 if there is a probe in PROBES
-   featuring the given POPS.  It returns 0 otherwise.  */
+/* Helper function that returns true if there is a probe in PROBES
+   featuring the given SPOPS.  It returns false otherwise.  */
 
-static int
-exists_probe_with_pops (const std::vector<bound_probe> &probes,
-			const struct probe_ops *pops)
+static bool
+exists_probe_with_spops (const std::vector<bound_probe> &probes,
+			 const static_probe_ops *spops)
 {
   struct bound_probe *probe;
-  int ix;
 
   for (const bound_probe &probe : probes)
-    if (probe.probe->pops == pops)
-      return 1;
+    if (probe.prob->get_static_ops () == spops)
+      return true;
 
-  return 0;
+  return false;
 }
 
 /* Helper function that parses a probe linespec of the form [PROVIDER
@@ -538,8 +510,8 @@ parse_probe_linespec (const char *str, std::string *provider,
 /* See comment in probe.h.  */
 
 void
-info_probes_for_ops (const char *arg, int from_tty,
-		     const struct probe_ops *pops)
+info_probes_for_spops (const char *arg, int from_tty,
+		       const static_probe_ops *spops)
 {
   std::string provider, probe_name, objname;
   int any_found;
@@ -554,26 +526,28 @@ info_probes_for_ops (const char *arg, int from_tty,
   parse_probe_linespec (arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, pops);
+    = collect_probes (objname, provider, probe_name, spops);
 
-  if (pops == NULL)
+  if (spops == &any_static_probe_ops)
     {
-      /* If the probe_ops is NULL, it means the user has requested a "simple"
-	 `info probes', i.e., she wants to print all information about all
-	 probes.  For that, we have to identify how many extra fields we will
-	 need to add in the ui_out table.
-
-	 To do that, we iterate over all probe_ops, querying each one about
-	 its extra fields, and incrementing `ui_out_extra_fields' to reflect
-	 that number.  But note that we ignore the probe_ops for which no probes
-	 are defined with the given search criteria.  */
-
-      for (const probe_ops *po : all_probe_ops)
-	if (exists_probe_with_pops (probes, po))
+      /* If SPOPS is &any_static_probe_ops, it means the user has
+	 requested a "simple" `info probes', i.e., she wants to print
+	 all information about all probes.  For that, we have to
+	 identify how many extra fields we will need to add in the
+	 ui_out table.
+
+	 To do that, we iterate over all static_probe_ops, querying
+	 each one about its extra fields, and incrementing
+	 `ui_out_extra_fields' to reflect that number.  But note that
+	 we ignore the static_probe_ops for which no probes are
+	 defined with the given search criteria.  */
+
+      for (const static_probe_ops *po : all_static_probe_ops)
+	if (exists_probe_with_spops (probes, po))
 	  ui_out_extra_fields += get_number_extra_fields (po);
     }
   else
-    ui_out_extra_fields = get_number_extra_fields (pops);
+    ui_out_extra_fields = get_number_extra_fields (spops);
 
   {
     ui_out_emit_table table_emitter (current_uiout,
@@ -589,11 +563,12 @@ info_probes_for_ops (const char *arg, int from_tty,
        `name' and `objname').  */
     for (const bound_probe &probe : probes)
       {
-	const char *probe_type = probe.probe->pops->type_name (probe.probe);
+	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
 
 	size_type = std::max (strlen (probe_type), size_type);
-	size_name = std::max (strlen (probe.probe->name), size_name);
-	size_provider = std::max (strlen (probe.probe->provider), size_provider);
+	size_name = std::max (strlen (probe.prob->get_name ()), size_name);
+	size_provider = std::max (strlen (probe.prob->get_provider ()),
+				  size_provider);
 	size_objname = std::max (strlen (objfile_name (probe.objfile)),
 				 size_objname);
       }
@@ -604,44 +579,46 @@ info_probes_for_ops (const char *arg, int from_tty,
     current_uiout->table_header (size_name, ui_left, "name", _("Name"));
     current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
 
-    if (pops == NULL)
+    if (spops == &any_static_probe_ops)
       {
 	/* We have to generate the table header for each new probe type
 	   that we will print.  Note that this excludes probe types not
 	   having any defined probe with the search criteria.  */
-	for (const probe_ops *po : all_probe_ops)
-	  if (exists_probe_with_pops (probes, po))
+	for (const static_probe_ops *po : all_static_probe_ops)
+	  if (exists_probe_with_spops (probes, po))
 	    gen_ui_out_table_header_info (probes, po);
       }
     else
-      gen_ui_out_table_header_info (probes, pops);
+      gen_ui_out_table_header_info (probes, spops);
 
     current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
     current_uiout->table_body ();
 
     for (const bound_probe &probe : probes)
       {
-	const char *probe_type = probe.probe->pops->type_name (probe.probe);
+	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
 
 	ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
 
-	current_uiout->field_string ("type",probe_type);
-	current_uiout->field_string ("provider", probe.probe->provider);
-	current_uiout->field_string ("name", probe.probe->name);
-	current_uiout->field_core_addr ("addr", probe.probe->arch,
-					get_probe_address (probe.probe,
-							   probe.objfile));
+	current_uiout->field_string ("type", probe_type);
+	current_uiout->field_string ("provider", probe.prob->get_provider ());
+	current_uiout->field_string ("name", probe.prob->get_name ());
+	current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
+					probe.prob->get_relocated_address
+					(probe.objfile));
 
-	if (pops == NULL)
+	if (spops == &any_static_probe_ops)
 	  {
-	    for (const probe_ops *po : all_probe_ops)
-	      if (probe.probe->pops == po)
-		print_ui_out_info (probe.probe);
-	      else if (exists_probe_with_pops (probes, po))
-		print_ui_out_not_applicables (po);
+	    for (const static_probe_ops *po : all_static_probe_ops)
+	      {
+		if (probe.prob->get_static_ops () == po)
+		  print_ui_out_info (probe.prob);
+		else if (exists_probe_with_spops (probes, po))
+		  print_ui_out_not_applicables (po);
+	      }
 	  }
 	else
-	  print_ui_out_info (probe.probe);
+	  print_ui_out_info (probe.prob);
 
 	current_uiout->field_string ("object",
 				     objfile_name (probe.objfile));
@@ -660,7 +637,7 @@ info_probes_for_ops (const char *arg, int from_tty,
 static void
 info_probes_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, NULL);
+  info_probes_for_spops (arg, from_tty, &any_static_probe_ops);
 }
 
 /* Implementation of the `enable probes' command.  */
@@ -673,7 +650,7 @@ enable_probes_command (const char *arg, int from_tty)
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, NULL);
+    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
@@ -684,17 +661,17 @@ enable_probes_command (const char *arg, int from_tty)
      notion of enabling a probe.  */
   for (const bound_probe &probe: probes)
     {
-      const struct probe_ops *pops = probe.probe->pops;
-
-      if (pops->enable_probe != NULL)
+      if (probe.prob->can_enable ())
 	{
-	  pops->enable_probe (probe.probe);
+	  probe.prob->enable ();
 	  current_uiout->message (_("Probe %s:%s enabled.\n"),
-				  probe.probe->provider, probe.probe->name);
+				  probe.prob->get_provider (),
+				  probe.prob->get_name ());
 	}
       else
 	current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
-				probe.probe->provider, probe.probe->name);
+				probe.prob->get_provider (),
+				probe.prob->get_name ());
     }
 }
 
@@ -708,7 +685,7 @@ disable_probes_command (const char *arg, int from_tty)
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, NULL /* pops */);
+    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
@@ -719,55 +696,22 @@ disable_probes_command (const char *arg, int from_tty)
      notion of enabling a probe.  */
   for (const bound_probe &probe : probes)
     {
-      const struct probe_ops *pops = probe.probe->pops;
-
-      if (pops->disable_probe != NULL)
+      if (probe.prob->can_enable ())
 	{
-	  pops->disable_probe (probe.probe);
+	  probe.prob->disable ();
 	  current_uiout->message (_("Probe %s:%s disabled.\n"),
-				  probe.probe->provider, probe.probe->name);
+				  probe.prob->get_provider (),
+				  probe.prob->get_name ());
 	}
       else
 	current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
-				probe.probe->provider, probe.probe->name);
+				probe.prob->get_provider (),
+				probe.prob->get_name ());
     }
 }
 
 /* See comments in probe.h.  */
 
-CORE_ADDR
-get_probe_address (struct probe *probe, struct objfile *objfile)
-{
-  return probe->pops->get_probe_address (probe, objfile);
-}
-
-/* See comments in probe.h.  */
-
-unsigned
-get_probe_argument_count (struct probe *probe, struct frame_info *frame)
-{
-  return probe->pops->get_probe_argument_count (probe, frame);
-}
-
-/* See comments in probe.h.  */
-
-int
-can_evaluate_probe_arguments (struct probe *probe)
-{
-  return probe->pops->can_evaluate_probe_arguments (probe);
-}
-
-/* See comments in probe.h.  */
-
-struct value *
-evaluate_probe_argument (struct probe *probe, unsigned n,
-			 struct frame_info *frame)
-{
-  return probe->pops->evaluate_probe_argument (probe, n, frame);
-}
-
-/* See comments in probe.h.  */
-
 struct value *
 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
 {
@@ -775,22 +719,22 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
   unsigned n_args;
 
   probe = find_probe_by_pc (get_frame_pc (frame));
-  if (!probe.probe)
+  if (!probe.prob)
     return NULL;
 
-  n_args = get_probe_argument_count (probe.probe, frame);
+  n_args = probe.prob->get_argument_count (frame);
   if (n >= n_args)
     return NULL;
 
-  return evaluate_probe_argument (probe.probe, n, frame);
+  return probe.prob->evaluate_argument (n, frame);
 }
 
 /* See comment in probe.h.  */
 
-const struct probe_ops *
-probe_linespec_to_ops (const char **linespecp)
+const struct static_probe_ops *
+probe_linespec_to_static_ops (const char **linespecp)
 {
-  for (const probe_ops *ops : all_probe_ops)
+  for (const static_probe_ops *ops : all_static_probe_ops)
     if (ops->is_linespec (linespecp))
       return ops;
 
@@ -820,31 +764,48 @@ probe_is_linespec_by_keyword (const char **linespecp, const char *const *keyword
   return 0;
 }
 
-/* Implementation of `is_linespec' method for `struct probe_ops'.  */
+/* Implementation of `is_linespec' method.  */
 
-static int
-probe_any_is_linespec (const char **linespecp)
+bool
+any_static_probe_ops::is_linespec (const char **linespecp) const
 {
   static const char *const keywords[] = { "-p", "-probe", NULL };
 
   return probe_is_linespec_by_keyword (linespecp, keywords);
 }
 
-/* Dummy method used for `probe_ops_any'.  */
+/* Implementation of 'get_probes' method.  */
 
-static void
-probe_any_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+void
+any_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				  struct objfile *objfile) const
 {
   /* No probes can be provided by this dummy backend.  */
 }
 
-/* Operations associated with a generic probe.  */
+/* Implementation of the 'type_name' method.  */
 
-const struct probe_ops probe_ops_any =
+const char *
+any_static_probe_ops::type_name () const
 {
-  probe_any_is_linespec,
-  probe_any_get_probes,
-};
+  return NULL;
+}
+
+/* Implementation of the 'emit_info_probes_extra_fields' method.  */
+
+bool
+any_static_probe_ops::emit_info_probes_extra_fields () const
+{
+  return false;
+}
+
+/* Implementation of the 'gen_info_probes_table_header' method.  */
+
+void
+any_static_probe_ops::gen_info_probes_table_header
+  (std::vector<struct info_probe_column> *heads) const
+{
+}
 
 /* See comments in probe.h.  */
 
@@ -890,10 +851,10 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL)
+  if (pc_probe.prob == NULL)
     error (_("No probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
   if (sel == -1)
     return value_from_longest (builtin_type (arch)->builtin_int, n_args);
 
@@ -901,7 +862,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
     error (_("Invalid probe argument %d -- probe has %u arguments available"),
 	   sel, n_args);
 
-  return evaluate_probe_argument (pc_probe.probe, sel, frame);
+  return pc_probe.prob->evaluate_argument (sel, frame);
 }
 
 /* This is called to compile one of the $_probe_arg* convenience
@@ -922,10 +883,10 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL)
+  if (pc_probe.prob == NULL)
     error (_("No probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
 
   if (sel == -1)
     {
@@ -940,7 +901,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
     error (_("Invalid probe argument %d -- probe has %d arguments available"),
 	   sel, n_args);
 
-  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
+  pc_probe.prob->compile_to_ax (expr, value, sel);
 }
 
 static const struct internalvar_funcs probe_funcs =
@@ -951,12 +912,12 @@ static const struct internalvar_funcs probe_funcs =
 };
 
 
-std::vector<const probe_ops *> all_probe_ops;
+std::vector<const static_probe_ops *> all_static_probe_ops;
 
 void
 _initialize_probe (void)
 {
-  all_probe_ops.push_back (&probe_ops_any);
+  all_static_probe_ops.push_back (&any_static_probe_ops);
 
   create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
 				(void *) (uintptr_t) -1);
diff --git a/gdb/probe.h b/gdb/probe.h
index 822e5c89a9..9ad183013b 100644
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -30,7 +30,6 @@ struct info_probe_column
   {
     /* The internal name of the field.  This string cannot be capitalized nor
        localized, e.g., "extra_field".  */
-
     const char *field_name;
 
     /* The field name to be printed in the `info probes' command.  This
@@ -38,165 +37,206 @@ struct info_probe_column
     const char *print_name;
   };
 
-typedef struct info_probe_column info_probe_column_s;
-DEF_VEC_O (info_probe_column_s);
-
-/* Operations associated with a probe.  */
-
-struct probe_ops
-  {
-    /* Method responsible for verifying if LINESPECP is a valid linespec for
-       a probe breakpoint.  It should return 1 if it is, or zero if it is not.
-       It also should update LINESPECP in order to discard the breakpoint
-       option associated with this linespec.  For example, if the option is
-       `-probe', and the LINESPECP is `-probe abc', the function should
-       return 1 and set LINESPECP to `abc'.  */
-
-    int (*is_linespec) (const char **linespecp);
-
-    /* Function that should fill PROBES with known probes from OBJFILE.  */
-
-    void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile);
-
-    /* Compute the probe's relocated address.  OBJFILE is the objfile
-       in which the probe originated.  */
-
-    CORE_ADDR (*get_probe_address) (struct probe *probe,
-				    struct objfile *objfile);
-
-    /* Return the number of arguments of PROBE.  This function can
-       throw an exception.  */
-
-    unsigned (*get_probe_argument_count) (struct probe *probe,
-					  struct frame_info *frame);
-
-    /* Return 1 if the probe interface can evaluate the arguments of probe
-       PROBE, zero otherwise.  See the comments on
-       sym_probe_fns:can_evaluate_probe_arguments for more details.  */
-
-    int (*can_evaluate_probe_arguments) (struct probe *probe);
-
-    /* Evaluate the Nth argument from the PROBE, returning a value
-       corresponding to it.  The argument number is represented N.
-       This function can throw an exception.  */
-
-    struct value *(*evaluate_probe_argument) (struct probe *probe,
-					      unsigned n,
-					      struct frame_info *frame);
-
-    /* Compile the Nth argument of the PROBE to an agent expression.
-       The argument number is represented by N.  */
-
-    void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
-			   struct axs_value *axs_value, unsigned n);
+/* Operations that act on probes, but are specific to each backend.
+   These methods do not go into the 'class probe' because they do not
+   act on a single probe; instead, they are used to operate on many
+   probes at once, or to provide information about the probe backend
+   itself, instead of a single probe.
 
-    /* Set the semaphore associated with the PROBE.  This function only makes
-       sense if the probe has a concept of semaphore associated to a
-       probe, otherwise it can be set to NULL.  */
+   Each probe backend needs to inherit this class and implement all of
+   the virtual functions specified here.  Then, an object shall be
+   instantiated and added (or "registered") to the
+   ALL_STATIC_PROBE_OPS vector so that the frontend probe interface
+   can use it in the generic probe functions.  */
 
-    void (*set_semaphore) (struct probe *probe, struct objfile *objfile,
-			   struct gdbarch *gdbarch);
-
-    /* Clear the semaphore associated with the PROBE.  This function only
-       makes sense if the probe has a concept of semaphore associated to
-       a probe, otherwise it can be set to NULL.  */
-
-    void (*clear_semaphore) (struct probe *probe, struct objfile *objfile,
-			     struct gdbarch *gdbarch);
-
-    /* Function called to destroy PROBE's specific data.  This function
-       shall not free PROBE itself.  */
-
-    void (*destroy) (struct probe *probe);
-
-    /* Return a pointer to a name identifying the probe type.  This is
-       the string that will be displayed in the "Type" column of the
-       `info probes' command.  */
+class static_probe_ops
+{
+public:
+  /* Method responsible for verifying if LINESPECP is a valid linespec
+     for a probe breakpoint.  It should return true if it is, or false
+     if it is not.  It also should update LINESPECP in order to
+     discard the breakpoint option associated with this linespec.  For
+     example, if the option is `-probe', and the LINESPECP is `-probe
+     abc', the function should return 1 and set LINESPECP to
+     `abc'.  */
+  virtual bool is_linespec (const char **linespecp) const = 0;
+
+  /* Function that should fill PROBES with known probes from OBJFILE.  */
+  virtual void get_probes (std::vector<probe *> *probes,
+			    struct objfile *objfile) const = 0;
+
+  /* Return a pointer to a name identifying the probe type.  This is
+     the string that will be displayed in the "Type" column of the
+     `info probes' command.  */
+  virtual const char *type_name () const = 0;
+
+  /* Return true if the probe type will emit extra fields when the
+     user issues a "info probes" command.  If this function returns
+     false, then GEN_INFO_PROBES_TABLE_HEADER and
+     GEN_INFO_PROBES_TABLE_VALUES are not used.  */
+  virtual bool emit_info_probes_extra_fields () const = 0;
+
+  /* Function responsible for providing the extra fields that will be
+     printed in the `info probes' command.  It should fill HEADS
+     with whatever extra fields it needs.  If no extra fields are
+     required by the probe backend, the method EMIT_INFO_PROBES_FIELDS
+     should return false.  */
+  virtual void gen_info_probes_table_header
+    (std::vector<struct info_probe_column> *heads) const = 0;
+};
 
-    const char *(*type_name) (struct probe *probe);
+/* Definition of a vector of static_probe_ops.  */
 
-    /* Function responsible for providing the extra fields that will be
-       printed in the `info probes' command.  It should fill HEADS
-       with whatever extra fields it needs.  If the backend doesn't need
-       to print extra fields, it can set this method to NULL.  */
+extern std::vector<const static_probe_ops *> all_static_probe_ops;
 
-    void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
+/* Helper function that, given KEYWORDS, iterate over it trying to match
+   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
+   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
+   is returned.  */
 
-    /* Function that will fill VALUES with the values of the extra fields
-       to be printed for PROBE.  If the backend implements the
-       `gen_ui_out_table_header' method, then it should implement
-       this method as well.  The backend should also guarantee that the
-       order and the number of values in the vector is exactly the same
-       as the order of the extra fields provided in the method
-       `gen_ui_out_table_header'.  If a certain field is to be skipped
-       when printing the information, you can push a NULL value in that
-       position in the vector.  */
+extern int probe_is_linespec_by_keyword (const char **linespecp,
+					 const char *const *keywords);
 
-    void (*gen_info_probes_table_values) (struct probe *probe,
-					  VEC (const_char_ptr) **values);
+/* Return specific STATIC_PROBE_OPS * matching *LINESPECP and possibly
+   updating LINESPECP to skip its "-probe-type " prefix.  Return
+   &static_probe_ops_any if LINESPECP matches "-probe ", that is any
+   unspecific probe.  Return NULL if LINESPECP is not identified as
+   any known probe type, *LINESPECP is not modified in such case.  */
 
-    /* Enable a probe.  The semantics of "enabling" a probe depend on
-       the specific backend and the field can be NULL in case enabling
-       probes is not supported.  This function can throw an
-       exception.  */
+extern const static_probe_ops *
+  probe_linespec_to_static_ops (const char **linespecp);
 
-    void (*enable_probe) (struct probe *probe);
+/* The probe itself.  The class contains generic information about the
+   probe.  */
 
-    /* Disable a probe.  The semantics of "disabling" a probe depend
-       on the specific backend and the field can be NULL in case
-       disabling probes is not supported.  This function can throw an
-       exception.  */
+class probe
+{
+public:
+  /* Default constructor for a probe.  */
+  probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+	 struct gdbarch *arch_)
+    : m_name (std::move (name_)), m_provider (std::move (provider_)),
+      m_address (address_), m_arch (arch_)
+  {}
 
-    void (*disable_probe) (struct probe *probe);
-  };
+  /* Virtual destructor.  */
+  virtual ~probe ()
+  {}
 
-/* Definition of a vector of probe_ops.  */
+  /* Compute the probe's relocated address.  OBJFILE is the objfile
+     in which the probe originated.  */
+  virtual CORE_ADDR get_relocated_address (struct objfile *objfile) = 0;
+
+  /* Return the number of arguments of the probe.  This function can
+     throw an exception.  */
+  virtual unsigned get_argument_count (struct frame_info *frame) = 0;
+
+  /* Return 1 if the probe interface can evaluate the arguments of
+     probe, zero otherwise.  See the comments on
+     sym_probe_fns:can_evaluate_probe_arguments for more
+     details.  */
+  virtual int can_evaluate_arguments () const = 0;
+
+  /* Evaluate the Nth argument from the probe, returning a value
+     corresponding to it.  The argument number is represented N.
+     This function can throw an exception.  */
+  virtual struct value *evaluate_argument (unsigned n,
+					   struct frame_info *frame) = 0;
+
+  /* Compile the Nth argument of the probe to an agent expression.
+     The argument number is represented by N.  */
+  virtual void compile_to_ax (struct agent_expr *aexpr,
+			      struct axs_value *axs_value,
+			      unsigned n) = 0;
+
+  /* Set the semaphore associated with the probe.  This function only
+     makes sense if the probe has a concept of semaphore associated to
+     a probe.  */
+  virtual void set_semaphore (struct objfile *objfile,
+			      struct gdbarch *gdbarch)
+  {}
 
-extern std::vector<const probe_ops *> all_probe_ops;
+  /* Clear the semaphore associated with the probe.  This function
+     only makes sense if the probe has a concept of semaphore
+     associated to a probe.  */
+  virtual void clear_semaphore (struct objfile *objfile,
+				struct gdbarch *gdbarch)
+  {}
 
-/* The probe_ops associated with the generic probe.  */
+  /* Return the pointer to the static_probe_ops instance related to
+     the probe type.  */
+  virtual const static_probe_ops *get_static_ops () const = 0;
+
+  /* Function that will fill VALUES with the values of the extra
+     fields to be printed for the probe.
+
+     If the backend implements the `gen_ui_out_table_header' method,
+     then it should implement this method as well.  The backend should
+     also guarantee that the order and the number of values in the
+     vector is exactly the same as the order of the extra fields
+     provided in the method `gen_ui_out_table_header'.  If a certain
+     field is to be skipped when printing the information, you can
+     push a NULL value in that position in the vector.  */
+  virtual void gen_info_probes_table_values
+    (std::vector<const char *> *values) const
+  {}
 
-extern const struct probe_ops probe_ops_any;
+  /* Return true if the probe can be enabled; false otherwise.  */
+  virtual bool can_enable () const
+  {
+    return false;
+  }
 
-/* Helper function that, given KEYWORDS, iterate over it trying to match
-   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
-   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
-   is returned.  */
+  /* Enable the probe.  The semantics of "enabling" a probe depend on
+     the specific backend.  This function can throw an exception.  */
+  virtual void enable ()
+  {}
 
-extern int probe_is_linespec_by_keyword (const char **linespecp,
-					 const char *const *keywords);
+  /* Disable the probe.  The semantics of "disabling" a probe depend
+     on the specific backend.  This function can throw an
+     exception.  */
+  virtual void disable ()
+  {}
 
-/* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
-   *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
-   *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
-   *LINESPECP is not identified as any known probe type, *LINESPECP is not
-   modified in such case.  */
+  /* Getter for M_NAME.  */
+  const char *get_name () const
+  {
+    return m_name.c_str ();
+  }
 
-extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
+  /* Getter for M_PROVIDER.  */
+  const char *get_provider () const
+  {
+    return m_provider.c_str ();
+  }
 
-/* The probe itself.  The struct contains generic information about the
-   probe, and then some specific information which should be stored in
-   the `probe_info' field.  */
+  /* Getter for M_ADDRESS.  */
+  CORE_ADDR get_address () const
+  {
+    return m_address;
+  }
 
-struct probe
+  /* Getter for M_ARCH.  */
+  struct gdbarch *get_gdbarch () const
   {
-    /* The operations associated with this probe.  */
-    const struct probe_ops *pops;
+    return m_arch;
+  }
 
-    /* The probe's architecture.  */
-    struct gdbarch *arch;
+private:
+  /* The name of the probe.  */
+  std::string m_name;
 
-    /* The name of the probe.  */
-    const char *name;
+  /* The provider of the probe.  It generally defaults to the name of
+     the objfile which contains the probe.  */
+  std::string m_provider;
 
-    /* The provider of the probe.  It generally defaults to the name of
-       the objfile which contains the probe.  */
-    const char *provider;
+  /* The address where the probe is inserted, relative to
+     SECT_OFF_TEXT.  */
+  CORE_ADDR m_address;
 
-    /* The address where the probe is inserted, relative to
-       SECT_OFF_TEXT.  */
-    CORE_ADDR address;
-  };
+  /* The probe's architecture.  */
+  struct gdbarch *m_arch;
+};
 
 /* A bound probe holds a pointer to a probe and a pointer to the
    probe's defining objfile.  This is needed because probes are
@@ -206,22 +246,18 @@ struct probe
 struct bound_probe
 {
   /* Create an empty bound_probe object.  */
-
   bound_probe ()
   {}
 
   /* Create and initialize a bound_probe object using PROBE and OBJFILE.  */
-
-  bound_probe (struct probe *probe_, struct objfile *objfile_)
-  : probe (probe_), objfile (objfile_)
+  bound_probe (probe *probe_, struct objfile *objfile_)
+  : prob (probe_), objfile (objfile_)
   {}
 
   /* The probe.  */
-
-  struct probe *probe = NULL;
+  probe *prob = NULL;
 
   /* The objfile in which the probe originated.  */
-
   struct objfile *objfile = NULL;
 };
 
@@ -234,11 +270,6 @@ extern std::vector<symtab_and_line> parse_probes
    struct program_space *pspace,
    struct linespec_result *canon);
 
-/* Helper function to register the proper probe_ops to a newly created probe.
-   This function is mainly called from `sym_get_probes'.  */
-
-extern void register_probe_ops (struct probe *probe);
-
 /* Given a PC, find an associated probe.  If a probe is found, return
    it.  If no probe is found, return a bound probe whose fields are
    both NULL.  */
@@ -253,13 +284,13 @@ 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
-   function that can be used by the probe backends to print their
-   `info probe TYPE'.  */
+/* Generate a `info probes' command output for probes associated with
+   SPOPS.  If SPOPS is related to the "any probe" type, then all probe
+   types are considered.  It is a helper function that can be used by
+   the probe backends to print their `info probe TYPE'.  */
 
-extern void info_probes_for_ops (const char *arg, int from_tty,
-				 const struct probe_ops *pops);
+extern void info_probes_for_spops (const char *arg, int from_tty,
+				   const static_probe_ops *spops);
 
 /* Return the `cmd_list_element' associated with the `info probes' command,
    or create a new one if it doesn't exist.  Helper function that serves the
@@ -268,34 +299,6 @@ extern void info_probes_for_ops (const char *arg, int from_tty,
 
 extern struct cmd_list_element **info_probes_cmdlist_get (void);
 
-/* Compute the probe's relocated address.  OBJFILE is the objfile in
-   which the probe originated.  */
-
-extern CORE_ADDR get_probe_address (struct probe *probe,
-				    struct objfile *objfile);
-
-/* Return the argument count of the specified probe.
-
-   This function can throw an exception.  */
-
-extern unsigned get_probe_argument_count (struct probe *probe,
-					  struct frame_info *frame);
-
-/* Return 1 if the probe interface associated with PROBE can evaluate
-   arguments, zero otherwise.  See the comments on the definition of
-   sym_probe_fns:can_evaluate_probe_arguments for more details.  */
-
-extern int can_evaluate_probe_arguments (struct probe *probe);
-
-/* Evaluate argument N of the specified probe.  N must be between 0
-   inclusive and get_probe_argument_count exclusive.
-
-   This function can throw an exception.  */
-
-extern struct value *evaluate_probe_argument (struct probe *probe,
-					      unsigned n,
-					      struct frame_info *frame);
-
 /* A convenience function that finds a probe at the PC in FRAME and
    evaluates argument N, with 0 <= N < number_of_args.  If there is no
    probe at that location, or if the probe does not have enough arguments,
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 5ec606de43..6e834fb5d7 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -351,7 +351,7 @@ struct svr4_info
   /* Table of struct probe_and_action instances, used by the
      probes-based interface to map breakpoint addresses to probes
      and their associated actions.  Lookup is performed using
-     probe_and_action->probe->address.  */
+     probe_and_action->prob->address.  */
   htab_t probes_table;
 
   /* List of objects loaded into the inferior, used by the probes-
@@ -1664,7 +1664,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ)
 struct probe_and_action
 {
   /* The probe.  */
-  struct probe *probe;
+  probe *prob;
 
   /* The relocated address of the probe.  */
   CORE_ADDR address;
@@ -1699,7 +1699,7 @@ equal_probe_and_action (const void *p1, const void *p2)
    probes table.  */
 
 static void
-register_solib_event_probe (struct probe *probe, CORE_ADDR address,
+register_solib_event_probe (probe *prob, CORE_ADDR address,
 			    enum probe_action action)
 {
   struct svr4_info *info = get_svr4_info ();
@@ -1712,13 +1712,13 @@ register_solib_event_probe (struct probe *probe, CORE_ADDR address,
 					    equal_probe_and_action,
 					    xfree, xcalloc, xfree);
 
-  lookup.probe = probe;
+  lookup.prob = prob;
   lookup.address = address;
   slot = htab_find_slot (info->probes_table, &lookup, INSERT);
   gdb_assert (*slot == HTAB_EMPTY_ENTRY);
 
   pa = XCNEW (struct probe_and_action);
-  pa->probe = probe;
+  pa->prob = prob;
   pa->address = address;
   pa->action = action;
 
@@ -1767,7 +1767,7 @@ solib_event_probe_action (struct probe_and_action *pa)
        arg2: struct link_map *new (optional, for incremental updates)  */
   TRY
     {
-      probe_argc = get_probe_argument_count (pa->probe, frame);
+      probe_argc = pa->prob->get_argument_count (frame);
     }
   CATCH (ex, RETURN_MASK_ERROR)
     {
@@ -1776,11 +1776,11 @@ solib_event_probe_action (struct probe_and_action *pa)
     }
   END_CATCH
 
-  /* If get_probe_argument_count throws an exception, probe_argc will
-     be set to zero.  However, if pa->probe does not have arguments,
-     then get_probe_argument_count will succeed but probe_argc will
-     also be zero.  Both cases happen because of different things, but
-     they are treated equally here: action will be set to
+  /* If get_argument_count throws an exception, probe_argc will be set
+     to zero.  However, if pa->prob does not have arguments, then
+     get_argument_count will succeed but probe_argc will also be zero.
+     Both cases happen because of different things, but they are
+     treated equally here: action will be set to
      PROBES_INTERFACE_FAILED.  */
   if (probe_argc == 2)
     action = FULL_RELOAD;
@@ -1922,7 +1922,7 @@ svr4_handle_solib_event (void)
       return;
     }
 
-  /* evaluate_probe_argument looks up symbols in the dynamic linker
+  /* evaluate_argument looks up symbols in the dynamic linker
      using find_pc_section.  find_pc_section is accelerated by a cache
      called the section map.  The section map is invalidated every
      time a shared library is loaded or unloaded, and if the inferior
@@ -1931,14 +1931,14 @@ svr4_handle_solib_event (void)
      We called find_pc_section in svr4_create_solib_event_breakpoints,
      so we can guarantee that the dynamic linker's sections are in the
      section map.  We can therefore inhibit section map updates across
-     these calls to evaluate_probe_argument and save a lot of time.  */
+     these calls to evaluate_argument and save a lot of time.  */
   inhibit_section_map_updates (current_program_space);
   usm_chain = make_cleanup (resume_section_map_updates_cleanup,
 			    current_program_space);
 
   TRY
     {
-      val = evaluate_probe_argument (pa->probe, 1, frame);
+      val = pa->prob->evaluate_argument (1, frame);
     }
   CATCH (ex, RETURN_MASK_ERROR)
     {
@@ -1979,7 +1979,7 @@ svr4_handle_solib_event (void)
     {
       TRY
 	{
-	  val = evaluate_probe_argument (pa->probe, 2, frame);
+	  val = pa->prob->evaluate_argument (2, frame);
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
@@ -2084,7 +2084,7 @@ svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
 
       for (probe *p : probes[i])
 	{
-	  CORE_ADDR address = get_probe_address (p, objfile);
+	  CORE_ADDR address = p->get_relocated_address (objfile);
 
 	  create_solib_event_breakpoint (gdbarch, address);
 	  register_solib_event_probe (p, address, action);
@@ -2126,7 +2126,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	  for (int i = 0; i < NUM_PROBES; i++)
 	    {
 	      const char *name = probe_info[i].name;
-	      struct probe *p;
+	      probe *p;
 	      char buf[32];
 
 	      /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
@@ -2160,7 +2160,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	      if (!checked_can_use_probe_arguments)
 		{
 		  p = probes[i][0];
-		  if (!can_evaluate_probe_arguments (p))
+		  if (!p->can_evaluate_arguments ())
 		    {
 		      all_probes_found = 0;
 		      break;
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 3472aa0e7b..10b1504937 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -34,11 +34,11 @@ struct objfile;
 struct obj_section;
 struct obstack;
 struct block;
-struct probe;
 struct value;
 struct frame_info;
 struct agent_expr;
 struct axs_value;
+class probe;
 
 /* Comparison function for symbol look ups.  */
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 7b8b5cc640..8bf9f3994f 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -41,10 +41,10 @@ struct axs_value;
 struct agent_expr;
 struct program_space;
 struct language_defn;
-struct probe;
 struct common_block;
 struct obj_section;
 struct cmd_list_element;
+class probe;
 struct lookup_name_info;
 
 /* How to match a lookup name against a symbol search name.  */
@@ -1702,7 +1702,7 @@ struct symtab_and_line
   bool explicit_line = false;
 
   /* The probe associated with this symtab_and_line.  */
-  struct probe *probe = NULL;
+  probe *prob = NULL;
   /* If PROBE is not NULL, then this is the objfile in which the probe
      originated.  */
   struct objfile *objfile = NULL;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 59a7b64ae8..76d05dfc13 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1654,11 +1654,9 @@ start_tracing (const char *notes)
       t->number_on_target = b->number;
 
       for (loc = b->loc; loc; loc = loc->next)
-	if (loc->probe.probe != NULL
-	    && loc->probe.probe->pops->set_semaphore != NULL)
-	  loc->probe.probe->pops->set_semaphore (loc->probe.probe,
-						 loc->probe.objfile,
-						 loc->gdbarch);
+	if (loc->probe.prob != NULL)
+	  loc->probe.prob->set_semaphore (loc->probe.objfile,
+					  loc->gdbarch);
 
       if (bp_location_downloaded)
 	observer_notify_breakpoint_modified (b);
@@ -1754,11 +1752,9 @@ stop_tracing (const char *note)
 	     but we don't really care if this semaphore goes out of sync.
 	     That's why we are decrementing it here, but not taking care
 	     in other places.  */
-	  if (loc->probe.probe != NULL
-	      && loc->probe.probe->pops->clear_semaphore != NULL)
-	    loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
-						     loc->probe.objfile,
-						     loc->gdbarch);
+	  if (loc->probe.prob != NULL)
+	    loc->probe.prob->clear_semaphore (loc->probe.objfile,
+					      loc->gdbarch);
 	}
     }
 
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
@ 2017-11-13 17:59 ` Sergio Durigan Junior
  2017-11-15  3:58   ` Simon Marchi
  2017-11-13 17:59 ` [PATCH 1/3] Convert generic " Sergio Durigan Junior
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:59 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch converts the SystemTap probe
interface (gdb/stap-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct stap_probe' to 'class
stap_probe', and a new 'class stap_static_probe_ops' to replace the
use of 'stap_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the stap-probe interface.

There are several helper functions used to parse parts of a stap
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
	variable.
	(stap_probe_arg_s): Delete type and VEC.
	(struct stap_probe): Delete.  Replace by...
	(class stap_static_probe_ops): ...this and...
	(class stap_probe): ...this.  Rename variables to add 'm_'
	prefix.  Do not use 'union' for arguments anymore.
	(stap_get_expected_argument_type): Receive probe name instead
	of 'struct stap_probe'.  Adjust code.
	(stap_parse_probe_arguments): Rename to...
	(stap_probe::parse_arguments): ...this.  Adjust code to
	reflect change.
	(stap_get_probe_address): Rename to...
	(stap_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(stap_get_probe_argument_count): Rename to...
	(stap_probe::get_argument_count): ...this.  Adjust code
	to reflect change.
	(stap_get_arg): Rename to...
	(stap_probe::get_arg_by_number'): ...this. Adjust code to
	reflect change.
	(can_evaluate_probe_arguments): Rename to...
	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(stap_evaluate_probe_argument): Rename to...
	(stap_probe::evaluate_argument): ...this.  Adjust code
	to reflect change.
	(stap_compile_to_ax): Rename to...
	(stap_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(stap_probe_destroy): Delete.
	(stap_modify_semaphore): Adjust comment.
	(stap_set_semaphore): Rename to...
	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
	change.
	(stap_clear_semaphore): Rename to...
	(stap_probe::clear_semaphore): ...this.  Adjust code to
	reflect	change.
	(stap_probe::get_static_ops): New method.
	(handle_stap_probe): Adjust code to create instance of
	'stap_probe'.
	(stap_get_probes): Rename to...
	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
	reflect change.
	(stap_probe_is_linespec): Rename to...
	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
	reflect change.
	(stap_type_name): Rename to...
	(stap_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(stap_static_probe_ops::emit_info_probes_extra_fields): New
	method.
	(stap_gen_info_probes_table_header): Rename to...
	(stap_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(stap_gen_info_probes_table_values): Rename to...
	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(struct probe_ops stap_probe_ops): Delete.
	(info_probes_stap_command): Use 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
---
 gdb/stap-probe.c | 478 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 244 insertions(+), 234 deletions(-)

diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 6fa0d20280..c169ffc488 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -45,10 +45,6 @@
 
 #define STAP_BASE_SECTION_NAME ".stapsdt.base"
 
-/* Forward declaration. */
-
-extern const struct probe_ops stap_probe_ops;
-
 /* Should we display debug information for the probe's argument expression
    parsing?  */
 
@@ -95,32 +91,135 @@ struct stap_probe_arg
   struct expression *aexpr;
 };
 
-typedef struct stap_probe_arg stap_probe_arg_s;
-DEF_VEC_O (stap_probe_arg_s);
+/* Class that implements the static probe methods for "stap" probes.  */
 
-struct stap_probe
+class stap_static_probe_ops : public static_probe_ops
 {
-  /* Generic information about the probe.  This shall be the first element
-     of this struct, in order to maintain binary compatibility with the
-     `struct probe' and be able to fully abstract it.  */
-  struct probe p;
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  bool emit_info_probes_extra_fields () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_header
+    (std::vector<struct info_probe_column> *heads) const override;
+};
+
+/* SystemTap static_probe_ops.  */
+
+const stap_static_probe_ops stap_static_probe_ops;
 
+class stap_probe : public probe
+{
+public:
+  /* Constructor for stap_probe.  */
+  stap_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+	      struct gdbarch *arch_, CORE_ADDR sem_addr, const char *args_text)
+    : probe (std::move (name_), std::move (provider_), address_, arch_),
+      m_sem_addr (sem_addr),
+      m_have_parsed_args (false), m_unparsed_args_text (args_text)
+  {}
+
+  /* Destructor for stap_probe.  */
+  ~stap_probe ()
+  {
+    if (m_have_parsed_args)
+      for (struct stap_probe_arg arg : m_parsed_args)
+	xfree (arg.aexpr);
+  }
+
+  /* See probe.h.  */
+  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
+
+  /* See probe.h.  */
+  unsigned get_argument_count (struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  int can_evaluate_arguments () const override;
+
+  /* See probe.h.  */
+  struct value *evaluate_argument (unsigned n,
+				   struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  void compile_to_ax (struct agent_expr *aexpr,
+		      struct axs_value *axs_value,
+		      unsigned n) override;
+
+  /* See probe.h.  */
+  void set_semaphore (struct objfile *objfile,
+		      struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  void clear_semaphore (struct objfile *objfile,
+			struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  const static_probe_ops *get_static_ops () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_values
+    (std::vector<const char *> *values) const override;
+
+  /* Return argument N of probe.
+
+     If the probe's arguments have not been parsed yet, parse them.  If
+     there are no arguments, throw an exception (error).  Otherwise,
+     return the requested argument.  */
+  struct stap_probe_arg *get_arg_by_number (unsigned n,
+					    struct gdbarch *gdbarch)
+  {
+    if (!m_have_parsed_args)
+      this->parse_arguments (gdbarch);
+
+    gdb_assert (m_have_parsed_args);
+    if (m_parsed_args.empty ())
+      internal_error (__FILE__, __LINE__,
+		      _("Probe '%s' apparently does not have arguments, but \n"
+			"GDB is requesting its argument number %u anyway.  "
+			"This should not happen.  Please report this bug."),
+		      this->get_name (), n);
+
+    return &m_parsed_args[n];
+  }
+
+  /* Function which parses an argument string from the probe,
+     correctly splitting the arguments and storing their information
+     in properly ways.
+
+     Consider the following argument string (x86 syntax):
+
+     `4@%eax 4@$10'
+
+     We have two arguments, `%eax' and `$10', both with 32-bit
+     unsigned bitness.  This function basically handles them, properly
+     filling some structures with this information.  */
+  void parse_arguments (struct gdbarch *gdbarch);
+
+private:
   /* If the probe has a semaphore associated, then this is the value of
      it, relative to SECT_OFF_DATA.  */
-  CORE_ADDR sem_addr;
+  CORE_ADDR m_sem_addr;
 
-  /* One if the arguments have been parsed.  */
-  unsigned int args_parsed : 1;
+  /* True if the arguments have been parsed.  */
+  bool m_have_parsed_args;
 
-  union
-    {
-      const char *text;
+  /* The text version of the probe's arguments, unparsed.  */
+  const char *m_unparsed_args_text;
 
-      /* Information about each argument.  This is an array of `stap_probe_arg',
-	 with each entry representing one argument.  */
-      VEC (stap_probe_arg_s) *vec;
-    }
-  args_u;
+  /* Information about each argument.  This is an array of `stap_probe_arg',
+     with each entry representing one argument.  This is only valid if
+     M_ARGS_PARSED is true.  */
+  std::vector<struct stap_probe_arg> m_parsed_args;
 };
 
 /* When parsing the arguments, we have to establish different precedences
@@ -326,7 +425,7 @@ stap_get_opcode (const char **s)
 static struct type *
 stap_get_expected_argument_type (struct gdbarch *gdbarch,
 				 enum stap_arg_bitness b,
-				 const struct stap_probe *probe)
+				 const char *probe_name)
 {
   switch (b)
     {
@@ -361,8 +460,7 @@ stap_get_expected_argument_type (struct gdbarch *gdbarch,
       return builtin_type (gdbarch)->builtin_uint64;
 
     default:
-      error (_("Undefined bitness for probe '%s'."),
-	     probe->p.name);
+      error (_("Undefined bitness for probe '%s'."), probe_name);
       break;
     }
 }
@@ -1081,26 +1179,16 @@ stap_parse_argument (const char **arg, struct type *atype,
   return p.pstate.expout;
 }
 
-/* Function which parses an argument string from PROBE, correctly splitting
-   the arguments and storing their information in properly ways.
+/* Implementation of 'parse_probe_arguments' method.  */
 
-   Consider the following argument string (x86 syntax):
-
-   `4@%eax 4@$10'
-
-   We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
-   This function basically handles them, properly filling some structures with
-   this information.  */
-
-static void
-stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
+void
+stap_probe::parse_arguments (struct gdbarch *gdbarch)
 {
   const char *cur;
 
-  gdb_assert (!probe->args_parsed);
-  cur = probe->args_u.text;
-  probe->args_parsed = 1;
-  probe->args_u.vec = NULL;
+  gdb_assert (!m_have_parsed_args);
+  cur = m_unparsed_args_text;
+  m_have_parsed_args = true;
 
   if (cur == NULL || *cur == '\0' || *cur == ':')
     return;
@@ -1159,7 +1247,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 		/* We have an error, because we don't expect anything
 		   except 1, 2, 4 and 8.  */
 		warning (_("unrecognized bitness %s%c' for probe `%s'"),
-			 got_minus ? "`-" : "`", *cur, probe->p.name);
+			 got_minus ? "`-" : "`", *cur, this->get_name ());
 		return;
 	      }
 	    }
@@ -1173,7 +1261,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 	arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
 
       arg.atype = stap_get_expected_argument_type (gdbarch, arg.bitness,
-						   probe);
+						   this->get_name ());
 
       expr = stap_parse_argument (&cur, arg.atype, gdbarch);
 
@@ -1191,35 +1279,31 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
       /* Start it over again.  */
       cur = skip_spaces (cur);
 
-      VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
+      m_parsed_args.push_back (arg);
     }
 }
 
-/* Implementation of the get_probe_address method.  */
+/* Implementation of the get_relocated_address method.  */
 
-static CORE_ADDR
-stap_get_probe_address (struct probe *probe, struct objfile *objfile)
+CORE_ADDR
+stap_probe::get_relocated_address (struct objfile *objfile)
 {
-  return probe->address + ANOFFSET (objfile->section_offsets,
-				    SECT_OFF_DATA (objfile));
+  return this->get_address () + ANOFFSET (objfile->section_offsets,
+					  SECT_OFF_DATA (objfile));
 }
 
 /* Given PROBE, returns the number of arguments present in that probe's
    argument string.  */
 
-static unsigned
-stap_get_probe_argument_count (struct probe *probe_generic,
-			       struct frame_info *frame)
+unsigned
+stap_probe::get_argument_count (struct frame_info *frame)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (!probe->args_parsed)
+  if (!m_have_parsed_args)
     {
-      if (can_evaluate_probe_arguments (probe_generic))
-	stap_parse_probe_arguments (probe, gdbarch);
+      if (this->can_evaluate_arguments ())
+	this->parse_arguments (gdbarch);
       else
 	{
 	  static int have_warned_stap_incomplete = 0;
@@ -1234,13 +1318,12 @@ stap_get_probe_argument_count (struct probe *probe_generic,
 	    }
 
 	  /* Marking the arguments as "already parsed".  */
-	  probe->args_u.vec = NULL;
-	  probe->args_parsed = 1;
+	  m_have_parsed_args = true;
 	}
     }
 
-  gdb_assert (probe->args_parsed);
-  return VEC_length (stap_probe_arg_s, probe->args_u.vec);
+  gdb_assert (m_have_parsed_args);
+  return m_parsed_args.size ();
 }
 
 /* Return 1 if OP is a valid operator inside a probe argument, or zero
@@ -1279,36 +1362,12 @@ stap_is_operator (const char *op)
   return ret;
 }
 
-/* Return argument N of probe PROBE.
-
-   If the probe's arguments have not been parsed yet, parse them.  If
-   there are no arguments, throw an exception (error).  Otherwise,
-   return the requested argument.  */
-
-static struct stap_probe_arg *
-stap_get_arg (struct stap_probe *probe, unsigned n, struct gdbarch *gdbarch)
-{
-  if (!probe->args_parsed)
-    stap_parse_probe_arguments (probe, gdbarch);
-
-  gdb_assert (probe->args_parsed);
-  if (probe->args_u.vec == NULL)
-    internal_error (__FILE__, __LINE__,
-		    _("Probe '%s' apparently does not have arguments, but \n"
-		      "GDB is requesting its argument number %u anyway.  "
-		      "This should not happen.  Please report this bug."),
-		    probe->p.name, n);
-
-  return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
-}
-
-/* Implement the `can_evaluate_probe_arguments' method of probe_ops.  */
+/* Implement the `can_evaluate_arguments' method.  */
 
-static int
-stap_can_evaluate_probe_arguments (struct probe *probe_generic)
+int
+stap_probe::can_evaluate_arguments () const
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = stap_probe->p.arch;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* For SystemTap probes, we have to guarantee that the method
      stap_is_single_operand is defined on gdbarch.  If it is not, then it
@@ -1319,35 +1378,28 @@ stap_can_evaluate_probe_arguments (struct probe *probe_generic)
 /* Evaluate the probe's argument N (indexed from 0), returning a value
    corresponding to it.  Assertion is thrown if N does not exist.  */
 
-static struct value *
-stap_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
-			      struct frame_info *frame)
+struct value *
+stap_probe::evaluate_argument (unsigned n, struct frame_info *frame)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = get_frame_arch (frame);
   struct stap_probe_arg *arg;
   int pos = 0;
+  struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, gdbarch);
+  arg = this->get_arg_by_number (n, gdbarch);
   return evaluate_subexp_standard (arg->atype, arg->aexpr, &pos, EVAL_NORMAL);
 }
 
 /* Compile the probe's argument N (indexed from 0) to agent expression.
    Assertion is thrown if N does not exist.  */
 
-static void
-stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
-		    struct axs_value *value, unsigned n)
+void
+stap_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
+			   unsigned n)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
   struct stap_probe_arg *arg;
   union exp_element *pc;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, expr->gdbarch);
+  arg = this->get_arg_by_number (n, expr->gdbarch);
 
   pc = arg->aexpr->elts;
   gen_expr (arg->aexpr, &pc, expr, value);
@@ -1355,35 +1407,12 @@ stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
   require_rvalue (expr, value);
   value->type = arg->atype;
 }
-
-/* Destroy (free) the data related to PROBE.  PROBE memory itself is not feed
-   as it is allocated on an obstack.  */
-
-static void
-stap_probe_destroy (struct probe *probe_generic)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (probe->args_parsed)
-    {
-      struct stap_probe_arg *arg;
-      int ix;
-
-      for (ix = 0; VEC_iterate (stap_probe_arg_s, probe->args_u.vec, ix, arg);
-	   ++ix)
-	xfree (arg->aexpr);
-      VEC_free (stap_probe_arg_s, probe->args_u.vec);
-    }
-}
-
 \f
 
 /* Set or clear a SystemTap semaphore.  ADDRESS is the semaphore's
-   address.  SET is zero if the semaphore should be cleared, or one
-   if it should be set.  This is a helper function for `stap_semaphore_down'
-   and `stap_semaphore_up'.  */
+   address.  SET is zero if the semaphore should be cleared, or one if
+   it should be set.  This is a helper function for
+   'stap_probe::set_semaphore' and 'stap_probe::clear_semaphore'.  */
 
 static void
 stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
@@ -1419,43 +1448,58 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
     warning (_("Could not write the value of a SystemTap semaphore."));
 }
 
-/* Set a SystemTap semaphore.  SEM is the semaphore's address.  Semaphores
-   act as reference counters, so calls to this function must be paired with
-   calls to `stap_semaphore_down'.
+/* Implementation of the 'set_semaphore' method.
 
-   This function and `stap_semaphore_down' race with another tool changing
-   the probes, but that is too rare to care.  */
+   SystemTap semaphores act as reference counters, so calls to this
+   function must be paired with calls to 'clear_semaphore'.
 
-static void
-stap_set_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		    struct gdbarch *gdbarch)
+   This function and 'clear_semaphore' race with another tool
+   changing the probes, but that is too rare to care.  */
+
+void
+stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   CORE_ADDR addr;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  addr = (probe->sem_addr
+  addr = (m_sem_addr
 	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
   stap_modify_semaphore (addr, 1, gdbarch);
 }
 
-/* Clear a SystemTap semaphore.  SEM is the semaphore's address.  */
+/* Implementation of the 'clear_semaphore' method.  */
 
-static void
-stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		      struct gdbarch *gdbarch)
+void
+stap_probe::clear_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   CORE_ADDR addr;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  addr = (probe->sem_addr
+  addr = (m_sem_addr
 	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
   stap_modify_semaphore (addr, 0, gdbarch);
 }
 
+/* Implementation of the 'get_static_ops' method.  */
+
+const static_probe_ops *
+stap_probe::get_static_ops () const
+{
+  return &stap_static_probe_ops;
+}
+
+/* Implementation of the 'gen_info_probes_table_values' method.  */
+
+void
+stap_probe::gen_info_probes_table_values
+  (std::vector<const char *> *values) const
+{
+  const char *val = NULL;
+
+  if (m_sem_addr != 0)
+    val = print_core_address (this->get_gdbarch (), m_sem_addr);
+
+  values->push_back (val);
+}
+
 /* Helper function that parses the information contained in a
    SystemTap's probe.  Basically, the information consists in:
 
@@ -1478,21 +1522,14 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   int size = bfd_get_arch_size (abfd) / 8;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
-  CORE_ADDR base_ref;
-  const char *probe_args = NULL;
-  struct stap_probe *ret;
-
-  ret = XOBNEW (&objfile->per_bfd->storage_obstack, struct stap_probe);
-  ret->p.pops = &stap_probe_ops;
-  ret->p.arch = gdbarch;
 
   /* Provider and the name of the probe.  */
-  ret->p.provider = (char *) &el->data[3 * size];
-  ret->p.name = ((const char *)
-		 memchr (ret->p.provider, '\0',
-			 (char *) el->data + el->size - ret->p.provider));
+  const char *provider = (const char *) &el->data[3 * size];
+  const char *name = ((const char *)
+		      memchr (provider, '\0',
+			      (char *) el->data + el->size - provider));
   /* Making sure there is a name.  */
-  if (ret->p.name == NULL)
+  if (name == NULL)
     {
       complaint (&symfile_complaints, _("corrupt probe name when "
 					"reading `%s'"),
@@ -1503,32 +1540,32 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
   else
-    ++ret->p.name;
+    ++name;
 
   /* Retrieving the probe's address.  */
-  ret->p.address = extract_typed_address (&el->data[0], ptr_type);
+  CORE_ADDR address = extract_typed_address (&el->data[0], ptr_type);
 
   /* Link-time sh_addr of `.stapsdt.base' section.  */
-  base_ref = extract_typed_address (&el->data[size], ptr_type);
+  CORE_ADDR base_ref = extract_typed_address (&el->data[size], ptr_type);
 
   /* Semaphore address.  */
-  ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
+  CORE_ADDR sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
 
-  ret->p.address += base - base_ref;
-  if (ret->sem_addr != 0)
-    ret->sem_addr += base - base_ref;
+  address += base - base_ref;
+  if (sem_addr != 0)
+    sem_addr += base - base_ref;
 
   /* Arguments.  We can only extract the argument format if there is a valid
      name for this probe.  */
-  probe_args = ((const char*)
-		memchr (ret->p.name, '\0',
-			(char *) el->data + el->size - ret->p.name));
+  const char *probe_args = ((const char*)
+			    memchr (name, '\0',
+				    (char *) el->data + el->size - name));
 
   if (probe_args != NULL)
     ++probe_args;
 
   if (probe_args == NULL
-      || (memchr (probe_args, '\0', (char *) el->data + el->size - ret->p.name)
+      || (memchr (probe_args, '\0', (char *) el->data + el->size - name)
 	  != el->data + el->size - 1))
     {
       complaint (&symfile_complaints, _("corrupt probe argument when "
@@ -1539,11 +1576,11 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
 
-  ret->args_parsed = 0;
-  ret->args_u.text = probe_args;
+  stap_probe *ret = new stap_probe (std::string (name), std::string (provider),
+				    address, gdbarch, sem_addr, probe_args);
 
   /* Successfully created probe.  */
-  probesp->push_back ((struct probe *) ret);
+  probesp->push_back (ret);
 }
 
 /* Helper function which tries to find the base address of the SystemTap
@@ -1584,11 +1621,21 @@ get_stap_base_address (bfd *obfd, bfd_vma *base)
   return 1;
 }
 
-/* Helper function for `elf_get_probes', which gathers information about all
-   SystemTap probes from OBJFILE.  */
+/* Implementation of the 'is_linespec' method.  */
 
-static void
-stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+bool
+stap_static_probe_ops::is_linespec (const char **linespecp) const
+{
+  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+
+  return probe_is_linespec_by_keyword (linespecp, keywords);
+}
+
+/* Implementation of the 'get_probes' method.  */
+
+void
+stap_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				   struct objfile *objfile) const
 {
   /* If we are here, then this is the first time we are parsing the
      SystemTap probe's information.  We basically have to count how many
@@ -1640,83 +1687,46 @@ stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
 
 /* Implementation of the type_name method.  */
 
-static const char *
-stap_type_name (struct probe *probe)
+const char *
+stap_static_probe_ops::type_name () const
 {
-  gdb_assert (probe->pops == &stap_probe_ops);
   return "stap";
 }
 
-static int
-stap_probe_is_linespec (const char **linespecp)
-{
-  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+/* Implementation of the 'emit_info_probes_extra_fields' method.  */
 
-  return probe_is_linespec_by_keyword (linespecp, keywords);
+bool
+stap_static_probe_ops::emit_info_probes_extra_fields () const
+{
+  return true;
 }
 
-static void
-stap_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
+/* Implementation of the 'gen_info_probes_table_header' method.  */
+
+void
+stap_static_probe_ops::gen_info_probes_table_header
+  (std::vector<struct info_probe_column> *heads) const
 {
-  info_probe_column_s stap_probe_column;
+  struct info_probe_column stap_probe_column;
 
   stap_probe_column.field_name = "semaphore";
   stap_probe_column.print_name = _("Semaphore");
 
-  VEC_safe_push (info_probe_column_s, *heads, &stap_probe_column);
-}
-
-static void
-stap_gen_info_probes_table_values (struct probe *probe_generic,
-				   VEC (const_char_ptr) **ret)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch;
-  const char *val = NULL;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  gdbarch = probe->p.arch;
-
-  if (probe->sem_addr != 0)
-    val = print_core_address (gdbarch, probe->sem_addr);
-
-  VEC_safe_push (const_char_ptr, *ret, val);
+  heads->push_back (stap_probe_column);
 }
 
-/* SystemTap probe_ops.  */
-
-const struct probe_ops stap_probe_ops =
-{
-  stap_probe_is_linespec,
-  stap_get_probes,
-  stap_get_probe_address,
-  stap_get_probe_argument_count,
-  stap_can_evaluate_probe_arguments,
-  stap_evaluate_probe_argument,
-  stap_compile_to_ax,
-  stap_set_semaphore,
-  stap_clear_semaphore,
-  stap_probe_destroy,
-  stap_type_name,
-  stap_gen_info_probes_table_header,
-  stap_gen_info_probes_table_values,
-  NULL,  /* enable_probe  */
-  NULL   /* disable_probe  */
-};
-
 /* Implementation of the `info probes stap' command.  */
 
 static void
 info_probes_stap_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, &stap_probe_ops);
+  info_probes_for_spops (arg, from_tty, &stap_static_probe_ops);
 }
 
 void
 _initialize_stap_probe (void)
 {
-  all_probe_ops.push_back (&stap_probe_ops);
+  all_static_probe_ops.push_back (&stap_static_probe_ops);
 
   add_setshow_zuinteger_cmd ("stap-expression", class_maintenance,
 			     &stap_expression_debug,
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 3/3] Convert DTrace probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
  2017-11-13 17:59 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
  2017-11-13 17:59 ` [PATCH 1/3] Convert generic " Sergio Durigan Junior
@ 2017-11-13 17:59 ` Sergio Durigan Junior
  2017-11-15  4:40   ` Simon Marchi
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  3 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:59 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch converts the DTrace probe
interface (gdb/dtrace-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct dtrace_probe' to 'class
dtrace_probe', and a new 'class dtrace_static_probe_ops' to replace the
use of 'dtrace_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the dtrace-probe interface.

There are several helper functions used to parse parts of a dtrace
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* dtrace-probe.c (struct probe_ops dtrace_probe_ops): Delete.
	(dtrace_probe_arg_s): Delete type and VEC.
	(dtrace_probe_enabler_s): Likewise.
	(struct dtrace_probe): Replace by...
	(class dtrace_static_probe_ops): ...this and...
	(class dtrace_probe): ...this.
	(dtrace_probe_is_linespec): Rename to...
	(dtrace_static_probe_ops::is_linespec): ...this.  Adjust code
	to reflect change.
	(dtrace_process_dof_probe): Use 'std::vector' instead of VEC.
	Adjust code.  Create new instance of 'dtrace_probe'.
	(dtrace_build_arg_exprs): Rename to...
	(dtrace_probe::build_arg_exprs): ...this.  Adjust code to
	reflect change.
	(dtrace_get_probes): Rename to...
	(dtrace_static_probe_ops::get_probes): ...this.  Adjust code
	to reflect change.
	(dtrace_get_arg): Rename to...
	(dtrace_probe::get_arg_by_number): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_is_enabled): Rename to...
	(dtrace_probe::is_enabled): ...this.  Adjust code to reflect
	change.
	(dtrace_get_probe_address): Rename to...
	(dtrace_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(dtrace_get_probe_argument_count): Rename to...
	(dtrace_probe::get_argument_count): ...this.  Adjust code to
	reflect change.
	(dtrace_can_evaluate_probe_arguments): Rename to...
	(dtrace_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(dtrace_evaluate_probe_argument): Rename to...
	(dtrace_probe::evaluate_argument): ...this.  Adjust code to
	reflect change.
	(dtrace_compile_to_ax): Rename to...
	(dtrace_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_destroy): Delete.
	(dtrace_type_name): Rename to...
	(dtrace_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(dtrace_probe::get_static_ops): New method.
	(dtrace_gen_info_probes_table_header): Rename to...
	(dtrace_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(dtrace_gen_info_probes_table_values): Rename to...
	(dtrace_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(dtrace_enable_probe): Rename to...
	(dtrace_probe::enable_probe): ...this.  Adjust code to reflect
	change.
	(dtrace_disable_probe): Rename to...
	(dtrace_probe::disable_probe): ...this.  Adjust code to reflect
	change.
	(struct probe_ops dtrace_probe_ops): Delete.
	(dtrace_static_probe_ops::emit_info_probes_extra_fields): New
	method.
	(info_probes_dtrace_command): Call 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_dtrace_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
---
 gdb/dtrace-probe.c | 528 +++++++++++++++++++++++++++--------------------------
 1 file changed, 268 insertions(+), 260 deletions(-)

diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 2bbe03e4b3..b53ff7ac6c 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -41,10 +41,6 @@
 # define SHT_SUNW_dof	0x6ffffff4
 #endif
 
-/* Forward declaration.  */
-
-extern const struct probe_ops dtrace_probe_ops;
-
 /* The following structure represents a single argument for the
    probe.  */
 
@@ -60,9 +56,6 @@ struct dtrace_probe_arg
   struct expression *expr;
 };
 
-typedef struct dtrace_probe_arg dtrace_probe_arg_s;
-DEF_VEC_O (dtrace_probe_arg_s);
-
 /* The following structure represents an enabler for a probe.  */
 
 struct dtrace_probe_enabler
@@ -73,39 +66,121 @@ struct dtrace_probe_enabler
   CORE_ADDR address;
 };
 
-typedef struct dtrace_probe_enabler dtrace_probe_enabler_s;
-DEF_VEC_O (dtrace_probe_enabler_s);
+/* Class that implements the static probe methods for "stap" probes.  */
+
+class dtrace_static_probe_ops : public static_probe_ops
+{
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  bool emit_info_probes_extra_fields () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_header
+    (std::vector<struct info_probe_column> *heads) const override;
+};
+
+/* DTrace static_probe_ops.  */
+
+const dtrace_static_probe_ops dtrace_static_probe_ops;
 
 /* The following structure represents a dtrace probe.  */
 
-struct dtrace_probe
+class dtrace_probe : public probe
 {
-  /* Generic information about the probe.  This must be the first
-     element of this struct, in order to maintain binary compatibility
-     with the `struct probe' and be able to fully abstract it.  */
-  struct probe p;
+public:
+  /* Constructor for dtrace_probe.  */
+  dtrace_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+		struct gdbarch *arch_,
+		std::vector<struct dtrace_probe_arg> &args_,
+		std::vector<struct dtrace_probe_enabler> &enablers_)
+    : probe (std::move (name_), std::move (provider_), address_, arch_),
+      m_args (std::move (args_)),
+      m_enablers (std::move (enablers_)),
+      m_args_expr_built (false)
+  {}
+
+  /* Destructor for dtrace_probe.  */
+  ~dtrace_probe ()
+  {
+    for (struct dtrace_probe_arg arg : m_args)
+      {
+	xfree (arg.type_str);
+	xfree (arg.expr);
+      }
+  }
+
+  /* See probe.h.  */
+  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
+
+  /* See probe.h.  */
+  unsigned get_argument_count (struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  int can_evaluate_arguments () const override;
+
+  /* See probe.h.  */
+  struct value *evaluate_argument (unsigned n,
+				   struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  void compile_to_ax (struct agent_expr *aexpr,
+		      struct axs_value *axs_value,
+		      unsigned n) override;
+
+  /* See probe.h.  */
+  const static_probe_ops *get_static_ops () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_values
+    (std::vector<const char *> *values) const override;
+
+  /* See probe.h.  */
+  bool can_enable () const override
+  {
+    return true;
+  }
+
+  /* See probe.h.  */
+  void enable () override;
 
+  /* See probe.h.  */
+  void disable () override;
+
+  /* Return the Nth argument of the probe.  */
+  struct dtrace_probe_arg *get_arg_by_number (unsigned n,
+					      struct gdbarch *gdbarch);
+
+  /* Build the GDB internal expressiosn that, once evaluated, will
+     calculate the values of the arguments of the probe.  */
+  void build_arg_exprs (struct gdbarch *gdbarch);
+
+  /* Determine whether the probe is "enabled" or "disabled".  A
+     disabled probe is a probe in which one or more enablers are
+     disabled.  */
+  bool is_enabled () const;
+
+private:
   /* A probe can have zero or more arguments.  */
-  int probe_argc;
-  VEC (dtrace_probe_arg_s) *args;
+  int m_argc;
+  std::vector<struct dtrace_probe_arg> m_args;
 
   /* A probe can have zero or more "enablers" associated with it.  */
-  VEC (dtrace_probe_enabler_s) *enablers;
+  std::vector<struct dtrace_probe_enabler> m_enablers;
 
   /* Whether the expressions for the arguments have been built.  */
-  unsigned int args_expr_built : 1;
+  bool m_args_expr_built;
 };
 
-/* Implementation of the probe_is_linespec method.  */
-
-static int
-dtrace_probe_is_linespec (const char **linespecp)
-{
-  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
-
-  return probe_is_linespec_by_keyword (linespecp, keywords);
-}
-
 /* DOF programs can contain an arbitrary number of sections of 26
    different types.  In order to support DTrace USDT probes we only
    need to handle a subset of these section types, fortunately.  These
@@ -322,8 +397,6 @@ dtrace_process_dof_probe (struct objfile *objfile,
 			  char *argtab, uint64_t strtab_size)
 {
   int i, j, num_probes, num_enablers;
-  struct cleanup *cleanup;
-  VEC (dtrace_probe_enabler_s) *enablers;
   char *p;
 
   /* Each probe section can define zero or more probes of two
@@ -368,9 +441,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
   /* Build the list of enablers for the probes defined in this Probe
      DOF section.  */
-  enablers = NULL;
-  cleanup
-    = make_cleanup (VEC_cleanup (dtrace_probe_enabler_s), &enablers);
+  std::vector<struct dtrace_probe_enabler> enablers;
   num_enablers = DOF_UINT (dof, probe->dofpr_nenoffs);
   for (i = 0; i < num_enablers; i++)
     {
@@ -380,38 +451,32 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
       enabler.address = DOF_UINT (dof, probe->dofpr_addr)
 	+ DOF_UINT (dof, enabler_offset);
-      VEC_safe_push (dtrace_probe_enabler_s, enablers, &enabler);
+      enablers.push_back (enabler);
     }
 
   for (i = 0; i < num_probes; i++)
     {
       uint32_t probe_offset
 	= ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
-      struct dtrace_probe *ret =
-	XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
-
-      ret->p.pops = &dtrace_probe_ops;
-      ret->p.arch = gdbarch;
-      ret->args_expr_built = 0;
 
       /* Set the provider and the name of the probe.  */
-      ret->p.provider
-	= xstrdup (strtab + DOF_UINT (dof, provider->dofpv_name));
-      ret->p.name = xstrdup (strtab + DOF_UINT (dof, probe->dofpr_name));
+      const char *probe_provider
+	= strtab + DOF_UINT (dof, provider->dofpv_name);
+      const char *name = strtab + DOF_UINT (dof, probe->dofpr_name);
 
       /* The probe address.  */
-      ret->p.address
+      CORE_ADDR address
 	= DOF_UINT (dof, probe->dofpr_addr) + DOF_UINT (dof, probe_offset);
 
       /* Number of arguments in the probe.  */
-      ret->probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
+      int probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
 
       /* Store argument type descriptions.  A description of the type
          of the argument is in the (J+1)th null-terminated string
          starting at 'strtab' + 'probe->dofpr_nargv'.  */
-      ret->args = NULL;
+      std::vector<struct dtrace_probe_arg> args;
       p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
-      for (j = 0; j < ret->probe_argc; j++)
+      for (j = 0; j < probe_argc; j++)
 	{
 	  struct dtrace_probe_arg arg;
 	  expression_up expr;
@@ -442,17 +507,18 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	  if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
 	    arg.type = expr->elts[1].type;
 
-	  VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
+	  args.push_back (arg);
 	}
 
-      /* Add the vector of enablers to this probe, if any.  */
-      ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
+      std::vector<struct dtrace_probe_enabler> enablers_copy = enablers;
+      dtrace_probe *ret = new dtrace_probe (std::string (name),
+					    std::string (probe_provider),
+					    address, gdbarch,
+					    args, enablers_copy);
 
       /* Successfully created probe.  */
-      probesp->push_back ((struct probe *) ret);
+      probesp->push_back (ret);
     }
-
-  do_cleanups (cleanup);
 }
 
 /* Helper function to collect the probes described in the DOF program
@@ -555,28 +621,23 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
 	     sect->name);
 }
 
-/* Helper function to build the GDB internal expressiosn that, once
-   evaluated, will calculate the values of the arguments of a given
-   PROBE.  */
+/* Implementation of 'build_arg_exprs' method.  */
 
-static void
-dtrace_build_arg_exprs (struct dtrace_probe *probe,
-			struct gdbarch *gdbarch)
+void
+dtrace_probe::build_arg_exprs (struct gdbarch *gdbarch)
 {
-  struct parser_state pstate;
-  struct dtrace_probe_arg *arg;
-  int i;
-
-  probe->args_expr_built = 1;
+  m_args_expr_built = true;
 
   /* Iterate over the arguments in the probe and build the
      corresponding GDB internal expression that will generate the
      value of the argument when executed at the PC of the probe.  */
-  for (i = 0; i < probe->probe_argc; i++)
+  for (int i = 0; i < m_argc; i++)
     {
+      struct dtrace_probe_arg *arg;
       struct cleanup *back_to;
+      struct parser_state pstate;
 
-      arg = VEC_index (dtrace_probe_arg_s, probe->args, i);
+      arg = &m_args[i];
 
       /* Initialize the expression buffer in the parser state.  The
 	 language does not matter, since we are using our own
@@ -606,138 +667,82 @@ dtrace_build_arg_exprs (struct dtrace_probe *probe,
     }
 }
 
-/* Helper function to return the Nth argument of a given PROBE.  */
-
-static struct dtrace_probe_arg *
-dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
-		struct gdbarch *gdbarch)
-{
-  if (!probe->args_expr_built)
-    dtrace_build_arg_exprs (probe, gdbarch);
-
-  return VEC_index (dtrace_probe_arg_s, probe->args, n);
-}
-
-/* Implementation of the get_probes method.  */
+/* Implementation of 'get_arg_by_number' method.  */
 
-static void
-dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+struct dtrace_probe_arg *
+dtrace_probe::get_arg_by_number (unsigned n, struct gdbarch *gdbarch)
 {
-  bfd *abfd = objfile->obfd;
-  asection *sect = NULL;
-
-  /* Do nothing in case this is a .debug file, instead of the objfile
-     itself.  */
-  if (objfile->separate_debug_objfile_backlink != NULL)
-    return;
+  if (!m_args_expr_built)
+    this->build_arg_exprs (gdbarch);
 
-  /* Iterate over the sections in OBJFILE looking for DTrace
-     information.  */
-  for (sect = abfd->sections; sect != NULL; sect = sect->next)
-    {
-      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
-	{
-	  bfd_byte *dof;
-
-	  /* Read the contents of the DOF section and then process it to
-	     extract the information of any probe defined into it.  */
-	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
-	    complaint (&symfile_complaints,
-		       _("could not obtain the contents of"
-			 "section '%s' in objfile `%s'."),
-		       sect->name, abfd->filename);
-      
-	  dtrace_process_dof (sect, objfile, probesp,
-			      (struct dtrace_dof_hdr *) dof);
-	  xfree (dof);
-	}
-    }
+  return &m_args[n];
 }
 
-/* Helper function to determine whether a given probe is "enabled" or
-   "disabled".  A disabled probe is a probe in which one or more
-   enablers are disabled.  */
+/* Implementation of the probe is_enabled method.  */
 
-static int
-dtrace_probe_is_enabled (struct dtrace_probe *probe)
+bool
+dtrace_probe::is_enabled () const
 {
-  int i;
-  struct gdbarch *gdbarch = probe->p.arch;
-  struct dtrace_probe_enabler *enabler;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, probe->enablers, i, enabler);
-       i++)
-    if (!gdbarch_dtrace_probe_is_enabled (gdbarch, enabler->address))
-      return 0;
+  for (struct dtrace_probe_enabler enabler : m_enablers)
+    if (!gdbarch_dtrace_probe_is_enabled (gdbarch, enabler.address))
+      return false;
 
-  return 1;
+  return true;
 }
 
 /* Implementation of the get_probe_address method.  */
 
-static CORE_ADDR
-dtrace_get_probe_address (struct probe *probe, struct objfile *objfile)
+CORE_ADDR
+dtrace_probe::get_relocated_address (struct objfile *objfile)
 {
-  gdb_assert (probe->pops == &dtrace_probe_ops);
-  return probe->address + ANOFFSET (objfile->section_offsets,
-				    SECT_OFF_DATA (objfile));
+  return this->get_address () + ANOFFSET (objfile->section_offsets,
+					  SECT_OFF_DATA (objfile));
 }
 
-/* Implementation of the get_probe_argument_count method.  */
+/* Implementation of the get_argument_count method.  */
 
-static unsigned
-dtrace_get_probe_argument_count (struct probe *probe_generic,
-				 struct frame_info *frame)
+unsigned
+dtrace_probe::get_argument_count (struct frame_info *frame)
 {
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  return dtrace_probe->probe_argc;
+  return m_argc;
 }
 
-/* Implementation of the can_evaluate_probe_arguments method.  */
+/* Implementation of the can_evaluate_arguments method.  */
 
-static int
-dtrace_can_evaluate_probe_arguments (struct probe *probe_generic)
+int
+dtrace_probe::can_evaluate_arguments () const
 {
-  struct gdbarch *gdbarch = probe_generic->arch;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
   return gdbarch_dtrace_parse_probe_argument_p (gdbarch);
 }
 
-/* Implementation of the evaluate_probe_argument method.  */
+/* Implementation of the evaluate_argument method.  */
 
-static struct value *
-dtrace_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
-				struct frame_info *frame)
+struct value *
+dtrace_probe::evaluate_argument (unsigned n,
+				 struct frame_info *frame)
 {
-  struct gdbarch *gdbarch = probe_generic->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
   struct dtrace_probe_arg *arg;
   int pos = 0;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  arg = dtrace_get_arg (dtrace_probe, n, gdbarch);
+  arg = this->get_arg_by_number (n, gdbarch);
   return evaluate_subexp_standard (arg->type, arg->expr, &pos, EVAL_NORMAL);
 }
 
 /* Implementation of the compile_to_ax method.  */
 
-static void
-dtrace_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
-		      struct axs_value *value, unsigned n)
+void
+dtrace_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
+			     unsigned n)
 {
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
   struct dtrace_probe_arg *arg;
   union exp_element *pc;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  arg = dtrace_get_arg (dtrace_probe, n, expr->gdbarch);
+  arg = this->get_arg_by_number (n, expr->gdbarch);
 
   pc = arg->expr->elts;
   gen_expr (arg->expr, &pc, expr, value);
@@ -746,83 +751,40 @@ dtrace_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
   value->type = arg->type;
 }
 
-/* Implementation of the probe_destroy method.  */
-
-static void
-dtrace_probe_destroy (struct probe *probe_generic)
-{
-  struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
-  struct dtrace_probe_arg *arg;
-  int i;
-
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  for (i = 0; VEC_iterate (dtrace_probe_arg_s, probe->args, i, arg); i++)
-    {
-      xfree (arg->type_str);
-      xfree (arg->expr);
-    }
-
-  VEC_free (dtrace_probe_enabler_s, probe->enablers);
-  VEC_free (dtrace_probe_arg_s, probe->args);
-}
-
-/* Implementation of the type_name method.  */
+/* Implementation of the 'get_static_ops' method.  */
 
-static const char *
-dtrace_type_name (struct probe *probe_generic)
+const static_probe_ops *
+dtrace_probe::get_static_ops () const
 {
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-  return "dtrace";
-}
-
-/* Implementation of the gen_info_probes_table_header method.  */
-
-static void
-dtrace_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
-{
-  info_probe_column_s dtrace_probe_column;
-
-  dtrace_probe_column.field_name = "enabled";
-  dtrace_probe_column.print_name = _("Enabled");
-
-  VEC_safe_push (info_probe_column_s, *heads, &dtrace_probe_column);
+  return &dtrace_static_probe_ops;
 }
 
 /* Implementation of the gen_info_probes_table_values method.  */
 
-static void
-dtrace_gen_info_probes_table_values (struct probe *probe_generic,
-				     VEC (const_char_ptr) **ret)
+void
+dtrace_probe::gen_info_probes_table_values
+  (std::vector<const char *> *values) const
 {
-  struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
   const char *val = NULL;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  if (VEC_empty (dtrace_probe_enabler_s, probe->enablers))
+  if (m_enablers.empty ())
     val = "always";
-  else if (!gdbarch_dtrace_probe_is_enabled_p (probe_generic->arch))
+  else if (!gdbarch_dtrace_probe_is_enabled_p (this->get_gdbarch ()))
     val = "unknown";
-  else if (dtrace_probe_is_enabled (probe))
+  else if (this->is_enabled ())
     val = "yes";
   else
     val = "no";
 
-  VEC_safe_push (const_char_ptr, *ret, val);
+  values->push_back (val);
 }
 
-/* Implementation of the enable_probe method.  */
+/* Implementation of the enable method.  */
 
-static void
-dtrace_enable_probe (struct probe *probe)
+void
+dtrace_probe::enable ()
 {
-  struct gdbarch *gdbarch = probe->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
-  struct dtrace_probe_enabler *enabler;
-  int i;
-
-  gdb_assert (probe->pops == &dtrace_probe_ops);
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* Enabling a dtrace probe implies patching the text section of the
      running process, so make sure the inferior is indeed running.  */
@@ -830,31 +792,23 @@ dtrace_enable_probe (struct probe *probe)
     error (_("No inferior running"));
 
   /* Fast path.  */
-  if (dtrace_probe_is_enabled (dtrace_probe))
+  if (this->is_enabled ())
     return;
 
   /* Iterate over all defined enabler in the given probe and enable
      them all using the corresponding gdbarch hook.  */
-
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
-       i++)
+  for (struct dtrace_probe_enabler enabler : m_enablers)
     if (gdbarch_dtrace_enable_probe_p (gdbarch))
-      gdbarch_dtrace_enable_probe (gdbarch, enabler->address);
+      gdbarch_dtrace_enable_probe (gdbarch, enabler.address);
 }
 
 
 /* Implementation of the disable_probe method.  */
 
-static void
-dtrace_disable_probe (struct probe *probe)
+void
+dtrace_probe::disable ()
 {
-  struct gdbarch *gdbarch = probe->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
-  struct dtrace_probe_enabler *enabler;
-  int i;
-
-  gdb_assert (probe->pops == &dtrace_probe_ops);
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* Disabling a dtrace probe implies patching the text section of the
      running process, so make sure the inferior is indeed running.  */
@@ -862,57 +816,111 @@ dtrace_disable_probe (struct probe *probe)
     error (_("No inferior running"));
 
   /* Fast path.  */
-  if (!dtrace_probe_is_enabled (dtrace_probe))
+  if (!this->is_enabled ())
     return;
 
   /* Are we trying to disable a probe that does not have any enabler
      associated?  */
-  if (VEC_empty (dtrace_probe_enabler_s, dtrace_probe->enablers))
-    error (_("Probe %s:%s cannot be disabled: no enablers."), probe->provider, probe->name);
+  if (m_enablers.empty ())
+    error (_("Probe %s:%s cannot be disabled: no enablers."),
+	   this->get_provider (), this->get_name ());
 
   /* Iterate over all defined enabler in the given probe and disable
      them all using the corresponding gdbarch hook.  */
-
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
-       i++)
+  for (struct dtrace_probe_enabler enabler : m_enablers)
     if (gdbarch_dtrace_disable_probe_p (gdbarch))
-      gdbarch_dtrace_disable_probe (gdbarch, enabler->address);
+      gdbarch_dtrace_disable_probe (gdbarch, enabler.address);
 }
 
-/* DTrace probe_ops.  */
-
-const struct probe_ops dtrace_probe_ops =
-{
-  dtrace_probe_is_linespec,
-  dtrace_get_probes,
-  dtrace_get_probe_address,
-  dtrace_get_probe_argument_count,
-  dtrace_can_evaluate_probe_arguments,
-  dtrace_evaluate_probe_argument,
-  dtrace_compile_to_ax,
-  NULL, /* set_semaphore  */
-  NULL, /* clear_semaphore  */
-  dtrace_probe_destroy,
-  dtrace_type_name,
-  dtrace_gen_info_probes_table_header,
-  dtrace_gen_info_probes_table_values,
-  dtrace_enable_probe,
-  dtrace_disable_probe
-};
+/* Implementation of the is_linespec method.  */
+
+bool
+dtrace_static_probe_ops::is_linespec (const char **linespecp) const
+{
+  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
+
+  return probe_is_linespec_by_keyword (linespecp, keywords);
+}
+
+/* Implementation of the get_probes method.  */
+
+void
+dtrace_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				     struct objfile *objfile) const
+{
+  bfd *abfd = objfile->obfd;
+  asection *sect = NULL;
+
+  /* Do nothing in case this is a .debug file, instead of the objfile
+     itself.  */
+  if (objfile->separate_debug_objfile_backlink != NULL)
+    return;
+
+  /* Iterate over the sections in OBJFILE looking for DTrace
+     information.  */
+  for (sect = abfd->sections; sect != NULL; sect = sect->next)
+    {
+      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
+	{
+	  bfd_byte *dof;
+
+	  /* Read the contents of the DOF section and then process it to
+	     extract the information of any probe defined into it.  */
+	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
+	    complaint (&symfile_complaints,
+		       _("could not obtain the contents of"
+			 "section '%s' in objfile `%s'."),
+		       sect->name, abfd->filename);
+      
+	  dtrace_process_dof (sect, objfile, probesp,
+			      (struct dtrace_dof_hdr *) dof);
+	  xfree (dof);
+	}
+    }
+}
+
+/* Implementation of the type_name method.  */
+
+const char *
+dtrace_static_probe_ops::type_name () const
+{
+  return "dtrace";
+}
+
+/* Implementation of the 'emit_info_probes_extra_fields' method.  */
+
+bool
+dtrace_static_probe_ops::emit_info_probes_extra_fields () const
+{
+  return true;
+}
+
+/* Implementation of the gen_info_probes_table_header method.  */
+
+void
+dtrace_static_probe_ops::gen_info_probes_table_header
+ (std::vector<struct info_probe_column> *heads) const
+{
+  struct info_probe_column dtrace_probe_column;
+
+  dtrace_probe_column.field_name = "enabled";
+  dtrace_probe_column.print_name = _("Enabled");
+
+  heads->push_back(dtrace_probe_column);
+}
 
 /* Implementation of the `info probes dtrace' command.  */
 
 static void
 info_probes_dtrace_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, &dtrace_probe_ops);
+  info_probes_for_spops (arg, from_tty, &dtrace_static_probe_ops);
 }
 
 void
 _initialize_dtrace_probe (void)
 {
-  all_probe_ops.push_back (&dtrace_probe_ops);
+  all_static_probe_ops.push_back (&dtrace_static_probe_ops);
 
   add_cmd ("dtrace", class_info, info_probes_dtrace_command,
 	   _("\
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups)
@ 2017-11-13 17:59 Sergio Durigan Junior
  2017-11-13 17:59 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:59 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch series performs the conversion of the probe interfaces
(generic, stap and dtrace) to C++, along with a few cleanups here and
there to make the code conform better to our standards.

This series needs to be committed/tested as one single patch, because
of inter-dependencies.  However, in order to facilitate the review
process, I decided to split things into logical units.

The main changes are the conversion of 'struct probe' to 'class
probe', and 'struct probe_ops' to 'class static_probe_ops'.  Almost
everything else in the patches are adjustments related to these
modifications.

It's important to say that 'class probe' contains the majority of the
methods that were previously living inside 'struct probe_ops'.
However, some methods are special in the sense the they don't act on a
specific probe object, but generically on a probe type (like a
factory).  For that reason the 'class static_probe_ops' had to be
created.

Most methods in 'class probe' are pure virtual and need to be defined
by the probe backend (stap or dtrace, for now).  Other methods (e.g.,
the 'enable' method) are virtual but non-pure and have a default,
dummy version implemented on 'class probe' itself, because the concept
of enabling a probe is not common to all types of probes.

I've also taken the opportunity to convert a few uses of "VEC" to
"std::vector", and to remove annoying spurious newlines from some
places.

The whole patch has been tested on BuildBot, without regressions.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 ` [PATCH 1/3] Convert generic " Sergio Durigan Junior
@ 2017-11-15  2:52   ` Simon Marchi
  2017-11-15  3:25     ` Simon Marchi
  2017-11-15  6:12     ` Sergio Durigan Junior
  0 siblings, 2 replies; 23+ messages in thread
From: Simon Marchi @ 2017-11-15  2:52 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 2017-11-13 12:58 PM, Sergio Durigan Junior wrote:
> This patch converts the generic probe interface (gdb/probe.[ch]) to
> C++, and also performs some cleanups that were on my TODO list for a
> while.
> 
> The main changes were the conversion of 'struct probe' to 'class
> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
> former now contains all the "dynamic", generic methods that act on a
> probe + the generic data related to it; the latter encapsulates a
> bunch of "static" methods that relate to the probe type, but not to a
> specific probe itself.

Personally I'm fine with this.  Maybe there would be a better C++-ish
design, but I'm not very good at that.  If others have suggestions, I'd
like to hear them.

> I've had to do a few renamings (e.g., on 'struct bound_probe' the
> field is called 'probe *prob' now, instead of 'struct probe *probe')
> because GCC was complaining about naming the field using the same name
> as the class.  Nothing major, though.  Generally speaking, the logic
> behind and the design behind the code are the same.
> 
> Even though I'm sending a series of patches, they need to be tested
> and committed as a single unit, because of inter-dependencies.  But it
> should be easier to review in separate logical units.
> 
> I've regtested this patch on BuildBot, no regressions found.
> 
> gdb/ChangeLog:
> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* break-catch-throw.c (fetch_probe_arguments): Use
> 	'probe.prob' instead of 'probe.probe'.
> 	* breakpoint.c (create_longjmp_master_breakpoint): Call
> 	'can_evaluate_arguments' and 'get_relocated_address' methods
> 	from probe.
> 	(create_exception_master_breakpoint): Likewise.
> 	(add_location_to_breakpoint): Use 'sal->prob' instead of
> 	'sal->probe'.
> 	(bkpt_probe_insert_location): Call 'set_semaphore' method from
> 	probe.
> 	(bkpt_probe_remove_location): Likewise, for 'clear_semaphore'.
> 	* elfread.c (elf_get_probes): Use 'static_probe_ops' instead
> 	of 'probe_ops'.
> 	(probe_key_free): Call 'delete' on probe.
> 	(check_exception_resume): Use 'probe.prob' instead of
> 	'probe.probe'.
> 	* location.c (string_to_event_location_basic): Call
> 	'probe_linespec_to_static_ops'.
> 	* probe.c (class any_static_probe_ops): New class.
> 	(any_static_probe_ops any_static_probe_ops): New variable.
> 	(parse_probes_in_pspace): Receive 'static_probe_ops' as
> 	argument.  Adjust code to reflect change.
> 	(parse_probes): Use 'static_probe_ops' instead of
> 	'probe_ops'.  Adjust code to reflect change.
> 	(find_probes_in_objfile): Call methods to get name and
> 	provider from probe.
> 	(find_probe_by_pc): Use 'result.prob' instead of
> 	'result.probe'.  Call 'get_relocated_address' method from
> 	probe.
> 	(collect_probes): Adjust comment and argument list to receive
> 	'static_probe_ops' instead of 'probe_ops'.  Adjust code to
> 	reflect change.  Call necessary methods from probe.
> 	(compare_probes): Call methods to get name and provider from
> 	probes.
> 	(gen_ui_out_table_header_info): Receive 'static_probe_ops'
> 	instead of 'probe_ops'.  Use 'std::vector' instead of VEC,
> 	adjust code accordingly.
> 	(print_ui_out_not_applicables): Likewise.
> 	(info_probes_for_ops): Rename to...
> 	(info_probes_for_spops): ...this.  Receive 'static_probe_ops'
> 	as argument instead of 'probe_ops'.  Adjust code.  Call
> 	necessary methods from probe.
> 	(info_probes_command): Use 'info_probes_for_spops'.
> 	(enable_probes_command): Pass correct argument to
> 	'collect_probes'.  Call methods from probe.
> 	(disable_probes_command): Likewise.
> 	(get_probe_address): Move to 'any_static_probe_ops::get_address'.
> 	(get_probe_argument_count): Move to
> 	'any_static_probe_ops::get_argument_count'.
> 	(can_evaluate_probe_arguments): Move to
> 	'any_static_probe_ops::can_evaluate_arguments'.
> 	(evaluate_probe_argument): Move to
> 	'any_static_probe_ops::evaluate_argument'.
> 	(probe_safe_evaluate_at_pc): Use 'probe.prob' instead of
> 	'probe.probe'.
> 	(probe_linespec_to_ops): Rename to...
> 	(probe_linespec_to_static_ops): ...this.  Adjust code.
> 	(probe_any_is_linespec): Rename to...
> 	(any_static_probe_ops::is_linespec): ...this.
> 	(probe_any_get_probes): Rename to...
> 	(any_static_probe_ops::get_probes): ...this.
> 	(any_static_probe_ops::type_name): New method.
> 	(any_static_probe_ops::emit_info_probes_extra_fields): New
> 	method.
> 	(any_static_probe_ops::gen_info_probes_table_header): New
> 	method.
> 	(compute_probe_arg): Use 'pc_probe.prob' instead of
> 	'pc_probe.probe'.  Call methods from probe.
> 	(compile_probe_arg): Likewise.
> 	(std::vector<const probe_ops *> all_probe_ops): Delete.
> 	(std::vector<const static_probe_ops *> all_static_probe_ops):
> 	New variable.
> 	(_initialize_probe): Use 'all_static_probe_ops' instead of
> 	'all_probe_ops'.
> 	* probe.h (struct info_probe_column) <field_name>: Delete
> 	extraneous newline
> 	(info_probe_column_s): Delete type and VEC.
> 	(struct probe_ops): Delete.  Replace with...
> 	(class static_probe_ops): ...this and...
> 	(clas probe): ...this.
> 	(struct bound_probe) <bound_probe>: Delete extraneous
> 	newline.  Adjust constructor to receive 'probe' instead of
> 	'struct probe'.
> 	<probe>: Rename to...
> 	<prob>: ...this.  Delete extraneous newline.
> 	<objfile>: Delete extraneous newline.
> 	(register_probe_ops): Delete unused prototype.
> 	(info_probes_for_ops): Rename to...
> 	(info_probes_for_spops): ...this.  Adjust comment.
> 	(get_probe_address): Move to 'probe::get_address'.
> 	(get_probe_argument_count): Move to
> 	'probe::get_argument_count'.
> 	(can_evaluate_probe_arguments): Move to
> 	'probe::can_evaluate_arguments'.
> 	(evaluate_probe_argument): Move to 'probe::evaluate_argument'.
> 	* solib-svr4.c (struct svr4_info): Adjust comment.
> 	(struct probe_and_action) <probe>: Rename to...
> 	<prob>: ...this.
> 	(register_solib_event_probe): Receive 'probe' instead of
> 	'struct probe' as argument.  Use 'prob' instead of 'probe'
> 	when applicable.
> 	(solib_event_probe_action): Call 'get_argument_count' method
> 	from probe.  Adjust comment.
> 	(svr4_handle_solib_event): Adjust comment.  Call
> 	'evaluate_argument' method from probe.
> 	(svr4_create_probe_breakpoints): Call 'get_relocated_address'
> 	from probe.
> 	(svr4_create_solib_event_breakpoints): Use 'probe' instead of
> 	'struct probe'.  Call 'can_evaluate_arguments' from probe.
> 	* symfile.h: Forward declare 'class probe' instead of 'struct
> 	probe'.
> 	* symtab.h: Likewise.
> 	(struct symtab_and_line) <probe>: Rename to...
> 	<prob>: ...this.
> 	* tracepoint.c (start_tracing): Use 'prob' when applicable.
> 	Call probe methods.
> 	(stop_tracing): Likewise.
> 
> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
> ---
>  gdb/break-catch-throw.c |  16 +-
>  gdb/breakpoint.c        |  20 +--
>  gdb/elfread.c           |   4 +-
>  gdb/infrun.c            |   2 +-
>  gdb/location.c          |   2 +-
>  gdb/probe.c             | 435 ++++++++++++++++++++++--------------------------
>  gdb/probe.h             | 363 ++++++++++++++++++++--------------------
>  gdb/solib-svr4.c        |  36 ++--
>  gdb/symfile.h           |   2 +-
>  gdb/symtab.h            |   4 +-
>  gdb/tracepoint.c        |  16 +-
>  11 files changed, 427 insertions(+), 473 deletions(-)
> 
> diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
> index fd8a113803..ffc100bb24 100644
> --- a/gdb/break-catch-throw.c
> +++ b/gdb/break-catch-throw.c
> @@ -106,20 +106,20 @@ fetch_probe_arguments (struct value **arg0, struct value **arg1)
>    unsigned n_args;
>  
>    pc_probe = find_probe_by_pc (pc);
> -  if (pc_probe.probe == NULL
> -      || strcmp (pc_probe.probe->provider, "libstdcxx") != 0
> -      || (strcmp (pc_probe.probe->name, "catch") != 0
> -	  && strcmp (pc_probe.probe->name, "throw") != 0
> -	  && strcmp (pc_probe.probe->name, "rethrow") != 0))
> +  if (pc_probe.prob == NULL
> +      || strcmp (pc_probe.prob->get_provider (), "libstdcxx") != 0
> +      || (strcmp (pc_probe.prob->get_name (), "catch") != 0
> +	  && strcmp (pc_probe.prob->get_name (), "throw") != 0
> +	  && strcmp (pc_probe.prob->get_name (), "rethrow") != 0))
>      error (_("not stopped at a C++ exception catchpoint"));
>  
> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
> +  n_args = pc_probe.prob->get_argument_count (frame);
>    if (n_args < 2)
>      error (_("C++ exception catchpoint has too few arguments"));
>  
>    if (arg0 != NULL)
> -    *arg0 = evaluate_probe_argument (pc_probe.probe, 0, frame);
> -  *arg1 = evaluate_probe_argument (pc_probe.probe, 1, frame);
> +    *arg0 = pc_probe.prob->evaluate_argument (0, frame);
> +  *arg1 = pc_probe.prob->evaluate_argument (1, frame);
>  
>    if ((arg0 != NULL && *arg0 == NULL) || *arg1 == NULL)
>      error (_("error computing probe argument at c++ exception catchpoint"));
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index b170a14cb5..1728aee838 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -3309,7 +3309,7 @@ create_longjmp_master_breakpoint (void)
>  	      /* We are only interested in checking one element.  */
>  	      probe *p = ret[0];
>  
> -	      if (!can_evaluate_probe_arguments (p))
> +	      if (!p->can_evaluate_arguments ())
>  		{
>  		  /* We cannot use the probe interface here, because it does
>  		     not know how to evaluate arguments.  */
> @@ -3329,7 +3329,7 @@ create_longjmp_master_breakpoint (void)
>  	      struct breakpoint *b;
>  
>  	      b = create_internal_breakpoint (gdbarch,
> -					      get_probe_address (p, objfile),
> +					      p->get_relocated_address (objfile),
>  					      bp_longjmp_master,
>  					      &internal_breakpoint_ops);
>  	      b->location = new_probe_location ("-probe-stap libc:longjmp");
> @@ -3462,7 +3462,7 @@ create_exception_master_breakpoint (void)
>  	      /* We are only interested in checking one element.  */
>  	      probe *p = ret[0];
>  
> -	      if (!can_evaluate_probe_arguments (p))
> +	      if (!p->can_evaluate_arguments ())
>  		{
>  		  /* We cannot use the probe interface here, because it does
>  		     not know how to evaluate arguments.  */
> @@ -3482,7 +3482,7 @@ create_exception_master_breakpoint (void)
>  	      struct breakpoint *b;
>  
>  	      b = create_internal_breakpoint (gdbarch,
> -					      get_probe_address (p, objfile),
> +					      p->get_relocated_address (objfile),
>  					      bp_exception_master,
>  					      &internal_breakpoint_ops);
>  	      b->location = new_probe_location ("-probe-stap libgcc:unwind");
> @@ -8694,7 +8694,7 @@ add_location_to_breakpoint (struct breakpoint *b,
>    loc->requested_address = sal->pc;
>    loc->address = adjusted_address;
>    loc->pspace = sal->pspace;
> -  loc->probe.probe = sal->probe;
> +  loc->probe.prob = sal->prob;
>    loc->probe.objfile = sal->objfile;
>    gdb_assert (loc->pspace != NULL);
>    loc->section = sal->section;
> @@ -12879,10 +12879,7 @@ bkpt_probe_insert_location (struct bp_location *bl)
>      {
>        /* The insertion was successful, now let's set the probe's semaphore
>  	 if needed.  */
> -      if (bl->probe.probe->pops->set_semaphore != NULL)
> -	bl->probe.probe->pops->set_semaphore (bl->probe.probe,
> -					      bl->probe.objfile,
> -					      bl->gdbarch);
> +      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
>      }
>  
>    return v;
> @@ -12893,10 +12890,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
>  			    enum remove_bp_reason reason)
>  {
>    /* Let's clear the semaphore before removing the location.  */
> -  if (bl->probe.probe->pops->clear_semaphore != NULL)
> -    bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
> -					    bl->probe.objfile,
> -					    bl->gdbarch);
> +  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
>  
>    return bkpt_remove_location (bl, reason);
>  }
> diff --git a/gdb/elfread.c b/gdb/elfread.c
> index cdef5a8c59..f2483025ba 100644
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -1324,7 +1324,7 @@ elf_get_probes (struct objfile *objfile)
>  
>        /* Here we try to gather information about all types of probes from the
>  	 objfile.  */
> -      for (const probe_ops *ops : all_probe_ops)
> +      for (const static_probe_ops *ops : all_static_probe_ops)
>  	ops->get_probes (probes_per_bfd, objfile);
>  
>        set_bfd_data (objfile->obfd, probe_key, probes_per_bfd);
> @@ -1342,7 +1342,7 @@ probe_key_free (bfd *abfd, void *d)
>    std::vector<probe *> *probes = (std::vector<probe *> *) d;
>  
>    for (probe *p : *probes)
> -    p->pops->destroy (p);
> +    delete p;
>  
>    delete probes;
>  }
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index e2d1248e75..4592100962 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -7583,7 +7583,7 @@ check_exception_resume (struct execution_control_state *ecs,
>       CFA and the HANDLER.  We ignore the CFA, extract the handler, and
>       set a breakpoint there.  */
>    probe = find_probe_by_pc (get_frame_pc (frame));
> -  if (probe.probe)
> +  if (probe.prob)
>      {
>        insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
>        return;
> diff --git a/gdb/location.c b/gdb/location.c
> index c78778edc1..5ed3623f0a 100644
> --- a/gdb/location.c
> +++ b/gdb/location.c
> @@ -844,7 +844,7 @@ string_to_event_location_basic (const char **stringp,
>  
>    /* Try the input as a probe spec.  */
>    cs = *stringp;
> -  if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
> +  if (cs != NULL && probe_linespec_to_static_ops (&cs) != NULL)
>      {
>        location = new_probe_location (*stringp);
>        *stringp += strlen (*stringp);
> diff --git a/gdb/probe.c b/gdb/probe.c
> index 829f6d18d7..0c47f904cb 100644
> --- a/gdb/probe.c
> +++ b/gdb/probe.c
> @@ -38,11 +38,38 @@
>  #include <algorithm>
>  #include "common/gdb_optional.h"
>  
> +/* Class that implements the static probe methods for "any" probe.  */
> +
> +class any_static_probe_ops : public static_probe_ops
> +{
> +public:
> +  /* See probe.h.  */
> +  bool is_linespec (const char **linespecp) const override;
> +
> +  /* See probe.h.  */
> +  void get_probes (std::vector<probe *> *probesp,
> +		   struct objfile *objfile) const override;
> +
> +  /* See probe.h.  */
> +  const char *type_name () const override;
> +
> +  /* See probe.h.  */
> +  bool emit_info_probes_extra_fields () const override;

I don't think we need this method (though maybe I'll get proven wrong
by the rest of the series).  At least in this patch, we can just call
gen_info_probes_table_header, and if the probe type doesn't supply
any header, we'll just iterate on an empty vector, which is the same
as returning early.

> +
> +  /* See probe.h.  */
> +  void gen_info_probes_table_header
> +    (std::vector<struct info_probe_column> *heads) const override;

I am wondering if this can return the vector directly.  Combined with
the suggestion above, it would simplify get_number_extra_fields, for example:

static int
get_number_extra_fields (const static_probe_ops *spops)
{
  return spops->gen_info_probes_table_header ().size ();
}

> +};
> +
> +/* Static operations associated with a generic probe.  */
> +
> +const any_static_probe_ops any_static_probe_ops;
> +
>  /* A helper for parse_probes that decodes a probe specification in
>     SEARCH_PSPACE.  It appends matching SALs to RESULT.  */
>  
>  static void
> -parse_probes_in_pspace (const struct probe_ops *probe_ops,
> +parse_probes_in_pspace (const static_probe_ops *spops,
>  			struct program_space *search_pspace,
>  			const char *objfile_namestr,
>  			const char *provider,
> @@ -67,21 +94,21 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops,
>  
>        for (probe *p : probes)
>  	{
> -	  if (probe_ops != &probe_ops_any && p->pops != probe_ops)
> +	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
>  	    continue;
>  
> -	  if (provider && strcmp (p->provider, provider) != 0)
> +	  if (provider && strcmp (p->get_provider (), provider) != 0)
>  	    continue;
>  
> -	  if (strcmp (p->name, name) != 0)
> +	  if (strcmp (p->get_name (), name) != 0)
>  	    continue;
>  
>  	  symtab_and_line sal;
> -	  sal.pc = get_probe_address (p, objfile);
> +	  sal.pc = p->get_relocated_address (objfile);
>  	  sal.explicit_pc = 1;
>  	  sal.section = find_pc_overlay (sal.pc);
>  	  sal.pspace = search_pspace;
> -	  sal.probe = p;
> +	  sal.prob = p;
>  	  sal.objfile = objfile;
>  
>  	  result->push_back (std::move (sal));
> @@ -98,15 +125,14 @@ parse_probes (const struct event_location *location,
>  {
>    char *arg_end, *arg;
>    char *objfile_namestr = NULL, *provider = NULL, *name, *p;
> -  const struct probe_ops *probe_ops;
>    const char *arg_start, *cs;
>  
>    gdb_assert (event_location_type (location) == PROBE_LOCATION);
>    arg_start = get_probe_location (location);
>  
>    cs = arg_start;
> -  probe_ops = probe_linespec_to_ops (&cs);
> -  if (probe_ops == NULL)
> +  const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
> +  if (spops == NULL)
>      error (_("'%s' is not a probe linespec"), arg_start);
>  
>    arg = (char *) cs;
> @@ -159,7 +185,7 @@ parse_probes (const struct event_location *location,
>    std::vector<symtab_and_line> result;
>    if (search_pspace != NULL)
>      {
> -      parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
> +      parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
>  			      provider, name, &result);
>      }
>    else
> @@ -167,7 +193,7 @@ parse_probes (const struct event_location *location,
>        struct program_space *pspace;
>  
>        ALL_PSPACES (pspace)
> -	parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
> +	parse_probes_in_pspace (spops, pspace, objfile_namestr,
>  				provider, name, &result);
>      }
>  
> @@ -206,10 +232,10 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider,
>      = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
>    for (probe *p : probes)
>      {
> -      if (strcmp (p->provider, provider) != 0)
> +      if (strcmp (p->get_provider (), provider) != 0)
>  	continue;
>  
> -      if (strcmp (p->name, name) != 0)
> +      if (strcmp (p->get_name (), name) != 0)
>  	continue;
>  
>        result.push_back (p);
> @@ -227,7 +253,7 @@ find_probe_by_pc (CORE_ADDR pc)
>    struct bound_probe result;
>  
>    result.objfile = NULL;
> -  result.probe = NULL;
> +  result.prob = NULL;
>  
>    ALL_OBJFILES (objfile)
>    {
> @@ -239,10 +265,10 @@ find_probe_by_pc (CORE_ADDR pc)
>      const std::vector<probe *> &probes
>        = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
>      for (probe *p : probes)
> -      if (get_probe_address (p, objfile) == pc)
> +      if (p->get_relocated_address (objfile) == pc)
>  	{
>  	  result.objfile = objfile;
> -	  result.probe = p;
> +	  result.prob = p;
>  	  return result;
>  	}
>    }
> @@ -253,12 +279,13 @@ find_probe_by_pc (CORE_ADDR pc)
>  \f
>  
>  /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
> -   If POPS is not NULL, only probes of this certain probe_ops will match.
> -   Each argument is a regexp, or NULL, which matches anything.  */
> +   If SPOPS is not &any_static_probe_ops, only probes related to this
> +   specific static probe ops will match.  Each argument is a regexp,
> +   or NULL, which matches anything.  */
>  
>  static std::vector<bound_probe>
>  collect_probes (const std::string &objname, const std::string &provider,
> -		const std::string &probe_name, const struct probe_ops *pops)
> +		const std::string &probe_name, const static_probe_ops *spops)
>  {
>    struct objfile *objfile;
>    std::vector<bound_probe> result;
> @@ -290,15 +317,15 @@ collect_probes (const std::string &objname, const std::string &provider,
>  
>        for (probe *p : probes)
>  	{
> -	  if (pops != NULL && p->pops != pops)
> +	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
>  	    continue;
>  
>  	  if (prov_pat
> -	      && prov_pat->exec (p->provider, 0, NULL, 0) != 0)
> +	      && prov_pat->exec (p->get_provider (), 0, NULL, 0) != 0)
>  	    continue;
>  
>  	  if (probe_pat
> -	      && probe_pat->exec (p->name, 0, NULL, 0) != 0)
> +	      && probe_pat->exec (p->get_name (), 0, NULL, 0) != 0)
>  	    continue;
>  
>  	  result.emplace_back (p, objfile);
> @@ -315,16 +342,16 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>  {
>    int v;
>  
> -  v = strcmp (a.probe->provider, b.probe->provider);
> +  v = strcmp (a.prob->get_provider (), b.prob->get_provider ());
>    if (v != 0)
>      return v < 0;
>  
> -  v = strcmp (a.probe->name, b.probe->name);
> +  v = strcmp (a.prob->get_name (), b.prob->get_name ());
>    if (v != 0)
>      return v < 0;
>  
> -  if (a.probe->address != b.probe->address)
> -    return a.probe->address < b.probe->address;
> +  if (a.prob->get_address () != b.prob->get_address ())
> +    return a.prob->get_address () < b.prob->get_address ();
>  
>    return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
>  }
> @@ -334,56 +361,37 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>  
>  static void
>  gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
> -			      const struct probe_ops *p)
> +			      const static_probe_ops *spops)
>  {
>    /* `headings' refers to the names of the columns when printing `info
>       probes'.  */
> -  VEC (info_probe_column_s) *headings = NULL;
> -  struct cleanup *c;
> -  info_probe_column_s *column;
> -  size_t headings_size;
> -  int ix;
> +  std::vector<struct info_probe_column> headings;
>  
> -  gdb_assert (p != NULL);
> +  gdb_assert (spops != NULL);
>  
> -  if (p->gen_info_probes_table_header == NULL
> -      && p->gen_info_probes_table_values == NULL)
> +  if (!spops->emit_info_probes_extra_fields ())
>      return;
>  
> -  gdb_assert (p->gen_info_probes_table_header != NULL
> -	      && p->gen_info_probes_table_values != NULL);
> -
> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
> -  p->gen_info_probes_table_header (&headings);
> -
> -  headings_size = VEC_length (info_probe_column_s, headings);
> +  spops->gen_info_probes_table_header (&headings);
>  
> -  for (ix = 0;
> -       VEC_iterate (info_probe_column_s, headings, ix, column);
> -       ++ix)
> +  for (struct info_probe_column column : headings)
>      {
> -      size_t size_max = strlen (column->print_name);
> +      size_t size_max = strlen (column.print_name);
>  
>        for (const bound_probe &probe : probes)
>  	{
>  	  /* `probe_fields' refers to the values of each new field that this
>  	     probe will display.  */
> -	  VEC (const_char_ptr) *probe_fields = NULL;
> -	  struct cleanup *c2;
> -	  const char *val;
> -	  int kx;
> +	  std::vector<const char *> probe_fields;
>  
> -	  if (probe.probe->pops != p)
> +	  if (probe.prob->get_static_ops () != spops)
>  	    continue;
>  
> -	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
> -	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
> +	  probe.prob->gen_info_probes_table_values (&probe_fields);
>  
> -	  gdb_assert (VEC_length (const_char_ptr, probe_fields)
> -		      == headings_size);
> +	  gdb_assert (probe_fields.size () == headings.size ());
>  
> -	  for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
> -	       ++kx)
> +	  for (const char *val : probe_fields)
>  	    {
>  	      /* It is valid to have a NULL value here, which means that the
>  		 backend does not have something to write and this particular
> @@ -393,128 +401,92 @@ gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
>  
>  	      size_max = std::max (strlen (val), size_max);
>  	    }
> -	  do_cleanups (c2);
>  	}
>  
>        current_uiout->table_header (size_max, ui_left,
> -				   column->field_name, column->print_name);
> +				   column.field_name, column.print_name);
>      }
> -
> -  do_cleanups (c);
>  }
>  
>  /* Helper function to print not-applicable strings for all the extra
> -   columns defined in a probe_ops.  */
> +   columns defined in a static_probe_ops.  */
>  
>  static void
> -print_ui_out_not_applicables (const struct probe_ops *pops)
> +print_ui_out_not_applicables (const static_probe_ops *spops)
>  {
>    struct cleanup *c;

This variable is now unused.

> -  VEC (info_probe_column_s) *headings = NULL;
> -  info_probe_column_s *column;
> -  int ix;
> +  std::vector<struct info_probe_column> headings;
>  
> -  if (pops->gen_info_probes_table_header == NULL)
> +  if (!spops->emit_info_probes_extra_fields ())
>      return;
>  
> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
> -  pops->gen_info_probes_table_header (&headings);
> -
> -  for (ix = 0;
> -       VEC_iterate (info_probe_column_s, headings, ix, column);
> -       ++ix)
> -    current_uiout->field_string (column->field_name, _("n/a"));
> +  spops->gen_info_probes_table_header (&headings);
>  
> -  do_cleanups (c);
> +  for (struct info_probe_column column : headings)
> +    current_uiout->field_string (column.field_name, _("n/a"));
>  }
>  
>  /* Helper function to print extra information about a probe and an objfile
>     represented by PROBE.  */
>  
>  static void
> -print_ui_out_info (struct probe *probe)
> +print_ui_out_info (probe *probe)
>  {
> -  int ix;
> -  int j = 0;
>    /* `values' refers to the actual values of each new field in the output
>       of `info probe'.  `headings' refers to the names of each new field.  */
> -  VEC (const_char_ptr) *values = NULL;
> -  VEC (info_probe_column_s) *headings = NULL;
> -  info_probe_column_s *column;
> -  struct cleanup *c;
> +  std::vector<struct info_probe_column> headings;
> +  std::vector<const char *> values;
> +  struct info_probe_column *column;

This variable is unused (build probe.c with -Wunused to see all of them).

>  
>    gdb_assert (probe != NULL);
> -  gdb_assert (probe->pops != NULL);
>  
> -  if (probe->pops->gen_info_probes_table_header == NULL
> -      && probe->pops->gen_info_probes_table_values == NULL)
> -    return;
> +  probe->get_static_ops ()->gen_info_probes_table_header (&headings);
> +  probe->gen_info_probes_table_values (&values);
>  
> -  gdb_assert (probe->pops->gen_info_probes_table_header != NULL
> -	      && probe->pops->gen_info_probes_table_values != NULL);
> +  gdb_assert (headings.size () == values.size ());
>  
> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
> -  make_cleanup (VEC_cleanup (const_char_ptr), &values);
> -
> -  probe->pops->gen_info_probes_table_header (&headings);
> -  probe->pops->gen_info_probes_table_values (probe, &values);
> -
> -  gdb_assert (VEC_length (info_probe_column_s, headings)
> -	      == VEC_length (const_char_ptr, values));
> -
> -  for (ix = 0;
> -       VEC_iterate (info_probe_column_s, headings, ix, column);
> -       ++ix)
> +  for (int ix = 0; ix < headings.size (); ++ix)
>      {
> -      const char *val = VEC_index (const_char_ptr, values, j++);
> +      struct info_probe_column column = headings[ix];
> +      const char *val = values[ix];
>  
>        if (val == NULL)
> -	current_uiout->field_skip (column->field_name);
> +	current_uiout->field_skip (column.field_name);
>        else
> -	current_uiout->field_string (column->field_name, val);
> +	current_uiout->field_string (column.field_name, val);
>      }
> -
> -  do_cleanups (c);
>  }
>  
>  /* Helper function that returns the number of extra fields which POPS will
>     need.  */
>  
>  static int
> -get_number_extra_fields (const struct probe_ops *pops)
> +get_number_extra_fields (const static_probe_ops *spops)
>  {
> -  VEC (info_probe_column_s) *headings = NULL;
> -  struct cleanup *c;
> -  int n;
> +  std::vector<info_probe_column> headings;
>  
> -  if (pops->gen_info_probes_table_header == NULL)
> +  if (!spops->emit_info_probes_extra_fields ())
>      return 0;
>  
> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
> -  pops->gen_info_probes_table_header (&headings);
> -
> -  n = VEC_length (info_probe_column_s, headings);
> +  spops->gen_info_probes_table_header (&headings);
>  
> -  do_cleanups (c);
> -
> -  return n;
> +  return headings.size ();
>  }
>  
> -/* Helper function that returns 1 if there is a probe in PROBES
> -   featuring the given POPS.  It returns 0 otherwise.  */
> +/* Helper function that returns true if there is a probe in PROBES
> +   featuring the given SPOPS.  It returns false otherwise.  */
>  
> -static int
> -exists_probe_with_pops (const std::vector<bound_probe> &probes,
> -			const struct probe_ops *pops)
> +static bool
> +exists_probe_with_spops (const std::vector<bound_probe> &probes,
> +			 const static_probe_ops *spops)
>  {
>    struct bound_probe *probe;
> -  int ix;
>  
>    for (const bound_probe &probe : probes)
> -    if (probe.probe->pops == pops)
> -      return 1;
> +    if (probe.prob->get_static_ops () == spops)
> +      return true;
>  
> -  return 0;
> +  return false;
>  }
>  
>  /* Helper function that parses a probe linespec of the form [PROVIDER
> @@ -538,8 +510,8 @@ parse_probe_linespec (const char *str, std::string *provider,
>  /* See comment in probe.h.  */
>  
>  void
> -info_probes_for_ops (const char *arg, int from_tty,
> -		     const struct probe_ops *pops)
> +info_probes_for_spops (const char *arg, int from_tty,
> +		       const static_probe_ops *spops)
>  {
>    std::string provider, probe_name, objname;
>    int any_found;
> @@ -554,26 +526,28 @@ info_probes_for_ops (const char *arg, int from_tty,
>    parse_probe_linespec (arg, &provider, &probe_name, &objname);
>  
>    std::vector<bound_probe> probes
> -    = collect_probes (objname, provider, probe_name, pops);
> +    = collect_probes (objname, provider, probe_name, spops);
>  
> -  if (pops == NULL)
> +  if (spops == &any_static_probe_ops)
>      {
> -      /* If the probe_ops is NULL, it means the user has requested a "simple"
> -	 `info probes', i.e., she wants to print all information about all
> -	 probes.  For that, we have to identify how many extra fields we will
> -	 need to add in the ui_out table.
> -
> -	 To do that, we iterate over all probe_ops, querying each one about
> -	 its extra fields, and incrementing `ui_out_extra_fields' to reflect
> -	 that number.  But note that we ignore the probe_ops for which no probes
> -	 are defined with the given search criteria.  */
> -
> -      for (const probe_ops *po : all_probe_ops)
> -	if (exists_probe_with_pops (probes, po))
> +      /* If SPOPS is &any_static_probe_ops, it means the user has
> +	 requested a "simple" `info probes', i.e., she wants to print
> +	 all information about all probes.  For that, we have to
> +	 identify how many extra fields we will need to add in the
> +	 ui_out table.
> +
> +	 To do that, we iterate over all static_probe_ops, querying
> +	 each one about its extra fields, and incrementing
> +	 `ui_out_extra_fields' to reflect that number.  But note that
> +	 we ignore the static_probe_ops for which no probes are
> +	 defined with the given search criteria.  */
> +
> +      for (const static_probe_ops *po : all_static_probe_ops)
> +	if (exists_probe_with_spops (probes, po))
>  	  ui_out_extra_fields += get_number_extra_fields (po);
>      }
>    else
> -    ui_out_extra_fields = get_number_extra_fields (pops);
> +    ui_out_extra_fields = get_number_extra_fields (spops);
>  
>    {
>      ui_out_emit_table table_emitter (current_uiout,
> @@ -589,11 +563,12 @@ info_probes_for_ops (const char *arg, int from_tty,
>         `name' and `objname').  */
>      for (const bound_probe &probe : probes)
>        {
> -	const char *probe_type = probe.probe->pops->type_name (probe.probe);
> +	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
>  
>  	size_type = std::max (strlen (probe_type), size_type);
> -	size_name = std::max (strlen (probe.probe->name), size_name);
> -	size_provider = std::max (strlen (probe.probe->provider), size_provider);
> +	size_name = std::max (strlen (probe.prob->get_name ()), size_name);
> +	size_provider = std::max (strlen (probe.prob->get_provider ()),
> +				  size_provider);
>  	size_objname = std::max (strlen (objfile_name (probe.objfile)),
>  				 size_objname);
>        }
> @@ -604,44 +579,46 @@ info_probes_for_ops (const char *arg, int from_tty,
>      current_uiout->table_header (size_name, ui_left, "name", _("Name"));
>      current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
>  
> -    if (pops == NULL)
> +    if (spops == &any_static_probe_ops)
>        {
>  	/* We have to generate the table header for each new probe type
>  	   that we will print.  Note that this excludes probe types not
>  	   having any defined probe with the search criteria.  */
> -	for (const probe_ops *po : all_probe_ops)
> -	  if (exists_probe_with_pops (probes, po))
> +	for (const static_probe_ops *po : all_static_probe_ops)
> +	  if (exists_probe_with_spops (probes, po))
>  	    gen_ui_out_table_header_info (probes, po);
>        }
>      else
> -      gen_ui_out_table_header_info (probes, pops);
> +      gen_ui_out_table_header_info (probes, spops);
>  
>      current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
>      current_uiout->table_body ();
>  
>      for (const bound_probe &probe : probes)
>        {
> -	const char *probe_type = probe.probe->pops->type_name (probe.probe);
> +	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
>  
>  	ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
>  
> -	current_uiout->field_string ("type",probe_type);
> -	current_uiout->field_string ("provider", probe.probe->provider);
> -	current_uiout->field_string ("name", probe.probe->name);
> -	current_uiout->field_core_addr ("addr", probe.probe->arch,
> -					get_probe_address (probe.probe,
> -							   probe.objfile));
> +	current_uiout->field_string ("type", probe_type);
> +	current_uiout->field_string ("provider", probe.prob->get_provider ());
> +	current_uiout->field_string ("name", probe.prob->get_name ());
> +	current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
> +					probe.prob->get_relocated_address
> +					(probe.objfile));
>  
> -	if (pops == NULL)
> +	if (spops == &any_static_probe_ops)
>  	  {
> -	    for (const probe_ops *po : all_probe_ops)
> -	      if (probe.probe->pops == po)
> -		print_ui_out_info (probe.probe);
> -	      else if (exists_probe_with_pops (probes, po))
> -		print_ui_out_not_applicables (po);
> +	    for (const static_probe_ops *po : all_static_probe_ops)
> +	      {
> +		if (probe.prob->get_static_ops () == po)
> +		  print_ui_out_info (probe.prob);
> +		else if (exists_probe_with_spops (probes, po))
> +		  print_ui_out_not_applicables (po);
> +	      }
>  	  }
>  	else
> -	  print_ui_out_info (probe.probe);
> +	  print_ui_out_info (probe.prob);
>  
>  	current_uiout->field_string ("object",
>  				     objfile_name (probe.objfile));
> @@ -660,7 +637,7 @@ info_probes_for_ops (const char *arg, int from_tty,
>  static void
>  info_probes_command (const char *arg, int from_tty)
>  {
> -  info_probes_for_ops (arg, from_tty, NULL);
> +  info_probes_for_spops (arg, from_tty, &any_static_probe_ops);
>  }
>  
>  /* Implementation of the `enable probes' command.  */
> @@ -673,7 +650,7 @@ enable_probes_command (const char *arg, int from_tty)
>    parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
>  
>    std::vector<bound_probe> probes
> -    = collect_probes (objname, provider, probe_name, NULL);
> +    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
>    if (probes.empty ())
>      {
>        current_uiout->message (_("No probes matched.\n"));
> @@ -684,17 +661,17 @@ enable_probes_command (const char *arg, int from_tty)
>       notion of enabling a probe.  */
>    for (const bound_probe &probe: probes)
>      {
> -      const struct probe_ops *pops = probe.probe->pops;
> -
> -      if (pops->enable_probe != NULL)
> +      if (probe.prob->can_enable ())
>  	{
> -	  pops->enable_probe (probe.probe);
> +	  probe.prob->enable ();
>  	  current_uiout->message (_("Probe %s:%s enabled.\n"),
> -				  probe.probe->provider, probe.probe->name);
> +				  probe.prob->get_provider (),
> +				  probe.prob->get_name ());
>  	}
>        else
>  	current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
> -				probe.probe->provider, probe.probe->name);
> +				probe.prob->get_provider (),
> +				probe.prob->get_name ());
>      }
>  }
>  
> @@ -708,7 +685,7 @@ disable_probes_command (const char *arg, int from_tty)
>    parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
>  
>    std::vector<bound_probe> probes
> -    = collect_probes (objname, provider, probe_name, NULL /* pops */);
> +    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
>    if (probes.empty ())
>      {
>        current_uiout->message (_("No probes matched.\n"));
> @@ -719,55 +696,22 @@ disable_probes_command (const char *arg, int from_tty)
>       notion of enabling a probe.  */
>    for (const bound_probe &probe : probes)
>      {
> -      const struct probe_ops *pops = probe.probe->pops;
> -
> -      if (pops->disable_probe != NULL)
> +      if (probe.prob->can_enable ())
>  	{
> -	  pops->disable_probe (probe.probe);
> +	  probe.prob->disable ();
>  	  current_uiout->message (_("Probe %s:%s disabled.\n"),
> -				  probe.probe->provider, probe.probe->name);
> +				  probe.prob->get_provider (),
> +				  probe.prob->get_name ());
>  	}
>        else
>  	current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
> -				probe.probe->provider, probe.probe->name);
> +				probe.prob->get_provider (),
> +				probe.prob->get_name ());
>      }
>  }
>  
>  /* See comments in probe.h.  */
>  
> -CORE_ADDR
> -get_probe_address (struct probe *probe, struct objfile *objfile)
> -{
> -  return probe->pops->get_probe_address (probe, objfile);
> -}
> -
> -/* See comments in probe.h.  */
> -
> -unsigned
> -get_probe_argument_count (struct probe *probe, struct frame_info *frame)
> -{
> -  return probe->pops->get_probe_argument_count (probe, frame);
> -}
> -
> -/* See comments in probe.h.  */
> -
> -int
> -can_evaluate_probe_arguments (struct probe *probe)
> -{
> -  return probe->pops->can_evaluate_probe_arguments (probe);
> -}
> -
> -/* See comments in probe.h.  */
> -
> -struct value *
> -evaluate_probe_argument (struct probe *probe, unsigned n,
> -			 struct frame_info *frame)
> -{
> -  return probe->pops->evaluate_probe_argument (probe, n, frame);
> -}
> -
> -/* See comments in probe.h.  */
> -
>  struct value *
>  probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
>  {
> @@ -775,22 +719,22 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
>    unsigned n_args;
>  
>    probe = find_probe_by_pc (get_frame_pc (frame));
> -  if (!probe.probe)
> +  if (!probe.prob)
>      return NULL;
>  
> -  n_args = get_probe_argument_count (probe.probe, frame);
> +  n_args = probe.prob->get_argument_count (frame);
>    if (n >= n_args)
>      return NULL;
>  
> -  return evaluate_probe_argument (probe.probe, n, frame);
> +  return probe.prob->evaluate_argument (n, frame);
>  }
>  
>  /* See comment in probe.h.  */
>  
> -const struct probe_ops *
> -probe_linespec_to_ops (const char **linespecp)
> +const struct static_probe_ops *
> +probe_linespec_to_static_ops (const char **linespecp)
>  {
> -  for (const probe_ops *ops : all_probe_ops)
> +  for (const static_probe_ops *ops : all_static_probe_ops)
>      if (ops->is_linespec (linespecp))
>        return ops;
>  
> @@ -820,31 +764,48 @@ probe_is_linespec_by_keyword (const char **linespecp, const char *const *keyword
>    return 0;
>  }
>  
> -/* Implementation of `is_linespec' method for `struct probe_ops'.  */
> +/* Implementation of `is_linespec' method.  */
>  
> -static int
> -probe_any_is_linespec (const char **linespecp)
> +bool
> +any_static_probe_ops::is_linespec (const char **linespecp) const
>  {
>    static const char *const keywords[] = { "-p", "-probe", NULL };
>  
>    return probe_is_linespec_by_keyword (linespecp, keywords);
>  }
>  
> -/* Dummy method used for `probe_ops_any'.  */
> +/* Implementation of 'get_probes' method.  */
>  
> -static void
> -probe_any_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
> +void
> +any_static_probe_ops::get_probes (std::vector<probe *> *probesp,
> +				  struct objfile *objfile) const
>  {
>    /* No probes can be provided by this dummy backend.  */
>  }
>  
> -/* Operations associated with a generic probe.  */
> +/* Implementation of the 'type_name' method.  */
>  
> -const struct probe_ops probe_ops_any =
> +const char *
> +any_static_probe_ops::type_name () const
>  {
> -  probe_any_is_linespec,
> -  probe_any_get_probes,
> -};
> +  return NULL;
> +}
> +
> +/* Implementation of the 'emit_info_probes_extra_fields' method.  */
> +
> +bool
> +any_static_probe_ops::emit_info_probes_extra_fields () const
> +{
> +  return false;
> +}
> +
> +/* Implementation of the 'gen_info_probes_table_header' method.  */
> +
> +void
> +any_static_probe_ops::gen_info_probes_table_header
> +  (std::vector<struct info_probe_column> *heads) const
> +{
> +}
>  
>  /* See comments in probe.h.  */
>  
> @@ -890,10 +851,10 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
>    gdb_assert (sel >= -1);
>  
>    pc_probe = find_probe_by_pc (pc);
> -  if (pc_probe.probe == NULL)
> +  if (pc_probe.prob == NULL)
>      error (_("No probe at PC %s"), core_addr_to_string (pc));
>  
> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
> +  n_args = pc_probe.prob->get_argument_count (frame);
>    if (sel == -1)
>      return value_from_longest (builtin_type (arch)->builtin_int, n_args);
>  
> @@ -901,7 +862,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
>      error (_("Invalid probe argument %d -- probe has %u arguments available"),
>  	   sel, n_args);
>  
> -  return evaluate_probe_argument (pc_probe.probe, sel, frame);
> +  return pc_probe.prob->evaluate_argument (sel, frame);
>  }
>  
>  /* This is called to compile one of the $_probe_arg* convenience
> @@ -922,10 +883,10 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
>    gdb_assert (sel >= -1);
>  
>    pc_probe = find_probe_by_pc (pc);
> -  if (pc_probe.probe == NULL)
> +  if (pc_probe.prob == NULL)
>      error (_("No probe at PC %s"), core_addr_to_string (pc));
>  
> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
> +  n_args = pc_probe.prob->get_argument_count (frame);
>  
>    if (sel == -1)
>      {
> @@ -940,7 +901,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
>      error (_("Invalid probe argument %d -- probe has %d arguments available"),
>  	   sel, n_args);
>  
> -  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
> +  pc_probe.prob->compile_to_ax (expr, value, sel);
>  }
>  
>  static const struct internalvar_funcs probe_funcs =
> @@ -951,12 +912,12 @@ static const struct internalvar_funcs probe_funcs =
>  };
>  
>  
> -std::vector<const probe_ops *> all_probe_ops;
> +std::vector<const static_probe_ops *> all_static_probe_ops;
>  
>  void
>  _initialize_probe (void)
>  {
> -  all_probe_ops.push_back (&probe_ops_any);
> +  all_static_probe_ops.push_back (&any_static_probe_ops);
>  
>    create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
>  				(void *) (uintptr_t) -1);
> diff --git a/gdb/probe.h b/gdb/probe.h
> index 822e5c89a9..9ad183013b 100644
> --- a/gdb/probe.h
> +++ b/gdb/probe.h
> @@ -30,7 +30,6 @@ struct info_probe_column
>    {
>      /* The internal name of the field.  This string cannot be capitalized nor
>         localized, e.g., "extra_field".  */
> -
>      const char *field_name;
>  
>      /* The field name to be printed in the `info probes' command.  This
> @@ -38,165 +37,206 @@ struct info_probe_column
>      const char *print_name;
>    };
>  
> -typedef struct info_probe_column info_probe_column_s;
> -DEF_VEC_O (info_probe_column_s);
> -
> -/* Operations associated with a probe.  */
> -
> -struct probe_ops
> -  {
> -    /* Method responsible for verifying if LINESPECP is a valid linespec for
> -       a probe breakpoint.  It should return 1 if it is, or zero if it is not.
> -       It also should update LINESPECP in order to discard the breakpoint
> -       option associated with this linespec.  For example, if the option is
> -       `-probe', and the LINESPECP is `-probe abc', the function should
> -       return 1 and set LINESPECP to `abc'.  */
> -
> -    int (*is_linespec) (const char **linespecp);
> -
> -    /* Function that should fill PROBES with known probes from OBJFILE.  */
> -
> -    void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile);
> -
> -    /* Compute the probe's relocated address.  OBJFILE is the objfile
> -       in which the probe originated.  */
> -
> -    CORE_ADDR (*get_probe_address) (struct probe *probe,
> -				    struct objfile *objfile);
> -
> -    /* Return the number of arguments of PROBE.  This function can
> -       throw an exception.  */
> -
> -    unsigned (*get_probe_argument_count) (struct probe *probe,
> -					  struct frame_info *frame);
> -
> -    /* Return 1 if the probe interface can evaluate the arguments of probe
> -       PROBE, zero otherwise.  See the comments on
> -       sym_probe_fns:can_evaluate_probe_arguments for more details.  */
> -
> -    int (*can_evaluate_probe_arguments) (struct probe *probe);

This could return a bool.

> -
> -    /* Evaluate the Nth argument from the PROBE, returning a value
> -       corresponding to it.  The argument number is represented N.
> -       This function can throw an exception.  */
> -
> -    struct value *(*evaluate_probe_argument) (struct probe *probe,
> -					      unsigned n,
> -					      struct frame_info *frame);
> -
> -    /* Compile the Nth argument of the PROBE to an agent expression.
> -       The argument number is represented by N.  */
> -
> -    void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
> -			   struct axs_value *axs_value, unsigned n);
> +/* Operations that act on probes, but are specific to each backend.
> +   These methods do not go into the 'class probe' because they do not
> +   act on a single probe; instead, they are used to operate on many
> +   probes at once, or to provide information about the probe backend
> +   itself, instead of a single probe.
>  
> -    /* Set the semaphore associated with the PROBE.  This function only makes
> -       sense if the probe has a concept of semaphore associated to a
> -       probe, otherwise it can be set to NULL.  */
> +   Each probe backend needs to inherit this class and implement all of
> +   the virtual functions specified here.  Then, an object shall be
> +   instantiated and added (or "registered") to the
> +   ALL_STATIC_PROBE_OPS vector so that the frontend probe interface
> +   can use it in the generic probe functions.  */
>  
> -    void (*set_semaphore) (struct probe *probe, struct objfile *objfile,
> -			   struct gdbarch *gdbarch);
> -
> -    /* Clear the semaphore associated with the PROBE.  This function only
> -       makes sense if the probe has a concept of semaphore associated to
> -       a probe, otherwise it can be set to NULL.  */
> -
> -    void (*clear_semaphore) (struct probe *probe, struct objfile *objfile,
> -			     struct gdbarch *gdbarch);
> -
> -    /* Function called to destroy PROBE's specific data.  This function
> -       shall not free PROBE itself.  */
> -
> -    void (*destroy) (struct probe *probe);
> -
> -    /* Return a pointer to a name identifying the probe type.  This is
> -       the string that will be displayed in the "Type" column of the
> -       `info probes' command.  */
> +class static_probe_ops
> +{
> +public:
> +  /* Method responsible for verifying if LINESPECP is a valid linespec
> +     for a probe breakpoint.  It should return true if it is, or false
> +     if it is not.  It also should update LINESPECP in order to
> +     discard the breakpoint option associated with this linespec.  For
> +     example, if the option is `-probe', and the LINESPECP is `-probe
> +     abc', the function should return 1 and set LINESPECP to
> +     `abc'.  */
> +  virtual bool is_linespec (const char **linespecp) const = 0;
> +
> +  /* Function that should fill PROBES with known probes from OBJFILE.  */
> +  virtual void get_probes (std::vector<probe *> *probes,
> +			    struct objfile *objfile) const = 0;
> +
> +  /* Return a pointer to a name identifying the probe type.  This is
> +     the string that will be displayed in the "Type" column of the
> +     `info probes' command.  */
> +  virtual const char *type_name () const = 0;
> +
> +  /* Return true if the probe type will emit extra fields when the
> +     user issues a "info probes" command.  If this function returns
> +     false, then GEN_INFO_PROBES_TABLE_HEADER and
> +     GEN_INFO_PROBES_TABLE_VALUES are not used.  */
> +  virtual bool emit_info_probes_extra_fields () const = 0;
> +
> +  /* Function responsible for providing the extra fields that will be
> +     printed in the `info probes' command.  It should fill HEADS
> +     with whatever extra fields it needs.  If no extra fields are
> +     required by the probe backend, the method EMIT_INFO_PROBES_FIELDS
> +     should return false.  */
> +  virtual void gen_info_probes_table_header
> +    (std::vector<struct info_probe_column> *heads) const = 0;
> +};
>  
> -    const char *(*type_name) (struct probe *probe);
> +/* Definition of a vector of static_probe_ops.  */
>  
> -    /* Function responsible for providing the extra fields that will be
> -       printed in the `info probes' command.  It should fill HEADS
> -       with whatever extra fields it needs.  If the backend doesn't need
> -       to print extra fields, it can set this method to NULL.  */
> +extern std::vector<const static_probe_ops *> all_static_probe_ops;
>  
> -    void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
> +/* Helper function that, given KEYWORDS, iterate over it trying to match
> +   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
> +   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
> +   is returned.  */
>  
> -    /* Function that will fill VALUES with the values of the extra fields
> -       to be printed for PROBE.  If the backend implements the
> -       `gen_ui_out_table_header' method, then it should implement
> -       this method as well.  The backend should also guarantee that the
> -       order and the number of values in the vector is exactly the same
> -       as the order of the extra fields provided in the method
> -       `gen_ui_out_table_header'.  If a certain field is to be skipped
> -       when printing the information, you can push a NULL value in that
> -       position in the vector.  */
> +extern int probe_is_linespec_by_keyword (const char **linespecp,
> +					 const char *const *keywords);
>  
> -    void (*gen_info_probes_table_values) (struct probe *probe,
> -					  VEC (const_char_ptr) **values);
> +/* Return specific STATIC_PROBE_OPS * matching *LINESPECP and possibly
> +   updating LINESPECP to skip its "-probe-type " prefix.  Return
> +   &static_probe_ops_any if LINESPECP matches "-probe ", that is any
> +   unspecific probe.  Return NULL if LINESPECP is not identified as
> +   any known probe type, *LINESPECP is not modified in such case.  */
>  
> -    /* Enable a probe.  The semantics of "enabling" a probe depend on
> -       the specific backend and the field can be NULL in case enabling
> -       probes is not supported.  This function can throw an
> -       exception.  */
> +extern const static_probe_ops *
> +  probe_linespec_to_static_ops (const char **linespecp);
>  
> -    void (*enable_probe) (struct probe *probe);
> +/* The probe itself.  The class contains generic information about the
> +   probe.  */
>  
> -    /* Disable a probe.  The semantics of "disabling" a probe depend
> -       on the specific backend and the field can be NULL in case
> -       disabling probes is not supported.  This function can throw an
> -       exception.  */
> +class probe
> +{
> +public:
> +  /* Default constructor for a probe.  */
> +  probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
> +	 struct gdbarch *arch_)
> +    : m_name (std::move (name_)), m_provider (std::move (provider_)),
> +      m_address (address_), m_arch (arch_)
> +  {}
>  
> -    void (*disable_probe) (struct probe *probe);
> -  };
> +  /* Virtual destructor.  */
> +  virtual ~probe ()
> +  {}
>  
> -/* Definition of a vector of probe_ops.  */
> +  /* Compute the probe's relocated address.  OBJFILE is the objfile
> +     in which the probe originated.  */
> +  virtual CORE_ADDR get_relocated_address (struct objfile *objfile) = 0;
> +
> +  /* Return the number of arguments of the probe.  This function can
> +     throw an exception.  */
> +  virtual unsigned get_argument_count (struct frame_info *frame) = 0;
> +
> +  /* Return 1 if the probe interface can evaluate the arguments of
> +     probe, zero otherwise.  See the comments on
> +     sym_probe_fns:can_evaluate_probe_arguments for more
> +     details.  */
> +  virtual int can_evaluate_arguments () const = 0;
> +
> +  /* Evaluate the Nth argument from the probe, returning a value
> +     corresponding to it.  The argument number is represented N.
> +     This function can throw an exception.  */
> +  virtual struct value *evaluate_argument (unsigned n,
> +					   struct frame_info *frame) = 0;
> +
> +  /* Compile the Nth argument of the probe to an agent expression.
> +     The argument number is represented by N.  */
> +  virtual void compile_to_ax (struct agent_expr *aexpr,
> +			      struct axs_value *axs_value,
> +			      unsigned n) = 0;
> +
> +  /* Set the semaphore associated with the probe.  This function only
> +     makes sense if the probe has a concept of semaphore associated to
> +     a probe.  */
> +  virtual void set_semaphore (struct objfile *objfile,
> +			      struct gdbarch *gdbarch)
> +  {}
>  
> -extern std::vector<const probe_ops *> all_probe_ops;
> +  /* Clear the semaphore associated with the probe.  This function
> +     only makes sense if the probe has a concept of semaphore
> +     associated to a probe.  */
> +  virtual void clear_semaphore (struct objfile *objfile,
> +				struct gdbarch *gdbarch)
> +  {}
>  
> -/* The probe_ops associated with the generic probe.  */
> +  /* Return the pointer to the static_probe_ops instance related to
> +     the probe type.  */
> +  virtual const static_probe_ops *get_static_ops () const = 0;
> +
> +  /* Function that will fill VALUES with the values of the extra
> +     fields to be printed for the probe.
> +
> +     If the backend implements the `gen_ui_out_table_header' method,
> +     then it should implement this method as well.  The backend should
> +     also guarantee that the order and the number of values in the
> +     vector is exactly the same as the order of the extra fields
> +     provided in the method `gen_ui_out_table_header'.  If a certain
> +     field is to be skipped when printing the information, you can
> +     push a NULL value in that position in the vector.  */
> +  virtual void gen_info_probes_table_values
> +    (std::vector<const char *> *values) const
> +  {}
>  
> -extern const struct probe_ops probe_ops_any;
> +  /* Return true if the probe can be enabled; false otherwise.  */
> +  virtual bool can_enable () const
> +  {
> +    return false;
> +  }
>  
> -/* Helper function that, given KEYWORDS, iterate over it trying to match
> -   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
> -   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
> -   is returned.  */
> +  /* Enable the probe.  The semantics of "enabling" a probe depend on
> +     the specific backend.  This function can throw an exception.  */
> +  virtual void enable ()
> +  {}
>  
> -extern int probe_is_linespec_by_keyword (const char **linespecp,
> -					 const char *const *keywords);
> +  /* Disable the probe.  The semantics of "disabling" a probe depend
> +     on the specific backend.  This function can throw an
> +     exception.  */
> +  virtual void disable ()
> +  {}
>  
> -/* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
> -   *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
> -   *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
> -   *LINESPECP is not identified as any known probe type, *LINESPECP is not
> -   modified in such case.  */
> +  /* Getter for M_NAME.  */
> +  const char *get_name () const
> +  {
> +    return m_name.c_str ();
> +  }
>  
> -extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
> +  /* Getter for M_PROVIDER.  */
> +  const char *get_provider () const
> +  {
> +    return m_provider.c_str ();
> +  }

I'd suggest making get_name and get_provider return an std::string.
Most usages use strcmp/strlen, which can be replaced with their C++
equivalent.  Other usages are used to pass to uiout methods, like
field_string.  I think we could add an overload to these methods
that take a const std::string& instead of a const char *, for
convenience.  But I'm fine if we do it in another patchset, so you
don't have to complicate things for nothing in this patchset.

>  
> -/* The probe itself.  The struct contains generic information about the
> -   probe, and then some specific information which should be stored in
> -   the `probe_info' field.  */
> +  /* Getter for M_ADDRESS.  */
> +  CORE_ADDR get_address () const
> +  {
> +    return m_address;
> +  }
>  
> -struct probe
> +  /* Getter for M_ARCH.  */
> +  struct gdbarch *get_gdbarch () const
>    {
> -    /* The operations associated with this probe.  */
> -    const struct probe_ops *pops;
> +    return m_arch;
> +  }
>  
> -    /* The probe's architecture.  */
> -    struct gdbarch *arch;
> +private:
> +  /* The name of the probe.  */
> +  std::string m_name;
>  
> -    /* The name of the probe.  */
> -    const char *name;
> +  /* The provider of the probe.  It generally defaults to the name of
> +     the objfile which contains the probe.  */
> +  std::string m_provider;
>  
> -    /* The provider of the probe.  It generally defaults to the name of
> -       the objfile which contains the probe.  */
> -    const char *provider;
> +  /* The address where the probe is inserted, relative to
> +     SECT_OFF_TEXT.  */
> +  CORE_ADDR m_address;
>  
> -    /* The address where the probe is inserted, relative to
> -       SECT_OFF_TEXT.  */
> -    CORE_ADDR address;
> -  };
> +  /* The probe's architecture.  */
> +  struct gdbarch *m_arch;
> +};
>  
>  /* A bound probe holds a pointer to a probe and a pointer to the
>     probe's defining objfile.  This is needed because probes are
> @@ -206,22 +246,18 @@ struct probe
>  struct bound_probe
>  {
>    /* Create an empty bound_probe object.  */
> -
>    bound_probe ()
>    {}
>  
>    /* Create and initialize a bound_probe object using PROBE and OBJFILE.  */
> -
> -  bound_probe (struct probe *probe_, struct objfile *objfile_)
> -  : probe (probe_), objfile (objfile_)
> +  bound_probe (probe *probe_, struct objfile *objfile_)
> +  : prob (probe_), objfile (objfile_)
>    {}
>  
>    /* The probe.  */
> -
> -  struct probe *probe = NULL;
> +  probe *prob = NULL;
>  
>    /* The objfile in which the probe originated.  */
> -
>    struct objfile *objfile = NULL;
>  };
>  
> @@ -234,11 +270,6 @@ extern std::vector<symtab_and_line> parse_probes
>     struct program_space *pspace,
>     struct linespec_result *canon);
>  
> -/* Helper function to register the proper probe_ops to a newly created probe.
> -   This function is mainly called from `sym_get_probes'.  */
> -
> -extern void register_probe_ops (struct probe *probe);
> -
>  /* Given a PC, find an associated probe.  If a probe is found, return
>     it.  If no probe is found, return a bound probe whose fields are
>     both NULL.  */
> @@ -253,13 +284,13 @@ 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
> -   function that can be used by the probe backends to print their
> -   `info probe TYPE'.  */
> +/* Generate a `info probes' command output for probes associated with
> +   SPOPS.  If SPOPS is related to the "any probe" type, then all probe
> +   types are considered.  It is a helper function that can be used by
> +   the probe backends to print their `info probe TYPE'.  */
>  
> -extern void info_probes_for_ops (const char *arg, int from_tty,
> -				 const struct probe_ops *pops);
> +extern void info_probes_for_spops (const char *arg, int from_tty,
> +				   const static_probe_ops *spops);
>  
>  /* Return the `cmd_list_element' associated with the `info probes' command,
>     or create a new one if it doesn't exist.  Helper function that serves the
> @@ -268,34 +299,6 @@ extern void info_probes_for_ops (const char *arg, int from_tty,
>  
>  extern struct cmd_list_element **info_probes_cmdlist_get (void);
>  
> -/* Compute the probe's relocated address.  OBJFILE is the objfile in
> -   which the probe originated.  */
> -
> -extern CORE_ADDR get_probe_address (struct probe *probe,
> -				    struct objfile *objfile);
> -
> -/* Return the argument count of the specified probe.
> -
> -   This function can throw an exception.  */
> -
> -extern unsigned get_probe_argument_count (struct probe *probe,
> -					  struct frame_info *frame);
> -
> -/* Return 1 if the probe interface associated with PROBE can evaluate
> -   arguments, zero otherwise.  See the comments on the definition of
> -   sym_probe_fns:can_evaluate_probe_arguments for more details.  */
> -
> -extern int can_evaluate_probe_arguments (struct probe *probe);
> -
> -/* Evaluate argument N of the specified probe.  N must be between 0
> -   inclusive and get_probe_argument_count exclusive.
> -
> -   This function can throw an exception.  */
> -
> -extern struct value *evaluate_probe_argument (struct probe *probe,
> -					      unsigned n,
> -					      struct frame_info *frame);
> -
>  /* A convenience function that finds a probe at the PC in FRAME and
>     evaluates argument N, with 0 <= N < number_of_args.  If there is no
>     probe at that location, or if the probe does not have enough arguments,
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 5ec606de43..6e834fb5d7 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -351,7 +351,7 @@ struct svr4_info
>    /* Table of struct probe_and_action instances, used by the
>       probes-based interface to map breakpoint addresses to probes
>       and their associated actions.  Lookup is performed using
> -     probe_and_action->probe->address.  */
> +     probe_and_action->prob->address.  */
>    htab_t probes_table;
>  
>    /* List of objects loaded into the inferior, used by the probes-
> @@ -1664,7 +1664,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ)
>  struct probe_and_action
>  {
>    /* The probe.  */
> -  struct probe *probe;
> +  probe *prob;
>  
>    /* The relocated address of the probe.  */
>    CORE_ADDR address;
> @@ -1699,7 +1699,7 @@ equal_probe_and_action (const void *p1, const void *p2)
>     probes table.  */
>  
>  static void
> -register_solib_event_probe (struct probe *probe, CORE_ADDR address,
> +register_solib_event_probe (probe *prob, CORE_ADDR address,
>  			    enum probe_action action)
>  {
>    struct svr4_info *info = get_svr4_info ();
> @@ -1712,13 +1712,13 @@ register_solib_event_probe (struct probe *probe, CORE_ADDR address,
>  					    equal_probe_and_action,
>  					    xfree, xcalloc, xfree);
>  
> -  lookup.probe = probe;
> +  lookup.prob = prob;
>    lookup.address = address;
>    slot = htab_find_slot (info->probes_table, &lookup, INSERT);
>    gdb_assert (*slot == HTAB_EMPTY_ENTRY);
>  
>    pa = XCNEW (struct probe_and_action);
> -  pa->probe = probe;
> +  pa->prob = prob;
>    pa->address = address;
>    pa->action = action;
>  
> @@ -1767,7 +1767,7 @@ solib_event_probe_action (struct probe_and_action *pa)
>         arg2: struct link_map *new (optional, for incremental updates)  */
>    TRY
>      {
> -      probe_argc = get_probe_argument_count (pa->probe, frame);
> +      probe_argc = pa->prob->get_argument_count (frame);
>      }
>    CATCH (ex, RETURN_MASK_ERROR)
>      {
> @@ -1776,11 +1776,11 @@ solib_event_probe_action (struct probe_and_action *pa)
>      }
>    END_CATCH
>  
> -  /* If get_probe_argument_count throws an exception, probe_argc will
> -     be set to zero.  However, if pa->probe does not have arguments,
> -     then get_probe_argument_count will succeed but probe_argc will
> -     also be zero.  Both cases happen because of different things, but
> -     they are treated equally here: action will be set to
> +  /* If get_argument_count throws an exception, probe_argc will be set
> +     to zero.  However, if pa->prob does not have arguments, then
> +     get_argument_count will succeed but probe_argc will also be zero.
> +     Both cases happen because of different things, but they are
> +     treated equally here: action will be set to
>       PROBES_INTERFACE_FAILED.  */
>    if (probe_argc == 2)
>      action = FULL_RELOAD;
> @@ -1922,7 +1922,7 @@ svr4_handle_solib_event (void)
>        return;
>      }
>  
> -  /* evaluate_probe_argument looks up symbols in the dynamic linker
> +  /* evaluate_argument looks up symbols in the dynamic linker
>       using find_pc_section.  find_pc_section is accelerated by a cache
>       called the section map.  The section map is invalidated every
>       time a shared library is loaded or unloaded, and if the inferior
> @@ -1931,14 +1931,14 @@ svr4_handle_solib_event (void)
>       We called find_pc_section in svr4_create_solib_event_breakpoints,
>       so we can guarantee that the dynamic linker's sections are in the
>       section map.  We can therefore inhibit section map updates across
> -     these calls to evaluate_probe_argument and save a lot of time.  */
> +     these calls to evaluate_argument and save a lot of time.  */
>    inhibit_section_map_updates (current_program_space);
>    usm_chain = make_cleanup (resume_section_map_updates_cleanup,
>  			    current_program_space);
>  
>    TRY
>      {
> -      val = evaluate_probe_argument (pa->probe, 1, frame);
> +      val = pa->prob->evaluate_argument (1, frame);
>      }
>    CATCH (ex, RETURN_MASK_ERROR)
>      {
> @@ -1979,7 +1979,7 @@ svr4_handle_solib_event (void)
>      {
>        TRY
>  	{
> -	  val = evaluate_probe_argument (pa->probe, 2, frame);
> +	  val = pa->prob->evaluate_argument (2, frame);
>  	}
>        CATCH (ex, RETURN_MASK_ERROR)
>  	{
> @@ -2084,7 +2084,7 @@ svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
>  
>        for (probe *p : probes[i])
>  	{
> -	  CORE_ADDR address = get_probe_address (p, objfile);
> +	  CORE_ADDR address = p->get_relocated_address (objfile);
>  
>  	  create_solib_event_breakpoint (gdbarch, address);
>  	  register_solib_event_probe (p, address, action);
> @@ -2126,7 +2126,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
>  	  for (int i = 0; i < NUM_PROBES; i++)
>  	    {
>  	      const char *name = probe_info[i].name;
> -	      struct probe *p;
> +	      probe *p;
>  	      char buf[32];
>  
>  	      /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
> @@ -2160,7 +2160,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
>  	      if (!checked_can_use_probe_arguments)
>  		{
>  		  p = probes[i][0];
> -		  if (!can_evaluate_probe_arguments (p))
> +		  if (!p->can_evaluate_arguments ())
>  		    {
>  		      all_probes_found = 0;
>  		      break;
> diff --git a/gdb/symfile.h b/gdb/symfile.h
> index 3472aa0e7b..10b1504937 100644
> --- a/gdb/symfile.h
> +++ b/gdb/symfile.h
> @@ -34,11 +34,11 @@ struct objfile;
>  struct obj_section;
>  struct obstack;
>  struct block;
> -struct probe;
>  struct value;
>  struct frame_info;
>  struct agent_expr;
>  struct axs_value;
> +class probe;
>  
>  /* Comparison function for symbol look ups.  */
>  
> diff --git a/gdb/symtab.h b/gdb/symtab.h
> index 7b8b5cc640..8bf9f3994f 100644
> --- a/gdb/symtab.h
> +++ b/gdb/symtab.h
> @@ -41,10 +41,10 @@ struct axs_value;
>  struct agent_expr;
>  struct program_space;
>  struct language_defn;
> -struct probe;
>  struct common_block;
>  struct obj_section;
>  struct cmd_list_element;
> +class probe;
>  struct lookup_name_info;
>  
>  /* How to match a lookup name against a symbol search name.  */
> @@ -1702,7 +1702,7 @@ struct symtab_and_line
>    bool explicit_line = false;
>  
>    /* The probe associated with this symtab_and_line.  */
> -  struct probe *probe = NULL;
> +  probe *prob = NULL;
>    /* If PROBE is not NULL, then this is the objfile in which the probe
>       originated.  */
>    struct objfile *objfile = NULL;
> diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
> index 59a7b64ae8..76d05dfc13 100644
> --- a/gdb/tracepoint.c
> +++ b/gdb/tracepoint.c
> @@ -1654,11 +1654,9 @@ start_tracing (const char *notes)
>        t->number_on_target = b->number;
>  
>        for (loc = b->loc; loc; loc = loc->next)
> -	if (loc->probe.probe != NULL
> -	    && loc->probe.probe->pops->set_semaphore != NULL)
> -	  loc->probe.probe->pops->set_semaphore (loc->probe.probe,
> -						 loc->probe.objfile,
> -						 loc->gdbarch);
> +	if (loc->probe.prob != NULL)
> +	  loc->probe.prob->set_semaphore (loc->probe.objfile,
> +					  loc->gdbarch);
>  
>        if (bp_location_downloaded)
>  	observer_notify_breakpoint_modified (b);
> @@ -1754,11 +1752,9 @@ stop_tracing (const char *note)
>  	     but we don't really care if this semaphore goes out of sync.
>  	     That's why we are decrementing it here, but not taking care
>  	     in other places.  */
> -	  if (loc->probe.probe != NULL
> -	      && loc->probe.probe->pops->clear_semaphore != NULL)
> -	    loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
> -						     loc->probe.objfile,
> -						     loc->gdbarch);
> +	  if (loc->probe.prob != NULL)
> +	    loc->probe.prob->clear_semaphore (loc->probe.objfile,
> +					      loc->gdbarch);
>  	}
>      }
>  
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-15  2:52   ` Simon Marchi
@ 2017-11-15  3:25     ` Simon Marchi
  2017-11-15  6:15       ` Sergio Durigan Junior
  2017-11-15  6:12     ` Sergio Durigan Junior
  1 sibling, 1 reply; 23+ messages in thread
From: Simon Marchi @ 2017-11-15  3:25 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

Damn, I hit send too soon... here's review part 2.  Actually, there's
wasn't much left.

On 2017-11-14 09:52 PM, Simon Marchi wrote:
> On 2017-11-13 12:58 PM, Sergio Durigan Junior wrote:
>> This patch converts the generic probe interface (gdb/probe.[ch]) to
>> C++, and also performs some cleanups that were on my TODO list for a
>> while.
>>
>> The main changes were the conversion of 'struct probe' to 'class
>> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
>> former now contains all the "dynamic", generic methods that act on a
>> probe + the generic data related to it; the latter encapsulates a
>> bunch of "static" methods that relate to the probe type, but not to a
>> specific probe itself.
> 
> Personally I'm fine with this.  Maybe there would be a better C++-ish
> design, but I'm not very good at that.  If others have suggestions, I'd
> like to hear them.

Given your description, I think "class probe_type" would be a good name
instead of static_probe_ops.

>> -extern const struct probe_ops probe_ops_any;
>> +  /* Return true if the probe can be enabled; false otherwise.  */
>> +  virtual bool can_enable () const
>> +  {
>> +    return false;
>> +  }

Should this be in the static_probe_ops?  Is the fact that a probe can be
enabled/disabled a property of the probe, or the probe type?

Thanks!

Simon

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
@ 2017-11-15  3:58   ` Simon Marchi
  2017-11-15 22:49     ` Sergio Durigan Junior
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Marchi @ 2017-11-15  3:58 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 2017-11-13 12:59 PM, Sergio Durigan Junior wrote:
> This patch converts the SystemTap probe
> interface (gdb/stap-probe.[ch]) to C++, and also performs some
> cleanups that were on my TODO list for a while.
> 
> The main changes were the conversion of 'struct stap_probe' to 'class
> stap_probe', and a new 'class stap_static_probe_ops' to replace the
> use of 'stap_probe_ops'.  Both classes implement the virtual methods
> exported by their parents, 'class probe' and 'class static_probe_ops',
> respectively.  I believe it's now a bit simpler to understand the
> logic behind the stap-probe interface.
> 
> There are several helper functions used to parse parts of a stap
> probe, and since they are generic and don't need to know about the
> probe they're working on, I decided to leave them as simple static
> functions (instead of e.g. converting them to class methods).
> 
> I've also converted a few uses of "VEC" to "std::vector", which makes
> the code simpler and easier to maintain.  And, as usual, some cleanups
> here and there.
> 
> Even though I'm sending a series of patches, they need to be tested
> and committed as a single unit, because of inter-dependencies.  But it
> should be easier to review in separate logical units.

Hi Sergio,

This look very good to me.  In general, try to use const-references when
iterating on vector of objects (in all 3 patches).  A few comments below.

> I've regtested this patch on BuildBot, no regressions found.
> 
> gdb/ChangeLog:
> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
> 	variable.
> 	(stap_probe_arg_s): Delete type and VEC.
> 	(struct stap_probe): Delete.  Replace by...
> 	(class stap_static_probe_ops): ...this and...
> 	(class stap_probe): ...this.  Rename variables to add 'm_'
> 	prefix.  Do not use 'union' for arguments anymore.
> 	(stap_get_expected_argument_type): Receive probe name instead
> 	of 'struct stap_probe'.  Adjust code.
> 	(stap_parse_probe_arguments): Rename to...
> 	(stap_probe::parse_arguments): ...this.  Adjust code to
> 	reflect change.
> 	(stap_get_probe_address): Rename to...
> 	(stap_probe::get_relocated_address): ...this.  Adjust code
> 	to reflect change.
> 	(stap_get_probe_argument_count): Rename to...
> 	(stap_probe::get_argument_count): ...this.  Adjust code
> 	to reflect change.
> 	(stap_get_arg): Rename to...
> 	(stap_probe::get_arg_by_number'): ...this. Adjust code to
> 	reflect change.
> 	(can_evaluate_probe_arguments): Rename to...
> 	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
> 	to reflect change.
> 	(stap_evaluate_probe_argument): Rename to...
> 	(stap_probe::evaluate_argument): ...this.  Adjust code
> 	to reflect change.
> 	(stap_compile_to_ax): Rename to...
> 	(stap_probe::compile_to_ax): ...this.  Adjust code to
> 	reflect change.
> 	(stap_probe_destroy): Delete.
> 	(stap_modify_semaphore): Adjust comment.
> 	(stap_set_semaphore): Rename to...
> 	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
> 	change.
> 	(stap_clear_semaphore): Rename to...
> 	(stap_probe::clear_semaphore): ...this.  Adjust code to
> 	reflect	change.
> 	(stap_probe::get_static_ops): New method.
> 	(handle_stap_probe): Adjust code to create instance of
> 	'stap_probe'.
> 	(stap_get_probes): Rename to...
> 	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
> 	reflect change.
> 	(stap_probe_is_linespec): Rename to...
> 	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
> 	reflect change.
> 	(stap_type_name): Rename to...
> 	(stap_static_probe_ops::type_name): ...this.  Adjust code to
> 	reflect change.
> 	(stap_static_probe_ops::emit_info_probes_extra_fields): New
> 	method.
> 	(stap_gen_info_probes_table_header): Rename to...
> 	(stap_static_probe_ops::gen_info_probes_table_header):
> 	...this.  Adjust code to reflect change.
> 	(stap_gen_info_probes_table_values): Rename to...
> 	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
> 	code to reflect change.
> 	(struct probe_ops stap_probe_ops): Delete.
> 	(info_probes_stap_command): Use 'info_probes_for_spops'
> 	instead of 'info_probes_for_ops'.
> 	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
> 	of 'all_probe_ops'.
> ---
>  gdb/stap-probe.c | 478 ++++++++++++++++++++++++++++---------------------------
>  1 file changed, 244 insertions(+), 234 deletions(-)
> 
> diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
> index 6fa0d20280..c169ffc488 100644
> --- a/gdb/stap-probe.c
> +++ b/gdb/stap-probe.c
> @@ -45,10 +45,6 @@
>  
>  #define STAP_BASE_SECTION_NAME ".stapsdt.base"
>  
> -/* Forward declaration. */
> -
> -extern const struct probe_ops stap_probe_ops;
> -
>  /* Should we display debug information for the probe's argument expression
>     parsing?  */
>  
> @@ -95,32 +91,135 @@ struct stap_probe_arg
>    struct expression *aexpr;
>  };
>  
> -typedef struct stap_probe_arg stap_probe_arg_s;
> -DEF_VEC_O (stap_probe_arg_s);
> +/* Class that implements the static probe methods for "stap" probes.  */
>  
> -struct stap_probe
> +class stap_static_probe_ops : public static_probe_ops
>  {
> -  /* Generic information about the probe.  This shall be the first element
> -     of this struct, in order to maintain binary compatibility with the
> -     `struct probe' and be able to fully abstract it.  */
> -  struct probe p;
> +public:
> +  /* See probe.h.  */
> +  bool is_linespec (const char **linespecp) const override;
> +
> +  /* See probe.h.  */
> +  void get_probes (std::vector<probe *> *probesp,
> +		   struct objfile *objfile) const override;
> +
> +  /* See probe.h.  */
> +  const char *type_name () const override;
> +
> +  /* See probe.h.  */
> +  bool emit_info_probes_extra_fields () const override;
> +
> +  /* See probe.h.  */
> +  void gen_info_probes_table_header
> +    (std::vector<struct info_probe_column> *heads) const override;
> +};
> +
> +/* SystemTap static_probe_ops.  */
> +
> +const stap_static_probe_ops stap_static_probe_ops;
>  
> +class stap_probe : public probe
> +{
> +public:
> +  /* Constructor for stap_probe.  */
> +  stap_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
> +	      struct gdbarch *arch_, CORE_ADDR sem_addr, const char *args_text)
> +    : probe (std::move (name_), std::move (provider_), address_, arch_),
> +      m_sem_addr (sem_addr),
> +      m_have_parsed_args (false), m_unparsed_args_text (args_text)
> +  {}
> +
> +  /* Destructor for stap_probe.  */
> +  ~stap_probe ()
> +  {
> +    if (m_have_parsed_args)
> +      for (struct stap_probe_arg arg : m_parsed_args)
> +	xfree (arg.aexpr);
> +  }

I would suggest adding a destructor to stap_probe_arg instead, since it's
the object that "owns" the expression.  You would need to disable copy
construction and assignment (using DISABLE_COPY_AND_ASSIGN) to avoid double
free.  You can then add a simple constructor and use emplace_back when
inserting in the vector.


> +
> +  /* See probe.h.  */
> +  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
> +
> +  /* See probe.h.  */
> +  unsigned get_argument_count (struct frame_info *frame) override;
> +
> +  /* See probe.h.  */
> +  int can_evaluate_arguments () const override;
> +
> +  /* See probe.h.  */
> +  struct value *evaluate_argument (unsigned n,
> +				   struct frame_info *frame) override;
> +
> +  /* See probe.h.  */
> +  void compile_to_ax (struct agent_expr *aexpr,
> +		      struct axs_value *axs_value,
> +		      unsigned n) override;
> +
> +  /* See probe.h.  */
> +  void set_semaphore (struct objfile *objfile,
> +		      struct gdbarch *gdbarch) override;
> +
> +  /* See probe.h.  */
> +  void clear_semaphore (struct objfile *objfile,
> +			struct gdbarch *gdbarch) override;
> +
> +  /* See probe.h.  */
> +  const static_probe_ops *get_static_ops () const override;
> +
> +  /* See probe.h.  */
> +  void gen_info_probes_table_values
> +    (std::vector<const char *> *values) const override;
> +
> +  /* Return argument N of probe.
> +
> +     If the probe's arguments have not been parsed yet, parse them.  If
> +     there are no arguments, throw an exception (error).  Otherwise,
> +     return the requested argument.  */
> +  struct stap_probe_arg *get_arg_by_number (unsigned n,
> +					    struct gdbarch *gdbarch)
> +  {
> +    if (!m_have_parsed_args)
> +      this->parse_arguments (gdbarch);
> +
> +    gdb_assert (m_have_parsed_args);
> +    if (m_parsed_args.empty ())
> +      internal_error (__FILE__, __LINE__,
> +		      _("Probe '%s' apparently does not have arguments, but \n"
> +			"GDB is requesting its argument number %u anyway.  "
> +			"This should not happen.  Please report this bug."),
> +		      this->get_name (), n);
> +
> +    return &m_parsed_args[n];

There wasn't one before, but it sounds to me like there should be a bound check here...

> @@ -1081,26 +1179,16 @@ stap_parse_argument (const char **arg, struct type *atype,
>    return p.pstate.expout;
>  }
>  
> -/* Function which parses an argument string from PROBE, correctly splitting
> -   the arguments and storing their information in properly ways.
> +/* Implementation of 'parse_probe_arguments' method.  */

of 'parse_arguments' method ?

> +void
> +stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
>  {
> -  struct stap_probe *probe = (struct stap_probe *) probe_generic;
>    CORE_ADDR addr;
>  
> -  gdb_assert (probe_generic->pops == &stap_probe_ops);
> -
> -  addr = (probe->sem_addr
> +  addr = (m_sem_addr
>  	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));

While at it, you could replace this with get_relocated_address() so that this
computation is not duplicated.  Same with clear_semaphore.

Thanks,

Simon

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] Convert DTrace probe interface to C++ (and perform some cleanups)
  2017-11-13 17:59 ` [PATCH 3/3] Convert DTrace " Sergio Durigan Junior
@ 2017-11-15  4:40   ` Simon Marchi
  2017-11-16  4:11     ` Sergio Durigan Junior
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Marchi @ 2017-11-15  4:40 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

Hi Sergio,

On 2017-11-13 12:59 PM, Sergio Durigan Junior wrote:
> This patch converts the DTrace probe
> interface (gdb/dtrace-probe.[ch]) to C++, and also performs some
> cleanups that were on my TODO list for a while.
> 
> The main changes were the conversion of 'struct dtrace_probe' to 'class
> dtrace_probe', and a new 'class dtrace_static_probe_ops' to replace the
> use of 'dtrace_probe_ops'.  Both classes implement the virtual methods
> exported by their parents, 'class probe' and 'class static_probe_ops',
> respectively.  I believe it's now a bit simpler to understand the
> logic behind the dtrace-probe interface.
> 
> There are several helper functions used to parse parts of a dtrace
> probe, and since they are generic and don't need to know about the
> probe they're working on, I decided to leave them as simple static
> functions (instead of e.g. converting them to class methods).
> 
> I've also converted a few uses of "VEC" to "std::vector", which makes
> the code simpler and easier to maintain.  And, as usual, some cleanups
> here and there.
> 
> Even though I'm sending a series of patches, they need to be tested
> and committed as a single unit, because of inter-dependencies.  But it
> should be easier to review in separate logical units.
> 
> I've regtested this patch on BuildBot, no regressions found.
> 
> gdb/ChangeLog:
> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* dtrace-probe.c (struct probe_ops dtrace_probe_ops): Delete.
> 	(dtrace_probe_arg_s): Delete type and VEC.
> 	(dtrace_probe_enabler_s): Likewise.
> 	(struct dtrace_probe): Replace by...
> 	(class dtrace_static_probe_ops): ...this and...
> 	(class dtrace_probe): ...this.
> 	(dtrace_probe_is_linespec): Rename to...
> 	(dtrace_static_probe_ops::is_linespec): ...this.  Adjust code
> 	to reflect change.
> 	(dtrace_process_dof_probe): Use 'std::vector' instead of VEC.
> 	Adjust code.  Create new instance of 'dtrace_probe'.
> 	(dtrace_build_arg_exprs): Rename to...
> 	(dtrace_probe::build_arg_exprs): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_get_probes): Rename to...
> 	(dtrace_static_probe_ops::get_probes): ...this.  Adjust code
> 	to reflect change.
> 	(dtrace_get_arg): Rename to...
> 	(dtrace_probe::get_arg_by_number): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_probe_is_enabled): Rename to...
> 	(dtrace_probe::is_enabled): ...this.  Adjust code to reflect
> 	change.
> 	(dtrace_get_probe_address): Rename to...
> 	(dtrace_probe::get_relocated_address): ...this.  Adjust code
> 	to reflect change.
> 	(dtrace_get_probe_argument_count): Rename to...
> 	(dtrace_probe::get_argument_count): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_can_evaluate_probe_arguments): Rename to...
> 	(dtrace_probe::can_evaluate_arguments): ...this.  Adjust code
> 	to reflect change.
> 	(dtrace_evaluate_probe_argument): Rename to...
> 	(dtrace_probe::evaluate_argument): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_compile_to_ax): Rename to...
> 	(dtrace_probe::compile_to_ax): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_probe_destroy): Delete.
> 	(dtrace_type_name): Rename to...
> 	(dtrace_static_probe_ops::type_name): ...this.  Adjust code to
> 	reflect change.
> 	(dtrace_probe::get_static_ops): New method.
> 	(dtrace_gen_info_probes_table_header): Rename to...
> 	(dtrace_static_probe_ops::gen_info_probes_table_header):
> 	...this.  Adjust code to reflect change.
> 	(dtrace_gen_info_probes_table_values): Rename to...
> 	(dtrace_probe::gen_info_probes_table_values): ...this.  Adjust
> 	code to reflect change.
> 	(dtrace_enable_probe): Rename to...
> 	(dtrace_probe::enable_probe): ...this.  Adjust code to reflect
> 	change.
> 	(dtrace_disable_probe): Rename to...
> 	(dtrace_probe::disable_probe): ...this.  Adjust code to reflect
> 	change.
> 	(struct probe_ops dtrace_probe_ops): Delete.
> 	(dtrace_static_probe_ops::emit_info_probes_extra_fields): New
> 	method.
> 	(info_probes_dtrace_command): Call 'info_probes_for_spops'
> 	instead of 'info_probes_for_ops'.
> 	(_initialize_dtrace_probe): Use 'all_static_probe_ops' instead
> 	of 'all_probe_ops'.
> ---
>  gdb/dtrace-probe.c | 528 +++++++++++++++++++++++++++--------------------------
>  1 file changed, 268 insertions(+), 260 deletions(-)
> 
> diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
> index 2bbe03e4b3..b53ff7ac6c 100644
> --- a/gdb/dtrace-probe.c
> +++ b/gdb/dtrace-probe.c
> @@ -41,10 +41,6 @@
>  # define SHT_SUNW_dof	0x6ffffff4
>  #endif
>  
> -/* Forward declaration.  */
> -
> -extern const struct probe_ops dtrace_probe_ops;
> -
>  /* The following structure represents a single argument for the
>     probe.  */
>  
> @@ -60,9 +56,6 @@ struct dtrace_probe_arg
>    struct expression *expr;
>  };
>  
> -typedef struct dtrace_probe_arg dtrace_probe_arg_s;
> -DEF_VEC_O (dtrace_probe_arg_s);
> -
>  /* The following structure represents an enabler for a probe.  */
>  
>  struct dtrace_probe_enabler
> @@ -73,39 +66,121 @@ struct dtrace_probe_enabler
>    CORE_ADDR address;
>  };
>  
> -typedef struct dtrace_probe_enabler dtrace_probe_enabler_s;
> -DEF_VEC_O (dtrace_probe_enabler_s);
> +/* Class that implements the static probe methods for "stap" probes.  */
> +
> +class dtrace_static_probe_ops : public static_probe_ops
> +{
> +public:
> +  /* See probe.h.  */
> +  bool is_linespec (const char **linespecp) const override;
> +
> +  /* See probe.h.  */
> +  void get_probes (std::vector<probe *> *probesp,
> +		   struct objfile *objfile) const override;
> +
> +  /* See probe.h.  */
> +  const char *type_name () const override;
> +
> +  /* See probe.h.  */
> +  bool emit_info_probes_extra_fields () const override;
> +
> +  /* See probe.h.  */
> +  void gen_info_probes_table_header
> +    (std::vector<struct info_probe_column> *heads) const override;
> +};
> +
> +/* DTrace static_probe_ops.  */
> +
> +const dtrace_static_probe_ops dtrace_static_probe_ops;
>  
>  /* The following structure represents a dtrace probe.  */
>  
> -struct dtrace_probe
> +class dtrace_probe : public probe
>  {
> -  /* Generic information about the probe.  This must be the first
> -     element of this struct, in order to maintain binary compatibility
> -     with the `struct probe' and be able to fully abstract it.  */
> -  struct probe p;
> +public:
> +  /* Constructor for dtrace_probe.  */
> +  dtrace_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
> +		struct gdbarch *arch_,
> +		std::vector<struct dtrace_probe_arg> &args_,
> +		std::vector<struct dtrace_probe_enabler> &enablers_)

I am wondering why you don't use && for the vectors, as you do with the strings.
If the constructor is "stealing" from the vectors passed as parameter, I think it
would make sense if the parameters were &&, to indicate to the caller that they'll
be moved from (and force it to use std::move).

> +    : probe (std::move (name_), std::move (provider_), address_, arch_),
> +      m_args (std::move (args_)),
> +      m_enablers (std::move (enablers_)),
> +      m_args_expr_built (false)
> +  {}
> +
> +  /* Destructor for dtrace_probe.  */
> +  ~dtrace_probe ()
> +  {
> +    for (struct dtrace_probe_arg arg : m_args)
> +      {
> +	xfree (arg.type_str);
> +	xfree (arg.expr);
> +      }

As for stap_probe, I think defining a destructor in dtrace_probe_arg would
be clearer.

> +  }
> +
> +  /* See probe.h.  */
> +  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
> +
> +  /* See probe.h.  */
> +  unsigned get_argument_count (struct frame_info *frame) override;
> +
> +  /* See probe.h.  */
> +  int can_evaluate_arguments () const override;
> +
> +  /* See probe.h.  */
> +  struct value *evaluate_argument (unsigned n,
> +				   struct frame_info *frame) override;
> +
> +  /* See probe.h.  */
> +  void compile_to_ax (struct agent_expr *aexpr,
> +		      struct axs_value *axs_value,
> +		      unsigned n) override;
> +
> +  /* See probe.h.  */
> +  const static_probe_ops *get_static_ops () const override;
> +
> +  /* See probe.h.  */
> +  void gen_info_probes_table_values
> +    (std::vector<const char *> *values) const override;
> +
> +  /* See probe.h.  */
> +  bool can_enable () const override
> +  {
> +    return true;
> +  }
> +
> +  /* See probe.h.  */
> +  void enable () override;
>  
> +  /* See probe.h.  */
> +  void disable () override;
> +
> +  /* Return the Nth argument of the probe.  */
> +  struct dtrace_probe_arg *get_arg_by_number (unsigned n,
> +					      struct gdbarch *gdbarch);
> +
> +  /* Build the GDB internal expressiosn that, once evaluated, will
> +     calculate the values of the arguments of the probe.  */
> +  void build_arg_exprs (struct gdbarch *gdbarch);
> +
> +  /* Determine whether the probe is "enabled" or "disabled".  A
> +     disabled probe is a probe in which one or more enablers are
> +     disabled.  */
> +  bool is_enabled () const;
> +
> +private:
>    /* A probe can have zero or more arguments.  */
> -  int probe_argc;
> -  VEC (dtrace_probe_arg_s) *args;
> +  int m_argc;

It seems like this field is never set, but used at least once.  Should we use args->size() instead?

> +  std::vector<struct dtrace_probe_arg> m_args;
>  
>    /* A probe can have zero or more "enablers" associated with it.  */
> -  VEC (dtrace_probe_enabler_s) *enablers;
> +  std::vector<struct dtrace_probe_enabler> m_enablers;
>  
>    /* Whether the expressions for the arguments have been built.  */
> -  unsigned int args_expr_built : 1;
> +  bool m_args_expr_built;
>  };
>  
> -/* Implementation of the probe_is_linespec method.  */
> -
> -static int
> -dtrace_probe_is_linespec (const char **linespecp)
> -{
> -  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
> -
> -  return probe_is_linespec_by_keyword (linespecp, keywords);
> -}
> -
>  /* DOF programs can contain an arbitrary number of sections of 26
>     different types.  In order to support DTrace USDT probes we only
>     need to handle a subset of these section types, fortunately.  These
> @@ -322,8 +397,6 @@ dtrace_process_dof_probe (struct objfile *objfile,
>  			  char *argtab, uint64_t strtab_size)
>  {
>    int i, j, num_probes, num_enablers;
> -  struct cleanup *cleanup;
> -  VEC (dtrace_probe_enabler_s) *enablers;
>    char *p;
>  
>    /* Each probe section can define zero or more probes of two
> @@ -368,9 +441,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
>  
>    /* Build the list of enablers for the probes defined in this Probe
>       DOF section.  */
> -  enablers = NULL;
> -  cleanup
> -    = make_cleanup (VEC_cleanup (dtrace_probe_enabler_s), &enablers);
> +  std::vector<struct dtrace_probe_enabler> enablers;
>    num_enablers = DOF_UINT (dof, probe->dofpr_nenoffs);
>    for (i = 0; i < num_enablers; i++)
>      {
> @@ -380,38 +451,32 @@ dtrace_process_dof_probe (struct objfile *objfile,
>  
>        enabler.address = DOF_UINT (dof, probe->dofpr_addr)
>  	+ DOF_UINT (dof, enabler_offset);
> -      VEC_safe_push (dtrace_probe_enabler_s, enablers, &enabler);
> +      enablers.push_back (enabler);
>      }
>  
>    for (i = 0; i < num_probes; i++)
>      {
>        uint32_t probe_offset
>  	= ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
> -      struct dtrace_probe *ret =
> -	XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
> -
> -      ret->p.pops = &dtrace_probe_ops;
> -      ret->p.arch = gdbarch;
> -      ret->args_expr_built = 0;
>  
>        /* Set the provider and the name of the probe.  */
> -      ret->p.provider
> -	= xstrdup (strtab + DOF_UINT (dof, provider->dofpv_name));
> -      ret->p.name = xstrdup (strtab + DOF_UINT (dof, probe->dofpr_name));
> +      const char *probe_provider
> +	= strtab + DOF_UINT (dof, provider->dofpv_name);
> +      const char *name = strtab + DOF_UINT (dof, probe->dofpr_name);
>  
>        /* The probe address.  */
> -      ret->p.address
> +      CORE_ADDR address
>  	= DOF_UINT (dof, probe->dofpr_addr) + DOF_UINT (dof, probe_offset);
>  
>        /* Number of arguments in the probe.  */
> -      ret->probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
> +      int probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
>  
>        /* Store argument type descriptions.  A description of the type
>           of the argument is in the (J+1)th null-terminated string
>           starting at 'strtab' + 'probe->dofpr_nargv'.  */
> -      ret->args = NULL;
> +      std::vector<struct dtrace_probe_arg> args;
>        p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
> -      for (j = 0; j < ret->probe_argc; j++)
> +      for (j = 0; j < probe_argc; j++)
>  	{
>  	  struct dtrace_probe_arg arg;
>  	  expression_up expr;
> @@ -442,17 +507,18 @@ dtrace_process_dof_probe (struct objfile *objfile,
>  	  if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
>  	    arg.type = expr->elts[1].type;
>  
> -	  VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
> +	  args.push_back (arg);
>  	}
>  
> -      /* Add the vector of enablers to this probe, if any.  */
> -      ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
> +      std::vector<struct dtrace_probe_enabler> enablers_copy = enablers;

Why is this copy necessary?  What happens with the original vector?

> +      dtrace_probe *ret = new dtrace_probe (std::string (name),
> +					    std::string (probe_provider),
> +					    address, gdbarch,
> +					    args, enablers_copy);
>  
>        /* Successfully created probe.  */
> -      probesp->push_back ((struct probe *) ret);
> +      probesp->push_back (ret);
>      }
> -
> -  do_cleanups (cleanup);
>  }
>  
>  /* Helper function to collect the probes described in the DOF program
> @@ -555,28 +621,23 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
>  	     sect->name);
>  }
>  
> -/* Helper function to build the GDB internal expressiosn that, once
> -   evaluated, will calculate the values of the arguments of a given
> -   PROBE.  */
> +/* Implementation of 'build_arg_exprs' method.  */
>  
> -static void
> -dtrace_build_arg_exprs (struct dtrace_probe *probe,
> -			struct gdbarch *gdbarch)
> +void
> +dtrace_probe::build_arg_exprs (struct gdbarch *gdbarch)
>  {
> -  struct parser_state pstate;
> -  struct dtrace_probe_arg *arg;
> -  int i;
> -
> -  probe->args_expr_built = 1;
> +  m_args_expr_built = true;
>  
>    /* Iterate over the arguments in the probe and build the
>       corresponding GDB internal expression that will generate the
>       value of the argument when executed at the PC of the probe.  */
> -  for (i = 0; i < probe->probe_argc; i++)
> +  for (int i = 0; i < m_argc; i++)
>      {
> +      struct dtrace_probe_arg *arg;
>        struct cleanup *back_to;
> +      struct parser_state pstate;
>  
> -      arg = VEC_index (dtrace_probe_arg_s, probe->args, i);
> +      arg = &m_args[i];
>  
>        /* Initialize the expression buffer in the parser state.  The
>  	 language does not matter, since we are using our own
> @@ -606,138 +667,82 @@ dtrace_build_arg_exprs (struct dtrace_probe *probe,
>      }
>  }
>  
> -/* Helper function to return the Nth argument of a given PROBE.  */
> -
> -static struct dtrace_probe_arg *
> -dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
> -		struct gdbarch *gdbarch)
> -{
> -  if (!probe->args_expr_built)
> -    dtrace_build_arg_exprs (probe, gdbarch);
> -
> -  return VEC_index (dtrace_probe_arg_s, probe->args, n);
> -}
> -
> -/* Implementation of the get_probes method.  */
> +/* Implementation of 'get_arg_by_number' method.  */
>  
> -static void
> -dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
> +struct dtrace_probe_arg *
> +dtrace_probe::get_arg_by_number (unsigned n, struct gdbarch *gdbarch)
>  {
> -  bfd *abfd = objfile->obfd;
> -  asection *sect = NULL;
> -
> -  /* Do nothing in case this is a .debug file, instead of the objfile
> -     itself.  */
> -  if (objfile->separate_debug_objfile_backlink != NULL)
> -    return;
> +  if (!m_args_expr_built)
> +    this->build_arg_exprs (gdbarch);
>  
> -  /* Iterate over the sections in OBJFILE looking for DTrace
> -     information.  */
> -  for (sect = abfd->sections; sect != NULL; sect = sect->next)
> -    {
> -      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
> -	{
> -	  bfd_byte *dof;
> -
> -	  /* Read the contents of the DOF section and then process it to
> -	     extract the information of any probe defined into it.  */
> -	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
> -	    complaint (&symfile_complaints,
> -		       _("could not obtain the contents of"
> -			 "section '%s' in objfile `%s'."),
> -		       sect->name, abfd->filename);
> -      
> -	  dtrace_process_dof (sect, objfile, probesp,
> -			      (struct dtrace_dof_hdr *) dof);
> -	  xfree (dof);
> -	}
> -    }
> +  return &m_args[n];

It would be nice to add a gdb_assert (n < m_args.size ()) here.

Thanks,

Simon

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-15  2:52   ` Simon Marchi
  2017-11-15  3:25     ` Simon Marchi
@ 2017-11-15  6:12     ` Sergio Durigan Junior
  1 sibling, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-15  6:12 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches

Hey Simon,

Thanks for the review.  Comments below.

On Tuesday, November 14 2017, Simon Marchi wrote:

> On 2017-11-13 12:58 PM, Sergio Durigan Junior wrote:
>> This patch converts the generic probe interface (gdb/probe.[ch]) to
>> C++, and also performs some cleanups that were on my TODO list for a
>> while.
>> 
>> The main changes were the conversion of 'struct probe' to 'class
>> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
>> former now contains all the "dynamic", generic methods that act on a
>> probe + the generic data related to it; the latter encapsulates a
>> bunch of "static" methods that relate to the probe type, but not to a
>> specific probe itself.
>
> Personally I'm fine with this.  Maybe there would be a better C++-ish
> design, but I'm not very good at that.  If others have suggestions, I'd
> like to hear them.

Great!

>> I've had to do a few renamings (e.g., on 'struct bound_probe' the
>> field is called 'probe *prob' now, instead of 'struct probe *probe')
>> because GCC was complaining about naming the field using the same name
>> as the class.  Nothing major, though.  Generally speaking, the logic
>> behind and the design behind the code are the same.
>> 
>> Even though I'm sending a series of patches, they need to be tested
>> and committed as a single unit, because of inter-dependencies.  But it
>> should be easier to review in separate logical units.
>> 
>> I've regtested this patch on BuildBot, no regressions found.
>> 
>> gdb/ChangeLog:
>> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* break-catch-throw.c (fetch_probe_arguments): Use
>> 	'probe.prob' instead of 'probe.probe'.
>> 	* breakpoint.c (create_longjmp_master_breakpoint): Call
>> 	'can_evaluate_arguments' and 'get_relocated_address' methods
>> 	from probe.
>> 	(create_exception_master_breakpoint): Likewise.
>> 	(add_location_to_breakpoint): Use 'sal->prob' instead of
>> 	'sal->probe'.
>> 	(bkpt_probe_insert_location): Call 'set_semaphore' method from
>> 	probe.
>> 	(bkpt_probe_remove_location): Likewise, for 'clear_semaphore'.
>> 	* elfread.c (elf_get_probes): Use 'static_probe_ops' instead
>> 	of 'probe_ops'.
>> 	(probe_key_free): Call 'delete' on probe.
>> 	(check_exception_resume): Use 'probe.prob' instead of
>> 	'probe.probe'.
>> 	* location.c (string_to_event_location_basic): Call
>> 	'probe_linespec_to_static_ops'.
>> 	* probe.c (class any_static_probe_ops): New class.
>> 	(any_static_probe_ops any_static_probe_ops): New variable.
>> 	(parse_probes_in_pspace): Receive 'static_probe_ops' as
>> 	argument.  Adjust code to reflect change.
>> 	(parse_probes): Use 'static_probe_ops' instead of
>> 	'probe_ops'.  Adjust code to reflect change.
>> 	(find_probes_in_objfile): Call methods to get name and
>> 	provider from probe.
>> 	(find_probe_by_pc): Use 'result.prob' instead of
>> 	'result.probe'.  Call 'get_relocated_address' method from
>> 	probe.
>> 	(collect_probes): Adjust comment and argument list to receive
>> 	'static_probe_ops' instead of 'probe_ops'.  Adjust code to
>> 	reflect change.  Call necessary methods from probe.
>> 	(compare_probes): Call methods to get name and provider from
>> 	probes.
>> 	(gen_ui_out_table_header_info): Receive 'static_probe_ops'
>> 	instead of 'probe_ops'.  Use 'std::vector' instead of VEC,
>> 	adjust code accordingly.
>> 	(print_ui_out_not_applicables): Likewise.
>> 	(info_probes_for_ops): Rename to...
>> 	(info_probes_for_spops): ...this.  Receive 'static_probe_ops'
>> 	as argument instead of 'probe_ops'.  Adjust code.  Call
>> 	necessary methods from probe.
>> 	(info_probes_command): Use 'info_probes_for_spops'.
>> 	(enable_probes_command): Pass correct argument to
>> 	'collect_probes'.  Call methods from probe.
>> 	(disable_probes_command): Likewise.
>> 	(get_probe_address): Move to 'any_static_probe_ops::get_address'.
>> 	(get_probe_argument_count): Move to
>> 	'any_static_probe_ops::get_argument_count'.
>> 	(can_evaluate_probe_arguments): Move to
>> 	'any_static_probe_ops::can_evaluate_arguments'.
>> 	(evaluate_probe_argument): Move to
>> 	'any_static_probe_ops::evaluate_argument'.
>> 	(probe_safe_evaluate_at_pc): Use 'probe.prob' instead of
>> 	'probe.probe'.
>> 	(probe_linespec_to_ops): Rename to...
>> 	(probe_linespec_to_static_ops): ...this.  Adjust code.
>> 	(probe_any_is_linespec): Rename to...
>> 	(any_static_probe_ops::is_linespec): ...this.
>> 	(probe_any_get_probes): Rename to...
>> 	(any_static_probe_ops::get_probes): ...this.
>> 	(any_static_probe_ops::type_name): New method.
>> 	(any_static_probe_ops::emit_info_probes_extra_fields): New
>> 	method.
>> 	(any_static_probe_ops::gen_info_probes_table_header): New
>> 	method.
>> 	(compute_probe_arg): Use 'pc_probe.prob' instead of
>> 	'pc_probe.probe'.  Call methods from probe.
>> 	(compile_probe_arg): Likewise.
>> 	(std::vector<const probe_ops *> all_probe_ops): Delete.
>> 	(std::vector<const static_probe_ops *> all_static_probe_ops):
>> 	New variable.
>> 	(_initialize_probe): Use 'all_static_probe_ops' instead of
>> 	'all_probe_ops'.
>> 	* probe.h (struct info_probe_column) <field_name>: Delete
>> 	extraneous newline
>> 	(info_probe_column_s): Delete type and VEC.
>> 	(struct probe_ops): Delete.  Replace with...
>> 	(class static_probe_ops): ...this and...
>> 	(clas probe): ...this.
>> 	(struct bound_probe) <bound_probe>: Delete extraneous
>> 	newline.  Adjust constructor to receive 'probe' instead of
>> 	'struct probe'.
>> 	<probe>: Rename to...
>> 	<prob>: ...this.  Delete extraneous newline.
>> 	<objfile>: Delete extraneous newline.
>> 	(register_probe_ops): Delete unused prototype.
>> 	(info_probes_for_ops): Rename to...
>> 	(info_probes_for_spops): ...this.  Adjust comment.
>> 	(get_probe_address): Move to 'probe::get_address'.
>> 	(get_probe_argument_count): Move to
>> 	'probe::get_argument_count'.
>> 	(can_evaluate_probe_arguments): Move to
>> 	'probe::can_evaluate_arguments'.
>> 	(evaluate_probe_argument): Move to 'probe::evaluate_argument'.
>> 	* solib-svr4.c (struct svr4_info): Adjust comment.
>> 	(struct probe_and_action) <probe>: Rename to...
>> 	<prob>: ...this.
>> 	(register_solib_event_probe): Receive 'probe' instead of
>> 	'struct probe' as argument.  Use 'prob' instead of 'probe'
>> 	when applicable.
>> 	(solib_event_probe_action): Call 'get_argument_count' method
>> 	from probe.  Adjust comment.
>> 	(svr4_handle_solib_event): Adjust comment.  Call
>> 	'evaluate_argument' method from probe.
>> 	(svr4_create_probe_breakpoints): Call 'get_relocated_address'
>> 	from probe.
>> 	(svr4_create_solib_event_breakpoints): Use 'probe' instead of
>> 	'struct probe'.  Call 'can_evaluate_arguments' from probe.
>> 	* symfile.h: Forward declare 'class probe' instead of 'struct
>> 	probe'.
>> 	* symtab.h: Likewise.
>> 	(struct symtab_and_line) <probe>: Rename to...
>> 	<prob>: ...this.
>> 	* tracepoint.c (start_tracing): Use 'prob' when applicable.
>> 	Call probe methods.
>> 	(stop_tracing): Likewise.
>> 
>> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
>> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
>> Signed-off-by: Sergio Durigan Junior <sergiodj@redhat.com>
>> ---
>>  gdb/break-catch-throw.c |  16 +-
>>  gdb/breakpoint.c        |  20 +--
>>  gdb/elfread.c           |   4 +-
>>  gdb/infrun.c            |   2 +-
>>  gdb/location.c          |   2 +-
>>  gdb/probe.c             | 435 ++++++++++++++++++++++--------------------------
>>  gdb/probe.h             | 363 ++++++++++++++++++++--------------------
>>  gdb/solib-svr4.c        |  36 ++--
>>  gdb/symfile.h           |   2 +-
>>  gdb/symtab.h            |   4 +-
>>  gdb/tracepoint.c        |  16 +-
>>  11 files changed, 427 insertions(+), 473 deletions(-)
>> 
>> diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
>> index fd8a113803..ffc100bb24 100644
>> --- a/gdb/break-catch-throw.c
>> +++ b/gdb/break-catch-throw.c
>> @@ -106,20 +106,20 @@ fetch_probe_arguments (struct value **arg0, struct value **arg1)
>>    unsigned n_args;
>>  
>>    pc_probe = find_probe_by_pc (pc);
>> -  if (pc_probe.probe == NULL
>> -      || strcmp (pc_probe.probe->provider, "libstdcxx") != 0
>> -      || (strcmp (pc_probe.probe->name, "catch") != 0
>> -	  && strcmp (pc_probe.probe->name, "throw") != 0
>> -	  && strcmp (pc_probe.probe->name, "rethrow") != 0))
>> +  if (pc_probe.prob == NULL
>> +      || strcmp (pc_probe.prob->get_provider (), "libstdcxx") != 0
>> +      || (strcmp (pc_probe.prob->get_name (), "catch") != 0
>> +	  && strcmp (pc_probe.prob->get_name (), "throw") != 0
>> +	  && strcmp (pc_probe.prob->get_name (), "rethrow") != 0))
>>      error (_("not stopped at a C++ exception catchpoint"));
>>  
>> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
>> +  n_args = pc_probe.prob->get_argument_count (frame);
>>    if (n_args < 2)
>>      error (_("C++ exception catchpoint has too few arguments"));
>>  
>>    if (arg0 != NULL)
>> -    *arg0 = evaluate_probe_argument (pc_probe.probe, 0, frame);
>> -  *arg1 = evaluate_probe_argument (pc_probe.probe, 1, frame);
>> +    *arg0 = pc_probe.prob->evaluate_argument (0, frame);
>> +  *arg1 = pc_probe.prob->evaluate_argument (1, frame);
>>  
>>    if ((arg0 != NULL && *arg0 == NULL) || *arg1 == NULL)
>>      error (_("error computing probe argument at c++ exception catchpoint"));
>> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
>> index b170a14cb5..1728aee838 100644
>> --- a/gdb/breakpoint.c
>> +++ b/gdb/breakpoint.c
>> @@ -3309,7 +3309,7 @@ create_longjmp_master_breakpoint (void)
>>  	      /* We are only interested in checking one element.  */
>>  	      probe *p = ret[0];
>>  
>> -	      if (!can_evaluate_probe_arguments (p))
>> +	      if (!p->can_evaluate_arguments ())
>>  		{
>>  		  /* We cannot use the probe interface here, because it does
>>  		     not know how to evaluate arguments.  */
>> @@ -3329,7 +3329,7 @@ create_longjmp_master_breakpoint (void)
>>  	      struct breakpoint *b;
>>  
>>  	      b = create_internal_breakpoint (gdbarch,
>> -					      get_probe_address (p, objfile),
>> +					      p->get_relocated_address (objfile),
>>  					      bp_longjmp_master,
>>  					      &internal_breakpoint_ops);
>>  	      b->location = new_probe_location ("-probe-stap libc:longjmp");
>> @@ -3462,7 +3462,7 @@ create_exception_master_breakpoint (void)
>>  	      /* We are only interested in checking one element.  */
>>  	      probe *p = ret[0];
>>  
>> -	      if (!can_evaluate_probe_arguments (p))
>> +	      if (!p->can_evaluate_arguments ())
>>  		{
>>  		  /* We cannot use the probe interface here, because it does
>>  		     not know how to evaluate arguments.  */
>> @@ -3482,7 +3482,7 @@ create_exception_master_breakpoint (void)
>>  	      struct breakpoint *b;
>>  
>>  	      b = create_internal_breakpoint (gdbarch,
>> -					      get_probe_address (p, objfile),
>> +					      p->get_relocated_address (objfile),
>>  					      bp_exception_master,
>>  					      &internal_breakpoint_ops);
>>  	      b->location = new_probe_location ("-probe-stap libgcc:unwind");
>> @@ -8694,7 +8694,7 @@ add_location_to_breakpoint (struct breakpoint *b,
>>    loc->requested_address = sal->pc;
>>    loc->address = adjusted_address;
>>    loc->pspace = sal->pspace;
>> -  loc->probe.probe = sal->probe;
>> +  loc->probe.prob = sal->prob;
>>    loc->probe.objfile = sal->objfile;
>>    gdb_assert (loc->pspace != NULL);
>>    loc->section = sal->section;
>> @@ -12879,10 +12879,7 @@ bkpt_probe_insert_location (struct bp_location *bl)
>>      {
>>        /* The insertion was successful, now let's set the probe's semaphore
>>  	 if needed.  */
>> -      if (bl->probe.probe->pops->set_semaphore != NULL)
>> -	bl->probe.probe->pops->set_semaphore (bl->probe.probe,
>> -					      bl->probe.objfile,
>> -					      bl->gdbarch);
>> +      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
>>      }
>>  
>>    return v;
>> @@ -12893,10 +12890,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
>>  			    enum remove_bp_reason reason)
>>  {
>>    /* Let's clear the semaphore before removing the location.  */
>> -  if (bl->probe.probe->pops->clear_semaphore != NULL)
>> -    bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
>> -					    bl->probe.objfile,
>> -					    bl->gdbarch);
>> +  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
>>  
>>    return bkpt_remove_location (bl, reason);
>>  }
>> diff --git a/gdb/elfread.c b/gdb/elfread.c
>> index cdef5a8c59..f2483025ba 100644
>> --- a/gdb/elfread.c
>> +++ b/gdb/elfread.c
>> @@ -1324,7 +1324,7 @@ elf_get_probes (struct objfile *objfile)
>>  
>>        /* Here we try to gather information about all types of probes from the
>>  	 objfile.  */
>> -      for (const probe_ops *ops : all_probe_ops)
>> +      for (const static_probe_ops *ops : all_static_probe_ops)
>>  	ops->get_probes (probes_per_bfd, objfile);
>>  
>>        set_bfd_data (objfile->obfd, probe_key, probes_per_bfd);
>> @@ -1342,7 +1342,7 @@ probe_key_free (bfd *abfd, void *d)
>>    std::vector<probe *> *probes = (std::vector<probe *> *) d;
>>  
>>    for (probe *p : *probes)
>> -    p->pops->destroy (p);
>> +    delete p;
>>  
>>    delete probes;
>>  }
>> diff --git a/gdb/infrun.c b/gdb/infrun.c
>> index e2d1248e75..4592100962 100644
>> --- a/gdb/infrun.c
>> +++ b/gdb/infrun.c
>> @@ -7583,7 +7583,7 @@ check_exception_resume (struct execution_control_state *ecs,
>>       CFA and the HANDLER.  We ignore the CFA, extract the handler, and
>>       set a breakpoint there.  */
>>    probe = find_probe_by_pc (get_frame_pc (frame));
>> -  if (probe.probe)
>> +  if (probe.prob)
>>      {
>>        insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
>>        return;
>> diff --git a/gdb/location.c b/gdb/location.c
>> index c78778edc1..5ed3623f0a 100644
>> --- a/gdb/location.c
>> +++ b/gdb/location.c
>> @@ -844,7 +844,7 @@ string_to_event_location_basic (const char **stringp,
>>  
>>    /* Try the input as a probe spec.  */
>>    cs = *stringp;
>> -  if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
>> +  if (cs != NULL && probe_linespec_to_static_ops (&cs) != NULL)
>>      {
>>        location = new_probe_location (*stringp);
>>        *stringp += strlen (*stringp);
>> diff --git a/gdb/probe.c b/gdb/probe.c
>> index 829f6d18d7..0c47f904cb 100644
>> --- a/gdb/probe.c
>> +++ b/gdb/probe.c
>> @@ -38,11 +38,38 @@
>>  #include <algorithm>
>>  #include "common/gdb_optional.h"
>>  
>> +/* Class that implements the static probe methods for "any" probe.  */
>> +
>> +class any_static_probe_ops : public static_probe_ops
>> +{
>> +public:
>> +  /* See probe.h.  */
>> +  bool is_linespec (const char **linespecp) const override;
>> +
>> +  /* See probe.h.  */
>> +  void get_probes (std::vector<probe *> *probesp,
>> +		   struct objfile *objfile) const override;
>> +
>> +  /* See probe.h.  */
>> +  const char *type_name () const override;
>> +
>> +  /* See probe.h.  */
>> +  bool emit_info_probes_extra_fields () const override;
>
> I don't think we need this method (though maybe I'll get proven wrong
> by the rest of the series).  At least in this patch, we can just call
> gen_info_probes_table_header, and if the probe type doesn't supply
> any header, we'll just iterate on an empty vector, which is the same
> as returning early.

Ahm, you're right.  Now that I think about it I don't recall why I added
this method.  I'll delete it in the next version.

>> +
>> +  /* See probe.h.  */
>> +  void gen_info_probes_table_header
>> +    (std::vector<struct info_probe_column> *heads) const override;
>
> I am wondering if this can return the vector directly.  Combined with
> the suggestion above, it would simplify get_number_extra_fields, for example:
>
> static int
> get_number_extra_fields (const static_probe_ops *spops)
> {
>   return spops->gen_info_probes_table_header ().size ();
> }

I guess that works too.  I'll make the change.

>> +};
>> +
>> +/* Static operations associated with a generic probe.  */
>> +
>> +const any_static_probe_ops any_static_probe_ops;
>> +
>>  /* A helper for parse_probes that decodes a probe specification in
>>     SEARCH_PSPACE.  It appends matching SALs to RESULT.  */
>>  
>>  static void
>> -parse_probes_in_pspace (const struct probe_ops *probe_ops,
>> +parse_probes_in_pspace (const static_probe_ops *spops,
>>  			struct program_space *search_pspace,
>>  			const char *objfile_namestr,
>>  			const char *provider,
>> @@ -67,21 +94,21 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops,
>>  
>>        for (probe *p : probes)
>>  	{
>> -	  if (probe_ops != &probe_ops_any && p->pops != probe_ops)
>> +	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
>>  	    continue;
>>  
>> -	  if (provider && strcmp (p->provider, provider) != 0)
>> +	  if (provider && strcmp (p->get_provider (), provider) != 0)
>>  	    continue;
>>  
>> -	  if (strcmp (p->name, name) != 0)
>> +	  if (strcmp (p->get_name (), name) != 0)
>>  	    continue;
>>  
>>  	  symtab_and_line sal;
>> -	  sal.pc = get_probe_address (p, objfile);
>> +	  sal.pc = p->get_relocated_address (objfile);
>>  	  sal.explicit_pc = 1;
>>  	  sal.section = find_pc_overlay (sal.pc);
>>  	  sal.pspace = search_pspace;
>> -	  sal.probe = p;
>> +	  sal.prob = p;
>>  	  sal.objfile = objfile;
>>  
>>  	  result->push_back (std::move (sal));
>> @@ -98,15 +125,14 @@ parse_probes (const struct event_location *location,
>>  {
>>    char *arg_end, *arg;
>>    char *objfile_namestr = NULL, *provider = NULL, *name, *p;
>> -  const struct probe_ops *probe_ops;
>>    const char *arg_start, *cs;
>>  
>>    gdb_assert (event_location_type (location) == PROBE_LOCATION);
>>    arg_start = get_probe_location (location);
>>  
>>    cs = arg_start;
>> -  probe_ops = probe_linespec_to_ops (&cs);
>> -  if (probe_ops == NULL)
>> +  const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
>> +  if (spops == NULL)
>>      error (_("'%s' is not a probe linespec"), arg_start);
>>  
>>    arg = (char *) cs;
>> @@ -159,7 +185,7 @@ parse_probes (const struct event_location *location,
>>    std::vector<symtab_and_line> result;
>>    if (search_pspace != NULL)
>>      {
>> -      parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
>> +      parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
>>  			      provider, name, &result);
>>      }
>>    else
>> @@ -167,7 +193,7 @@ parse_probes (const struct event_location *location,
>>        struct program_space *pspace;
>>  
>>        ALL_PSPACES (pspace)
>> -	parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
>> +	parse_probes_in_pspace (spops, pspace, objfile_namestr,
>>  				provider, name, &result);
>>      }
>>  
>> @@ -206,10 +232,10 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider,
>>      = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
>>    for (probe *p : probes)
>>      {
>> -      if (strcmp (p->provider, provider) != 0)
>> +      if (strcmp (p->get_provider (), provider) != 0)
>>  	continue;
>>  
>> -      if (strcmp (p->name, name) != 0)
>> +      if (strcmp (p->get_name (), name) != 0)
>>  	continue;
>>  
>>        result.push_back (p);
>> @@ -227,7 +253,7 @@ find_probe_by_pc (CORE_ADDR pc)
>>    struct bound_probe result;
>>  
>>    result.objfile = NULL;
>> -  result.probe = NULL;
>> +  result.prob = NULL;
>>  
>>    ALL_OBJFILES (objfile)
>>    {
>> @@ -239,10 +265,10 @@ find_probe_by_pc (CORE_ADDR pc)
>>      const std::vector<probe *> &probes
>>        = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
>>      for (probe *p : probes)
>> -      if (get_probe_address (p, objfile) == pc)
>> +      if (p->get_relocated_address (objfile) == pc)
>>  	{
>>  	  result.objfile = objfile;
>> -	  result.probe = p;
>> +	  result.prob = p;
>>  	  return result;
>>  	}
>>    }
>> @@ -253,12 +279,13 @@ find_probe_by_pc (CORE_ADDR pc)
>>  \f
>>  
>>  /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
>> -   If POPS is not NULL, only probes of this certain probe_ops will match.
>> -   Each argument is a regexp, or NULL, which matches anything.  */
>> +   If SPOPS is not &any_static_probe_ops, only probes related to this
>> +   specific static probe ops will match.  Each argument is a regexp,
>> +   or NULL, which matches anything.  */
>>  
>>  static std::vector<bound_probe>
>>  collect_probes (const std::string &objname, const std::string &provider,
>> -		const std::string &probe_name, const struct probe_ops *pops)
>> +		const std::string &probe_name, const static_probe_ops *spops)
>>  {
>>    struct objfile *objfile;
>>    std::vector<bound_probe> result;
>> @@ -290,15 +317,15 @@ collect_probes (const std::string &objname, const std::string &provider,
>>  
>>        for (probe *p : probes)
>>  	{
>> -	  if (pops != NULL && p->pops != pops)
>> +	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
>>  	    continue;
>>  
>>  	  if (prov_pat
>> -	      && prov_pat->exec (p->provider, 0, NULL, 0) != 0)
>> +	      && prov_pat->exec (p->get_provider (), 0, NULL, 0) != 0)
>>  	    continue;
>>  
>>  	  if (probe_pat
>> -	      && probe_pat->exec (p->name, 0, NULL, 0) != 0)
>> +	      && probe_pat->exec (p->get_name (), 0, NULL, 0) != 0)
>>  	    continue;
>>  
>>  	  result.emplace_back (p, objfile);
>> @@ -315,16 +342,16 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>>  {
>>    int v;
>>  
>> -  v = strcmp (a.probe->provider, b.probe->provider);
>> +  v = strcmp (a.prob->get_provider (), b.prob->get_provider ());
>>    if (v != 0)
>>      return v < 0;
>>  
>> -  v = strcmp (a.probe->name, b.probe->name);
>> +  v = strcmp (a.prob->get_name (), b.prob->get_name ());
>>    if (v != 0)
>>      return v < 0;
>>  
>> -  if (a.probe->address != b.probe->address)
>> -    return a.probe->address < b.probe->address;
>> +  if (a.prob->get_address () != b.prob->get_address ())
>> +    return a.prob->get_address () < b.prob->get_address ();
>>  
>>    return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
>>  }
>> @@ -334,56 +361,37 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>>  
>>  static void
>>  gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
>> -			      const struct probe_ops *p)
>> +			      const static_probe_ops *spops)
>>  {
>>    /* `headings' refers to the names of the columns when printing `info
>>       probes'.  */
>> -  VEC (info_probe_column_s) *headings = NULL;
>> -  struct cleanup *c;
>> -  info_probe_column_s *column;
>> -  size_t headings_size;
>> -  int ix;
>> +  std::vector<struct info_probe_column> headings;
>>  
>> -  gdb_assert (p != NULL);
>> +  gdb_assert (spops != NULL);
>>  
>> -  if (p->gen_info_probes_table_header == NULL
>> -      && p->gen_info_probes_table_values == NULL)
>> +  if (!spops->emit_info_probes_extra_fields ())
>>      return;
>>  
>> -  gdb_assert (p->gen_info_probes_table_header != NULL
>> -	      && p->gen_info_probes_table_values != NULL);
>> -
>> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
>> -  p->gen_info_probes_table_header (&headings);
>> -
>> -  headings_size = VEC_length (info_probe_column_s, headings);
>> +  spops->gen_info_probes_table_header (&headings);
>>  
>> -  for (ix = 0;
>> -       VEC_iterate (info_probe_column_s, headings, ix, column);
>> -       ++ix)
>> +  for (struct info_probe_column column : headings)
>>      {
>> -      size_t size_max = strlen (column->print_name);
>> +      size_t size_max = strlen (column.print_name);
>>  
>>        for (const bound_probe &probe : probes)
>>  	{
>>  	  /* `probe_fields' refers to the values of each new field that this
>>  	     probe will display.  */
>> -	  VEC (const_char_ptr) *probe_fields = NULL;
>> -	  struct cleanup *c2;
>> -	  const char *val;
>> -	  int kx;
>> +	  std::vector<const char *> probe_fields;
>>  
>> -	  if (probe.probe->pops != p)
>> +	  if (probe.prob->get_static_ops () != spops)
>>  	    continue;
>>  
>> -	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
>> -	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
>> +	  probe.prob->gen_info_probes_table_values (&probe_fields);
>>  
>> -	  gdb_assert (VEC_length (const_char_ptr, probe_fields)
>> -		      == headings_size);
>> +	  gdb_assert (probe_fields.size () == headings.size ());
>>  
>> -	  for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
>> -	       ++kx)
>> +	  for (const char *val : probe_fields)
>>  	    {
>>  	      /* It is valid to have a NULL value here, which means that the
>>  		 backend does not have something to write and this particular
>> @@ -393,128 +401,92 @@ gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
>>  
>>  	      size_max = std::max (strlen (val), size_max);
>>  	    }
>> -	  do_cleanups (c2);
>>  	}
>>  
>>        current_uiout->table_header (size_max, ui_left,
>> -				   column->field_name, column->print_name);
>> +				   column.field_name, column.print_name);
>>      }
>> -
>> -  do_cleanups (c);
>>  }
>>  
>>  /* Helper function to print not-applicable strings for all the extra
>> -   columns defined in a probe_ops.  */
>> +   columns defined in a static_probe_ops.  */
>>  
>>  static void
>> -print_ui_out_not_applicables (const struct probe_ops *pops)
>> +print_ui_out_not_applicables (const static_probe_ops *spops)
>>  {
>>    struct cleanup *c;
>
> This variable is now unused.

Ops, removed.

>> -  VEC (info_probe_column_s) *headings = NULL;
>> -  info_probe_column_s *column;
>> -  int ix;
>> +  std::vector<struct info_probe_column> headings;
>>  
>> -  if (pops->gen_info_probes_table_header == NULL)
>> +  if (!spops->emit_info_probes_extra_fields ())
>>      return;
>>  
>> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
>> -  pops->gen_info_probes_table_header (&headings);
>> -
>> -  for (ix = 0;
>> -       VEC_iterate (info_probe_column_s, headings, ix, column);
>> -       ++ix)
>> -    current_uiout->field_string (column->field_name, _("n/a"));
>> +  spops->gen_info_probes_table_header (&headings);
>>  
>> -  do_cleanups (c);
>> +  for (struct info_probe_column column : headings)
>> +    current_uiout->field_string (column.field_name, _("n/a"));
>>  }
>>  
>>  /* Helper function to print extra information about a probe and an objfile
>>     represented by PROBE.  */
>>  
>>  static void
>> -print_ui_out_info (struct probe *probe)
>> +print_ui_out_info (probe *probe)
>>  {
>> -  int ix;
>> -  int j = 0;
>>    /* `values' refers to the actual values of each new field in the output
>>       of `info probe'.  `headings' refers to the names of each new field.  */
>> -  VEC (const_char_ptr) *values = NULL;
>> -  VEC (info_probe_column_s) *headings = NULL;
>> -  info_probe_column_s *column;
>> -  struct cleanup *c;
>> +  std::vector<struct info_probe_column> headings;
>> +  std::vector<const char *> values;
>> +  struct info_probe_column *column;
>
> This variable is unused (build probe.c with -Wunused to see all of them).

OK, removed all the instances of unused vars, thanks.

>>  
>>    gdb_assert (probe != NULL);
>> -  gdb_assert (probe->pops != NULL);
>>  
>> -  if (probe->pops->gen_info_probes_table_header == NULL
>> -      && probe->pops->gen_info_probes_table_values == NULL)
>> -    return;
>> +  probe->get_static_ops ()->gen_info_probes_table_header (&headings);
>> +  probe->gen_info_probes_table_values (&values);
>>  
>> -  gdb_assert (probe->pops->gen_info_probes_table_header != NULL
>> -	      && probe->pops->gen_info_probes_table_values != NULL);
>> +  gdb_assert (headings.size () == values.size ());
>>  
>> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
>> -  make_cleanup (VEC_cleanup (const_char_ptr), &values);
>> -
>> -  probe->pops->gen_info_probes_table_header (&headings);
>> -  probe->pops->gen_info_probes_table_values (probe, &values);
>> -
>> -  gdb_assert (VEC_length (info_probe_column_s, headings)
>> -	      == VEC_length (const_char_ptr, values));
>> -
>> -  for (ix = 0;
>> -       VEC_iterate (info_probe_column_s, headings, ix, column);
>> -       ++ix)
>> +  for (int ix = 0; ix < headings.size (); ++ix)
>>      {
>> -      const char *val = VEC_index (const_char_ptr, values, j++);
>> +      struct info_probe_column column = headings[ix];
>> +      const char *val = values[ix];
>>  
>>        if (val == NULL)
>> -	current_uiout->field_skip (column->field_name);
>> +	current_uiout->field_skip (column.field_name);
>>        else
>> -	current_uiout->field_string (column->field_name, val);
>> +	current_uiout->field_string (column.field_name, val);
>>      }
>> -
>> -  do_cleanups (c);
>>  }
>>  
>>  /* Helper function that returns the number of extra fields which POPS will
>>     need.  */
>>  
>>  static int
>> -get_number_extra_fields (const struct probe_ops *pops)
>> +get_number_extra_fields (const static_probe_ops *spops)
>>  {
>> -  VEC (info_probe_column_s) *headings = NULL;
>> -  struct cleanup *c;
>> -  int n;
>> +  std::vector<info_probe_column> headings;
>>  
>> -  if (pops->gen_info_probes_table_header == NULL)
>> +  if (!spops->emit_info_probes_extra_fields ())
>>      return 0;
>>  
>> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
>> -  pops->gen_info_probes_table_header (&headings);
>> -
>> -  n = VEC_length (info_probe_column_s, headings);
>> +  spops->gen_info_probes_table_header (&headings);
>>  
>> -  do_cleanups (c);
>> -
>> -  return n;
>> +  return headings.size ();
>>  }
>>  
>> -/* Helper function that returns 1 if there is a probe in PROBES
>> -   featuring the given POPS.  It returns 0 otherwise.  */
>> +/* Helper function that returns true if there is a probe in PROBES
>> +   featuring the given SPOPS.  It returns false otherwise.  */
>>  
>> -static int
>> -exists_probe_with_pops (const std::vector<bound_probe> &probes,
>> -			const struct probe_ops *pops)
>> +static bool
>> +exists_probe_with_spops (const std::vector<bound_probe> &probes,
>> +			 const static_probe_ops *spops)
>>  {
>>    struct bound_probe *probe;
>> -  int ix;
>>  
>>    for (const bound_probe &probe : probes)
>> -    if (probe.probe->pops == pops)
>> -      return 1;
>> +    if (probe.prob->get_static_ops () == spops)
>> +      return true;
>>  
>> -  return 0;
>> +  return false;
>>  }
>>  
>>  /* Helper function that parses a probe linespec of the form [PROVIDER
>> @@ -538,8 +510,8 @@ parse_probe_linespec (const char *str, std::string *provider,
>>  /* See comment in probe.h.  */
>>  
>>  void
>> -info_probes_for_ops (const char *arg, int from_tty,
>> -		     const struct probe_ops *pops)
>> +info_probes_for_spops (const char *arg, int from_tty,
>> +		       const static_probe_ops *spops)
>>  {
>>    std::string provider, probe_name, objname;
>>    int any_found;
>> @@ -554,26 +526,28 @@ info_probes_for_ops (const char *arg, int from_tty,
>>    parse_probe_linespec (arg, &provider, &probe_name, &objname);
>>  
>>    std::vector<bound_probe> probes
>> -    = collect_probes (objname, provider, probe_name, pops);
>> +    = collect_probes (objname, provider, probe_name, spops);
>>  
>> -  if (pops == NULL)
>> +  if (spops == &any_static_probe_ops)
>>      {
>> -      /* If the probe_ops is NULL, it means the user has requested a "simple"
>> -	 `info probes', i.e., she wants to print all information about all
>> -	 probes.  For that, we have to identify how many extra fields we will
>> -	 need to add in the ui_out table.
>> -
>> -	 To do that, we iterate over all probe_ops, querying each one about
>> -	 its extra fields, and incrementing `ui_out_extra_fields' to reflect
>> -	 that number.  But note that we ignore the probe_ops for which no probes
>> -	 are defined with the given search criteria.  */
>> -
>> -      for (const probe_ops *po : all_probe_ops)
>> -	if (exists_probe_with_pops (probes, po))
>> +      /* If SPOPS is &any_static_probe_ops, it means the user has
>> +	 requested a "simple" `info probes', i.e., she wants to print
>> +	 all information about all probes.  For that, we have to
>> +	 identify how many extra fields we will need to add in the
>> +	 ui_out table.
>> +
>> +	 To do that, we iterate over all static_probe_ops, querying
>> +	 each one about its extra fields, and incrementing
>> +	 `ui_out_extra_fields' to reflect that number.  But note that
>> +	 we ignore the static_probe_ops for which no probes are
>> +	 defined with the given search criteria.  */
>> +
>> +      for (const static_probe_ops *po : all_static_probe_ops)
>> +	if (exists_probe_with_spops (probes, po))
>>  	  ui_out_extra_fields += get_number_extra_fields (po);
>>      }
>>    else
>> -    ui_out_extra_fields = get_number_extra_fields (pops);
>> +    ui_out_extra_fields = get_number_extra_fields (spops);
>>  
>>    {
>>      ui_out_emit_table table_emitter (current_uiout,
>> @@ -589,11 +563,12 @@ info_probes_for_ops (const char *arg, int from_tty,
>>         `name' and `objname').  */
>>      for (const bound_probe &probe : probes)
>>        {
>> -	const char *probe_type = probe.probe->pops->type_name (probe.probe);
>> +	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
>>  
>>  	size_type = std::max (strlen (probe_type), size_type);
>> -	size_name = std::max (strlen (probe.probe->name), size_name);
>> -	size_provider = std::max (strlen (probe.probe->provider), size_provider);
>> +	size_name = std::max (strlen (probe.prob->get_name ()), size_name);
>> +	size_provider = std::max (strlen (probe.prob->get_provider ()),
>> +				  size_provider);
>>  	size_objname = std::max (strlen (objfile_name (probe.objfile)),
>>  				 size_objname);
>>        }
>> @@ -604,44 +579,46 @@ info_probes_for_ops (const char *arg, int from_tty,
>>      current_uiout->table_header (size_name, ui_left, "name", _("Name"));
>>      current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
>>  
>> -    if (pops == NULL)
>> +    if (spops == &any_static_probe_ops)
>>        {
>>  	/* We have to generate the table header for each new probe type
>>  	   that we will print.  Note that this excludes probe types not
>>  	   having any defined probe with the search criteria.  */
>> -	for (const probe_ops *po : all_probe_ops)
>> -	  if (exists_probe_with_pops (probes, po))
>> +	for (const static_probe_ops *po : all_static_probe_ops)
>> +	  if (exists_probe_with_spops (probes, po))
>>  	    gen_ui_out_table_header_info (probes, po);
>>        }
>>      else
>> -      gen_ui_out_table_header_info (probes, pops);
>> +      gen_ui_out_table_header_info (probes, spops);
>>  
>>      current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
>>      current_uiout->table_body ();
>>  
>>      for (const bound_probe &probe : probes)
>>        {
>> -	const char *probe_type = probe.probe->pops->type_name (probe.probe);
>> +	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
>>  
>>  	ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
>>  
>> -	current_uiout->field_string ("type",probe_type);
>> -	current_uiout->field_string ("provider", probe.probe->provider);
>> -	current_uiout->field_string ("name", probe.probe->name);
>> -	current_uiout->field_core_addr ("addr", probe.probe->arch,
>> -					get_probe_address (probe.probe,
>> -							   probe.objfile));
>> +	current_uiout->field_string ("type", probe_type);
>> +	current_uiout->field_string ("provider", probe.prob->get_provider ());
>> +	current_uiout->field_string ("name", probe.prob->get_name ());
>> +	current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
>> +					probe.prob->get_relocated_address
>> +					(probe.objfile));
>>  
>> -	if (pops == NULL)
>> +	if (spops == &any_static_probe_ops)
>>  	  {
>> -	    for (const probe_ops *po : all_probe_ops)
>> -	      if (probe.probe->pops == po)
>> -		print_ui_out_info (probe.probe);
>> -	      else if (exists_probe_with_pops (probes, po))
>> -		print_ui_out_not_applicables (po);
>> +	    for (const static_probe_ops *po : all_static_probe_ops)
>> +	      {
>> +		if (probe.prob->get_static_ops () == po)
>> +		  print_ui_out_info (probe.prob);
>> +		else if (exists_probe_with_spops (probes, po))
>> +		  print_ui_out_not_applicables (po);
>> +	      }
>>  	  }
>>  	else
>> -	  print_ui_out_info (probe.probe);
>> +	  print_ui_out_info (probe.prob);
>>  
>>  	current_uiout->field_string ("object",
>>  				     objfile_name (probe.objfile));
>> @@ -660,7 +637,7 @@ info_probes_for_ops (const char *arg, int from_tty,
>>  static void
>>  info_probes_command (const char *arg, int from_tty)
>>  {
>> -  info_probes_for_ops (arg, from_tty, NULL);
>> +  info_probes_for_spops (arg, from_tty, &any_static_probe_ops);
>>  }
>>  
>>  /* Implementation of the `enable probes' command.  */
>> @@ -673,7 +650,7 @@ enable_probes_command (const char *arg, int from_tty)
>>    parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
>>  
>>    std::vector<bound_probe> probes
>> -    = collect_probes (objname, provider, probe_name, NULL);
>> +    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
>>    if (probes.empty ())
>>      {
>>        current_uiout->message (_("No probes matched.\n"));
>> @@ -684,17 +661,17 @@ enable_probes_command (const char *arg, int from_tty)
>>       notion of enabling a probe.  */
>>    for (const bound_probe &probe: probes)
>>      {
>> -      const struct probe_ops *pops = probe.probe->pops;
>> -
>> -      if (pops->enable_probe != NULL)
>> +      if (probe.prob->can_enable ())
>>  	{
>> -	  pops->enable_probe (probe.probe);
>> +	  probe.prob->enable ();
>>  	  current_uiout->message (_("Probe %s:%s enabled.\n"),
>> -				  probe.probe->provider, probe.probe->name);
>> +				  probe.prob->get_provider (),
>> +				  probe.prob->get_name ());
>>  	}
>>        else
>>  	current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
>> -				probe.probe->provider, probe.probe->name);
>> +				probe.prob->get_provider (),
>> +				probe.prob->get_name ());
>>      }
>>  }
>>  
>> @@ -708,7 +685,7 @@ disable_probes_command (const char *arg, int from_tty)
>>    parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
>>  
>>    std::vector<bound_probe> probes
>> -    = collect_probes (objname, provider, probe_name, NULL /* pops */);
>> +    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
>>    if (probes.empty ())
>>      {
>>        current_uiout->message (_("No probes matched.\n"));
>> @@ -719,55 +696,22 @@ disable_probes_command (const char *arg, int from_tty)
>>       notion of enabling a probe.  */
>>    for (const bound_probe &probe : probes)
>>      {
>> -      const struct probe_ops *pops = probe.probe->pops;
>> -
>> -      if (pops->disable_probe != NULL)
>> +      if (probe.prob->can_enable ())
>>  	{
>> -	  pops->disable_probe (probe.probe);
>> +	  probe.prob->disable ();
>>  	  current_uiout->message (_("Probe %s:%s disabled.\n"),
>> -				  probe.probe->provider, probe.probe->name);
>> +				  probe.prob->get_provider (),
>> +				  probe.prob->get_name ());
>>  	}
>>        else
>>  	current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
>> -				probe.probe->provider, probe.probe->name);
>> +				probe.prob->get_provider (),
>> +				probe.prob->get_name ());
>>      }
>>  }
>>  
>>  /* See comments in probe.h.  */
>>  
>> -CORE_ADDR
>> -get_probe_address (struct probe *probe, struct objfile *objfile)
>> -{
>> -  return probe->pops->get_probe_address (probe, objfile);
>> -}
>> -
>> -/* See comments in probe.h.  */
>> -
>> -unsigned
>> -get_probe_argument_count (struct probe *probe, struct frame_info *frame)
>> -{
>> -  return probe->pops->get_probe_argument_count (probe, frame);
>> -}
>> -
>> -/* See comments in probe.h.  */
>> -
>> -int
>> -can_evaluate_probe_arguments (struct probe *probe)
>> -{
>> -  return probe->pops->can_evaluate_probe_arguments (probe);
>> -}
>> -
>> -/* See comments in probe.h.  */
>> -
>> -struct value *
>> -evaluate_probe_argument (struct probe *probe, unsigned n,
>> -			 struct frame_info *frame)
>> -{
>> -  return probe->pops->evaluate_probe_argument (probe, n, frame);
>> -}
>> -
>> -/* See comments in probe.h.  */
>> -
>>  struct value *
>>  probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
>>  {
>> @@ -775,22 +719,22 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
>>    unsigned n_args;
>>  
>>    probe = find_probe_by_pc (get_frame_pc (frame));
>> -  if (!probe.probe)
>> +  if (!probe.prob)
>>      return NULL;
>>  
>> -  n_args = get_probe_argument_count (probe.probe, frame);
>> +  n_args = probe.prob->get_argument_count (frame);
>>    if (n >= n_args)
>>      return NULL;
>>  
>> -  return evaluate_probe_argument (probe.probe, n, frame);
>> +  return probe.prob->evaluate_argument (n, frame);
>>  }
>>  
>>  /* See comment in probe.h.  */
>>  
>> -const struct probe_ops *
>> -probe_linespec_to_ops (const char **linespecp)
>> +const struct static_probe_ops *
>> +probe_linespec_to_static_ops (const char **linespecp)
>>  {
>> -  for (const probe_ops *ops : all_probe_ops)
>> +  for (const static_probe_ops *ops : all_static_probe_ops)
>>      if (ops->is_linespec (linespecp))
>>        return ops;
>>  
>> @@ -820,31 +764,48 @@ probe_is_linespec_by_keyword (const char **linespecp, const char *const *keyword
>>    return 0;
>>  }
>>  
>> -/* Implementation of `is_linespec' method for `struct probe_ops'.  */
>> +/* Implementation of `is_linespec' method.  */
>>  
>> -static int
>> -probe_any_is_linespec (const char **linespecp)
>> +bool
>> +any_static_probe_ops::is_linespec (const char **linespecp) const
>>  {
>>    static const char *const keywords[] = { "-p", "-probe", NULL };
>>  
>>    return probe_is_linespec_by_keyword (linespecp, keywords);
>>  }
>>  
>> -/* Dummy method used for `probe_ops_any'.  */
>> +/* Implementation of 'get_probes' method.  */
>>  
>> -static void
>> -probe_any_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
>> +void
>> +any_static_probe_ops::get_probes (std::vector<probe *> *probesp,
>> +				  struct objfile *objfile) const
>>  {
>>    /* No probes can be provided by this dummy backend.  */
>>  }
>>  
>> -/* Operations associated with a generic probe.  */
>> +/* Implementation of the 'type_name' method.  */
>>  
>> -const struct probe_ops probe_ops_any =
>> +const char *
>> +any_static_probe_ops::type_name () const
>>  {
>> -  probe_any_is_linespec,
>> -  probe_any_get_probes,
>> -};
>> +  return NULL;
>> +}
>> +
>> +/* Implementation of the 'emit_info_probes_extra_fields' method.  */
>> +
>> +bool
>> +any_static_probe_ops::emit_info_probes_extra_fields () const
>> +{
>> +  return false;
>> +}
>> +
>> +/* Implementation of the 'gen_info_probes_table_header' method.  */
>> +
>> +void
>> +any_static_probe_ops::gen_info_probes_table_header
>> +  (std::vector<struct info_probe_column> *heads) const
>> +{
>> +}
>>  
>>  /* See comments in probe.h.  */
>>  
>> @@ -890,10 +851,10 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
>>    gdb_assert (sel >= -1);
>>  
>>    pc_probe = find_probe_by_pc (pc);
>> -  if (pc_probe.probe == NULL)
>> +  if (pc_probe.prob == NULL)
>>      error (_("No probe at PC %s"), core_addr_to_string (pc));
>>  
>> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
>> +  n_args = pc_probe.prob->get_argument_count (frame);
>>    if (sel == -1)
>>      return value_from_longest (builtin_type (arch)->builtin_int, n_args);
>>  
>> @@ -901,7 +862,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
>>      error (_("Invalid probe argument %d -- probe has %u arguments available"),
>>  	   sel, n_args);
>>  
>> -  return evaluate_probe_argument (pc_probe.probe, sel, frame);
>> +  return pc_probe.prob->evaluate_argument (sel, frame);
>>  }
>>  
>>  /* This is called to compile one of the $_probe_arg* convenience
>> @@ -922,10 +883,10 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
>>    gdb_assert (sel >= -1);
>>  
>>    pc_probe = find_probe_by_pc (pc);
>> -  if (pc_probe.probe == NULL)
>> +  if (pc_probe.prob == NULL)
>>      error (_("No probe at PC %s"), core_addr_to_string (pc));
>>  
>> -  n_args = get_probe_argument_count (pc_probe.probe, frame);
>> +  n_args = pc_probe.prob->get_argument_count (frame);
>>  
>>    if (sel == -1)
>>      {
>> @@ -940,7 +901,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
>>      error (_("Invalid probe argument %d -- probe has %d arguments available"),
>>  	   sel, n_args);
>>  
>> -  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
>> +  pc_probe.prob->compile_to_ax (expr, value, sel);
>>  }
>>  
>>  static const struct internalvar_funcs probe_funcs =
>> @@ -951,12 +912,12 @@ static const struct internalvar_funcs probe_funcs =
>>  };
>>  
>>  
>> -std::vector<const probe_ops *> all_probe_ops;
>> +std::vector<const static_probe_ops *> all_static_probe_ops;
>>  
>>  void
>>  _initialize_probe (void)
>>  {
>> -  all_probe_ops.push_back (&probe_ops_any);
>> +  all_static_probe_ops.push_back (&any_static_probe_ops);
>>  
>>    create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
>>  				(void *) (uintptr_t) -1);
>> diff --git a/gdb/probe.h b/gdb/probe.h
>> index 822e5c89a9..9ad183013b 100644
>> --- a/gdb/probe.h
>> +++ b/gdb/probe.h
>> @@ -30,7 +30,6 @@ struct info_probe_column
>>    {
>>      /* The internal name of the field.  This string cannot be capitalized nor
>>         localized, e.g., "extra_field".  */
>> -
>>      const char *field_name;
>>  
>>      /* The field name to be printed in the `info probes' command.  This
>> @@ -38,165 +37,206 @@ struct info_probe_column
>>      const char *print_name;
>>    };
>>  
>> -typedef struct info_probe_column info_probe_column_s;
>> -DEF_VEC_O (info_probe_column_s);
>> -
>> -/* Operations associated with a probe.  */
>> -
>> -struct probe_ops
>> -  {
>> -    /* Method responsible for verifying if LINESPECP is a valid linespec for
>> -       a probe breakpoint.  It should return 1 if it is, or zero if it is not.
>> -       It also should update LINESPECP in order to discard the breakpoint
>> -       option associated with this linespec.  For example, if the option is
>> -       `-probe', and the LINESPECP is `-probe abc', the function should
>> -       return 1 and set LINESPECP to `abc'.  */
>> -
>> -    int (*is_linespec) (const char **linespecp);
>> -
>> -    /* Function that should fill PROBES with known probes from OBJFILE.  */
>> -
>> -    void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile);
>> -
>> -    /* Compute the probe's relocated address.  OBJFILE is the objfile
>> -       in which the probe originated.  */
>> -
>> -    CORE_ADDR (*get_probe_address) (struct probe *probe,
>> -				    struct objfile *objfile);
>> -
>> -    /* Return the number of arguments of PROBE.  This function can
>> -       throw an exception.  */
>> -
>> -    unsigned (*get_probe_argument_count) (struct probe *probe,
>> -					  struct frame_info *frame);
>> -
>> -    /* Return 1 if the probe interface can evaluate the arguments of probe
>> -       PROBE, zero otherwise.  See the comments on
>> -       sym_probe_fns:can_evaluate_probe_arguments for more details.  */
>> -
>> -    int (*can_evaluate_probe_arguments) (struct probe *probe);
>
> This could return a bool.

This function was renamed to 'can_evaluate_arguments', but yeah, updated.

>> -
>> -    /* Evaluate the Nth argument from the PROBE, returning a value
>> -       corresponding to it.  The argument number is represented N.
>> -       This function can throw an exception.  */
>> -
>> -    struct value *(*evaluate_probe_argument) (struct probe *probe,
>> -					      unsigned n,
>> -					      struct frame_info *frame);
>> -
>> -    /* Compile the Nth argument of the PROBE to an agent expression.
>> -       The argument number is represented by N.  */
>> -
>> -    void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
>> -			   struct axs_value *axs_value, unsigned n);
>> +/* Operations that act on probes, but are specific to each backend.
>> +   These methods do not go into the 'class probe' because they do not
>> +   act on a single probe; instead, they are used to operate on many
>> +   probes at once, or to provide information about the probe backend
>> +   itself, instead of a single probe.
>>  
>> -    /* Set the semaphore associated with the PROBE.  This function only makes
>> -       sense if the probe has a concept of semaphore associated to a
>> -       probe, otherwise it can be set to NULL.  */
>> +   Each probe backend needs to inherit this class and implement all of
>> +   the virtual functions specified here.  Then, an object shall be
>> +   instantiated and added (or "registered") to the
>> +   ALL_STATIC_PROBE_OPS vector so that the frontend probe interface
>> +   can use it in the generic probe functions.  */
>>  
>> -    void (*set_semaphore) (struct probe *probe, struct objfile *objfile,
>> -			   struct gdbarch *gdbarch);
>> -
>> -    /* Clear the semaphore associated with the PROBE.  This function only
>> -       makes sense if the probe has a concept of semaphore associated to
>> -       a probe, otherwise it can be set to NULL.  */
>> -
>> -    void (*clear_semaphore) (struct probe *probe, struct objfile *objfile,
>> -			     struct gdbarch *gdbarch);
>> -
>> -    /* Function called to destroy PROBE's specific data.  This function
>> -       shall not free PROBE itself.  */
>> -
>> -    void (*destroy) (struct probe *probe);
>> -
>> -    /* Return a pointer to a name identifying the probe type.  This is
>> -       the string that will be displayed in the "Type" column of the
>> -       `info probes' command.  */
>> +class static_probe_ops
>> +{
>> +public:
>> +  /* Method responsible for verifying if LINESPECP is a valid linespec
>> +     for a probe breakpoint.  It should return true if it is, or false
>> +     if it is not.  It also should update LINESPECP in order to
>> +     discard the breakpoint option associated with this linespec.  For
>> +     example, if the option is `-probe', and the LINESPECP is `-probe
>> +     abc', the function should return 1 and set LINESPECP to
>> +     `abc'.  */
>> +  virtual bool is_linespec (const char **linespecp) const = 0;
>> +
>> +  /* Function that should fill PROBES with known probes from OBJFILE.  */
>> +  virtual void get_probes (std::vector<probe *> *probes,
>> +			    struct objfile *objfile) const = 0;
>> +
>> +  /* Return a pointer to a name identifying the probe type.  This is
>> +     the string that will be displayed in the "Type" column of the
>> +     `info probes' command.  */
>> +  virtual const char *type_name () const = 0;
>> +
>> +  /* Return true if the probe type will emit extra fields when the
>> +     user issues a "info probes" command.  If this function returns
>> +     false, then GEN_INFO_PROBES_TABLE_HEADER and
>> +     GEN_INFO_PROBES_TABLE_VALUES are not used.  */
>> +  virtual bool emit_info_probes_extra_fields () const = 0;
>> +
>> +  /* Function responsible for providing the extra fields that will be
>> +     printed in the `info probes' command.  It should fill HEADS
>> +     with whatever extra fields it needs.  If no extra fields are
>> +     required by the probe backend, the method EMIT_INFO_PROBES_FIELDS
>> +     should return false.  */
>> +  virtual void gen_info_probes_table_header
>> +    (std::vector<struct info_probe_column> *heads) const = 0;
>> +};
>>  
>> -    const char *(*type_name) (struct probe *probe);
>> +/* Definition of a vector of static_probe_ops.  */
>>  
>> -    /* Function responsible for providing the extra fields that will be
>> -       printed in the `info probes' command.  It should fill HEADS
>> -       with whatever extra fields it needs.  If the backend doesn't need
>> -       to print extra fields, it can set this method to NULL.  */
>> +extern std::vector<const static_probe_ops *> all_static_probe_ops;
>>  
>> -    void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
>> +/* Helper function that, given KEYWORDS, iterate over it trying to match
>> +   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
>> +   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
>> +   is returned.  */
>>  
>> -    /* Function that will fill VALUES with the values of the extra fields
>> -       to be printed for PROBE.  If the backend implements the
>> -       `gen_ui_out_table_header' method, then it should implement
>> -       this method as well.  The backend should also guarantee that the
>> -       order and the number of values in the vector is exactly the same
>> -       as the order of the extra fields provided in the method
>> -       `gen_ui_out_table_header'.  If a certain field is to be skipped
>> -       when printing the information, you can push a NULL value in that
>> -       position in the vector.  */
>> +extern int probe_is_linespec_by_keyword (const char **linespecp,
>> +					 const char *const *keywords);
>>  
>> -    void (*gen_info_probes_table_values) (struct probe *probe,
>> -					  VEC (const_char_ptr) **values);
>> +/* Return specific STATIC_PROBE_OPS * matching *LINESPECP and possibly
>> +   updating LINESPECP to skip its "-probe-type " prefix.  Return
>> +   &static_probe_ops_any if LINESPECP matches "-probe ", that is any
>> +   unspecific probe.  Return NULL if LINESPECP is not identified as
>> +   any known probe type, *LINESPECP is not modified in such case.  */
>>  
>> -    /* Enable a probe.  The semantics of "enabling" a probe depend on
>> -       the specific backend and the field can be NULL in case enabling
>> -       probes is not supported.  This function can throw an
>> -       exception.  */
>> +extern const static_probe_ops *
>> +  probe_linespec_to_static_ops (const char **linespecp);
>>  
>> -    void (*enable_probe) (struct probe *probe);
>> +/* The probe itself.  The class contains generic information about the
>> +   probe.  */
>>  
>> -    /* Disable a probe.  The semantics of "disabling" a probe depend
>> -       on the specific backend and the field can be NULL in case
>> -       disabling probes is not supported.  This function can throw an
>> -       exception.  */
>> +class probe
>> +{
>> +public:
>> +  /* Default constructor for a probe.  */
>> +  probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
>> +	 struct gdbarch *arch_)
>> +    : m_name (std::move (name_)), m_provider (std::move (provider_)),
>> +      m_address (address_), m_arch (arch_)
>> +  {}
>>  
>> -    void (*disable_probe) (struct probe *probe);
>> -  };
>> +  /* Virtual destructor.  */
>> +  virtual ~probe ()
>> +  {}
>>  
>> -/* Definition of a vector of probe_ops.  */
>> +  /* Compute the probe's relocated address.  OBJFILE is the objfile
>> +     in which the probe originated.  */
>> +  virtual CORE_ADDR get_relocated_address (struct objfile *objfile) = 0;
>> +
>> +  /* Return the number of arguments of the probe.  This function can
>> +     throw an exception.  */
>> +  virtual unsigned get_argument_count (struct frame_info *frame) = 0;
>> +
>> +  /* Return 1 if the probe interface can evaluate the arguments of
>> +     probe, zero otherwise.  See the comments on
>> +     sym_probe_fns:can_evaluate_probe_arguments for more
>> +     details.  */
>> +  virtual int can_evaluate_arguments () const = 0;
>> +
>> +  /* Evaluate the Nth argument from the probe, returning a value
>> +     corresponding to it.  The argument number is represented N.
>> +     This function can throw an exception.  */
>> +  virtual struct value *evaluate_argument (unsigned n,
>> +					   struct frame_info *frame) = 0;
>> +
>> +  /* Compile the Nth argument of the probe to an agent expression.
>> +     The argument number is represented by N.  */
>> +  virtual void compile_to_ax (struct agent_expr *aexpr,
>> +			      struct axs_value *axs_value,
>> +			      unsigned n) = 0;
>> +
>> +  /* Set the semaphore associated with the probe.  This function only
>> +     makes sense if the probe has a concept of semaphore associated to
>> +     a probe.  */
>> +  virtual void set_semaphore (struct objfile *objfile,
>> +			      struct gdbarch *gdbarch)
>> +  {}
>>  
>> -extern std::vector<const probe_ops *> all_probe_ops;
>> +  /* Clear the semaphore associated with the probe.  This function
>> +     only makes sense if the probe has a concept of semaphore
>> +     associated to a probe.  */
>> +  virtual void clear_semaphore (struct objfile *objfile,
>> +				struct gdbarch *gdbarch)
>> +  {}
>>  
>> -/* The probe_ops associated with the generic probe.  */
>> +  /* Return the pointer to the static_probe_ops instance related to
>> +     the probe type.  */
>> +  virtual const static_probe_ops *get_static_ops () const = 0;
>> +
>> +  /* Function that will fill VALUES with the values of the extra
>> +     fields to be printed for the probe.
>> +
>> +     If the backend implements the `gen_ui_out_table_header' method,
>> +     then it should implement this method as well.  The backend should
>> +     also guarantee that the order and the number of values in the
>> +     vector is exactly the same as the order of the extra fields
>> +     provided in the method `gen_ui_out_table_header'.  If a certain
>> +     field is to be skipped when printing the information, you can
>> +     push a NULL value in that position in the vector.  */
>> +  virtual void gen_info_probes_table_values
>> +    (std::vector<const char *> *values) const
>> +  {}
>>  
>> -extern const struct probe_ops probe_ops_any;
>> +  /* Return true if the probe can be enabled; false otherwise.  */
>> +  virtual bool can_enable () const
>> +  {
>> +    return false;
>> +  }
>>  
>> -/* Helper function that, given KEYWORDS, iterate over it trying to match
>> -   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
>> -   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
>> -   is returned.  */
>> +  /* Enable the probe.  The semantics of "enabling" a probe depend on
>> +     the specific backend.  This function can throw an exception.  */
>> +  virtual void enable ()
>> +  {}
>>  
>> -extern int probe_is_linespec_by_keyword (const char **linespecp,
>> -					 const char *const *keywords);
>> +  /* Disable the probe.  The semantics of "disabling" a probe depend
>> +     on the specific backend.  This function can throw an
>> +     exception.  */
>> +  virtual void disable ()
>> +  {}
>>  
>> -/* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
>> -   *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
>> -   *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
>> -   *LINESPECP is not identified as any known probe type, *LINESPECP is not
>> -   modified in such case.  */
>> +  /* Getter for M_NAME.  */
>> +  const char *get_name () const
>> +  {
>> +    return m_name.c_str ();
>> +  }
>>  
>> -extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
>> +  /* Getter for M_PROVIDER.  */
>> +  const char *get_provider () const
>> +  {
>> +    return m_provider.c_str ();
>> +  }
>
> I'd suggest making get_name and get_provider return an std::string.
> Most usages use strcmp/strlen, which can be replaced with their C++
> equivalent.  Other usages are used to pass to uiout methods, like
> field_string.  I think we could add an overload to these methods
> that take a const std::string& instead of a const char *, for
> convenience.  But I'm fine if we do it in another patchset, so you
> don't have to complicate things for nothing in this patchset.

OK, no problem.  Converted to const std::string&.

>>  
>> -/* The probe itself.  The struct contains generic information about the
>> -   probe, and then some specific information which should be stored in
>> -   the `probe_info' field.  */
>> +  /* Getter for M_ADDRESS.  */
>> +  CORE_ADDR get_address () const
>> +  {
>> +    return m_address;
>> +  }
>>  
>> -struct probe
>> +  /* Getter for M_ARCH.  */
>> +  struct gdbarch *get_gdbarch () const
>>    {
>> -    /* The operations associated with this probe.  */
>> -    const struct probe_ops *pops;
>> +    return m_arch;
>> +  }
>>  
>> -    /* The probe's architecture.  */
>> -    struct gdbarch *arch;
>> +private:
>> +  /* The name of the probe.  */
>> +  std::string m_name;
>>  
>> -    /* The name of the probe.  */
>> -    const char *name;
>> +  /* The provider of the probe.  It generally defaults to the name of
>> +     the objfile which contains the probe.  */
>> +  std::string m_provider;
>>  
>> -    /* The provider of the probe.  It generally defaults to the name of
>> -       the objfile which contains the probe.  */
>> -    const char *provider;
>> +  /* The address where the probe is inserted, relative to
>> +     SECT_OFF_TEXT.  */
>> +  CORE_ADDR m_address;
>>  
>> -    /* The address where the probe is inserted, relative to
>> -       SECT_OFF_TEXT.  */
>> -    CORE_ADDR address;
>> -  };
>> +  /* The probe's architecture.  */
>> +  struct gdbarch *m_arch;
>> +};
>>  
>>  /* A bound probe holds a pointer to a probe and a pointer to the
>>     probe's defining objfile.  This is needed because probes are
>> @@ -206,22 +246,18 @@ struct probe
>>  struct bound_probe
>>  {
>>    /* Create an empty bound_probe object.  */
>> -
>>    bound_probe ()
>>    {}
>>  
>>    /* Create and initialize a bound_probe object using PROBE and OBJFILE.  */
>> -
>> -  bound_probe (struct probe *probe_, struct objfile *objfile_)
>> -  : probe (probe_), objfile (objfile_)
>> +  bound_probe (probe *probe_, struct objfile *objfile_)
>> +  : prob (probe_), objfile (objfile_)
>>    {}
>>  
>>    /* The probe.  */
>> -
>> -  struct probe *probe = NULL;
>> +  probe *prob = NULL;
>>  
>>    /* The objfile in which the probe originated.  */
>> -
>>    struct objfile *objfile = NULL;
>>  };
>>  
>> @@ -234,11 +270,6 @@ extern std::vector<symtab_and_line> parse_probes
>>     struct program_space *pspace,
>>     struct linespec_result *canon);
>>  
>> -/* Helper function to register the proper probe_ops to a newly created probe.
>> -   This function is mainly called from `sym_get_probes'.  */
>> -
>> -extern void register_probe_ops (struct probe *probe);
>> -
>>  /* Given a PC, find an associated probe.  If a probe is found, return
>>     it.  If no probe is found, return a bound probe whose fields are
>>     both NULL.  */
>> @@ -253,13 +284,13 @@ 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
>> -   function that can be used by the probe backends to print their
>> -   `info probe TYPE'.  */
>> +/* Generate a `info probes' command output for probes associated with
>> +   SPOPS.  If SPOPS is related to the "any probe" type, then all probe
>> +   types are considered.  It is a helper function that can be used by
>> +   the probe backends to print their `info probe TYPE'.  */
>>  
>> -extern void info_probes_for_ops (const char *arg, int from_tty,
>> -				 const struct probe_ops *pops);
>> +extern void info_probes_for_spops (const char *arg, int from_tty,
>> +				   const static_probe_ops *spops);
>>  
>>  /* Return the `cmd_list_element' associated with the `info probes' command,
>>     or create a new one if it doesn't exist.  Helper function that serves the
>> @@ -268,34 +299,6 @@ extern void info_probes_for_ops (const char *arg, int from_tty,
>>  
>>  extern struct cmd_list_element **info_probes_cmdlist_get (void);
>>  
>> -/* Compute the probe's relocated address.  OBJFILE is the objfile in
>> -   which the probe originated.  */
>> -
>> -extern CORE_ADDR get_probe_address (struct probe *probe,
>> -				    struct objfile *objfile);
>> -
>> -/* Return the argument count of the specified probe.
>> -
>> -   This function can throw an exception.  */
>> -
>> -extern unsigned get_probe_argument_count (struct probe *probe,
>> -					  struct frame_info *frame);
>> -
>> -/* Return 1 if the probe interface associated with PROBE can evaluate
>> -   arguments, zero otherwise.  See the comments on the definition of
>> -   sym_probe_fns:can_evaluate_probe_arguments for more details.  */
>> -
>> -extern int can_evaluate_probe_arguments (struct probe *probe);
>> -
>> -/* Evaluate argument N of the specified probe.  N must be between 0
>> -   inclusive and get_probe_argument_count exclusive.
>> -
>> -   This function can throw an exception.  */
>> -
>> -extern struct value *evaluate_probe_argument (struct probe *probe,
>> -					      unsigned n,
>> -					      struct frame_info *frame);
>> -
>>  /* A convenience function that finds a probe at the PC in FRAME and
>>     evaluates argument N, with 0 <= N < number_of_args.  If there is no
>>     probe at that location, or if the probe does not have enough arguments,
>> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
>> index 5ec606de43..6e834fb5d7 100644
>> --- a/gdb/solib-svr4.c
>> +++ b/gdb/solib-svr4.c
>> @@ -351,7 +351,7 @@ struct svr4_info
>>    /* Table of struct probe_and_action instances, used by the
>>       probes-based interface to map breakpoint addresses to probes
>>       and their associated actions.  Lookup is performed using
>> -     probe_and_action->probe->address.  */
>> +     probe_and_action->prob->address.  */
>>    htab_t probes_table;
>>  
>>    /* List of objects loaded into the inferior, used by the probes-
>> @@ -1664,7 +1664,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ)
>>  struct probe_and_action
>>  {
>>    /* The probe.  */
>> -  struct probe *probe;
>> +  probe *prob;
>>  
>>    /* The relocated address of the probe.  */
>>    CORE_ADDR address;
>> @@ -1699,7 +1699,7 @@ equal_probe_and_action (const void *p1, const void *p2)
>>     probes table.  */
>>  
>>  static void
>> -register_solib_event_probe (struct probe *probe, CORE_ADDR address,
>> +register_solib_event_probe (probe *prob, CORE_ADDR address,
>>  			    enum probe_action action)
>>  {
>>    struct svr4_info *info = get_svr4_info ();
>> @@ -1712,13 +1712,13 @@ register_solib_event_probe (struct probe *probe, CORE_ADDR address,
>>  					    equal_probe_and_action,
>>  					    xfree, xcalloc, xfree);
>>  
>> -  lookup.probe = probe;
>> +  lookup.prob = prob;
>>    lookup.address = address;
>>    slot = htab_find_slot (info->probes_table, &lookup, INSERT);
>>    gdb_assert (*slot == HTAB_EMPTY_ENTRY);
>>  
>>    pa = XCNEW (struct probe_and_action);
>> -  pa->probe = probe;
>> +  pa->prob = prob;
>>    pa->address = address;
>>    pa->action = action;
>>  
>> @@ -1767,7 +1767,7 @@ solib_event_probe_action (struct probe_and_action *pa)
>>         arg2: struct link_map *new (optional, for incremental updates)  */
>>    TRY
>>      {
>> -      probe_argc = get_probe_argument_count (pa->probe, frame);
>> +      probe_argc = pa->prob->get_argument_count (frame);
>>      }
>>    CATCH (ex, RETURN_MASK_ERROR)
>>      {
>> @@ -1776,11 +1776,11 @@ solib_event_probe_action (struct probe_and_action *pa)
>>      }
>>    END_CATCH
>>  
>> -  /* If get_probe_argument_count throws an exception, probe_argc will
>> -     be set to zero.  However, if pa->probe does not have arguments,
>> -     then get_probe_argument_count will succeed but probe_argc will
>> -     also be zero.  Both cases happen because of different things, but
>> -     they are treated equally here: action will be set to
>> +  /* If get_argument_count throws an exception, probe_argc will be set
>> +     to zero.  However, if pa->prob does not have arguments, then
>> +     get_argument_count will succeed but probe_argc will also be zero.
>> +     Both cases happen because of different things, but they are
>> +     treated equally here: action will be set to
>>       PROBES_INTERFACE_FAILED.  */
>>    if (probe_argc == 2)
>>      action = FULL_RELOAD;
>> @@ -1922,7 +1922,7 @@ svr4_handle_solib_event (void)
>>        return;
>>      }
>>  
>> -  /* evaluate_probe_argument looks up symbols in the dynamic linker
>> +  /* evaluate_argument looks up symbols in the dynamic linker
>>       using find_pc_section.  find_pc_section is accelerated by a cache
>>       called the section map.  The section map is invalidated every
>>       time a shared library is loaded or unloaded, and if the inferior
>> @@ -1931,14 +1931,14 @@ svr4_handle_solib_event (void)
>>       We called find_pc_section in svr4_create_solib_event_breakpoints,
>>       so we can guarantee that the dynamic linker's sections are in the
>>       section map.  We can therefore inhibit section map updates across
>> -     these calls to evaluate_probe_argument and save a lot of time.  */
>> +     these calls to evaluate_argument and save a lot of time.  */
>>    inhibit_section_map_updates (current_program_space);
>>    usm_chain = make_cleanup (resume_section_map_updates_cleanup,
>>  			    current_program_space);
>>  
>>    TRY
>>      {
>> -      val = evaluate_probe_argument (pa->probe, 1, frame);
>> +      val = pa->prob->evaluate_argument (1, frame);
>>      }
>>    CATCH (ex, RETURN_MASK_ERROR)
>>      {
>> @@ -1979,7 +1979,7 @@ svr4_handle_solib_event (void)
>>      {
>>        TRY
>>  	{
>> -	  val = evaluate_probe_argument (pa->probe, 2, frame);
>> +	  val = pa->prob->evaluate_argument (2, frame);
>>  	}
>>        CATCH (ex, RETURN_MASK_ERROR)
>>  	{
>> @@ -2084,7 +2084,7 @@ svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
>>  
>>        for (probe *p : probes[i])
>>  	{
>> -	  CORE_ADDR address = get_probe_address (p, objfile);
>> +	  CORE_ADDR address = p->get_relocated_address (objfile);
>>  
>>  	  create_solib_event_breakpoint (gdbarch, address);
>>  	  register_solib_event_probe (p, address, action);
>> @@ -2126,7 +2126,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
>>  	  for (int i = 0; i < NUM_PROBES; i++)
>>  	    {
>>  	      const char *name = probe_info[i].name;
>> -	      struct probe *p;
>> +	      probe *p;
>>  	      char buf[32];
>>  
>>  	      /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
>> @@ -2160,7 +2160,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
>>  	      if (!checked_can_use_probe_arguments)
>>  		{
>>  		  p = probes[i][0];
>> -		  if (!can_evaluate_probe_arguments (p))
>> +		  if (!p->can_evaluate_arguments ())
>>  		    {
>>  		      all_probes_found = 0;
>>  		      break;
>> diff --git a/gdb/symfile.h b/gdb/symfile.h
>> index 3472aa0e7b..10b1504937 100644
>> --- a/gdb/symfile.h
>> +++ b/gdb/symfile.h
>> @@ -34,11 +34,11 @@ struct objfile;
>>  struct obj_section;
>>  struct obstack;
>>  struct block;
>> -struct probe;
>>  struct value;
>>  struct frame_info;
>>  struct agent_expr;
>>  struct axs_value;
>> +class probe;
>>  
>>  /* Comparison function for symbol look ups.  */
>>  
>> diff --git a/gdb/symtab.h b/gdb/symtab.h
>> index 7b8b5cc640..8bf9f3994f 100644
>> --- a/gdb/symtab.h
>> +++ b/gdb/symtab.h
>> @@ -41,10 +41,10 @@ struct axs_value;
>>  struct agent_expr;
>>  struct program_space;
>>  struct language_defn;
>> -struct probe;
>>  struct common_block;
>>  struct obj_section;
>>  struct cmd_list_element;
>> +class probe;
>>  struct lookup_name_info;
>>  
>>  /* How to match a lookup name against a symbol search name.  */
>> @@ -1702,7 +1702,7 @@ struct symtab_and_line
>>    bool explicit_line = false;
>>  
>>    /* The probe associated with this symtab_and_line.  */
>> -  struct probe *probe = NULL;
>> +  probe *prob = NULL;
>>    /* If PROBE is not NULL, then this is the objfile in which the probe
>>       originated.  */
>>    struct objfile *objfile = NULL;
>> diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
>> index 59a7b64ae8..76d05dfc13 100644
>> --- a/gdb/tracepoint.c
>> +++ b/gdb/tracepoint.c
>> @@ -1654,11 +1654,9 @@ start_tracing (const char *notes)
>>        t->number_on_target = b->number;
>>  
>>        for (loc = b->loc; loc; loc = loc->next)
>> -	if (loc->probe.probe != NULL
>> -	    && loc->probe.probe->pops->set_semaphore != NULL)
>> -	  loc->probe.probe->pops->set_semaphore (loc->probe.probe,
>> -						 loc->probe.objfile,
>> -						 loc->gdbarch);
>> +	if (loc->probe.prob != NULL)
>> +	  loc->probe.prob->set_semaphore (loc->probe.objfile,
>> +					  loc->gdbarch);
>>  
>>        if (bp_location_downloaded)
>>  	observer_notify_breakpoint_modified (b);
>> @@ -1754,11 +1752,9 @@ stop_tracing (const char *note)
>>  	     but we don't really care if this semaphore goes out of sync.
>>  	     That's why we are decrementing it here, but not taking care
>>  	     in other places.  */
>> -	  if (loc->probe.probe != NULL
>> -	      && loc->probe.probe->pops->clear_semaphore != NULL)
>> -	    loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
>> -						     loc->probe.objfile,
>> -						     loc->gdbarch);
>> +	  if (loc->probe.prob != NULL)
>> +	    loc->probe.prob->clear_semaphore (loc->probe.objfile,
>> +					      loc->gdbarch);
>>  	}
>>      }
>>  
>> 

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-15  3:25     ` Simon Marchi
@ 2017-11-15  6:15       ` Sergio Durigan Junior
  0 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-15  6:15 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches

On Tuesday, November 14 2017, Simon Marchi wrote:

> Damn, I hit send too soon... here's review part 2.  Actually, there's
> wasn't much left.

Thanks.

> On 2017-11-14 09:52 PM, Simon Marchi wrote:
>> On 2017-11-13 12:58 PM, Sergio Durigan Junior wrote:
>>> This patch converts the generic probe interface (gdb/probe.[ch]) to
>>> C++, and also performs some cleanups that were on my TODO list for a
>>> while.
>>>
>>> The main changes were the conversion of 'struct probe' to 'class
>>> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
>>> former now contains all the "dynamic", generic methods that act on a
>>> probe + the generic data related to it; the latter encapsulates a
>>> bunch of "static" methods that relate to the probe type, but not to a
>>> specific probe itself.
>> 
>> Personally I'm fine with this.  Maybe there would be a better C++-ish
>> design, but I'm not very good at that.  If others have suggestions, I'd
>> like to hear them.
>
> Given your description, I think "class probe_type" would be a good name
> instead of static_probe_ops.

You know, "class probe_type" was one of the many names that crossed my
mind.  I didn't like it because it doesn't convey the meaning that I
want here, which is that this class is "generic".  I still think
"static_probe_ops" is a better fit.

>>> -extern const struct probe_ops probe_ops_any;
>>> +  /* Return true if the probe can be enabled; false otherwise.  */
>>> +  virtual bool can_enable () const
>>> +  {
>>> +    return false;
>>> +  }
>
> Should this be in the static_probe_ops?  Is the fact that a probe can be
> enabled/disabled a property of the probe, or the probe type?

You're right, it should be on static_probe_ops indeed.  I'll move it
there.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
  2017-11-15  3:58   ` Simon Marchi
@ 2017-11-15 22:49     ` Sergio Durigan Junior
  0 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-15 22:49 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches

On Tuesday, November 14 2017, Simon Marchi wrote:

> On 2017-11-13 12:59 PM, Sergio Durigan Junior wrote:
>> This patch converts the SystemTap probe
>> interface (gdb/stap-probe.[ch]) to C++, and also performs some
>> cleanups that were on my TODO list for a while.
>> 
>> The main changes were the conversion of 'struct stap_probe' to 'class
>> stap_probe', and a new 'class stap_static_probe_ops' to replace the
>> use of 'stap_probe_ops'.  Both classes implement the virtual methods
>> exported by their parents, 'class probe' and 'class static_probe_ops',
>> respectively.  I believe it's now a bit simpler to understand the
>> logic behind the stap-probe interface.
>> 
>> There are several helper functions used to parse parts of a stap
>> probe, and since they are generic and don't need to know about the
>> probe they're working on, I decided to leave them as simple static
>> functions (instead of e.g. converting them to class methods).
>> 
>> I've also converted a few uses of "VEC" to "std::vector", which makes
>> the code simpler and easier to maintain.  And, as usual, some cleanups
>> here and there.
>> 
>> Even though I'm sending a series of patches, they need to be tested
>> and committed as a single unit, because of inter-dependencies.  But it
>> should be easier to review in separate logical units.
>
> Hi Sergio,
>
> This look very good to me.  In general, try to use const-references when
> iterating on vector of objects (in all 3 patches).  A few comments below.

Hey Simon,

Thanks for the review.  I also saw your comment on IRC; good catch,
thanks.  I'll update the code.

>> I've regtested this patch on BuildBot, no regressions found.
>> 
>> gdb/ChangeLog:
>> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
>> 	variable.
>> 	(stap_probe_arg_s): Delete type and VEC.
>> 	(struct stap_probe): Delete.  Replace by...
>> 	(class stap_static_probe_ops): ...this and...
>> 	(class stap_probe): ...this.  Rename variables to add 'm_'
>> 	prefix.  Do not use 'union' for arguments anymore.
>> 	(stap_get_expected_argument_type): Receive probe name instead
>> 	of 'struct stap_probe'.  Adjust code.
>> 	(stap_parse_probe_arguments): Rename to...
>> 	(stap_probe::parse_arguments): ...this.  Adjust code to
>> 	reflect change.
>> 	(stap_get_probe_address): Rename to...
>> 	(stap_probe::get_relocated_address): ...this.  Adjust code
>> 	to reflect change.
>> 	(stap_get_probe_argument_count): Rename to...
>> 	(stap_probe::get_argument_count): ...this.  Adjust code
>> 	to reflect change.
>> 	(stap_get_arg): Rename to...
>> 	(stap_probe::get_arg_by_number'): ...this. Adjust code to
>> 	reflect change.
>> 	(can_evaluate_probe_arguments): Rename to...
>> 	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
>> 	to reflect change.
>> 	(stap_evaluate_probe_argument): Rename to...
>> 	(stap_probe::evaluate_argument): ...this.  Adjust code
>> 	to reflect change.
>> 	(stap_compile_to_ax): Rename to...
>> 	(stap_probe::compile_to_ax): ...this.  Adjust code to
>> 	reflect change.
>> 	(stap_probe_destroy): Delete.
>> 	(stap_modify_semaphore): Adjust comment.
>> 	(stap_set_semaphore): Rename to...
>> 	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
>> 	change.
>> 	(stap_clear_semaphore): Rename to...
>> 	(stap_probe::clear_semaphore): ...this.  Adjust code to
>> 	reflect	change.
>> 	(stap_probe::get_static_ops): New method.
>> 	(handle_stap_probe): Adjust code to create instance of
>> 	'stap_probe'.
>> 	(stap_get_probes): Rename to...
>> 	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
>> 	reflect change.
>> 	(stap_probe_is_linespec): Rename to...
>> 	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
>> 	reflect change.
>> 	(stap_type_name): Rename to...
>> 	(stap_static_probe_ops::type_name): ...this.  Adjust code to
>> 	reflect change.
>> 	(stap_static_probe_ops::emit_info_probes_extra_fields): New
>> 	method.
>> 	(stap_gen_info_probes_table_header): Rename to...
>> 	(stap_static_probe_ops::gen_info_probes_table_header):
>> 	...this.  Adjust code to reflect change.
>> 	(stap_gen_info_probes_table_values): Rename to...
>> 	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
>> 	code to reflect change.
>> 	(struct probe_ops stap_probe_ops): Delete.
>> 	(info_probes_stap_command): Use 'info_probes_for_spops'
>> 	instead of 'info_probes_for_ops'.
>> 	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
>> 	of 'all_probe_ops'.
>> ---
>>  gdb/stap-probe.c | 478 ++++++++++++++++++++++++++++---------------------------
>>  1 file changed, 244 insertions(+), 234 deletions(-)
>> 
>> diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
>> index 6fa0d20280..c169ffc488 100644
>> --- a/gdb/stap-probe.c
>> +++ b/gdb/stap-probe.c
>> @@ -45,10 +45,6 @@
>>  
>>  #define STAP_BASE_SECTION_NAME ".stapsdt.base"
>>  
>> -/* Forward declaration. */
>> -
>> -extern const struct probe_ops stap_probe_ops;
>> -
>>  /* Should we display debug information for the probe's argument expression
>>     parsing?  */
>>  
>> @@ -95,32 +91,135 @@ struct stap_probe_arg
>>    struct expression *aexpr;
>>  };
>>  
>> -typedef struct stap_probe_arg stap_probe_arg_s;
>> -DEF_VEC_O (stap_probe_arg_s);
>> +/* Class that implements the static probe methods for "stap" probes.  */
>>  
>> -struct stap_probe
>> +class stap_static_probe_ops : public static_probe_ops
>>  {
>> -  /* Generic information about the probe.  This shall be the first element
>> -     of this struct, in order to maintain binary compatibility with the
>> -     `struct probe' and be able to fully abstract it.  */
>> -  struct probe p;
>> +public:
>> +  /* See probe.h.  */
>> +  bool is_linespec (const char **linespecp) const override;
>> +
>> +  /* See probe.h.  */
>> +  void get_probes (std::vector<probe *> *probesp,
>> +		   struct objfile *objfile) const override;
>> +
>> +  /* See probe.h.  */
>> +  const char *type_name () const override;
>> +
>> +  /* See probe.h.  */
>> +  bool emit_info_probes_extra_fields () const override;
>> +
>> +  /* See probe.h.  */
>> +  void gen_info_probes_table_header
>> +    (std::vector<struct info_probe_column> *heads) const override;
>> +};
>> +
>> +/* SystemTap static_probe_ops.  */
>> +
>> +const stap_static_probe_ops stap_static_probe_ops;
>>  
>> +class stap_probe : public probe
>> +{
>> +public:
>> +  /* Constructor for stap_probe.  */
>> +  stap_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
>> +	      struct gdbarch *arch_, CORE_ADDR sem_addr, const char *args_text)
>> +    : probe (std::move (name_), std::move (provider_), address_, arch_),
>> +      m_sem_addr (sem_addr),
>> +      m_have_parsed_args (false), m_unparsed_args_text (args_text)
>> +  {}
>> +
>> +  /* Destructor for stap_probe.  */
>> +  ~stap_probe ()
>> +  {
>> +    if (m_have_parsed_args)
>> +      for (struct stap_probe_arg arg : m_parsed_args)
>> +	xfree (arg.aexpr);
>> +  }
>
> I would suggest adding a destructor to stap_probe_arg instead, since it's
> the object that "owns" the expression.  You would need to disable copy
> construction and assignment (using DISABLE_COPY_AND_ASSIGN) to avoid double
> free.  You can then add a simple constructor and use emplace_back when
> inserting in the vector.

Good point.  As we discussed on IRC, I implemented things the way you
proposed, with expression_up.  I'll send the updated patch.

>> +
>> +  /* See probe.h.  */
>> +  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
>> +
>> +  /* See probe.h.  */
>> +  unsigned get_argument_count (struct frame_info *frame) override;
>> +
>> +  /* See probe.h.  */
>> +  int can_evaluate_arguments () const override;
>> +
>> +  /* See probe.h.  */
>> +  struct value *evaluate_argument (unsigned n,
>> +				   struct frame_info *frame) override;
>> +
>> +  /* See probe.h.  */
>> +  void compile_to_ax (struct agent_expr *aexpr,
>> +		      struct axs_value *axs_value,
>> +		      unsigned n) override;
>> +
>> +  /* See probe.h.  */
>> +  void set_semaphore (struct objfile *objfile,
>> +		      struct gdbarch *gdbarch) override;
>> +
>> +  /* See probe.h.  */
>> +  void clear_semaphore (struct objfile *objfile,
>> +			struct gdbarch *gdbarch) override;
>> +
>> +  /* See probe.h.  */
>> +  const static_probe_ops *get_static_ops () const override;
>> +
>> +  /* See probe.h.  */
>> +  void gen_info_probes_table_values
>> +    (std::vector<const char *> *values) const override;
>> +
>> +  /* Return argument N of probe.
>> +
>> +     If the probe's arguments have not been parsed yet, parse them.  If
>> +     there are no arguments, throw an exception (error).  Otherwise,
>> +     return the requested argument.  */
>> +  struct stap_probe_arg *get_arg_by_number (unsigned n,
>> +					    struct gdbarch *gdbarch)
>> +  {
>> +    if (!m_have_parsed_args)
>> +      this->parse_arguments (gdbarch);
>> +
>> +    gdb_assert (m_have_parsed_args);
>> +    if (m_parsed_args.empty ())
>> +      internal_error (__FILE__, __LINE__,
>> +		      _("Probe '%s' apparently does not have arguments, but \n"
>> +			"GDB is requesting its argument number %u anyway.  "
>> +			"This should not happen.  Please report this bug."),
>> +		      this->get_name (), n);
>> +
>> +    return &m_parsed_args[n];
>
> There wasn't one before, but it sounds to me like there should be a bound check here...

Will do.

>> @@ -1081,26 +1179,16 @@ stap_parse_argument (const char **arg, struct type *atype,
>>    return p.pstate.expout;
>>  }
>>  
>> -/* Function which parses an argument string from PROBE, correctly splitting
>> -   the arguments and storing their information in properly ways.
>> +/* Implementation of 'parse_probe_arguments' method.  */
>
> of 'parse_arguments' method ?

Fixed.

>> +void
>> +stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
>>  {
>> -  struct stap_probe *probe = (struct stap_probe *) probe_generic;
>>    CORE_ADDR addr;
>>  
>> -  gdb_assert (probe_generic->pops == &stap_probe_ops);
>> -
>> -  addr = (probe->sem_addr
>> +  addr = (m_sem_addr
>>  	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
>
> While at it, you could replace this with get_relocated_address() so that this
> computation is not duplicated.  Same with clear_semaphore.

Sure thing, done.

Thanks for the review.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/3] Convert DTrace probe interface to C++ (and perform some cleanups)
  2017-11-15  4:40   ` Simon Marchi
@ 2017-11-16  4:11     ` Sergio Durigan Junior
  0 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-16  4:11 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches

On Tuesday, November 14 2017, Simon Marchi wrote:

> Hi Sergio,

Hey Simon,

Thanks for the review.

> On 2017-11-13 12:59 PM, Sergio Durigan Junior wrote:
>> This patch converts the DTrace probe
>> interface (gdb/dtrace-probe.[ch]) to C++, and also performs some
>> cleanups that were on my TODO list for a while.
>> 
>> The main changes were the conversion of 'struct dtrace_probe' to 'class
>> dtrace_probe', and a new 'class dtrace_static_probe_ops' to replace the
>> use of 'dtrace_probe_ops'.  Both classes implement the virtual methods
>> exported by their parents, 'class probe' and 'class static_probe_ops',
>> respectively.  I believe it's now a bit simpler to understand the
>> logic behind the dtrace-probe interface.
>> 
>> There are several helper functions used to parse parts of a dtrace
>> probe, and since they are generic and don't need to know about the
>> probe they're working on, I decided to leave them as simple static
>> functions (instead of e.g. converting them to class methods).
>> 
>> I've also converted a few uses of "VEC" to "std::vector", which makes
>> the code simpler and easier to maintain.  And, as usual, some cleanups
>> here and there.
>> 
>> Even though I'm sending a series of patches, they need to be tested
>> and committed as a single unit, because of inter-dependencies.  But it
>> should be easier to review in separate logical units.
>> 
>> I've regtested this patch on BuildBot, no regressions found.
>> 
>> gdb/ChangeLog:
>> 2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* dtrace-probe.c (struct probe_ops dtrace_probe_ops): Delete.
>> 	(dtrace_probe_arg_s): Delete type and VEC.
>> 	(dtrace_probe_enabler_s): Likewise.
>> 	(struct dtrace_probe): Replace by...
>> 	(class dtrace_static_probe_ops): ...this and...
>> 	(class dtrace_probe): ...this.
>> 	(dtrace_probe_is_linespec): Rename to...
>> 	(dtrace_static_probe_ops::is_linespec): ...this.  Adjust code
>> 	to reflect change.
>> 	(dtrace_process_dof_probe): Use 'std::vector' instead of VEC.
>> 	Adjust code.  Create new instance of 'dtrace_probe'.
>> 	(dtrace_build_arg_exprs): Rename to...
>> 	(dtrace_probe::build_arg_exprs): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_get_probes): Rename to...
>> 	(dtrace_static_probe_ops::get_probes): ...this.  Adjust code
>> 	to reflect change.
>> 	(dtrace_get_arg): Rename to...
>> 	(dtrace_probe::get_arg_by_number): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_probe_is_enabled): Rename to...
>> 	(dtrace_probe::is_enabled): ...this.  Adjust code to reflect
>> 	change.
>> 	(dtrace_get_probe_address): Rename to...
>> 	(dtrace_probe::get_relocated_address): ...this.  Adjust code
>> 	to reflect change.
>> 	(dtrace_get_probe_argument_count): Rename to...
>> 	(dtrace_probe::get_argument_count): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_can_evaluate_probe_arguments): Rename to...
>> 	(dtrace_probe::can_evaluate_arguments): ...this.  Adjust code
>> 	to reflect change.
>> 	(dtrace_evaluate_probe_argument): Rename to...
>> 	(dtrace_probe::evaluate_argument): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_compile_to_ax): Rename to...
>> 	(dtrace_probe::compile_to_ax): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_probe_destroy): Delete.
>> 	(dtrace_type_name): Rename to...
>> 	(dtrace_static_probe_ops::type_name): ...this.  Adjust code to
>> 	reflect change.
>> 	(dtrace_probe::get_static_ops): New method.
>> 	(dtrace_gen_info_probes_table_header): Rename to...
>> 	(dtrace_static_probe_ops::gen_info_probes_table_header):
>> 	...this.  Adjust code to reflect change.
>> 	(dtrace_gen_info_probes_table_values): Rename to...
>> 	(dtrace_probe::gen_info_probes_table_values): ...this.  Adjust
>> 	code to reflect change.
>> 	(dtrace_enable_probe): Rename to...
>> 	(dtrace_probe::enable_probe): ...this.  Adjust code to reflect
>> 	change.
>> 	(dtrace_disable_probe): Rename to...
>> 	(dtrace_probe::disable_probe): ...this.  Adjust code to reflect
>> 	change.
>> 	(struct probe_ops dtrace_probe_ops): Delete.
>> 	(dtrace_static_probe_ops::emit_info_probes_extra_fields): New
>> 	method.
>> 	(info_probes_dtrace_command): Call 'info_probes_for_spops'
>> 	instead of 'info_probes_for_ops'.
>> 	(_initialize_dtrace_probe): Use 'all_static_probe_ops' instead
>> 	of 'all_probe_ops'.
>> ---
>>  gdb/dtrace-probe.c | 528 +++++++++++++++++++++++++++--------------------------
>>  1 file changed, 268 insertions(+), 260 deletions(-)
>> 
>> diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
>> index 2bbe03e4b3..b53ff7ac6c 100644
>> --- a/gdb/dtrace-probe.c
>> +++ b/gdb/dtrace-probe.c
>> @@ -41,10 +41,6 @@
>>  # define SHT_SUNW_dof	0x6ffffff4
>>  #endif
>>  
>> -/* Forward declaration.  */
>> -
>> -extern const struct probe_ops dtrace_probe_ops;
>> -
>>  /* The following structure represents a single argument for the
>>     probe.  */
>>  
>> @@ -60,9 +56,6 @@ struct dtrace_probe_arg
>>    struct expression *expr;
>>  };
>>  
>> -typedef struct dtrace_probe_arg dtrace_probe_arg_s;
>> -DEF_VEC_O (dtrace_probe_arg_s);
>> -
>>  /* The following structure represents an enabler for a probe.  */
>>  
>>  struct dtrace_probe_enabler
>> @@ -73,39 +66,121 @@ struct dtrace_probe_enabler
>>    CORE_ADDR address;
>>  };
>>  
>> -typedef struct dtrace_probe_enabler dtrace_probe_enabler_s;
>> -DEF_VEC_O (dtrace_probe_enabler_s);
>> +/* Class that implements the static probe methods for "stap" probes.  */
>> +
>> +class dtrace_static_probe_ops : public static_probe_ops
>> +{
>> +public:
>> +  /* See probe.h.  */
>> +  bool is_linespec (const char **linespecp) const override;
>> +
>> +  /* See probe.h.  */
>> +  void get_probes (std::vector<probe *> *probesp,
>> +		   struct objfile *objfile) const override;
>> +
>> +  /* See probe.h.  */
>> +  const char *type_name () const override;
>> +
>> +  /* See probe.h.  */
>> +  bool emit_info_probes_extra_fields () const override;
>> +
>> +  /* See probe.h.  */
>> +  void gen_info_probes_table_header
>> +    (std::vector<struct info_probe_column> *heads) const override;
>> +};
>> +
>> +/* DTrace static_probe_ops.  */
>> +
>> +const dtrace_static_probe_ops dtrace_static_probe_ops;
>>  
>>  /* The following structure represents a dtrace probe.  */
>>  
>> -struct dtrace_probe
>> +class dtrace_probe : public probe
>>  {
>> -  /* Generic information about the probe.  This must be the first
>> -     element of this struct, in order to maintain binary compatibility
>> -     with the `struct probe' and be able to fully abstract it.  */
>> -  struct probe p;
>> +public:
>> +  /* Constructor for dtrace_probe.  */
>> +  dtrace_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
>> +		struct gdbarch *arch_,
>> +		std::vector<struct dtrace_probe_arg> &args_,
>> +		std::vector<struct dtrace_probe_enabler> &enablers_)
>
> I am wondering why you don't use && for the vectors, as you do with the strings.
> If the constructor is "stealing" from the vectors passed as parameter, I think it
> would make sense if the parameters were &&, to indicate to the caller that they'll
> be moved from (and force it to use std::move).

That's true.  I think I was misunderstanding the relationship between
rvalues, lvalues and &&.  Fixed.

>> +    : probe (std::move (name_), std::move (provider_), address_, arch_),
>> +      m_args (std::move (args_)),
>> +      m_enablers (std::move (enablers_)),
>> +      m_args_expr_built (false)
>> +  {}
>> +
>> +  /* Destructor for dtrace_probe.  */
>> +  ~dtrace_probe ()
>> +  {
>> +    for (struct dtrace_probe_arg arg : m_args)
>> +      {
>> +	xfree (arg.type_str);
>> +	xfree (arg.expr);
>> +      }
>
> As for stap_probe, I think defining a destructor in dtrace_probe_arg would
> be clearer.

I used the same approach as in stap-probe.c: expression_up,
emplace_back, a constructor that takes care of std::move'ing things, and
no destructor.  I also converted 'type_str' to std::string.

>> +  }
>> +
>> +  /* See probe.h.  */
>> +  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
>> +
>> +  /* See probe.h.  */
>> +  unsigned get_argument_count (struct frame_info *frame) override;
>> +
>> +  /* See probe.h.  */
>> +  int can_evaluate_arguments () const override;
>> +
>> +  /* See probe.h.  */
>> +  struct value *evaluate_argument (unsigned n,
>> +				   struct frame_info *frame) override;
>> +
>> +  /* See probe.h.  */
>> +  void compile_to_ax (struct agent_expr *aexpr,
>> +		      struct axs_value *axs_value,
>> +		      unsigned n) override;
>> +
>> +  /* See probe.h.  */
>> +  const static_probe_ops *get_static_ops () const override;
>> +
>> +  /* See probe.h.  */
>> +  void gen_info_probes_table_values
>> +    (std::vector<const char *> *values) const override;
>> +
>> +  /* See probe.h.  */
>> +  bool can_enable () const override
>> +  {
>> +    return true;
>> +  }
>> +
>> +  /* See probe.h.  */
>> +  void enable () override;
>>  
>> +  /* See probe.h.  */
>> +  void disable () override;
>> +
>> +  /* Return the Nth argument of the probe.  */
>> +  struct dtrace_probe_arg *get_arg_by_number (unsigned n,
>> +					      struct gdbarch *gdbarch);
>> +
>> +  /* Build the GDB internal expressiosn that, once evaluated, will
>> +     calculate the values of the arguments of the probe.  */
>> +  void build_arg_exprs (struct gdbarch *gdbarch);
>> +
>> +  /* Determine whether the probe is "enabled" or "disabled".  A
>> +     disabled probe is a probe in which one or more enablers are
>> +     disabled.  */
>> +  bool is_enabled () const;
>> +
>> +private:
>>    /* A probe can have zero or more arguments.  */
>> -  int probe_argc;
>> -  VEC (dtrace_probe_arg_s) *args;
>> +  int m_argc;
>
> It seems like this field is never set, but used at least once.  Should we use args->size() instead?

OK, no problem.  Done.

>> +  std::vector<struct dtrace_probe_arg> m_args;
>>  
>>    /* A probe can have zero or more "enablers" associated with it.  */
>> -  VEC (dtrace_probe_enabler_s) *enablers;
>> +  std::vector<struct dtrace_probe_enabler> m_enablers;
>>  
>>    /* Whether the expressions for the arguments have been built.  */
>> -  unsigned int args_expr_built : 1;
>> +  bool m_args_expr_built;
>>  };
>>  
>> -/* Implementation of the probe_is_linespec method.  */
>> -
>> -static int
>> -dtrace_probe_is_linespec (const char **linespecp)
>> -{
>> -  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
>> -
>> -  return probe_is_linespec_by_keyword (linespecp, keywords);
>> -}
>> -
>>  /* DOF programs can contain an arbitrary number of sections of 26
>>     different types.  In order to support DTrace USDT probes we only
>>     need to handle a subset of these section types, fortunately.  These
>> @@ -322,8 +397,6 @@ dtrace_process_dof_probe (struct objfile *objfile,
>>  			  char *argtab, uint64_t strtab_size)
>>  {
>>    int i, j, num_probes, num_enablers;
>> -  struct cleanup *cleanup;
>> -  VEC (dtrace_probe_enabler_s) *enablers;
>>    char *p;
>>  
>>    /* Each probe section can define zero or more probes of two
>> @@ -368,9 +441,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
>>  
>>    /* Build the list of enablers for the probes defined in this Probe
>>       DOF section.  */
>> -  enablers = NULL;
>> -  cleanup
>> -    = make_cleanup (VEC_cleanup (dtrace_probe_enabler_s), &enablers);
>> +  std::vector<struct dtrace_probe_enabler> enablers;
>>    num_enablers = DOF_UINT (dof, probe->dofpr_nenoffs);
>>    for (i = 0; i < num_enablers; i++)
>>      {
>> @@ -380,38 +451,32 @@ dtrace_process_dof_probe (struct objfile *objfile,
>>  
>>        enabler.address = DOF_UINT (dof, probe->dofpr_addr)
>>  	+ DOF_UINT (dof, enabler_offset);
>> -      VEC_safe_push (dtrace_probe_enabler_s, enablers, &enabler);
>> +      enablers.push_back (enabler);
>>      }
>>  
>>    for (i = 0; i < num_probes; i++)
>>      {
>>        uint32_t probe_offset
>>  	= ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
>> -      struct dtrace_probe *ret =
>> -	XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
>> -
>> -      ret->p.pops = &dtrace_probe_ops;
>> -      ret->p.arch = gdbarch;
>> -      ret->args_expr_built = 0;
>>  
>>        /* Set the provider and the name of the probe.  */
>> -      ret->p.provider
>> -	= xstrdup (strtab + DOF_UINT (dof, provider->dofpv_name));
>> -      ret->p.name = xstrdup (strtab + DOF_UINT (dof, probe->dofpr_name));
>> +      const char *probe_provider
>> +	= strtab + DOF_UINT (dof, provider->dofpv_name);
>> +      const char *name = strtab + DOF_UINT (dof, probe->dofpr_name);
>>  
>>        /* The probe address.  */
>> -      ret->p.address
>> +      CORE_ADDR address
>>  	= DOF_UINT (dof, probe->dofpr_addr) + DOF_UINT (dof, probe_offset);
>>  
>>        /* Number of arguments in the probe.  */
>> -      ret->probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
>> +      int probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
>>  
>>        /* Store argument type descriptions.  A description of the type
>>           of the argument is in the (J+1)th null-terminated string
>>           starting at 'strtab' + 'probe->dofpr_nargv'.  */
>> -      ret->args = NULL;
>> +      std::vector<struct dtrace_probe_arg> args;
>>        p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
>> -      for (j = 0; j < ret->probe_argc; j++)
>> +      for (j = 0; j < probe_argc; j++)
>>  	{
>>  	  struct dtrace_probe_arg arg;
>>  	  expression_up expr;
>> @@ -442,17 +507,18 @@ dtrace_process_dof_probe (struct objfile *objfile,
>>  	  if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
>>  	    arg.type = expr->elts[1].type;
>>  
>> -	  VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
>> +	  args.push_back (arg);
>>  	}
>>  
>> -      /* Add the vector of enablers to this probe, if any.  */
>> -      ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
>> +      std::vector<struct dtrace_probe_enabler> enablers_copy = enablers;
>
> Why is this copy necessary?  What happens with the original vector?

This copy is necessary because the original vector should be intact on
every iteration, but dtrace_probe's constructor performs a 'std::move'
on it.  I could have passed the original vector as an argument (by
value), and not perform the std::move in the constructor, if you prefer.

>> +      dtrace_probe *ret = new dtrace_probe (std::string (name),
>> +					    std::string (probe_provider),
>> +					    address, gdbarch,
>> +					    args, enablers_copy);
>>  
>>        /* Successfully created probe.  */
>> -      probesp->push_back ((struct probe *) ret);
>> +      probesp->push_back (ret);
>>      }
>> -
>> -  do_cleanups (cleanup);
>>  }
>>  
>>  /* Helper function to collect the probes described in the DOF program
>> @@ -555,28 +621,23 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
>>  	     sect->name);
>>  }
>>  
>> -/* Helper function to build the GDB internal expressiosn that, once
>> -   evaluated, will calculate the values of the arguments of a given
>> -   PROBE.  */
>> +/* Implementation of 'build_arg_exprs' method.  */
>>  
>> -static void
>> -dtrace_build_arg_exprs (struct dtrace_probe *probe,
>> -			struct gdbarch *gdbarch)
>> +void
>> +dtrace_probe::build_arg_exprs (struct gdbarch *gdbarch)
>>  {
>> -  struct parser_state pstate;
>> -  struct dtrace_probe_arg *arg;
>> -  int i;
>> -
>> -  probe->args_expr_built = 1;
>> +  m_args_expr_built = true;
>>  
>>    /* Iterate over the arguments in the probe and build the
>>       corresponding GDB internal expression that will generate the
>>       value of the argument when executed at the PC of the probe.  */
>> -  for (i = 0; i < probe->probe_argc; i++)
>> +  for (int i = 0; i < m_argc; i++)
>>      {
>> +      struct dtrace_probe_arg *arg;
>>        struct cleanup *back_to;
>> +      struct parser_state pstate;
>>  
>> -      arg = VEC_index (dtrace_probe_arg_s, probe->args, i);
>> +      arg = &m_args[i];
>>  
>>        /* Initialize the expression buffer in the parser state.  The
>>  	 language does not matter, since we are using our own
>> @@ -606,138 +667,82 @@ dtrace_build_arg_exprs (struct dtrace_probe *probe,
>>      }
>>  }
>>  
>> -/* Helper function to return the Nth argument of a given PROBE.  */
>> -
>> -static struct dtrace_probe_arg *
>> -dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
>> -		struct gdbarch *gdbarch)
>> -{
>> -  if (!probe->args_expr_built)
>> -    dtrace_build_arg_exprs (probe, gdbarch);
>> -
>> -  return VEC_index (dtrace_probe_arg_s, probe->args, n);
>> -}
>> -
>> -/* Implementation of the get_probes method.  */
>> +/* Implementation of 'get_arg_by_number' method.  */
>>  
>> -static void
>> -dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
>> +struct dtrace_probe_arg *
>> +dtrace_probe::get_arg_by_number (unsigned n, struct gdbarch *gdbarch)
>>  {
>> -  bfd *abfd = objfile->obfd;
>> -  asection *sect = NULL;
>> -
>> -  /* Do nothing in case this is a .debug file, instead of the objfile
>> -     itself.  */
>> -  if (objfile->separate_debug_objfile_backlink != NULL)
>> -    return;
>> +  if (!m_args_expr_built)
>> +    this->build_arg_exprs (gdbarch);
>>  
>> -  /* Iterate over the sections in OBJFILE looking for DTrace
>> -     information.  */
>> -  for (sect = abfd->sections; sect != NULL; sect = sect->next)
>> -    {
>> -      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
>> -	{
>> -	  bfd_byte *dof;
>> -
>> -	  /* Read the contents of the DOF section and then process it to
>> -	     extract the information of any probe defined into it.  */
>> -	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
>> -	    complaint (&symfile_complaints,
>> -		       _("could not obtain the contents of"
>> -			 "section '%s' in objfile `%s'."),
>> -		       sect->name, abfd->filename);
>> -      
>> -	  dtrace_process_dof (sect, objfile, probesp,
>> -			      (struct dtrace_dof_hdr *) dof);
>> -	  xfree (dof);
>> -	}
>> -    }
>> +  return &m_args[n];
>
> It would be nice to add a gdb_assert (n < m_args.size ()) here.

I've added a bound check and an internal_error, just like I did for
stap-probe.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 0/3] Convert probe interfaces to C++ (and perform some cleanups)
  2017-11-13 17:59 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
                   ` (2 preceding siblings ...)
  2017-11-13 17:59 ` [PATCH 3/3] Convert DTrace " Sergio Durigan Junior
@ 2017-11-16  4:37 ` Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
                     ` (3 more replies)
  3 siblings, 4 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-16  4:37 UTC (permalink / raw)
  To: GDB Patches; +Cc: Simon Marchi

[ The changes for each patch are described at the top of each message.  ]

This patch series performs the conversion of the probe interfaces
(generic, stap and dtrace) to C++, along with a few cleanups here and
there to make the code conform better to our standards.

This series needs to be committed/tested as one single patch, because
of inter-dependencies.  However, in order to facilitate the review
process, I decided to split things into logical units.

The main changes are the conversion of 'struct probe' to 'class
probe', and 'struct probe_ops' to 'class static_probe_ops'.  Almost
everything else in the patches are adjustments related to these
modifications.

It's important to say that 'class probe' contains the majority of the
methods that were previously living inside 'struct probe_ops'.
However, some methods are special in the sense the they don't act on a
specific probe object, but generically on a probe type (like a
factory).  For that reason the 'class static_probe_ops' had to be
created.

Most methods in 'class probe' are pure virtual and need to be defined
by the probe backend (stap or dtrace, for now).  Other methods (e.g.,
the 'enable' method) are virtual but non-pure and have a default,
dummy version implemented on 'class probe' itself, because the concept
of enabling a probe is not common to all types of probes.

I've also taken the opportunity to convert a few uses of "VEC" to
"std::vector", and to remove annoying spurious newlines from some
places.

The whole patch has been tested on BuildBot, without regressions.
However, it is important to mention that I could not test the DTrace
part of the patch because the test framework used to test it is not
working; see <https://sourceware.org/bugzilla/show_bug.cgi?id=22420>.


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 3/3] Convert DTrace " Sergio Durigan Junior
@ 2017-11-16  4:38   ` Sergio Durigan Junior
  2017-11-22 20:39     ` Simon Marchi
  2017-11-21 16:25   ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  3 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-16  4:38 UTC (permalink / raw)
  To: GDB Patches; +Cc: Simon Marchi, Sergio Durigan Junior

Changes from v1:

- Remove emit_info_probes_extra_fields method.

- Make gen_info_* methods return the vector directly.  Modify code
  accordingly.

- Cleanup unused variables.

- Make can_evaluate_arguments return bool.

- Make get_name and get_provider return a const std::string &.  Modify
  code accordingly.

- Move can_enable method from 'class probe' to 'class
  static_probe_ops'.

- Use const references when iterating on vector of objects.

This patch converts the generic probe interface (gdb/probe.[ch]) to
C++, and also performs some cleanups that were on my TODO list for a
while.

The main changes were the conversion of 'struct probe' to 'class
probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
former now contains all the "dynamic", generic methods that act on a
probe + the generic data related to it; the latter encapsulates a
bunch of "static" methods that relate to the probe type, but not to a
specific probe itself.

I've had to do a few renamings (e.g., on 'struct bound_probe' the
field is called 'probe *prob' now, instead of 'struct probe *probe')
because GCC was complaining about naming the field using the same name
as the class.  Nothing major, though.  Generally speaking, the logic
behind and the design behind the code are the same.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* break-catch-throw.c (fetch_probe_arguments): Use
	'probe.prob' instead of 'probe.probe'.
	* breakpoint.c (create_longjmp_master_breakpoint): Call
	'can_evaluate_arguments' and 'get_relocated_address' methods
	from probe.
	(create_exception_master_breakpoint): Likewise.
	(add_location_to_breakpoint): Use 'sal->prob' instead of
	'sal->probe'.
	(bkpt_probe_insert_location): Call 'set_semaphore' method from
	probe.
	(bkpt_probe_remove_location): Likewise, for 'clear_semaphore'.
	* elfread.c (elf_get_probes): Use 'static_probe_ops' instead
	of 'probe_ops'.
	(probe_key_free): Call 'delete' on probe.
	(check_exception_resume): Use 'probe.prob' instead of
	'probe.probe'.
	* location.c (string_to_event_location_basic): Call
	'probe_linespec_to_static_ops'.
	* probe.c (class any_static_probe_ops): New class.
	(any_static_probe_ops any_static_probe_ops): New variable.
	(parse_probes_in_pspace): Receive 'static_probe_ops' as
	argument.  Adjust code to reflect change.
	(parse_probes): Use 'static_probe_ops' instead of
	'probe_ops'.  Adjust code to reflect change.
	(find_probes_in_objfile): Call methods to get name and
	provider from probe.
	(find_probe_by_pc): Use 'result.prob' instead of
	'result.probe'.  Call 'get_relocated_address' method from
	probe.
	(collect_probes): Adjust comment and argument list to receive
	'static_probe_ops' instead of 'probe_ops'.  Adjust code to
	reflect change.  Call necessary methods from probe.
	(compare_probes): Call methods to get name and provider from
	probes.
	(gen_ui_out_table_header_info): Receive 'static_probe_ops'
	instead of 'probe_ops'.  Use 'std::vector' instead of VEC,
	adjust code accordingly.
	(print_ui_out_not_applicables): Likewise.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Receive 'static_probe_ops'
	as argument instead of 'probe_ops'.  Adjust code.  Call
	necessary methods from probe.
	(info_probes_command): Use 'info_probes_for_spops'.
	(enable_probes_command): Pass correct argument to
	'collect_probes'.  Call methods from probe.
	(disable_probes_command): Likewise.
	(get_probe_address): Move to 'any_static_probe_ops::get_address'.
	(get_probe_argument_count): Move to
	'any_static_probe_ops::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'any_static_probe_ops::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to
	'any_static_probe_ops::evaluate_argument'.
	(probe_safe_evaluate_at_pc): Use 'probe.prob' instead of
	'probe.probe'.
	(probe_linespec_to_ops): Rename to...
	(probe_linespec_to_static_ops): ...this.  Adjust code.
	(probe_any_is_linespec): Rename to...
	(any_static_probe_ops::is_linespec): ...this.
	(probe_any_get_probes): Rename to...
	(any_static_probe_ops::get_probes): ...this.
	(any_static_probe_ops::type_name): New method.
	(any_static_probe_ops::gen_info_probes_table_header): New
	method.
	(compute_probe_arg): Use 'pc_probe.prob' instead of
	'pc_probe.probe'.  Call methods from probe.
	(compile_probe_arg): Likewise.
	(std::vector<const probe_ops *> all_probe_ops): Delete.
	(std::vector<const static_probe_ops *> all_static_probe_ops):
	New variable.
	(_initialize_probe): Use 'all_static_probe_ops' instead of
	'all_probe_ops'.
	* probe.h (struct info_probe_column) <field_name>: Delete
	extraneous newline
	(info_probe_column_s): Delete type and VEC.
	(struct probe_ops): Delete.  Replace with...
	(class static_probe_ops): ...this and...
	(clas probe): ...this.
	(struct bound_probe) <bound_probe>: Delete extraneous
	newline.  Adjust constructor to receive 'probe' instead of
	'struct probe'.
	<probe>: Rename to...
	<prob>: ...this.  Delete extraneous newline.
	<objfile>: Delete extraneous newline.
	(register_probe_ops): Delete unused prototype.
	(info_probes_for_ops): Rename to...
	(info_probes_for_spops): ...this.  Adjust comment.
	(get_probe_address): Move to 'probe::get_address'.
	(get_probe_argument_count): Move to
	'probe::get_argument_count'.
	(can_evaluate_probe_arguments): Move to
	'probe::can_evaluate_arguments'.
	(evaluate_probe_argument): Move to 'probe::evaluate_argument'.
	* solib-svr4.c (struct svr4_info): Adjust comment.
	(struct probe_and_action) <probe>: Rename to...
	<prob>: ...this.
	(register_solib_event_probe): Receive 'probe' instead of
	'struct probe' as argument.  Use 'prob' instead of 'probe'
	when applicable.
	(solib_event_probe_action): Call 'get_argument_count' method
	from probe.  Adjust comment.
	(svr4_handle_solib_event): Adjust comment.  Call
	'evaluate_argument' method from probe.
	(svr4_create_probe_breakpoints): Call 'get_relocated_address'
	from probe.
	(svr4_create_solib_event_breakpoints): Use 'probe' instead of
	'struct probe'.  Call 'can_evaluate_arguments' from probe.
	* symfile.h: Forward declare 'class probe' instead of 'struct
	probe'.
	* symtab.h: Likewise.
	(struct symtab_and_line) <probe>: Rename to...
	<prob>: ...this.
	* tracepoint.c (start_tracing): Use 'prob' when applicable.
	Call probe methods.
	(stop_tracing): Likewise.
---
 gdb/break-catch-throw.c |  16 +-
 gdb/breakpoint.c        |  20 +--
 gdb/elfread.c           |   4 +-
 gdb/infrun.c            |   2 +-
 gdb/location.c          |   2 +-
 gdb/probe.c             | 436 ++++++++++++++++++++----------------------------
 gdb/probe.h             | 358 ++++++++++++++++++++-------------------
 gdb/solib-svr4.c        |  36 ++--
 gdb/symfile.h           |   2 +-
 gdb/symtab.h            |   4 +-
 gdb/tracepoint.c        |  16 +-
 11 files changed, 406 insertions(+), 490 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index fd8a113803..edf5c380b5 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -106,20 +106,20 @@ fetch_probe_arguments (struct value **arg0, struct value **arg1)
   unsigned n_args;
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL
-      || strcmp (pc_probe.probe->provider, "libstdcxx") != 0
-      || (strcmp (pc_probe.probe->name, "catch") != 0
-	  && strcmp (pc_probe.probe->name, "throw") != 0
-	  && strcmp (pc_probe.probe->name, "rethrow") != 0))
+  if (pc_probe.prob == NULL
+      || pc_probe.prob->get_provider ().compare ("libstdcxx") != 0
+      || (pc_probe.prob->get_name ().compare ("catch") != 0
+	  && pc_probe.prob->get_name ().compare ("throw") != 0
+	  && pc_probe.prob->get_name ().compare ("rethrow") != 0))
     error (_("not stopped at a C++ exception catchpoint"));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
   if (n_args < 2)
     error (_("C++ exception catchpoint has too few arguments"));
 
   if (arg0 != NULL)
-    *arg0 = evaluate_probe_argument (pc_probe.probe, 0, frame);
-  *arg1 = evaluate_probe_argument (pc_probe.probe, 1, frame);
+    *arg0 = pc_probe.prob->evaluate_argument (0, frame);
+  *arg1 = pc_probe.prob->evaluate_argument (1, frame);
 
   if ((arg0 != NULL && *arg0 == NULL) || *arg1 == NULL)
     error (_("error computing probe argument at c++ exception catchpoint"));
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b170a14cb5..1728aee838 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3309,7 +3309,7 @@ create_longjmp_master_breakpoint (void)
 	      /* We are only interested in checking one element.  */
 	      probe *p = ret[0];
 
-	      if (!can_evaluate_probe_arguments (p))
+	      if (!p->can_evaluate_arguments ())
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
@@ -3329,7 +3329,7 @@ create_longjmp_master_breakpoint (void)
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (p, objfile),
+					      p->get_relocated_address (objfile),
 					      bp_longjmp_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libc:longjmp");
@@ -3462,7 +3462,7 @@ create_exception_master_breakpoint (void)
 	      /* We are only interested in checking one element.  */
 	      probe *p = ret[0];
 
-	      if (!can_evaluate_probe_arguments (p))
+	      if (!p->can_evaluate_arguments ())
 		{
 		  /* We cannot use the probe interface here, because it does
 		     not know how to evaluate arguments.  */
@@ -3482,7 +3482,7 @@ create_exception_master_breakpoint (void)
 	      struct breakpoint *b;
 
 	      b = create_internal_breakpoint (gdbarch,
-					      get_probe_address (p, objfile),
+					      p->get_relocated_address (objfile),
 					      bp_exception_master,
 					      &internal_breakpoint_ops);
 	      b->location = new_probe_location ("-probe-stap libgcc:unwind");
@@ -8694,7 +8694,7 @@ add_location_to_breakpoint (struct breakpoint *b,
   loc->requested_address = sal->pc;
   loc->address = adjusted_address;
   loc->pspace = sal->pspace;
-  loc->probe.probe = sal->probe;
+  loc->probe.prob = sal->prob;
   loc->probe.objfile = sal->objfile;
   gdb_assert (loc->pspace != NULL);
   loc->section = sal->section;
@@ -12879,10 +12879,7 @@ bkpt_probe_insert_location (struct bp_location *bl)
     {
       /* The insertion was successful, now let's set the probe's semaphore
 	 if needed.  */
-      if (bl->probe.probe->pops->set_semaphore != NULL)
-	bl->probe.probe->pops->set_semaphore (bl->probe.probe,
-					      bl->probe.objfile,
-					      bl->gdbarch);
+      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
     }
 
   return v;
@@ -12893,10 +12890,7 @@ bkpt_probe_remove_location (struct bp_location *bl,
 			    enum remove_bp_reason reason)
 {
   /* Let's clear the semaphore before removing the location.  */
-  if (bl->probe.probe->pops->clear_semaphore != NULL)
-    bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
-					    bl->probe.objfile,
-					    bl->gdbarch);
+  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
 
   return bkpt_remove_location (bl, reason);
 }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index cdef5a8c59..f2483025ba 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1324,7 +1324,7 @@ elf_get_probes (struct objfile *objfile)
 
       /* Here we try to gather information about all types of probes from the
 	 objfile.  */
-      for (const probe_ops *ops : all_probe_ops)
+      for (const static_probe_ops *ops : all_static_probe_ops)
 	ops->get_probes (probes_per_bfd, objfile);
 
       set_bfd_data (objfile->obfd, probe_key, probes_per_bfd);
@@ -1342,7 +1342,7 @@ probe_key_free (bfd *abfd, void *d)
   std::vector<probe *> *probes = (std::vector<probe *> *) d;
 
   for (probe *p : *probes)
-    p->pops->destroy (p);
+    delete p;
 
   delete probes;
 }
diff --git a/gdb/infrun.c b/gdb/infrun.c
index e2d1248e75..4592100962 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7583,7 +7583,7 @@ check_exception_resume (struct execution_control_state *ecs,
      CFA and the HANDLER.  We ignore the CFA, extract the handler, and
      set a breakpoint there.  */
   probe = find_probe_by_pc (get_frame_pc (frame));
-  if (probe.probe)
+  if (probe.prob)
     {
       insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
       return;
diff --git a/gdb/location.c b/gdb/location.c
index c78778edc1..5ed3623f0a 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -844,7 +844,7 @@ string_to_event_location_basic (const char **stringp,
 
   /* Try the input as a probe spec.  */
   cs = *stringp;
-  if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
+  if (cs != NULL && probe_linespec_to_static_ops (&cs) != NULL)
     {
       location = new_probe_location (*stringp);
       *stringp += strlen (*stringp);
diff --git a/gdb/probe.c b/gdb/probe.c
index 829f6d18d7..7acbb6cb2a 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -38,11 +38,35 @@
 #include <algorithm>
 #include "common/gdb_optional.h"
 
+/* Class that implements the static probe methods for "any" probe.  */
+
+class any_static_probe_ops : public static_probe_ops
+{
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  std::vector<struct info_probe_column> gen_info_probes_table_header
+    () const override;
+};
+
+/* Static operations associated with a generic probe.  */
+
+const any_static_probe_ops any_static_probe_ops;
+
 /* A helper for parse_probes that decodes a probe specification in
    SEARCH_PSPACE.  It appends matching SALs to RESULT.  */
 
 static void
-parse_probes_in_pspace (const struct probe_ops *probe_ops,
+parse_probes_in_pspace (const static_probe_ops *spops,
 			struct program_space *search_pspace,
 			const char *objfile_namestr,
 			const char *provider,
@@ -67,21 +91,21 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops,
 
       for (probe *p : probes)
 	{
-	  if (probe_ops != &probe_ops_any && p->pops != probe_ops)
+	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
 	    continue;
 
-	  if (provider && strcmp (p->provider, provider) != 0)
+	  if (provider != NULL && p->get_provider ().compare (provider) != 0)
 	    continue;
 
-	  if (strcmp (p->name, name) != 0)
+	  if (p->get_name ().compare (name) != 0)
 	    continue;
 
 	  symtab_and_line sal;
-	  sal.pc = get_probe_address (p, objfile);
+	  sal.pc = p->get_relocated_address (objfile);
 	  sal.explicit_pc = 1;
 	  sal.section = find_pc_overlay (sal.pc);
 	  sal.pspace = search_pspace;
-	  sal.probe = p;
+	  sal.prob = p;
 	  sal.objfile = objfile;
 
 	  result->push_back (std::move (sal));
@@ -98,15 +122,14 @@ parse_probes (const struct event_location *location,
 {
   char *arg_end, *arg;
   char *objfile_namestr = NULL, *provider = NULL, *name, *p;
-  const struct probe_ops *probe_ops;
   const char *arg_start, *cs;
 
   gdb_assert (event_location_type (location) == PROBE_LOCATION);
   arg_start = get_probe_location (location);
 
   cs = arg_start;
-  probe_ops = probe_linespec_to_ops (&cs);
-  if (probe_ops == NULL)
+  const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
+  if (spops == NULL)
     error (_("'%s' is not a probe linespec"), arg_start);
 
   arg = (char *) cs;
@@ -159,7 +182,7 @@ parse_probes (const struct event_location *location,
   std::vector<symtab_and_line> result;
   if (search_pspace != NULL)
     {
-      parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
+      parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
 			      provider, name, &result);
     }
   else
@@ -167,7 +190,7 @@ parse_probes (const struct event_location *location,
       struct program_space *pspace;
 
       ALL_PSPACES (pspace)
-	parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
+	parse_probes_in_pspace (spops, pspace, objfile_namestr,
 				provider, name, &result);
     }
 
@@ -206,10 +229,10 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider,
     = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
   for (probe *p : probes)
     {
-      if (strcmp (p->provider, provider) != 0)
+      if (p->get_provider ().compare (provider) != 0)
 	continue;
 
-      if (strcmp (p->name, name) != 0)
+      if (p->get_name ().compare (name) != 0)
 	continue;
 
       result.push_back (p);
@@ -227,7 +250,7 @@ find_probe_by_pc (CORE_ADDR pc)
   struct bound_probe result;
 
   result.objfile = NULL;
-  result.probe = NULL;
+  result.prob = NULL;
 
   ALL_OBJFILES (objfile)
   {
@@ -239,10 +262,10 @@ find_probe_by_pc (CORE_ADDR pc)
     const std::vector<probe *> &probes
       = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
     for (probe *p : probes)
-      if (get_probe_address (p, objfile) == pc)
+      if (p->get_relocated_address (objfile) == pc)
 	{
 	  result.objfile = objfile;
-	  result.probe = p;
+	  result.prob = p;
 	  return result;
 	}
   }
@@ -253,12 +276,13 @@ find_probe_by_pc (CORE_ADDR pc)
 \f
 
 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
-   If POPS is not NULL, only probes of this certain probe_ops will match.
-   Each argument is a regexp, or NULL, which matches anything.  */
+   If SPOPS is not &any_static_probe_ops, only probes related to this
+   specific static probe ops will match.  Each argument is a regexp,
+   or NULL, which matches anything.  */
 
 static std::vector<bound_probe>
 collect_probes (const std::string &objname, const std::string &provider,
-		const std::string &probe_name, const struct probe_ops *pops)
+		const std::string &probe_name, const static_probe_ops *spops)
 {
   struct objfile *objfile;
   std::vector<bound_probe> result;
@@ -290,15 +314,15 @@ collect_probes (const std::string &objname, const std::string &provider,
 
       for (probe *p : probes)
 	{
-	  if (pops != NULL && p->pops != pops)
+	  if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
 	    continue;
 
 	  if (prov_pat
-	      && prov_pat->exec (p->provider, 0, NULL, 0) != 0)
+	      && prov_pat->exec (p->get_provider ().c_str (), 0, NULL, 0) != 0)
 	    continue;
 
 	  if (probe_pat
-	      && probe_pat->exec (p->name, 0, NULL, 0) != 0)
+	      && probe_pat->exec (p->get_name ().c_str (), 0, NULL, 0) != 0)
 	    continue;
 
 	  result.emplace_back (p, objfile);
@@ -315,16 +339,16 @@ compare_probes (const bound_probe &a, const bound_probe &b)
 {
   int v;
 
-  v = strcmp (a.probe->provider, b.probe->provider);
+  v = a.prob->get_provider ().compare (b.prob->get_provider ());
   if (v != 0)
     return v < 0;
 
-  v = strcmp (a.probe->name, b.probe->name);
+  v = a.prob->get_name ().compare (b.prob->get_name ());
   if (v != 0)
     return v < 0;
 
-  if (a.probe->address != b.probe->address)
-    return a.probe->address < b.probe->address;
+  if (a.prob->get_address () != b.prob->get_address ())
+    return a.prob->get_address () < b.prob->get_address ();
 
   return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
 }
@@ -334,56 +358,33 @@ compare_probes (const bound_probe &a, const bound_probe &b)
 
 static void
 gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
-			      const struct probe_ops *p)
+			      const static_probe_ops *spops)
 {
   /* `headings' refers to the names of the columns when printing `info
      probes'.  */
-  VEC (info_probe_column_s) *headings = NULL;
-  struct cleanup *c;
-  info_probe_column_s *column;
-  size_t headings_size;
-  int ix;
+  gdb_assert (spops != NULL);
 
-  gdb_assert (p != NULL);
+  std::vector<struct info_probe_column> headings
+    = spops->gen_info_probes_table_header ();
 
-  if (p->gen_info_probes_table_header == NULL
-      && p->gen_info_probes_table_values == NULL)
-    return;
-
-  gdb_assert (p->gen_info_probes_table_header != NULL
-	      && p->gen_info_probes_table_values != NULL);
-
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  p->gen_info_probes_table_header (&headings);
-
-  headings_size = VEC_length (info_probe_column_s, headings);
-
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
+  for (const struct info_probe_column &column : headings)
     {
-      size_t size_max = strlen (column->print_name);
+      size_t size_max = strlen (column.print_name);
 
       for (const bound_probe &probe : probes)
 	{
 	  /* `probe_fields' refers to the values of each new field that this
 	     probe will display.  */
-	  VEC (const_char_ptr) *probe_fields = NULL;
-	  struct cleanup *c2;
-	  const char *val;
-	  int kx;
 
-	  if (probe.probe->pops != p)
+	  if (probe.prob->get_static_ops () != spops)
 	    continue;
 
-	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
-	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
+  	  std::vector<const char *> probe_fields
+	    = probe.prob->gen_info_probes_table_values ();
 
-	  gdb_assert (VEC_length (const_char_ptr, probe_fields)
-		      == headings_size);
+	  gdb_assert (probe_fields.size () == headings.size ());
 
-	  for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
-	       ++kx)
+	  for (const char *val : probe_fields)
 	    {
 	      /* It is valid to have a NULL value here, which means that the
 		 backend does not have something to write and this particular
@@ -393,128 +394,75 @@ gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
 
 	      size_max = std::max (strlen (val), size_max);
 	    }
-	  do_cleanups (c2);
 	}
 
       current_uiout->table_header (size_max, ui_left,
-				   column->field_name, column->print_name);
+				   column.field_name, column.print_name);
     }
-
-  do_cleanups (c);
 }
 
 /* Helper function to print not-applicable strings for all the extra
-   columns defined in a probe_ops.  */
+   columns defined in a static_probe_ops.  */
 
 static void
-print_ui_out_not_applicables (const struct probe_ops *pops)
+print_ui_out_not_applicables (const static_probe_ops *spops)
 {
-  struct cleanup *c;
-  VEC (info_probe_column_s) *headings = NULL;
-  info_probe_column_s *column;
-  int ix;
-
-  if (pops->gen_info_probes_table_header == NULL)
-    return;
-
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  pops->gen_info_probes_table_header (&headings);
-
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
-    current_uiout->field_string (column->field_name, _("n/a"));
+   std::vector<struct info_probe_column> headings
+     = spops->gen_info_probes_table_header ();
 
-  do_cleanups (c);
+  for (const struct info_probe_column &column : headings)
+    current_uiout->field_string (column.field_name, _("n/a"));
 }
 
 /* Helper function to print extra information about a probe and an objfile
    represented by PROBE.  */
 
 static void
-print_ui_out_info (struct probe *probe)
+print_ui_out_info (probe *probe)
 {
-  int ix;
-  int j = 0;
   /* `values' refers to the actual values of each new field in the output
      of `info probe'.  `headings' refers to the names of each new field.  */
-  VEC (const_char_ptr) *values = NULL;
-  VEC (info_probe_column_s) *headings = NULL;
-  info_probe_column_s *column;
-  struct cleanup *c;
-
   gdb_assert (probe != NULL);
-  gdb_assert (probe->pops != NULL);
-
-  if (probe->pops->gen_info_probes_table_header == NULL
-      && probe->pops->gen_info_probes_table_values == NULL)
-    return;
-
-  gdb_assert (probe->pops->gen_info_probes_table_header != NULL
-	      && probe->pops->gen_info_probes_table_values != NULL);
-
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  make_cleanup (VEC_cleanup (const_char_ptr), &values);
+  std::vector<struct info_probe_column> headings
+    = probe->get_static_ops ()->gen_info_probes_table_header ();
+  std::vector<const char *> values
+    = probe->gen_info_probes_table_values ();
 
-  probe->pops->gen_info_probes_table_header (&headings);
-  probe->pops->gen_info_probes_table_values (probe, &values);
+  gdb_assert (headings.size () == values.size ());
 
-  gdb_assert (VEC_length (info_probe_column_s, headings)
-	      == VEC_length (const_char_ptr, values));
-
-  for (ix = 0;
-       VEC_iterate (info_probe_column_s, headings, ix, column);
-       ++ix)
+  for (int ix = 0; ix < headings.size (); ++ix)
     {
-      const char *val = VEC_index (const_char_ptr, values, j++);
+      struct info_probe_column column = headings[ix];
+      const char *val = values[ix];
 
       if (val == NULL)
-	current_uiout->field_skip (column->field_name);
+	current_uiout->field_skip (column.field_name);
       else
-	current_uiout->field_string (column->field_name, val);
+	current_uiout->field_string (column.field_name, val);
     }
-
-  do_cleanups (c);
 }
 
 /* Helper function that returns the number of extra fields which POPS will
    need.  */
 
 static int
-get_number_extra_fields (const struct probe_ops *pops)
+get_number_extra_fields (const static_probe_ops *spops)
 {
-  VEC (info_probe_column_s) *headings = NULL;
-  struct cleanup *c;
-  int n;
-
-  if (pops->gen_info_probes_table_header == NULL)
-    return 0;
-
-  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
-  pops->gen_info_probes_table_header (&headings);
-
-  n = VEC_length (info_probe_column_s, headings);
-
-  do_cleanups (c);
-
-  return n;
+  return spops->gen_info_probes_table_header ().size ();
 }
 
-/* Helper function that returns 1 if there is a probe in PROBES
-   featuring the given POPS.  It returns 0 otherwise.  */
+/* Helper function that returns true if there is a probe in PROBES
+   featuring the given SPOPS.  It returns false otherwise.  */
 
-static int
-exists_probe_with_pops (const std::vector<bound_probe> &probes,
-			const struct probe_ops *pops)
+static bool
+exists_probe_with_spops (const std::vector<bound_probe> &probes,
+			 const static_probe_ops *spops)
 {
-  struct bound_probe *probe;
-  int ix;
-
   for (const bound_probe &probe : probes)
-    if (probe.probe->pops == pops)
-      return 1;
+    if (probe.prob->get_static_ops () == spops)
+      return true;
 
-  return 0;
+  return false;
 }
 
 /* Helper function that parses a probe linespec of the form [PROVIDER
@@ -538,8 +486,8 @@ parse_probe_linespec (const char *str, std::string *provider,
 /* See comment in probe.h.  */
 
 void
-info_probes_for_ops (const char *arg, int from_tty,
-		     const struct probe_ops *pops)
+info_probes_for_spops (const char *arg, int from_tty,
+		       const static_probe_ops *spops)
 {
   std::string provider, probe_name, objname;
   int any_found;
@@ -554,26 +502,28 @@ info_probes_for_ops (const char *arg, int from_tty,
   parse_probe_linespec (arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, pops);
+    = collect_probes (objname, provider, probe_name, spops);
 
-  if (pops == NULL)
+  if (spops == &any_static_probe_ops)
     {
-      /* If the probe_ops is NULL, it means the user has requested a "simple"
-	 `info probes', i.e., she wants to print all information about all
-	 probes.  For that, we have to identify how many extra fields we will
-	 need to add in the ui_out table.
-
-	 To do that, we iterate over all probe_ops, querying each one about
-	 its extra fields, and incrementing `ui_out_extra_fields' to reflect
-	 that number.  But note that we ignore the probe_ops for which no probes
-	 are defined with the given search criteria.  */
-
-      for (const probe_ops *po : all_probe_ops)
-	if (exists_probe_with_pops (probes, po))
+      /* If SPOPS is &any_static_probe_ops, it means the user has
+	 requested a "simple" `info probes', i.e., she wants to print
+	 all information about all probes.  For that, we have to
+	 identify how many extra fields we will need to add in the
+	 ui_out table.
+
+	 To do that, we iterate over all static_probe_ops, querying
+	 each one about its extra fields, and incrementing
+	 `ui_out_extra_fields' to reflect that number.  But note that
+	 we ignore the static_probe_ops for which no probes are
+	 defined with the given search criteria.  */
+
+      for (const static_probe_ops *po : all_static_probe_ops)
+	if (exists_probe_with_spops (probes, po))
 	  ui_out_extra_fields += get_number_extra_fields (po);
     }
   else
-    ui_out_extra_fields = get_number_extra_fields (pops);
+    ui_out_extra_fields = get_number_extra_fields (spops);
 
   {
     ui_out_emit_table table_emitter (current_uiout,
@@ -589,11 +539,12 @@ info_probes_for_ops (const char *arg, int from_tty,
        `name' and `objname').  */
     for (const bound_probe &probe : probes)
       {
-	const char *probe_type = probe.probe->pops->type_name (probe.probe);
+	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
 
 	size_type = std::max (strlen (probe_type), size_type);
-	size_name = std::max (strlen (probe.probe->name), size_name);
-	size_provider = std::max (strlen (probe.probe->provider), size_provider);
+	size_name = std::max (probe.prob->get_name ().size (), size_name);
+	size_provider = std::max (probe.prob->get_provider ().size (),
+				  size_provider);
 	size_objname = std::max (strlen (objfile_name (probe.objfile)),
 				 size_objname);
       }
@@ -604,44 +555,47 @@ info_probes_for_ops (const char *arg, int from_tty,
     current_uiout->table_header (size_name, ui_left, "name", _("Name"));
     current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
 
-    if (pops == NULL)
+    if (spops == &any_static_probe_ops)
       {
 	/* We have to generate the table header for each new probe type
 	   that we will print.  Note that this excludes probe types not
 	   having any defined probe with the search criteria.  */
-	for (const probe_ops *po : all_probe_ops)
-	  if (exists_probe_with_pops (probes, po))
+	for (const static_probe_ops *po : all_static_probe_ops)
+	  if (exists_probe_with_spops (probes, po))
 	    gen_ui_out_table_header_info (probes, po);
       }
     else
-      gen_ui_out_table_header_info (probes, pops);
+      gen_ui_out_table_header_info (probes, spops);
 
     current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
     current_uiout->table_body ();
 
     for (const bound_probe &probe : probes)
       {
-	const char *probe_type = probe.probe->pops->type_name (probe.probe);
+	const char *probe_type = probe.prob->get_static_ops ()->type_name ();
 
 	ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
 
-	current_uiout->field_string ("type",probe_type);
-	current_uiout->field_string ("provider", probe.probe->provider);
-	current_uiout->field_string ("name", probe.probe->name);
-	current_uiout->field_core_addr ("addr", probe.probe->arch,
-					get_probe_address (probe.probe,
-							   probe.objfile));
+	current_uiout->field_string ("type", probe_type);
+	current_uiout->field_string ("provider",
+				     probe.prob->get_provider ().c_str ());
+	current_uiout->field_string ("name", probe.prob->get_name ().c_str ());
+	current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
+					probe.prob->get_relocated_address
+					(probe.objfile));
 
-	if (pops == NULL)
+	if (spops == &any_static_probe_ops)
 	  {
-	    for (const probe_ops *po : all_probe_ops)
-	      if (probe.probe->pops == po)
-		print_ui_out_info (probe.probe);
-	      else if (exists_probe_with_pops (probes, po))
-		print_ui_out_not_applicables (po);
+	    for (const static_probe_ops *po : all_static_probe_ops)
+	      {
+		if (probe.prob->get_static_ops () == po)
+		  print_ui_out_info (probe.prob);
+		else if (exists_probe_with_spops (probes, po))
+		  print_ui_out_not_applicables (po);
+	      }
 	  }
 	else
-	  print_ui_out_info (probe.probe);
+	  print_ui_out_info (probe.prob);
 
 	current_uiout->field_string ("object",
 				     objfile_name (probe.objfile));
@@ -660,7 +614,7 @@ info_probes_for_ops (const char *arg, int from_tty,
 static void
 info_probes_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, NULL);
+  info_probes_for_spops (arg, from_tty, &any_static_probe_ops);
 }
 
 /* Implementation of the `enable probes' command.  */
@@ -673,7 +627,7 @@ enable_probes_command (const char *arg, int from_tty)
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, NULL);
+    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
@@ -684,17 +638,17 @@ enable_probes_command (const char *arg, int from_tty)
      notion of enabling a probe.  */
   for (const bound_probe &probe: probes)
     {
-      const struct probe_ops *pops = probe.probe->pops;
-
-      if (pops->enable_probe != NULL)
+      if (probe.prob->get_static_ops ()->can_enable ())
 	{
-	  pops->enable_probe (probe.probe);
+	  probe.prob->enable ();
 	  current_uiout->message (_("Probe %s:%s enabled.\n"),
-				  probe.probe->provider, probe.probe->name);
+				  probe.prob->get_provider ().c_str (),
+				  probe.prob->get_name ().c_str ());
 	}
       else
 	current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
-				probe.probe->provider, probe.probe->name);
+				probe.prob->get_provider ().c_str (),
+				probe.prob->get_name ().c_str ());
     }
 }
 
@@ -708,7 +662,7 @@ disable_probes_command (const char *arg, int from_tty)
   parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
 
   std::vector<bound_probe> probes
-    = collect_probes (objname, provider, probe_name, NULL /* pops */);
+    = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
   if (probes.empty ())
     {
       current_uiout->message (_("No probes matched.\n"));
@@ -719,55 +673,22 @@ disable_probes_command (const char *arg, int from_tty)
      notion of enabling a probe.  */
   for (const bound_probe &probe : probes)
     {
-      const struct probe_ops *pops = probe.probe->pops;
-
-      if (pops->disable_probe != NULL)
+      if (probe.prob->get_static_ops ()->can_enable ())
 	{
-	  pops->disable_probe (probe.probe);
+	  probe.prob->disable ();
 	  current_uiout->message (_("Probe %s:%s disabled.\n"),
-				  probe.probe->provider, probe.probe->name);
+				  probe.prob->get_provider ().c_str (),
+				  probe.prob->get_name ().c_str ());
 	}
       else
 	current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
-				probe.probe->provider, probe.probe->name);
+				probe.prob->get_provider ().c_str (),
+				probe.prob->get_name ().c_str ());
     }
 }
 
 /* See comments in probe.h.  */
 
-CORE_ADDR
-get_probe_address (struct probe *probe, struct objfile *objfile)
-{
-  return probe->pops->get_probe_address (probe, objfile);
-}
-
-/* See comments in probe.h.  */
-
-unsigned
-get_probe_argument_count (struct probe *probe, struct frame_info *frame)
-{
-  return probe->pops->get_probe_argument_count (probe, frame);
-}
-
-/* See comments in probe.h.  */
-
-int
-can_evaluate_probe_arguments (struct probe *probe)
-{
-  return probe->pops->can_evaluate_probe_arguments (probe);
-}
-
-/* See comments in probe.h.  */
-
-struct value *
-evaluate_probe_argument (struct probe *probe, unsigned n,
-			 struct frame_info *frame)
-{
-  return probe->pops->evaluate_probe_argument (probe, n, frame);
-}
-
-/* See comments in probe.h.  */
-
 struct value *
 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
 {
@@ -775,22 +696,22 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
   unsigned n_args;
 
   probe = find_probe_by_pc (get_frame_pc (frame));
-  if (!probe.probe)
+  if (!probe.prob)
     return NULL;
 
-  n_args = get_probe_argument_count (probe.probe, frame);
+  n_args = probe.prob->get_argument_count (frame);
   if (n >= n_args)
     return NULL;
 
-  return evaluate_probe_argument (probe.probe, n, frame);
+  return probe.prob->evaluate_argument (n, frame);
 }
 
 /* See comment in probe.h.  */
 
-const struct probe_ops *
-probe_linespec_to_ops (const char **linespecp)
+const struct static_probe_ops *
+probe_linespec_to_static_ops (const char **linespecp)
 {
-  for (const probe_ops *ops : all_probe_ops)
+  for (const static_probe_ops *ops : all_static_probe_ops)
     if (ops->is_linespec (linespecp))
       return ops;
 
@@ -820,31 +741,40 @@ probe_is_linespec_by_keyword (const char **linespecp, const char *const *keyword
   return 0;
 }
 
-/* Implementation of `is_linespec' method for `struct probe_ops'.  */
+/* Implementation of `is_linespec' method.  */
 
-static int
-probe_any_is_linespec (const char **linespecp)
+bool
+any_static_probe_ops::is_linespec (const char **linespecp) const
 {
   static const char *const keywords[] = { "-p", "-probe", NULL };
 
   return probe_is_linespec_by_keyword (linespecp, keywords);
 }
 
-/* Dummy method used for `probe_ops_any'.  */
+/* Implementation of 'get_probes' method.  */
 
-static void
-probe_any_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+void
+any_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				  struct objfile *objfile) const
 {
   /* No probes can be provided by this dummy backend.  */
 }
 
-/* Operations associated with a generic probe.  */
+/* Implementation of the 'type_name' method.  */
 
-const struct probe_ops probe_ops_any =
+const char *
+any_static_probe_ops::type_name () const
 {
-  probe_any_is_linespec,
-  probe_any_get_probes,
-};
+  return NULL;
+}
+
+/* Implementation of the 'gen_info_probes_table_header' method.  */
+
+std::vector<struct info_probe_column>
+any_static_probe_ops::gen_info_probes_table_header () const
+{
+  return std::vector<struct info_probe_column> ();
+}
 
 /* See comments in probe.h.  */
 
@@ -883,17 +813,16 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
   CORE_ADDR pc = get_frame_pc (frame);
   int sel = (int) (uintptr_t) data;
   struct bound_probe pc_probe;
-  const struct sym_probe_fns *pc_probe_fns;
   unsigned n_args;
 
   /* SEL == -1 means "_probe_argc".  */
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL)
+  if (pc_probe.prob == NULL)
     error (_("No probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
   if (sel == -1)
     return value_from_longest (builtin_type (arch)->builtin_int, n_args);
 
@@ -901,7 +830,7 @@ compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
     error (_("Invalid probe argument %d -- probe has %u arguments available"),
 	   sel, n_args);
 
-  return evaluate_probe_argument (pc_probe.probe, sel, frame);
+  return pc_probe.prob->evaluate_argument (sel, frame);
 }
 
 /* This is called to compile one of the $_probe_arg* convenience
@@ -914,7 +843,6 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
   CORE_ADDR pc = expr->scope;
   int sel = (int) (uintptr_t) data;
   struct bound_probe pc_probe;
-  const struct sym_probe_fns *pc_probe_fns;
   int n_args;
   struct frame_info *frame = get_selected_frame (NULL);
 
@@ -922,10 +850,10 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
   gdb_assert (sel >= -1);
 
   pc_probe = find_probe_by_pc (pc);
-  if (pc_probe.probe == NULL)
+  if (pc_probe.prob == NULL)
     error (_("No probe at PC %s"), core_addr_to_string (pc));
 
-  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  n_args = pc_probe.prob->get_argument_count (frame);
 
   if (sel == -1)
     {
@@ -940,7 +868,7 @@ compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
     error (_("Invalid probe argument %d -- probe has %d arguments available"),
 	   sel, n_args);
 
-  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
+  pc_probe.prob->compile_to_ax (expr, value, sel);
 }
 
 static const struct internalvar_funcs probe_funcs =
@@ -951,12 +879,12 @@ static const struct internalvar_funcs probe_funcs =
 };
 
 
-std::vector<const probe_ops *> all_probe_ops;
+std::vector<const static_probe_ops *> all_static_probe_ops;
 
 void
 _initialize_probe (void)
 {
-  all_probe_ops.push_back (&probe_ops_any);
+  all_static_probe_ops.push_back (&any_static_probe_ops);
 
   create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
 				(void *) (uintptr_t) -1);
diff --git a/gdb/probe.h b/gdb/probe.h
index 822e5c89a9..9586774a50 100644
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -30,7 +30,6 @@ struct info_probe_column
   {
     /* The internal name of the field.  This string cannot be capitalized nor
        localized, e.g., "extra_field".  */
-
     const char *field_name;
 
     /* The field name to be printed in the `info probes' command.  This
@@ -38,165 +37,201 @@ struct info_probe_column
     const char *print_name;
   };
 
-typedef struct info_probe_column info_probe_column_s;
-DEF_VEC_O (info_probe_column_s);
+/* Operations that act on probes, but are specific to each backend.
+   These methods do not go into the 'class probe' because they do not
+   act on a single probe; instead, they are used to operate on many
+   probes at once, or to provide information about the probe backend
+   itself, instead of a single probe.
 
-/* Operations associated with a probe.  */
+   Each probe backend needs to inherit this class and implement all of
+   the virtual functions specified here.  Then, an object shall be
+   instantiated and added (or "registered") to the
+   ALL_STATIC_PROBE_OPS vector so that the frontend probe interface
+   can use it in the generic probe functions.  */
 
-struct probe_ops
+class static_probe_ops
+{
+public:
+  /* Method responsible for verifying if LINESPECP is a valid linespec
+     for a probe breakpoint.  It should return true if it is, or false
+     if it is not.  It also should update LINESPECP in order to
+     discard the breakpoint option associated with this linespec.  For
+     example, if the option is `-probe', and the LINESPECP is `-probe
+     abc', the function should return 1 and set LINESPECP to
+     `abc'.  */
+  virtual bool is_linespec (const char **linespecp) const = 0;
+
+  /* Function that should fill PROBES with known probes from OBJFILE.  */
+  virtual void get_probes (std::vector<probe *> *probes,
+			    struct objfile *objfile) const = 0;
+
+  /* Return a pointer to a name identifying the probe type.  This is
+     the string that will be displayed in the "Type" column of the
+     `info probes' command.  */
+  virtual const char *type_name () const = 0;
+
+  /* Return true if the probe can be enabled; false otherwise.  */
+  virtual bool can_enable () const
   {
-    /* Method responsible for verifying if LINESPECP is a valid linespec for
-       a probe breakpoint.  It should return 1 if it is, or zero if it is not.
-       It also should update LINESPECP in order to discard the breakpoint
-       option associated with this linespec.  For example, if the option is
-       `-probe', and the LINESPECP is `-probe abc', the function should
-       return 1 and set LINESPECP to `abc'.  */
-
-    int (*is_linespec) (const char **linespecp);
-
-    /* Function that should fill PROBES with known probes from OBJFILE.  */
-
-    void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile);
-
-    /* Compute the probe's relocated address.  OBJFILE is the objfile
-       in which the probe originated.  */
-
-    CORE_ADDR (*get_probe_address) (struct probe *probe,
-				    struct objfile *objfile);
-
-    /* Return the number of arguments of PROBE.  This function can
-       throw an exception.  */
-
-    unsigned (*get_probe_argument_count) (struct probe *probe,
-					  struct frame_info *frame);
-
-    /* Return 1 if the probe interface can evaluate the arguments of probe
-       PROBE, zero otherwise.  See the comments on
-       sym_probe_fns:can_evaluate_probe_arguments for more details.  */
-
-    int (*can_evaluate_probe_arguments) (struct probe *probe);
-
-    /* Evaluate the Nth argument from the PROBE, returning a value
-       corresponding to it.  The argument number is represented N.
-       This function can throw an exception.  */
-
-    struct value *(*evaluate_probe_argument) (struct probe *probe,
-					      unsigned n,
-					      struct frame_info *frame);
-
-    /* Compile the Nth argument of the PROBE to an agent expression.
-       The argument number is represented by N.  */
-
-    void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
-			   struct axs_value *axs_value, unsigned n);
-
-    /* Set the semaphore associated with the PROBE.  This function only makes
-       sense if the probe has a concept of semaphore associated to a
-       probe, otherwise it can be set to NULL.  */
-
-    void (*set_semaphore) (struct probe *probe, struct objfile *objfile,
-			   struct gdbarch *gdbarch);
-
-    /* Clear the semaphore associated with the PROBE.  This function only
-       makes sense if the probe has a concept of semaphore associated to
-       a probe, otherwise it can be set to NULL.  */
-
-    void (*clear_semaphore) (struct probe *probe, struct objfile *objfile,
-			     struct gdbarch *gdbarch);
-
-    /* Function called to destroy PROBE's specific data.  This function
-       shall not free PROBE itself.  */
-
-    void (*destroy) (struct probe *probe);
-
-    /* Return a pointer to a name identifying the probe type.  This is
-       the string that will be displayed in the "Type" column of the
-       `info probes' command.  */
-
-    const char *(*type_name) (struct probe *probe);
+    return false;
+  }
+
+  /* Function responsible for providing the extra fields that will be
+     printed in the `info probes' command.  It should fill HEADS
+     with whatever extra fields it needs.  If no extra fields are
+     required by the probe backend, the method EMIT_INFO_PROBES_FIELDS
+     should return false.  */
+  virtual std::vector<struct info_probe_column>
+    gen_info_probes_table_header () const = 0;
+};
 
-    /* Function responsible for providing the extra fields that will be
-       printed in the `info probes' command.  It should fill HEADS
-       with whatever extra fields it needs.  If the backend doesn't need
-       to print extra fields, it can set this method to NULL.  */
+/* Definition of a vector of static_probe_ops.  */
 
-    void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
+extern std::vector<const static_probe_ops *> all_static_probe_ops;
 
-    /* Function that will fill VALUES with the values of the extra fields
-       to be printed for PROBE.  If the backend implements the
-       `gen_ui_out_table_header' method, then it should implement
-       this method as well.  The backend should also guarantee that the
-       order and the number of values in the vector is exactly the same
-       as the order of the extra fields provided in the method
-       `gen_ui_out_table_header'.  If a certain field is to be skipped
-       when printing the information, you can push a NULL value in that
-       position in the vector.  */
+/* Helper function that, given KEYWORDS, iterate over it trying to match
+   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
+   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
+   is returned.  */
 
-    void (*gen_info_probes_table_values) (struct probe *probe,
-					  VEC (const_char_ptr) **values);
+extern int probe_is_linespec_by_keyword (const char **linespecp,
+					 const char *const *keywords);
 
-    /* Enable a probe.  The semantics of "enabling" a probe depend on
-       the specific backend and the field can be NULL in case enabling
-       probes is not supported.  This function can throw an
-       exception.  */
+/* Return specific STATIC_PROBE_OPS * matching *LINESPECP and possibly
+   updating LINESPECP to skip its "-probe-type " prefix.  Return
+   &static_probe_ops_any if LINESPECP matches "-probe ", that is any
+   unspecific probe.  Return NULL if LINESPECP is not identified as
+   any known probe type, *LINESPECP is not modified in such case.  */
 
-    void (*enable_probe) (struct probe *probe);
+extern const static_probe_ops *
+  probe_linespec_to_static_ops (const char **linespecp);
 
-    /* Disable a probe.  The semantics of "disabling" a probe depend
-       on the specific backend and the field can be NULL in case
-       disabling probes is not supported.  This function can throw an
-       exception.  */
+/* The probe itself.  The class contains generic information about the
+   probe.  */
 
-    void (*disable_probe) (struct probe *probe);
-  };
+class probe
+{
+public:
+  /* Default constructor for a probe.  */
+  probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+	 struct gdbarch *arch_)
+    : m_name (std::move (name_)), m_provider (std::move (provider_)),
+      m_address (address_), m_arch (arch_)
+  {}
 
-/* Definition of a vector of probe_ops.  */
+  /* Virtual destructor.  */
+  virtual ~probe ()
+  {}
 
-extern std::vector<const probe_ops *> all_probe_ops;
+  /* Compute the probe's relocated address.  OBJFILE is the objfile
+     in which the probe originated.  */
+  virtual CORE_ADDR get_relocated_address (struct objfile *objfile) = 0;
+
+  /* Return the number of arguments of the probe.  This function can
+     throw an exception.  */
+  virtual unsigned get_argument_count (struct frame_info *frame) = 0;
+
+  /* Return 1 if the probe interface can evaluate the arguments of
+     probe, zero otherwise.  See the comments on
+     sym_probe_fns:can_evaluate_probe_arguments for more
+     details.  */
+  virtual bool can_evaluate_arguments () const = 0;
+
+  /* Evaluate the Nth argument from the probe, returning a value
+     corresponding to it.  The argument number is represented N.
+     This function can throw an exception.  */
+  virtual struct value *evaluate_argument (unsigned n,
+					   struct frame_info *frame) = 0;
+
+  /* Compile the Nth argument of the probe to an agent expression.
+     The argument number is represented by N.  */
+  virtual void compile_to_ax (struct agent_expr *aexpr,
+			      struct axs_value *axs_value,
+			      unsigned n) = 0;
+
+  /* Set the semaphore associated with the probe.  This function only
+     makes sense if the probe has a concept of semaphore associated to
+     a probe.  */
+  virtual void set_semaphore (struct objfile *objfile,
+			      struct gdbarch *gdbarch)
+  {}
 
-/* The probe_ops associated with the generic probe.  */
+  /* Clear the semaphore associated with the probe.  This function
+     only makes sense if the probe has a concept of semaphore
+     associated to a probe.  */
+  virtual void clear_semaphore (struct objfile *objfile,
+				struct gdbarch *gdbarch)
+  {}
 
-extern const struct probe_ops probe_ops_any;
+  /* Return the pointer to the static_probe_ops instance related to
+     the probe type.  */
+  virtual const static_probe_ops *get_static_ops () const = 0;
+
+  /* Function that will fill VALUES with the values of the extra
+     fields to be printed for the probe.
+
+     If the backend implements the `gen_ui_out_table_header' method,
+     then it should implement this method as well.  The backend should
+     also guarantee that the order and the number of values in the
+     vector is exactly the same as the order of the extra fields
+     provided in the method `gen_ui_out_table_header'.  If a certain
+     field is to be skipped when printing the information, you can
+     push a NULL value in that position in the vector.  */
+  virtual std::vector<const char *> gen_info_probes_table_values () const
+  {
+    return std::vector<const char *> ();
+  }
 
-/* Helper function that, given KEYWORDS, iterate over it trying to match
-   each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
-   pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
-   is returned.  */
+  /* Enable the probe.  The semantics of "enabling" a probe depend on
+     the specific backend.  This function can throw an exception.  */
+  virtual void enable ()
+  {}
 
-extern int probe_is_linespec_by_keyword (const char **linespecp,
-					 const char *const *keywords);
+  /* Disable the probe.  The semantics of "disabling" a probe depend
+     on the specific backend.  This function can throw an
+     exception.  */
+  virtual void disable ()
+  {}
 
-/* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
-   *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
-   *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
-   *LINESPECP is not identified as any known probe type, *LINESPECP is not
-   modified in such case.  */
+  /* Getter for M_NAME.  */
+  const std::string &get_name () const
+  {
+    return m_name;
+  }
 
-extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
+  /* Getter for M_PROVIDER.  */
+  const std::string &get_provider () const
+  {
+    return m_provider;
+  }
 
-/* The probe itself.  The struct contains generic information about the
-   probe, and then some specific information which should be stored in
-   the `probe_info' field.  */
+  /* Getter for M_ADDRESS.  */
+  CORE_ADDR get_address () const
+  {
+    return m_address;
+  }
 
-struct probe
+  /* Getter for M_ARCH.  */
+  struct gdbarch *get_gdbarch () const
   {
-    /* The operations associated with this probe.  */
-    const struct probe_ops *pops;
+    return m_arch;
+  }
 
-    /* The probe's architecture.  */
-    struct gdbarch *arch;
+private:
+  /* The name of the probe.  */
+  std::string m_name;
 
-    /* The name of the probe.  */
-    const char *name;
+  /* The provider of the probe.  It generally defaults to the name of
+     the objfile which contains the probe.  */
+  std::string m_provider;
 
-    /* The provider of the probe.  It generally defaults to the name of
-       the objfile which contains the probe.  */
-    const char *provider;
+  /* The address where the probe is inserted, relative to
+     SECT_OFF_TEXT.  */
+  CORE_ADDR m_address;
 
-    /* The address where the probe is inserted, relative to
-       SECT_OFF_TEXT.  */
-    CORE_ADDR address;
-  };
+  /* The probe's architecture.  */
+  struct gdbarch *m_arch;
+};
 
 /* A bound probe holds a pointer to a probe and a pointer to the
    probe's defining objfile.  This is needed because probes are
@@ -206,22 +241,18 @@ struct probe
 struct bound_probe
 {
   /* Create an empty bound_probe object.  */
-
   bound_probe ()
   {}
 
   /* Create and initialize a bound_probe object using PROBE and OBJFILE.  */
-
-  bound_probe (struct probe *probe_, struct objfile *objfile_)
-  : probe (probe_), objfile (objfile_)
+  bound_probe (probe *probe_, struct objfile *objfile_)
+  : prob (probe_), objfile (objfile_)
   {}
 
   /* The probe.  */
-
-  struct probe *probe = NULL;
+  probe *prob = NULL;
 
   /* The objfile in which the probe originated.  */
-
   struct objfile *objfile = NULL;
 };
 
@@ -234,11 +265,6 @@ extern std::vector<symtab_and_line> parse_probes
    struct program_space *pspace,
    struct linespec_result *canon);
 
-/* Helper function to register the proper probe_ops to a newly created probe.
-   This function is mainly called from `sym_get_probes'.  */
-
-extern void register_probe_ops (struct probe *probe);
-
 /* Given a PC, find an associated probe.  If a probe is found, return
    it.  If no probe is found, return a bound probe whose fields are
    both NULL.  */
@@ -253,13 +279,13 @@ 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
-   function that can be used by the probe backends to print their
-   `info probe TYPE'.  */
+/* Generate a `info probes' command output for probes associated with
+   SPOPS.  If SPOPS is related to the "any probe" type, then all probe
+   types are considered.  It is a helper function that can be used by
+   the probe backends to print their `info probe TYPE'.  */
 
-extern void info_probes_for_ops (const char *arg, int from_tty,
-				 const struct probe_ops *pops);
+extern void info_probes_for_spops (const char *arg, int from_tty,
+				   const static_probe_ops *spops);
 
 /* Return the `cmd_list_element' associated with the `info probes' command,
    or create a new one if it doesn't exist.  Helper function that serves the
@@ -268,34 +294,6 @@ extern void info_probes_for_ops (const char *arg, int from_tty,
 
 extern struct cmd_list_element **info_probes_cmdlist_get (void);
 
-/* Compute the probe's relocated address.  OBJFILE is the objfile in
-   which the probe originated.  */
-
-extern CORE_ADDR get_probe_address (struct probe *probe,
-				    struct objfile *objfile);
-
-/* Return the argument count of the specified probe.
-
-   This function can throw an exception.  */
-
-extern unsigned get_probe_argument_count (struct probe *probe,
-					  struct frame_info *frame);
-
-/* Return 1 if the probe interface associated with PROBE can evaluate
-   arguments, zero otherwise.  See the comments on the definition of
-   sym_probe_fns:can_evaluate_probe_arguments for more details.  */
-
-extern int can_evaluate_probe_arguments (struct probe *probe);
-
-/* Evaluate argument N of the specified probe.  N must be between 0
-   inclusive and get_probe_argument_count exclusive.
-
-   This function can throw an exception.  */
-
-extern struct value *evaluate_probe_argument (struct probe *probe,
-					      unsigned n,
-					      struct frame_info *frame);
-
 /* A convenience function that finds a probe at the PC in FRAME and
    evaluates argument N, with 0 <= N < number_of_args.  If there is no
    probe at that location, or if the probe does not have enough arguments,
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 5ec606de43..6e834fb5d7 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -351,7 +351,7 @@ struct svr4_info
   /* Table of struct probe_and_action instances, used by the
      probes-based interface to map breakpoint addresses to probes
      and their associated actions.  Lookup is performed using
-     probe_and_action->probe->address.  */
+     probe_and_action->prob->address.  */
   htab_t probes_table;
 
   /* List of objects loaded into the inferior, used by the probes-
@@ -1664,7 +1664,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ)
 struct probe_and_action
 {
   /* The probe.  */
-  struct probe *probe;
+  probe *prob;
 
   /* The relocated address of the probe.  */
   CORE_ADDR address;
@@ -1699,7 +1699,7 @@ equal_probe_and_action (const void *p1, const void *p2)
    probes table.  */
 
 static void
-register_solib_event_probe (struct probe *probe, CORE_ADDR address,
+register_solib_event_probe (probe *prob, CORE_ADDR address,
 			    enum probe_action action)
 {
   struct svr4_info *info = get_svr4_info ();
@@ -1712,13 +1712,13 @@ register_solib_event_probe (struct probe *probe, CORE_ADDR address,
 					    equal_probe_and_action,
 					    xfree, xcalloc, xfree);
 
-  lookup.probe = probe;
+  lookup.prob = prob;
   lookup.address = address;
   slot = htab_find_slot (info->probes_table, &lookup, INSERT);
   gdb_assert (*slot == HTAB_EMPTY_ENTRY);
 
   pa = XCNEW (struct probe_and_action);
-  pa->probe = probe;
+  pa->prob = prob;
   pa->address = address;
   pa->action = action;
 
@@ -1767,7 +1767,7 @@ solib_event_probe_action (struct probe_and_action *pa)
        arg2: struct link_map *new (optional, for incremental updates)  */
   TRY
     {
-      probe_argc = get_probe_argument_count (pa->probe, frame);
+      probe_argc = pa->prob->get_argument_count (frame);
     }
   CATCH (ex, RETURN_MASK_ERROR)
     {
@@ -1776,11 +1776,11 @@ solib_event_probe_action (struct probe_and_action *pa)
     }
   END_CATCH
 
-  /* If get_probe_argument_count throws an exception, probe_argc will
-     be set to zero.  However, if pa->probe does not have arguments,
-     then get_probe_argument_count will succeed but probe_argc will
-     also be zero.  Both cases happen because of different things, but
-     they are treated equally here: action will be set to
+  /* If get_argument_count throws an exception, probe_argc will be set
+     to zero.  However, if pa->prob does not have arguments, then
+     get_argument_count will succeed but probe_argc will also be zero.
+     Both cases happen because of different things, but they are
+     treated equally here: action will be set to
      PROBES_INTERFACE_FAILED.  */
   if (probe_argc == 2)
     action = FULL_RELOAD;
@@ -1922,7 +1922,7 @@ svr4_handle_solib_event (void)
       return;
     }
 
-  /* evaluate_probe_argument looks up symbols in the dynamic linker
+  /* evaluate_argument looks up symbols in the dynamic linker
      using find_pc_section.  find_pc_section is accelerated by a cache
      called the section map.  The section map is invalidated every
      time a shared library is loaded or unloaded, and if the inferior
@@ -1931,14 +1931,14 @@ svr4_handle_solib_event (void)
      We called find_pc_section in svr4_create_solib_event_breakpoints,
      so we can guarantee that the dynamic linker's sections are in the
      section map.  We can therefore inhibit section map updates across
-     these calls to evaluate_probe_argument and save a lot of time.  */
+     these calls to evaluate_argument and save a lot of time.  */
   inhibit_section_map_updates (current_program_space);
   usm_chain = make_cleanup (resume_section_map_updates_cleanup,
 			    current_program_space);
 
   TRY
     {
-      val = evaluate_probe_argument (pa->probe, 1, frame);
+      val = pa->prob->evaluate_argument (1, frame);
     }
   CATCH (ex, RETURN_MASK_ERROR)
     {
@@ -1979,7 +1979,7 @@ svr4_handle_solib_event (void)
     {
       TRY
 	{
-	  val = evaluate_probe_argument (pa->probe, 2, frame);
+	  val = pa->prob->evaluate_argument (2, frame);
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
@@ -2084,7 +2084,7 @@ svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
 
       for (probe *p : probes[i])
 	{
-	  CORE_ADDR address = get_probe_address (p, objfile);
+	  CORE_ADDR address = p->get_relocated_address (objfile);
 
 	  create_solib_event_breakpoint (gdbarch, address);
 	  register_solib_event_probe (p, address, action);
@@ -2126,7 +2126,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	  for (int i = 0; i < NUM_PROBES; i++)
 	    {
 	      const char *name = probe_info[i].name;
-	      struct probe *p;
+	      probe *p;
 	      char buf[32];
 
 	      /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
@@ -2160,7 +2160,7 @@ svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 	      if (!checked_can_use_probe_arguments)
 		{
 		  p = probes[i][0];
-		  if (!can_evaluate_probe_arguments (p))
+		  if (!p->can_evaluate_arguments ())
 		    {
 		      all_probes_found = 0;
 		      break;
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 3472aa0e7b..10b1504937 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -34,11 +34,11 @@ struct objfile;
 struct obj_section;
 struct obstack;
 struct block;
-struct probe;
 struct value;
 struct frame_info;
 struct agent_expr;
 struct axs_value;
+class probe;
 
 /* Comparison function for symbol look ups.  */
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index e419d8c734..144f0cf3ca 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -42,10 +42,10 @@ struct axs_value;
 struct agent_expr;
 struct program_space;
 struct language_defn;
-struct probe;
 struct common_block;
 struct obj_section;
 struct cmd_list_element;
+class probe;
 struct lookup_name_info;
 
 /* How to match a lookup name against a symbol search name.  */
@@ -1703,7 +1703,7 @@ struct symtab_and_line
   bool explicit_line = false;
 
   /* The probe associated with this symtab_and_line.  */
-  struct probe *probe = NULL;
+  probe *prob = NULL;
   /* If PROBE is not NULL, then this is the objfile in which the probe
      originated.  */
   struct objfile *objfile = NULL;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 59a7b64ae8..76d05dfc13 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1654,11 +1654,9 @@ start_tracing (const char *notes)
       t->number_on_target = b->number;
 
       for (loc = b->loc; loc; loc = loc->next)
-	if (loc->probe.probe != NULL
-	    && loc->probe.probe->pops->set_semaphore != NULL)
-	  loc->probe.probe->pops->set_semaphore (loc->probe.probe,
-						 loc->probe.objfile,
-						 loc->gdbarch);
+	if (loc->probe.prob != NULL)
+	  loc->probe.prob->set_semaphore (loc->probe.objfile,
+					  loc->gdbarch);
 
       if (bp_location_downloaded)
 	observer_notify_breakpoint_modified (b);
@@ -1754,11 +1752,9 @@ stop_tracing (const char *note)
 	     but we don't really care if this semaphore goes out of sync.
 	     That's why we are decrementing it here, but not taking care
 	     in other places.  */
-	  if (loc->probe.probe != NULL
-	      && loc->probe.probe->pops->clear_semaphore != NULL)
-	    loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
-						     loc->probe.objfile,
-						     loc->gdbarch);
+	  if (loc->probe.prob != NULL)
+	    loc->probe.prob->clear_semaphore (loc->probe.objfile,
+					      loc->gdbarch);
 	}
     }
 
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 3/3] Convert DTrace probe interface to C++ (and perform some cleanups)
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
@ 2017-11-16  4:38   ` Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 1/3] Convert generic " Sergio Durigan Junior
  2017-11-21 16:25   ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  3 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-16  4:38 UTC (permalink / raw)
  To: GDB Patches; +Cc: Simon Marchi, Sergio Durigan Junior

Changes from v1:

- Use 'expression_up' on 'struct dtrace_probe_arg'; new constructor on
  struct; delete destructor of 'dtrace_probe'.

- Use && for vectors on 'dtrace_probe' constructor.

- Get rid of 'm_argc'; use 'm_args.size ()' instead.

- Use const references when itearating over a vector of objects.

- Perform a bound check on 'get_arg_by_number'.

This patch converts the DTrace probe
interface (gdb/dtrace-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct dtrace_probe' to 'class
dtrace_probe', and a new 'class dtrace_static_probe_ops' to replace the
use of 'dtrace_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the dtrace-probe interface.

There are several helper functions used to parse parts of a dtrace
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I wasn't able to test these modifications because the current test
framework for DTrace probes is not working.  See
<https://sourceware.org/bugzilla/show_bug.cgi?id=22420>.

gdb/ChangeLog:
2017-11-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* dtrace-probe.c (struct probe_ops dtrace_probe_ops): Delete.
	(struct dtrace_probe_arg) <dtrace_probe_arg>: New constructor.
	<type_str>: Convert to 'std::string'.
	<expr>: Convert to 'expression_up'.
	(dtrace_probe_arg_s): Delete type and VEC.
	(dtrace_probe_enabler_s): Likewise.
	(struct dtrace_probe): Replace by...
	(class dtrace_static_probe_ops): ...this and...
	(class dtrace_probe): ...this.
	(dtrace_probe_is_linespec): Rename to...
	(dtrace_static_probe_ops::is_linespec): ...this.  Adjust code
	to reflect change.
	(dtrace_process_dof_probe): Use 'std::vector' instead of VEC.
	Adjust code.  Create new instance of 'dtrace_probe'.
	(dtrace_build_arg_exprs): Rename to...
	(dtrace_probe::build_arg_exprs): ...this.  Adjust code to
	reflect change.
	(dtrace_get_probes): Rename to...
	(dtrace_static_probe_ops::get_probes): ...this.  Adjust code
	to reflect change.
	(dtrace_get_arg): Rename to...
	(dtrace_probe::get_arg_by_number): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_is_enabled): Rename to...
	(dtrace_probe::is_enabled): ...this.  Adjust code to reflect
	change.
	(dtrace_get_probe_address): Rename to...
	(dtrace_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(dtrace_get_probe_argument_count): Rename to...
	(dtrace_probe::get_argument_count): ...this.  Adjust code to
	reflect change.
	(dtrace_can_evaluate_probe_arguments): Rename to...
	(dtrace_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(dtrace_evaluate_probe_argument): Rename to...
	(dtrace_probe::evaluate_argument): ...this.  Adjust code to
	reflect change.
	(dtrace_compile_to_ax): Rename to...
	(dtrace_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(dtrace_probe_destroy): Delete.
	(dtrace_type_name): Rename to...
	(dtrace_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(dtrace_probe::get_static_ops): New method.
	(dtrace_gen_info_probes_table_header): Rename to...
	(dtrace_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(dtrace_gen_info_probes_table_values): Rename to...
	(dtrace_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(dtrace_enable_probe): Rename to...
	(dtrace_probe::enable_probe): ...this.  Adjust code to reflect
	change.
	(dtrace_disable_probe): Rename to...
	(dtrace_probe::disable_probe): ...this.  Adjust code to reflect
	change.
	(struct probe_ops dtrace_probe_ops): Delete.
	(info_probes_dtrace_command): Call 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_dtrace_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
---
 gdb/dtrace-probe.c | 550 ++++++++++++++++++++++++++---------------------------
 1 file changed, 274 insertions(+), 276 deletions(-)

diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 2bbe03e4b3..ace3d306a1 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -41,28 +41,27 @@
 # define SHT_SUNW_dof	0x6ffffff4
 #endif
 
-/* Forward declaration.  */
-
-extern const struct probe_ops dtrace_probe_ops;
-
 /* The following structure represents a single argument for the
    probe.  */
 
 struct dtrace_probe_arg
 {
+  dtrace_probe_arg (struct type *type_, std::string &&type_str_,
+		    expression_up &&expr_)
+    : type (type_), type_str (std::move (type_str_)),
+      expr (std::move (expr_))
+  {}
+
   /* The type of the probe argument.  */
   struct type *type;
 
   /* A string describing the type.  */
-  char *type_str;
+  std::string type_str;
 
   /* The argument converted to an internal GDB expression.  */
-  struct expression *expr;
+  expression_up expr;
 };
 
-typedef struct dtrace_probe_arg dtrace_probe_arg_s;
-DEF_VEC_O (dtrace_probe_arg_s);
-
 /* The following structure represents an enabler for a probe.  */
 
 struct dtrace_probe_enabler
@@ -73,39 +72,106 @@ struct dtrace_probe_enabler
   CORE_ADDR address;
 };
 
-typedef struct dtrace_probe_enabler dtrace_probe_enabler_s;
-DEF_VEC_O (dtrace_probe_enabler_s);
+/* Class that implements the static probe methods for "stap" probes.  */
+
+class dtrace_static_probe_ops : public static_probe_ops
+{
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  bool can_enable () const override
+  {
+    return true;
+  }
+
+  /* See probe.h.  */
+  std::vector<struct info_probe_column> gen_info_probes_table_header
+    () const override;
+};
+
+/* DTrace static_probe_ops.  */
+
+const dtrace_static_probe_ops dtrace_static_probe_ops;
 
 /* The following structure represents a dtrace probe.  */
 
-struct dtrace_probe
+class dtrace_probe : public probe
 {
-  /* Generic information about the probe.  This must be the first
-     element of this struct, in order to maintain binary compatibility
-     with the `struct probe' and be able to fully abstract it.  */
-  struct probe p;
-
+public:
+  /* Constructor for dtrace_probe.  */
+  dtrace_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+		struct gdbarch *arch_,
+		std::vector<struct dtrace_probe_arg> &&args_,
+		std::vector<struct dtrace_probe_enabler> &&enablers_)
+    : probe (std::move (name_), std::move (provider_), address_, arch_),
+      m_args (std::move (args_)),
+      m_enablers (std::move (enablers_)),
+      m_args_expr_built (false)
+  {}
+
+  /* See probe.h.  */
+  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
+
+  /* See probe.h.  */
+  unsigned get_argument_count (struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  bool can_evaluate_arguments () const override;
+
+  /* See probe.h.  */
+  struct value *evaluate_argument (unsigned n,
+				   struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  void compile_to_ax (struct agent_expr *aexpr,
+		      struct axs_value *axs_value,
+		      unsigned n) override;
+
+  /* See probe.h.  */
+  const static_probe_ops *get_static_ops () const override;
+
+  /* See probe.h.  */
+  std::vector<const char *> gen_info_probes_table_values () const override;
+
+  /* See probe.h.  */
+  void enable () override;
+
+  /* See probe.h.  */
+  void disable () override;
+
+  /* Return the Nth argument of the probe.  */
+  struct dtrace_probe_arg *get_arg_by_number (unsigned n,
+					      struct gdbarch *gdbarch);
+
+  /* Build the GDB internal expressiosn that, once evaluated, will
+     calculate the values of the arguments of the probe.  */
+  void build_arg_exprs (struct gdbarch *gdbarch);
+
+  /* Determine whether the probe is "enabled" or "disabled".  A
+     disabled probe is a probe in which one or more enablers are
+     disabled.  */
+  bool is_enabled () const;
+
+private:
   /* A probe can have zero or more arguments.  */
-  int probe_argc;
-  VEC (dtrace_probe_arg_s) *args;
+  std::vector<struct dtrace_probe_arg> m_args;
 
   /* A probe can have zero or more "enablers" associated with it.  */
-  VEC (dtrace_probe_enabler_s) *enablers;
+  std::vector<struct dtrace_probe_enabler> m_enablers;
 
   /* Whether the expressions for the arguments have been built.  */
-  unsigned int args_expr_built : 1;
+  bool m_args_expr_built;
 };
 
-/* Implementation of the probe_is_linespec method.  */
-
-static int
-dtrace_probe_is_linespec (const char **linespecp)
-{
-  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
-
-  return probe_is_linespec_by_keyword (linespecp, keywords);
-}
-
 /* DOF programs can contain an arbitrary number of sections of 26
    different types.  In order to support DTrace USDT probes we only
    need to handle a subset of these section types, fortunately.  These
@@ -322,8 +388,6 @@ dtrace_process_dof_probe (struct objfile *objfile,
 			  char *argtab, uint64_t strtab_size)
 {
   int i, j, num_probes, num_enablers;
-  struct cleanup *cleanup;
-  VEC (dtrace_probe_enabler_s) *enablers;
   char *p;
 
   /* Each probe section can define zero or more probes of two
@@ -368,9 +432,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
   /* Build the list of enablers for the probes defined in this Probe
      DOF section.  */
-  enablers = NULL;
-  cleanup
-    = make_cleanup (VEC_cleanup (dtrace_probe_enabler_s), &enablers);
+  std::vector<struct dtrace_probe_enabler> enablers;
   num_enablers = DOF_UINT (dof, probe->dofpr_nenoffs);
   for (i = 0; i < num_enablers; i++)
     {
@@ -380,46 +442,38 @@ dtrace_process_dof_probe (struct objfile *objfile,
 
       enabler.address = DOF_UINT (dof, probe->dofpr_addr)
 	+ DOF_UINT (dof, enabler_offset);
-      VEC_safe_push (dtrace_probe_enabler_s, enablers, &enabler);
+      enablers.push_back (enabler);
     }
 
   for (i = 0; i < num_probes; i++)
     {
       uint32_t probe_offset
 	= ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
-      struct dtrace_probe *ret =
-	XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
-
-      ret->p.pops = &dtrace_probe_ops;
-      ret->p.arch = gdbarch;
-      ret->args_expr_built = 0;
 
       /* Set the provider and the name of the probe.  */
-      ret->p.provider
-	= xstrdup (strtab + DOF_UINT (dof, provider->dofpv_name));
-      ret->p.name = xstrdup (strtab + DOF_UINT (dof, probe->dofpr_name));
+      const char *probe_provider
+	= strtab + DOF_UINT (dof, provider->dofpv_name);
+      const char *name = strtab + DOF_UINT (dof, probe->dofpr_name);
 
       /* The probe address.  */
-      ret->p.address
+      CORE_ADDR address
 	= DOF_UINT (dof, probe->dofpr_addr) + DOF_UINT (dof, probe_offset);
 
       /* Number of arguments in the probe.  */
-      ret->probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
+      int probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
 
       /* Store argument type descriptions.  A description of the type
          of the argument is in the (J+1)th null-terminated string
          starting at 'strtab' + 'probe->dofpr_nargv'.  */
-      ret->args = NULL;
+      std::vector<struct dtrace_probe_arg> args;
       p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
-      for (j = 0; j < ret->probe_argc; j++)
+      for (j = 0; j < probe_argc; j++)
 	{
-	  struct dtrace_probe_arg arg;
 	  expression_up expr;
 
 	  /* Set arg.expr to ensure all fields in expr are initialized and
 	     the compiler will not warn when arg is used.  */
-	  arg.expr = NULL;
-	  arg.type_str = xstrdup (p);
+	  std::string type_str (p);
 
 	  /* Use strtab_size as a sentinel.  */
 	  while (*p++ != '\0' && p - strtab < strtab_size)
@@ -428,11 +482,13 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	  /* Try to parse a type expression from the type string.  If
 	     this does not work then we set the type to `long
 	     int'.  */
-          arg.type = builtin_type (gdbarch)->builtin_long;
+          struct type *type = builtin_type (gdbarch)->builtin_long;
 
 	  TRY
 	    {
-	      expr = parse_expression_with_language (arg.type_str, language_c);
+	      expression_up expr
+		= parse_expression_with_language (type_str.c_str (),
+						  language_c);
 	    }
 	  CATCH (ex, RETURN_MASK_ERROR)
 	    {
@@ -440,19 +496,21 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	  END_CATCH
 
 	  if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
-	    arg.type = expr->elts[1].type;
+	    type = expr->elts[1].type;
 
-	  VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
+	  args.emplace_back (type, std::move (type_str), std::move (expr));
 	}
 
-      /* Add the vector of enablers to this probe, if any.  */
-      ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
+      std::vector<struct dtrace_probe_enabler> enablers_copy = enablers;
+      dtrace_probe *ret = new dtrace_probe (std::string (name),
+					    std::string (probe_provider),
+					    address, gdbarch,
+					    std::move (args),
+					    std::move (enablers_copy));
 
       /* Successfully created probe.  */
-      probesp->push_back ((struct probe *) ret);
+      probesp->push_back (ret);
     }
-
-  do_cleanups (cleanup);
 }
 
 /* Helper function to collect the probes described in the DOF program
@@ -555,28 +613,21 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
 	     sect->name);
 }
 
-/* Helper function to build the GDB internal expressiosn that, once
-   evaluated, will calculate the values of the arguments of a given
-   PROBE.  */
+/* Implementation of 'build_arg_exprs' method.  */
 
-static void
-dtrace_build_arg_exprs (struct dtrace_probe *probe,
-			struct gdbarch *gdbarch)
+void
+dtrace_probe::build_arg_exprs (struct gdbarch *gdbarch)
 {
-  struct parser_state pstate;
-  struct dtrace_probe_arg *arg;
-  int i;
-
-  probe->args_expr_built = 1;
+  size_t argc = 0;
+  m_args_expr_built = true;
 
   /* Iterate over the arguments in the probe and build the
      corresponding GDB internal expression that will generate the
      value of the argument when executed at the PC of the probe.  */
-  for (i = 0; i < probe->probe_argc; i++)
+  for (struct dtrace_probe_arg &arg : m_args)
     {
       struct cleanup *back_to;
-
-      arg = VEC_index (dtrace_probe_arg_s, probe->args, i);
+      struct parser_state pstate;
 
       /* Initialize the expression buffer in the parser state.  The
 	 language does not matter, since we are using our own
@@ -586,243 +637,153 @@ dtrace_build_arg_exprs (struct dtrace_probe *probe,
 
       /* The argument value, which is ABI dependent and casted to
 	 `long int'.  */
-      gdbarch_dtrace_parse_probe_argument (gdbarch, &pstate, i);
+      gdbarch_dtrace_parse_probe_argument (gdbarch, &pstate, argc);
 
       discard_cleanups (back_to);
 
       /* Casting to the expected type, but only if the type was
 	 recognized at probe load time.  Otherwise the argument will
 	 be evaluated as the long integer passed to the probe.  */
-      if (arg->type != NULL)
+      if (arg.type != NULL)
 	{
 	  write_exp_elt_opcode (&pstate, UNOP_CAST);
-	  write_exp_elt_type (&pstate, arg->type);
+	  write_exp_elt_type (&pstate, arg.type);
 	  write_exp_elt_opcode (&pstate, UNOP_CAST);
 	}
 
       reallocate_expout (&pstate);
-      arg->expr = pstate.expout;
-      prefixify_expression (arg->expr);
+      arg.expr = expression_up (pstate.expout);
+      prefixify_expression (arg.expr.get ());
+      ++argc;
     }
 }
 
-/* Helper function to return the Nth argument of a given PROBE.  */
+/* Implementation of 'get_arg_by_number' method.  */
 
-static struct dtrace_probe_arg *
-dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
-		struct gdbarch *gdbarch)
+struct dtrace_probe_arg *
+dtrace_probe::get_arg_by_number (unsigned n, struct gdbarch *gdbarch)
 {
-  if (!probe->args_expr_built)
-    dtrace_build_arg_exprs (probe, gdbarch);
-
-  return VEC_index (dtrace_probe_arg_s, probe->args, n);
+  if (!m_args_expr_built)
+    this->build_arg_exprs (gdbarch);
+
+  if (n > m_args.size ())
+    internal_error (__FILE__, __LINE__,
+		    _("Probe '%s' has %d arguments, but GDB is requesting\n"
+		      "argument %u.  This should not happen.  Please\n"
+		      "report this bug."),
+		    this->get_name ().c_str (),
+		    (int) m_args.size (), n);
+
+  return &m_args[n];
 }
 
-/* Implementation of the get_probes method.  */
+/* Implementation of the probe is_enabled method.  */
 
-static void
-dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+bool
+dtrace_probe::is_enabled () const
 {
-  bfd *abfd = objfile->obfd;
-  asection *sect = NULL;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
-  /* Do nothing in case this is a .debug file, instead of the objfile
-     itself.  */
-  if (objfile->separate_debug_objfile_backlink != NULL)
-    return;
+  for (const struct dtrace_probe_enabler &enabler : m_enablers)
+    if (!gdbarch_dtrace_probe_is_enabled (gdbarch, enabler.address))
+      return false;
 
-  /* Iterate over the sections in OBJFILE looking for DTrace
-     information.  */
-  for (sect = abfd->sections; sect != NULL; sect = sect->next)
-    {
-      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
-	{
-	  bfd_byte *dof;
-
-	  /* Read the contents of the DOF section and then process it to
-	     extract the information of any probe defined into it.  */
-	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
-	    complaint (&symfile_complaints,
-		       _("could not obtain the contents of"
-			 "section '%s' in objfile `%s'."),
-		       sect->name, abfd->filename);
-      
-	  dtrace_process_dof (sect, objfile, probesp,
-			      (struct dtrace_dof_hdr *) dof);
-	  xfree (dof);
-	}
-    }
-}
-
-/* Helper function to determine whether a given probe is "enabled" or
-   "disabled".  A disabled probe is a probe in which one or more
-   enablers are disabled.  */
-
-static int
-dtrace_probe_is_enabled (struct dtrace_probe *probe)
-{
-  int i;
-  struct gdbarch *gdbarch = probe->p.arch;
-  struct dtrace_probe_enabler *enabler;
-
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, probe->enablers, i, enabler);
-       i++)
-    if (!gdbarch_dtrace_probe_is_enabled (gdbarch, enabler->address))
-      return 0;
-
-  return 1;
+  return true;
 }
 
 /* Implementation of the get_probe_address method.  */
 
-static CORE_ADDR
-dtrace_get_probe_address (struct probe *probe, struct objfile *objfile)
+CORE_ADDR
+dtrace_probe::get_relocated_address (struct objfile *objfile)
 {
-  gdb_assert (probe->pops == &dtrace_probe_ops);
-  return probe->address + ANOFFSET (objfile->section_offsets,
-				    SECT_OFF_DATA (objfile));
+  return this->get_address () + ANOFFSET (objfile->section_offsets,
+					  SECT_OFF_DATA (objfile));
 }
 
-/* Implementation of the get_probe_argument_count method.  */
+/* Implementation of the get_argument_count method.  */
 
-static unsigned
-dtrace_get_probe_argument_count (struct probe *probe_generic,
-				 struct frame_info *frame)
+unsigned
+dtrace_probe::get_argument_count (struct frame_info *frame)
 {
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  return dtrace_probe->probe_argc;
+  return m_args.size ();
 }
 
-/* Implementation of the can_evaluate_probe_arguments method.  */
+/* Implementation of the can_evaluate_arguments method.  */
 
-static int
-dtrace_can_evaluate_probe_arguments (struct probe *probe_generic)
+bool
+dtrace_probe::can_evaluate_arguments () const
 {
-  struct gdbarch *gdbarch = probe_generic->arch;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
   return gdbarch_dtrace_parse_probe_argument_p (gdbarch);
 }
 
-/* Implementation of the evaluate_probe_argument method.  */
+/* Implementation of the evaluate_argument method.  */
 
-static struct value *
-dtrace_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
-				struct frame_info *frame)
+struct value *
+dtrace_probe::evaluate_argument (unsigned n,
+				 struct frame_info *frame)
 {
-  struct gdbarch *gdbarch = probe_generic->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
   struct dtrace_probe_arg *arg;
   int pos = 0;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  arg = dtrace_get_arg (dtrace_probe, n, gdbarch);
-  return evaluate_subexp_standard (arg->type, arg->expr, &pos, EVAL_NORMAL);
+  arg = this->get_arg_by_number (n, gdbarch);
+  return evaluate_subexp_standard (arg->type, arg->expr.get (), &pos,
+				   EVAL_NORMAL);
 }
 
 /* Implementation of the compile_to_ax method.  */
 
-static void
-dtrace_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
-		      struct axs_value *value, unsigned n)
+void
+dtrace_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
+			     unsigned n)
 {
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
   struct dtrace_probe_arg *arg;
   union exp_element *pc;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  arg = dtrace_get_arg (dtrace_probe, n, expr->gdbarch);
+  arg = this->get_arg_by_number (n, expr->gdbarch);
 
   pc = arg->expr->elts;
-  gen_expr (arg->expr, &pc, expr, value);
+  gen_expr (arg->expr.get (), &pc, expr, value);
 
   require_rvalue (expr, value);
   value->type = arg->type;
 }
 
-/* Implementation of the probe_destroy method.  */
+/* Implementation of the 'get_static_ops' method.  */
 
-static void
-dtrace_probe_destroy (struct probe *probe_generic)
+const static_probe_ops *
+dtrace_probe::get_static_ops () const
 {
-  struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
-  struct dtrace_probe_arg *arg;
-  int i;
-
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  for (i = 0; VEC_iterate (dtrace_probe_arg_s, probe->args, i, arg); i++)
-    {
-      xfree (arg->type_str);
-      xfree (arg->expr);
-    }
-
-  VEC_free (dtrace_probe_enabler_s, probe->enablers);
-  VEC_free (dtrace_probe_arg_s, probe->args);
-}
-
-/* Implementation of the type_name method.  */
-
-static const char *
-dtrace_type_name (struct probe *probe_generic)
-{
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-  return "dtrace";
-}
-
-/* Implementation of the gen_info_probes_table_header method.  */
-
-static void
-dtrace_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
-{
-  info_probe_column_s dtrace_probe_column;
-
-  dtrace_probe_column.field_name = "enabled";
-  dtrace_probe_column.print_name = _("Enabled");
-
-  VEC_safe_push (info_probe_column_s, *heads, &dtrace_probe_column);
+  return &dtrace_static_probe_ops;
 }
 
 /* Implementation of the gen_info_probes_table_values method.  */
 
-static void
-dtrace_gen_info_probes_table_values (struct probe *probe_generic,
-				     VEC (const_char_ptr) **ret)
+std::vector<const char *>
+dtrace_probe::gen_info_probes_table_values () const
 {
-  struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
   const char *val = NULL;
 
-  gdb_assert (probe_generic->pops == &dtrace_probe_ops);
-
-  if (VEC_empty (dtrace_probe_enabler_s, probe->enablers))
+  if (m_enablers.empty ())
     val = "always";
-  else if (!gdbarch_dtrace_probe_is_enabled_p (probe_generic->arch))
+  else if (!gdbarch_dtrace_probe_is_enabled_p (this->get_gdbarch ()))
     val = "unknown";
-  else if (dtrace_probe_is_enabled (probe))
+  else if (this->is_enabled ())
     val = "yes";
   else
     val = "no";
 
-  VEC_safe_push (const_char_ptr, *ret, val);
+  return std::vector<const char *> { val };
 }
 
-/* Implementation of the enable_probe method.  */
+/* Implementation of the enable method.  */
 
-static void
-dtrace_enable_probe (struct probe *probe)
+void
+dtrace_probe::enable ()
 {
-  struct gdbarch *gdbarch = probe->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
-  struct dtrace_probe_enabler *enabler;
-  int i;
-
-  gdb_assert (probe->pops == &dtrace_probe_ops);
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* Enabling a dtrace probe implies patching the text section of the
      running process, so make sure the inferior is indeed running.  */
@@ -830,31 +791,23 @@ dtrace_enable_probe (struct probe *probe)
     error (_("No inferior running"));
 
   /* Fast path.  */
-  if (dtrace_probe_is_enabled (dtrace_probe))
+  if (this->is_enabled ())
     return;
 
   /* Iterate over all defined enabler in the given probe and enable
      them all using the corresponding gdbarch hook.  */
-
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
-       i++)
+  for (const struct dtrace_probe_enabler &enabler : m_enablers)
     if (gdbarch_dtrace_enable_probe_p (gdbarch))
-      gdbarch_dtrace_enable_probe (gdbarch, enabler->address);
+      gdbarch_dtrace_enable_probe (gdbarch, enabler.address);
 }
 
 
 /* Implementation of the disable_probe method.  */
 
-static void
-dtrace_disable_probe (struct probe *probe)
+void
+dtrace_probe::disable ()
 {
-  struct gdbarch *gdbarch = probe->arch;
-  struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
-  struct dtrace_probe_enabler *enabler;
-  int i;
-
-  gdb_assert (probe->pops == &dtrace_probe_ops);
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* Disabling a dtrace probe implies patching the text section of the
      running process, so make sure the inferior is indeed running.  */
@@ -862,57 +815,102 @@ dtrace_disable_probe (struct probe *probe)
     error (_("No inferior running"));
 
   /* Fast path.  */
-  if (!dtrace_probe_is_enabled (dtrace_probe))
+  if (!this->is_enabled ())
     return;
 
   /* Are we trying to disable a probe that does not have any enabler
      associated?  */
-  if (VEC_empty (dtrace_probe_enabler_s, dtrace_probe->enablers))
-    error (_("Probe %s:%s cannot be disabled: no enablers."), probe->provider, probe->name);
+  if (m_enablers.empty ())
+    error (_("Probe %s:%s cannot be disabled: no enablers."),
+	   this->get_provider ().c_str (), this->get_name ().c_str ());
 
   /* Iterate over all defined enabler in the given probe and disable
      them all using the corresponding gdbarch hook.  */
-
-  for (i = 0;
-       VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
-       i++)
+  for (struct dtrace_probe_enabler &enabler : m_enablers)
     if (gdbarch_dtrace_disable_probe_p (gdbarch))
-      gdbarch_dtrace_disable_probe (gdbarch, enabler->address);
+      gdbarch_dtrace_disable_probe (gdbarch, enabler.address);
 }
 
-/* DTrace probe_ops.  */
+/* Implementation of the is_linespec method.  */
 
-const struct probe_ops dtrace_probe_ops =
+bool
+dtrace_static_probe_ops::is_linespec (const char **linespecp) const
 {
-  dtrace_probe_is_linespec,
-  dtrace_get_probes,
-  dtrace_get_probe_address,
-  dtrace_get_probe_argument_count,
-  dtrace_can_evaluate_probe_arguments,
-  dtrace_evaluate_probe_argument,
-  dtrace_compile_to_ax,
-  NULL, /* set_semaphore  */
-  NULL, /* clear_semaphore  */
-  dtrace_probe_destroy,
-  dtrace_type_name,
-  dtrace_gen_info_probes_table_header,
-  dtrace_gen_info_probes_table_values,
-  dtrace_enable_probe,
-  dtrace_disable_probe
-};
+  static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
+
+  return probe_is_linespec_by_keyword (linespecp, keywords);
+}
+
+/* Implementation of the get_probes method.  */
+
+void
+dtrace_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				     struct objfile *objfile) const
+{
+  bfd *abfd = objfile->obfd;
+  asection *sect = NULL;
+
+  /* Do nothing in case this is a .debug file, instead of the objfile
+     itself.  */
+  if (objfile->separate_debug_objfile_backlink != NULL)
+    return;
+
+  /* Iterate over the sections in OBJFILE looking for DTrace
+     information.  */
+  for (sect = abfd->sections; sect != NULL; sect = sect->next)
+    {
+      if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
+	{
+	  bfd_byte *dof;
+
+	  /* Read the contents of the DOF section and then process it to
+	     extract the information of any probe defined into it.  */
+	  if (!bfd_malloc_and_get_section (abfd, sect, &dof))
+	    complaint (&symfile_complaints,
+		       _("could not obtain the contents of"
+			 "section '%s' in objfile `%s'."),
+		       sect->name, abfd->filename);
+      
+	  dtrace_process_dof (sect, objfile, probesp,
+			      (struct dtrace_dof_hdr *) dof);
+	  xfree (dof);
+	}
+    }
+}
+
+/* Implementation of the type_name method.  */
+
+const char *
+dtrace_static_probe_ops::type_name () const
+{
+  return "dtrace";
+}
+
+/* Implementation of the gen_info_probes_table_header method.  */
+
+std::vector<struct info_probe_column>
+dtrace_static_probe_ops::gen_info_probes_table_header () const
+{
+  struct info_probe_column dtrace_probe_column;
+
+  dtrace_probe_column.field_name = "enabled";
+  dtrace_probe_column.print_name = _("Enabled");
+
+  return std::vector<struct info_probe_column> { dtrace_probe_column };
+}
 
 /* Implementation of the `info probes dtrace' command.  */
 
 static void
 info_probes_dtrace_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, &dtrace_probe_ops);
+  info_probes_for_spops (arg, from_tty, &dtrace_static_probe_ops);
 }
 
 void
 _initialize_dtrace_probe (void)
 {
-  all_probe_ops.push_back (&dtrace_probe_ops);
+  all_static_probe_ops.push_back (&dtrace_static_probe_ops);
 
   add_cmd ("dtrace", class_info, info_probes_dtrace_command,
 	   _("\
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
@ 2017-11-16  4:38   ` Sergio Durigan Junior
  2017-11-16  4:38   ` [PATCH v2 3/3] Convert DTrace " Sergio Durigan Junior
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-16  4:38 UTC (permalink / raw)
  To: GDB Patches; +Cc: Simon Marchi, Sergio Durigan Junior

Changes from v1:

- Deleted destructor from 'class stap_probe'; created constructor in
  'struct stap_probe_arg'; use 'expression_up' instead of 'struct
  expression *'.

- Perform a bound check on 'get_arg_by_number'.

- Fix comment on 'parse_arguments'.

- Use 'get_relocated_address' on 'set_semaphore' and
  'clear_semaphore'.

This patch converts the SystemTap probe
interface (gdb/stap-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct stap_probe' to 'class
stap_probe', and a new 'class stap_static_probe_ops' to replace the
use of 'stap_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the stap-probe interface.

There are several helper functions used to parse parts of a stap
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-16  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Simon Marchi  <simark@simark.ca>

	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
	variable.
	(struct stap_probe_arg) <stap_probe_arg>: New constructor.
	<aexpr>: Change type to 'expression_up'.
	(stap_probe_arg_s): Delete type and VEC.
	(struct stap_probe): Delete.  Replace by...
	(class stap_static_probe_ops): ...this and...
	(class stap_probe): ...this.  Rename variables to add 'm_'
	prefix.  Do not use 'union' for arguments anymore.
	(stap_get_expected_argument_type): Receive probe name instead
	of 'struct stap_probe'.  Adjust code.
	(stap_parse_probe_arguments): Rename to...
	(stap_probe::parse_arguments): ...this.  Adjust code to
	reflect change.
	(stap_get_probe_address): Rename to...
	(stap_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(stap_get_probe_argument_count): Rename to...
	(stap_probe::get_argument_count): ...this.  Adjust code
	to reflect change.
	(stap_get_arg): Rename to...
	(stap_probe::get_arg_by_number'): ...this. Adjust code to
	reflect change.
	(can_evaluate_probe_arguments): Rename to...
	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(stap_evaluate_probe_argument): Rename to...
	(stap_probe::evaluate_argument): ...this.  Adjust code
	to reflect change.
	(stap_compile_to_ax): Rename to...
	(stap_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(stap_probe_destroy): Delete.
	(stap_modify_semaphore): Adjust comment.
	(stap_set_semaphore): Rename to...
	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
	change.
	(stap_clear_semaphore): Rename to...
	(stap_probe::clear_semaphore): ...this.  Adjust code to
	reflect	change.
	(stap_probe::get_static_ops): New method.
	(handle_stap_probe): Adjust code to create instance of
	'stap_probe'.
	(stap_get_probes): Rename to...
	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
	reflect change.
	(stap_probe_is_linespec): Rename to...
	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
	reflect change.
	(stap_type_name): Rename to...
	(stap_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(stap_gen_info_probes_table_header): Rename to...
	(stap_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(stap_gen_info_probes_table_values): Rename to...
	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(struct probe_ops stap_probe_ops): Delete.
	(info_probes_stap_command): Use 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
---
 gdb/stap-probe.c | 534 +++++++++++++++++++++++++++----------------------------
 1 file changed, 261 insertions(+), 273 deletions(-)

diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 6fa0d20280..63100c9fb3 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -45,10 +45,6 @@
 
 #define STAP_BASE_SECTION_NAME ".stapsdt.base"
 
-/* Forward declaration. */
-
-extern const struct probe_ops stap_probe_ops;
-
 /* Should we display debug information for the probe's argument expression
    parsing?  */
 
@@ -85,6 +81,12 @@ enum stap_arg_bitness
 
 struct stap_probe_arg
 {
+  /* Constructor for stap_probe_arg.  */
+  stap_probe_arg (enum stap_arg_bitness bitness_, struct type *atype_,
+		  expression_up &&aexpr_)
+  : bitness (bitness_), atype (atype_), aexpr (std::move (aexpr_))
+  {}
+
   /* The bitness of this argument.  */
   enum stap_arg_bitness bitness;
 
@@ -92,35 +94,134 @@ struct stap_probe_arg
   struct type *atype;
 
   /* The argument converted to an internal GDB expression.  */
-  struct expression *aexpr;
+  expression_up aexpr;
 };
 
-typedef struct stap_probe_arg stap_probe_arg_s;
-DEF_VEC_O (stap_probe_arg_s);
+/* Class that implements the static probe methods for "stap" probes.  */
 
-struct stap_probe
+class stap_static_probe_ops : public static_probe_ops
 {
-  /* Generic information about the probe.  This shall be the first element
-     of this struct, in order to maintain binary compatibility with the
-     `struct probe' and be able to fully abstract it.  */
-  struct probe p;
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
 
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  std::vector<struct info_probe_column> gen_info_probes_table_header
+    () const override;
+};
+
+/* SystemTap static_probe_ops.  */
+
+const stap_static_probe_ops stap_static_probe_ops;
+
+class stap_probe : public probe
+{
+public:
+  /* Constructor for stap_probe.  */
+  stap_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+	      struct gdbarch *arch_, CORE_ADDR sem_addr, const char *args_text)
+    : probe (std::move (name_), std::move (provider_), address_, arch_),
+      m_sem_addr (sem_addr),
+      m_have_parsed_args (false), m_unparsed_args_text (args_text)
+  {}
+
+  /* See probe.h.  */
+  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
+
+  /* See probe.h.  */
+  unsigned get_argument_count (struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  bool can_evaluate_arguments () const override;
+
+  /* See probe.h.  */
+  struct value *evaluate_argument (unsigned n,
+				   struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  void compile_to_ax (struct agent_expr *aexpr,
+		      struct axs_value *axs_value,
+		      unsigned n) override;
+
+  /* See probe.h.  */
+  void set_semaphore (struct objfile *objfile,
+		      struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  void clear_semaphore (struct objfile *objfile,
+			struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  const static_probe_ops *get_static_ops () const override;
+
+  /* See probe.h.  */
+  std::vector<const char *> gen_info_probes_table_values () const override;
+
+  /* Return argument N of probe.
+
+     If the probe's arguments have not been parsed yet, parse them.  If
+     there are no arguments, throw an exception (error).  Otherwise,
+     return the requested argument.  */
+  struct stap_probe_arg *get_arg_by_number (unsigned n,
+					    struct gdbarch *gdbarch)
+  {
+    if (!m_have_parsed_args)
+      this->parse_arguments (gdbarch);
+
+    gdb_assert (m_have_parsed_args);
+    if (m_parsed_args.empty ())
+      internal_error (__FILE__, __LINE__,
+		      _("Probe '%s' apparently does not have arguments, but \n"
+			"GDB is requesting its argument number %u anyway.  "
+			"This should not happen.  Please report this bug."),
+		      this->get_name ().c_str (), n);
+
+    if (n > m_parsed_args.size ())
+      internal_error (__FILE__, __LINE__,
+		      _("Probe '%s' has %d arguments, but GDB is requesting\n"
+			"argument %u.  This should not happen.  Please\n"
+			"report this bug."),
+		      this->get_name ().c_str (),
+		      (int) m_parsed_args.size (), n);
+
+    return &m_parsed_args[n];
+  }
+
+  /* Function which parses an argument string from the probe,
+     correctly splitting the arguments and storing their information
+     in properly ways.
+
+     Consider the following argument string (x86 syntax):
+
+     `4@%eax 4@$10'
+
+     We have two arguments, `%eax' and `$10', both with 32-bit
+     unsigned bitness.  This function basically handles them, properly
+     filling some structures with this information.  */
+  void parse_arguments (struct gdbarch *gdbarch);
+
+private:
   /* If the probe has a semaphore associated, then this is the value of
      it, relative to SECT_OFF_DATA.  */
-  CORE_ADDR sem_addr;
+  CORE_ADDR m_sem_addr;
 
-  /* One if the arguments have been parsed.  */
-  unsigned int args_parsed : 1;
+  /* True if the arguments have been parsed.  */
+  bool m_have_parsed_args;
 
-  union
-    {
-      const char *text;
+  /* The text version of the probe's arguments, unparsed.  */
+  const char *m_unparsed_args_text;
 
-      /* Information about each argument.  This is an array of `stap_probe_arg',
-	 with each entry representing one argument.  */
-      VEC (stap_probe_arg_s) *vec;
-    }
-  args_u;
+  /* Information about each argument.  This is an array of `stap_probe_arg',
+     with each entry representing one argument.  This is only valid if
+     M_ARGS_PARSED is true.  */
+  std::vector<struct stap_probe_arg> m_parsed_args;
 };
 
 /* When parsing the arguments, we have to establish different precedences
@@ -326,7 +427,7 @@ stap_get_opcode (const char **s)
 static struct type *
 stap_get_expected_argument_type (struct gdbarch *gdbarch,
 				 enum stap_arg_bitness b,
-				 const struct stap_probe *probe)
+				 const char *probe_name)
 {
   switch (b)
     {
@@ -361,8 +462,7 @@ stap_get_expected_argument_type (struct gdbarch *gdbarch,
       return builtin_type (gdbarch)->builtin_uint64;
 
     default:
-      error (_("Undefined bitness for probe '%s'."),
-	     probe->p.name);
+      error (_("Undefined bitness for probe '%s'."), probe_name);
       break;
     }
 }
@@ -1039,10 +1139,10 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
    - If we find an operator, we skip it.
 
    This function can also call a special function that will try to match
-   unknown tokens.  It will return 1 if the argument has been parsed
-   successfully, or zero otherwise.  */
+   unknown tokens.  It will return the expression_up generated from
+   parsing the argument.  */
 
-static struct expression *
+static expression_up
 stap_parse_argument (const char **arg, struct type *atype,
 		     struct gdbarch *gdbarch)
 {
@@ -1078,41 +1178,27 @@ stap_parse_argument (const char **arg, struct type *atype,
   *arg = p.arg;
 
   /* We can safely return EXPOUT here.  */
-  return p.pstate.expout;
+  return expression_up (p.pstate.expout);
 }
 
-/* Function which parses an argument string from PROBE, correctly splitting
-   the arguments and storing their information in properly ways.
-
-   Consider the following argument string (x86 syntax):
-
-   `4@%eax 4@$10'
+/* Implementation of 'parse_arguments' method.  */
 
-   We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
-   This function basically handles them, properly filling some structures with
-   this information.  */
-
-static void
-stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
+void
+stap_probe::parse_arguments (struct gdbarch *gdbarch)
 {
   const char *cur;
 
-  gdb_assert (!probe->args_parsed);
-  cur = probe->args_u.text;
-  probe->args_parsed = 1;
-  probe->args_u.vec = NULL;
+  gdb_assert (!m_have_parsed_args);
+  cur = m_unparsed_args_text;
+  m_have_parsed_args = true;
 
   if (cur == NULL || *cur == '\0' || *cur == ':')
     return;
 
   while (*cur != '\0')
     {
-      struct stap_probe_arg arg;
-      enum stap_arg_bitness b;
-      int got_minus = 0;
-      struct expression *expr;
-
-      memset (&arg, 0, sizeof (arg));
+      enum stap_arg_bitness bitness;
+      bool got_minus = false;
 
       /* We expect to find something like:
 
@@ -1128,30 +1214,30 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 	    {
 	      /* Discard the `-'.  */
 	      ++cur;
-	      got_minus = 1;
+	      got_minus = true;
 	    }
 
 	  /* Defining the bitness.  */
 	  switch (*cur)
 	    {
 	    case '1':
-	      b = (got_minus ? STAP_ARG_BITNESS_8BIT_SIGNED
-		   : STAP_ARG_BITNESS_8BIT_UNSIGNED);
+	      bitness = (got_minus ? STAP_ARG_BITNESS_8BIT_SIGNED
+			 : STAP_ARG_BITNESS_8BIT_UNSIGNED);
 	      break;
 
 	    case '2':
-	      b = (got_minus ? STAP_ARG_BITNESS_16BIT_SIGNED
-		   : STAP_ARG_BITNESS_16BIT_UNSIGNED);
+	      bitness = (got_minus ? STAP_ARG_BITNESS_16BIT_SIGNED
+			 : STAP_ARG_BITNESS_16BIT_UNSIGNED);
 	      break;
 
 	    case '4':
-	      b = (got_minus ? STAP_ARG_BITNESS_32BIT_SIGNED
-		   : STAP_ARG_BITNESS_32BIT_UNSIGNED);
+	      bitness = (got_minus ? STAP_ARG_BITNESS_32BIT_SIGNED
+			 : STAP_ARG_BITNESS_32BIT_UNSIGNED);
 	      break;
 
 	    case '8':
-	      b = (got_minus ? STAP_ARG_BITNESS_64BIT_SIGNED
-		   : STAP_ARG_BITNESS_64BIT_UNSIGNED);
+	      bitness = (got_minus ? STAP_ARG_BITNESS_64BIT_SIGNED
+			 : STAP_ARG_BITNESS_64BIT_UNSIGNED);
 	      break;
 
 	    default:
@@ -1159,67 +1245,60 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 		/* We have an error, because we don't expect anything
 		   except 1, 2, 4 and 8.  */
 		warning (_("unrecognized bitness %s%c' for probe `%s'"),
-			 got_minus ? "`-" : "`", *cur, probe->p.name);
+			 got_minus ? "`-" : "`", *cur,
+			 this->get_name ().c_str ());
 		return;
 	      }
 	    }
-
-	  arg.bitness = b;
-
 	  /* Discard the number and the `@' sign.  */
 	  cur += 2;
 	}
       else
-	arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
+	bitness = STAP_ARG_BITNESS_UNDEFINED;
 
-      arg.atype = stap_get_expected_argument_type (gdbarch, arg.bitness,
-						   probe);
+      struct type *atype
+	= stap_get_expected_argument_type (gdbarch, bitness,
+					   this->get_name ().c_str ());
 
-      expr = stap_parse_argument (&cur, arg.atype, gdbarch);
+      expression_up expr = stap_parse_argument (&cur, atype, gdbarch);
 
       if (stap_expression_debug)
-	dump_raw_expression (expr, gdb_stdlog,
+	dump_raw_expression (expr.get (), gdb_stdlog,
 			     "before conversion to prefix form");
 
-      prefixify_expression (expr);
+      prefixify_expression (expr.get ());
 
       if (stap_expression_debug)
-	dump_prefix_expression (expr, gdb_stdlog);
+	dump_prefix_expression (expr.get (), gdb_stdlog);
 
-      arg.aexpr = expr;
+      m_parsed_args.emplace_back (bitness, atype, std::move (expr));
 
       /* Start it over again.  */
       cur = skip_spaces (cur);
-
-      VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
     }
 }
 
-/* Implementation of the get_probe_address method.  */
+/* Implementation of the get_relocated_address method.  */
 
-static CORE_ADDR
-stap_get_probe_address (struct probe *probe, struct objfile *objfile)
+CORE_ADDR
+stap_probe::get_relocated_address (struct objfile *objfile)
 {
-  return probe->address + ANOFFSET (objfile->section_offsets,
-				    SECT_OFF_DATA (objfile));
+  return this->get_address () + ANOFFSET (objfile->section_offsets,
+					  SECT_OFF_DATA (objfile));
 }
 
 /* Given PROBE, returns the number of arguments present in that probe's
    argument string.  */
 
-static unsigned
-stap_get_probe_argument_count (struct probe *probe_generic,
-			       struct frame_info *frame)
+unsigned
+stap_probe::get_argument_count (struct frame_info *frame)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (!probe->args_parsed)
+  if (!m_have_parsed_args)
     {
-      if (can_evaluate_probe_arguments (probe_generic))
-	stap_parse_probe_arguments (probe, gdbarch);
+      if (this->can_evaluate_arguments ())
+	this->parse_arguments (gdbarch);
       else
 	{
 	  static int have_warned_stap_incomplete = 0;
@@ -1234,13 +1313,12 @@ stap_get_probe_argument_count (struct probe *probe_generic,
 	    }
 
 	  /* Marking the arguments as "already parsed".  */
-	  probe->args_u.vec = NULL;
-	  probe->args_parsed = 1;
+	  m_have_parsed_args = true;
 	}
     }
 
-  gdb_assert (probe->args_parsed);
-  return VEC_length (stap_probe_arg_s, probe->args_u.vec);
+  gdb_assert (m_have_parsed_args);
+  return m_parsed_args.size ();
 }
 
 /* Return 1 if OP is a valid operator inside a probe argument, or zero
@@ -1279,36 +1357,12 @@ stap_is_operator (const char *op)
   return ret;
 }
 
-/* Return argument N of probe PROBE.
+/* Implement the `can_evaluate_arguments' method.  */
 
-   If the probe's arguments have not been parsed yet, parse them.  If
-   there are no arguments, throw an exception (error).  Otherwise,
-   return the requested argument.  */
-
-static struct stap_probe_arg *
-stap_get_arg (struct stap_probe *probe, unsigned n, struct gdbarch *gdbarch)
-{
-  if (!probe->args_parsed)
-    stap_parse_probe_arguments (probe, gdbarch);
-
-  gdb_assert (probe->args_parsed);
-  if (probe->args_u.vec == NULL)
-    internal_error (__FILE__, __LINE__,
-		    _("Probe '%s' apparently does not have arguments, but \n"
-		      "GDB is requesting its argument number %u anyway.  "
-		      "This should not happen.  Please report this bug."),
-		    probe->p.name, n);
-
-  return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
-}
-
-/* Implement the `can_evaluate_probe_arguments' method of probe_ops.  */
-
-static int
-stap_can_evaluate_probe_arguments (struct probe *probe_generic)
+bool
+stap_probe::can_evaluate_arguments () const
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = stap_probe->p.arch;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* For SystemTap probes, we have to guarantee that the method
      stap_is_single_operand is defined on gdbarch.  If it is not, then it
@@ -1319,71 +1373,42 @@ stap_can_evaluate_probe_arguments (struct probe *probe_generic)
 /* Evaluate the probe's argument N (indexed from 0), returning a value
    corresponding to it.  Assertion is thrown if N does not exist.  */
 
-static struct value *
-stap_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
-			      struct frame_info *frame)
+struct value *
+stap_probe::evaluate_argument (unsigned n, struct frame_info *frame)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = get_frame_arch (frame);
   struct stap_probe_arg *arg;
   int pos = 0;
+  struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, gdbarch);
-  return evaluate_subexp_standard (arg->atype, arg->aexpr, &pos, EVAL_NORMAL);
+  arg = this->get_arg_by_number (n, gdbarch);
+  return evaluate_subexp_standard (arg->atype, arg->aexpr.get (), &pos,
+				   EVAL_NORMAL);
 }
 
 /* Compile the probe's argument N (indexed from 0) to agent expression.
    Assertion is thrown if N does not exist.  */
 
-static void
-stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
-		    struct axs_value *value, unsigned n)
+void
+stap_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
+			   unsigned n)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
   struct stap_probe_arg *arg;
   union exp_element *pc;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, expr->gdbarch);
+  arg = this->get_arg_by_number (n, expr->gdbarch);
 
   pc = arg->aexpr->elts;
-  gen_expr (arg->aexpr, &pc, expr, value);
+  gen_expr (arg->aexpr.get (), &pc, expr, value);
 
   require_rvalue (expr, value);
   value->type = arg->atype;
 }
-
-/* Destroy (free) the data related to PROBE.  PROBE memory itself is not feed
-   as it is allocated on an obstack.  */
-
-static void
-stap_probe_destroy (struct probe *probe_generic)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (probe->args_parsed)
-    {
-      struct stap_probe_arg *arg;
-      int ix;
-
-      for (ix = 0; VEC_iterate (stap_probe_arg_s, probe->args_u.vec, ix, arg);
-	   ++ix)
-	xfree (arg->aexpr);
-      VEC_free (stap_probe_arg_s, probe->args_u.vec);
-    }
-}
-
 \f
 
 /* Set or clear a SystemTap semaphore.  ADDRESS is the semaphore's
-   address.  SET is zero if the semaphore should be cleared, or one
-   if it should be set.  This is a helper function for `stap_semaphore_down'
-   and `stap_semaphore_up'.  */
+   address.  SET is zero if the semaphore should be cleared, or one if
+   it should be set.  This is a helper function for
+   'stap_probe::set_semaphore' and 'stap_probe::clear_semaphore'.  */
 
 static void
 stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
@@ -1419,41 +1444,47 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
     warning (_("Could not write the value of a SystemTap semaphore."));
 }
 
-/* Set a SystemTap semaphore.  SEM is the semaphore's address.  Semaphores
-   act as reference counters, so calls to this function must be paired with
-   calls to `stap_semaphore_down'.
+/* Implementation of the 'set_semaphore' method.
 
-   This function and `stap_semaphore_down' race with another tool changing
-   the probes, but that is too rare to care.  */
+   SystemTap semaphores act as reference counters, so calls to this
+   function must be paired with calls to 'clear_semaphore'.
 
-static void
-stap_set_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		    struct gdbarch *gdbarch)
+   This function and 'clear_semaphore' race with another tool
+   changing the probes, but that is too rare to care.  */
+
+void
+stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-  CORE_ADDR addr;
+  stap_modify_semaphore (this->get_relocated_address (objfile), 1, gdbarch);
+}
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
+/* Implementation of the 'clear_semaphore' method.  */
 
-  addr = (probe->sem_addr
-	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
-  stap_modify_semaphore (addr, 1, gdbarch);
+void
+stap_probe::clear_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
+{
+  stap_modify_semaphore (this->get_relocated_address (objfile), 0, gdbarch);
 }
 
-/* Clear a SystemTap semaphore.  SEM is the semaphore's address.  */
+/* Implementation of the 'get_static_ops' method.  */
 
-static void
-stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		      struct gdbarch *gdbarch)
+const static_probe_ops *
+stap_probe::get_static_ops () const
+{
+  return &stap_static_probe_ops;
+}
+
+/* Implementation of the 'gen_info_probes_table_values' method.  */
+
+std::vector<const char *>
+stap_probe::gen_info_probes_table_values () const
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-  CORE_ADDR addr;
+  const char *val = NULL;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
+  if (m_sem_addr != 0)
+    val = print_core_address (this->get_gdbarch (), m_sem_addr);
 
-  addr = (probe->sem_addr
-	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
-  stap_modify_semaphore (addr, 0, gdbarch);
+  return std::vector<const char *> { val };
 }
 
 /* Helper function that parses the information contained in a
@@ -1478,21 +1509,14 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   int size = bfd_get_arch_size (abfd) / 8;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
-  CORE_ADDR base_ref;
-  const char *probe_args = NULL;
-  struct stap_probe *ret;
-
-  ret = XOBNEW (&objfile->per_bfd->storage_obstack, struct stap_probe);
-  ret->p.pops = &stap_probe_ops;
-  ret->p.arch = gdbarch;
 
   /* Provider and the name of the probe.  */
-  ret->p.provider = (char *) &el->data[3 * size];
-  ret->p.name = ((const char *)
-		 memchr (ret->p.provider, '\0',
-			 (char *) el->data + el->size - ret->p.provider));
+  const char *provider = (const char *) &el->data[3 * size];
+  const char *name = ((const char *)
+		      memchr (provider, '\0',
+			      (char *) el->data + el->size - provider));
   /* Making sure there is a name.  */
-  if (ret->p.name == NULL)
+  if (name == NULL)
     {
       complaint (&symfile_complaints, _("corrupt probe name when "
 					"reading `%s'"),
@@ -1503,32 +1527,32 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
   else
-    ++ret->p.name;
+    ++name;
 
   /* Retrieving the probe's address.  */
-  ret->p.address = extract_typed_address (&el->data[0], ptr_type);
+  CORE_ADDR address = extract_typed_address (&el->data[0], ptr_type);
 
   /* Link-time sh_addr of `.stapsdt.base' section.  */
-  base_ref = extract_typed_address (&el->data[size], ptr_type);
+  CORE_ADDR base_ref = extract_typed_address (&el->data[size], ptr_type);
 
   /* Semaphore address.  */
-  ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
+  CORE_ADDR sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
 
-  ret->p.address += base - base_ref;
-  if (ret->sem_addr != 0)
-    ret->sem_addr += base - base_ref;
+  address += base - base_ref;
+  if (sem_addr != 0)
+    sem_addr += base - base_ref;
 
   /* Arguments.  We can only extract the argument format if there is a valid
      name for this probe.  */
-  probe_args = ((const char*)
-		memchr (ret->p.name, '\0',
-			(char *) el->data + el->size - ret->p.name));
+  const char *probe_args = ((const char*)
+			    memchr (name, '\0',
+				    (char *) el->data + el->size - name));
 
   if (probe_args != NULL)
     ++probe_args;
 
   if (probe_args == NULL
-      || (memchr (probe_args, '\0', (char *) el->data + el->size - ret->p.name)
+      || (memchr (probe_args, '\0', (char *) el->data + el->size - name)
 	  != el->data + el->size - 1))
     {
       complaint (&symfile_complaints, _("corrupt probe argument when "
@@ -1539,11 +1563,11 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
 
-  ret->args_parsed = 0;
-  ret->args_u.text = probe_args;
+  stap_probe *ret = new stap_probe (std::string (name), std::string (provider),
+				    address, gdbarch, sem_addr, probe_args);
 
   /* Successfully created probe.  */
-  probesp->push_back ((struct probe *) ret);
+  probesp->push_back (ret);
 }
 
 /* Helper function which tries to find the base address of the SystemTap
@@ -1584,11 +1608,21 @@ get_stap_base_address (bfd *obfd, bfd_vma *base)
   return 1;
 }
 
-/* Helper function for `elf_get_probes', which gathers information about all
-   SystemTap probes from OBJFILE.  */
+/* Implementation of the 'is_linespec' method.  */
 
-static void
-stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+bool
+stap_static_probe_ops::is_linespec (const char **linespecp) const
+{
+  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+
+  return probe_is_linespec_by_keyword (linespecp, keywords);
+}
+
+/* Implementation of the 'get_probes' method.  */
+
+void
+stap_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				   struct objfile *objfile) const
 {
   /* If we are here, then this is the first time we are parsing the
      SystemTap probe's information.  We basically have to count how many
@@ -1640,83 +1674,37 @@ stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
 
 /* Implementation of the type_name method.  */
 
-static const char *
-stap_type_name (struct probe *probe)
+const char *
+stap_static_probe_ops::type_name () const
 {
-  gdb_assert (probe->pops == &stap_probe_ops);
   return "stap";
 }
 
-static int
-stap_probe_is_linespec (const char **linespecp)
-{
-  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+/* Implementation of the 'gen_info_probes_table_header' method.  */
 
-  return probe_is_linespec_by_keyword (linespecp, keywords);
-}
-
-static void
-stap_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
+std::vector<struct info_probe_column>
+stap_static_probe_ops::gen_info_probes_table_header () const
 {
-  info_probe_column_s stap_probe_column;
+  struct info_probe_column stap_probe_column;
 
   stap_probe_column.field_name = "semaphore";
   stap_probe_column.print_name = _("Semaphore");
 
-  VEC_safe_push (info_probe_column_s, *heads, &stap_probe_column);
+  return std::vector<struct info_probe_column> { stap_probe_column };
 }
 
-static void
-stap_gen_info_probes_table_values (struct probe *probe_generic,
-				   VEC (const_char_ptr) **ret)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch;
-  const char *val = NULL;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  gdbarch = probe->p.arch;
-
-  if (probe->sem_addr != 0)
-    val = print_core_address (gdbarch, probe->sem_addr);
-
-  VEC_safe_push (const_char_ptr, *ret, val);
-}
-
-/* SystemTap probe_ops.  */
-
-const struct probe_ops stap_probe_ops =
-{
-  stap_probe_is_linespec,
-  stap_get_probes,
-  stap_get_probe_address,
-  stap_get_probe_argument_count,
-  stap_can_evaluate_probe_arguments,
-  stap_evaluate_probe_argument,
-  stap_compile_to_ax,
-  stap_set_semaphore,
-  stap_clear_semaphore,
-  stap_probe_destroy,
-  stap_type_name,
-  stap_gen_info_probes_table_header,
-  stap_gen_info_probes_table_values,
-  NULL,  /* enable_probe  */
-  NULL   /* disable_probe  */
-};
-
 /* Implementation of the `info probes stap' command.  */
 
 static void
 info_probes_stap_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, &stap_probe_ops);
+  info_probes_for_spops (arg, from_tty, &stap_static_probe_ops);
 }
 
 void
 _initialize_stap_probe (void)
 {
-  all_probe_ops.push_back (&stap_probe_ops);
+  all_static_probe_ops.push_back (&stap_static_probe_ops);
 
   add_setshow_zuinteger_cmd ("stap-expression", class_maintenance,
 			     &stap_expression_debug,
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/3] Convert probe interfaces to C++ (and perform some cleanups)
  2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
                     ` (2 preceding siblings ...)
  2017-11-16  4:38   ` [PATCH v2 1/3] Convert generic " Sergio Durigan Junior
@ 2017-11-21 16:25   ` Sergio Durigan Junior
  3 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-21 16:25 UTC (permalink / raw)
  To: GDB Patches; +Cc: Simon Marchi

Ping.

On Wednesday, November 15 2017, I wrote:

> [ The changes for each patch are described at the top of each message.  ]
>
> This patch series performs the conversion of the probe interfaces
> (generic, stap and dtrace) to C++, along with a few cleanups here and
> there to make the code conform better to our standards.
>
> This series needs to be committed/tested as one single patch, because
> of inter-dependencies.  However, in order to facilitate the review
> process, I decided to split things into logical units.
>
> The main changes are the conversion of 'struct probe' to 'class
> probe', and 'struct probe_ops' to 'class static_probe_ops'.  Almost
> everything else in the patches are adjustments related to these
> modifications.
>
> It's important to say that 'class probe' contains the majority of the
> methods that were previously living inside 'struct probe_ops'.
> However, some methods are special in the sense the they don't act on a
> specific probe object, but generically on a probe type (like a
> factory).  For that reason the 'class static_probe_ops' had to be
> created.
>
> Most methods in 'class probe' are pure virtual and need to be defined
> by the probe backend (stap or dtrace, for now).  Other methods (e.g.,
> the 'enable' method) are virtual but non-pure and have a default,
> dummy version implemented on 'class probe' itself, because the concept
> of enabling a probe is not common to all types of probes.
>
> I've also taken the opportunity to convert a few uses of "VEC" to
> "std::vector", and to remove annoying spurious newlines from some
> places.
>
> The whole patch has been tested on BuildBot, without regressions.
> However, it is important to mention that I could not test the DTrace
> part of the patch because the test framework used to test it is not
> working; see <https://sourceware.org/bugzilla/show_bug.cgi?id=22420>.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-16  4:38   ` [PATCH v2 1/3] Convert generic " Sergio Durigan Junior
@ 2017-11-22 20:39     ` Simon Marchi
  2017-11-22 22:36       ` Sergio Durigan Junior
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Marchi @ 2017-11-22 20:39 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Simon Marchi

On 2017-11-15 11:37 PM, Sergio Durigan Junior wrote:
> Changes from v1:
> 
> - Remove emit_info_probes_extra_fields method.
> 
> - Make gen_info_* methods return the vector directly.  Modify code
>   accordingly.
> 
> - Cleanup unused variables.
> 
> - Make can_evaluate_arguments return bool.
> 
> - Make get_name and get_provider return a const std::string &.  Modify
>   code accordingly.
> 
> - Move can_enable method from 'class probe' to 'class
>   static_probe_ops'.
> 
> - Use const references when iterating on vector of objects.
> 
> This patch converts the generic probe interface (gdb/probe.[ch]) to
> C++, and also performs some cleanups that were on my TODO list for a
> while.
> 
> The main changes were the conversion of 'struct probe' to 'class
> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
> former now contains all the "dynamic", generic methods that act on a
> probe + the generic data related to it; the latter encapsulates a
> bunch of "static" methods that relate to the probe type, but not to a
> specific probe itself.
> 
> I've had to do a few renamings (e.g., on 'struct bound_probe' the
> field is called 'probe *prob' now, instead of 'struct probe *probe')
> because GCC was complaining about naming the field using the same name
> as the class.  Nothing major, though.  Generally speaking, the logic
> behind and the design behind the code are the same.
> 
> Even though I'm sending a series of patches, they need to be tested
> and committed as a single unit, because of inter-dependencies.  But it
> should be easier to review in separate logical units.
> 
> I've regtested this patch on BuildBot, no regressions found.

Hi Sergio,

I've looked at it (the series) quickly, and it looks good to me.  Personally,
for comparing std::string with char*, I would use the form

  str != char_ptr

rather than

  str.compare (char_ptr) != 0

since I find it more readable, but I don't really mind.

One whitespace comment below.

> @@ -334,56 +358,33 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>  
>  static void
>  gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
> -			      const struct probe_ops *p)
> +			      const static_probe_ops *spops)
>  {
>    /* `headings' refers to the names of the columns when printing `info
>       probes'.  */
> -  VEC (info_probe_column_s) *headings = NULL;
> -  struct cleanup *c;
> -  info_probe_column_s *column;
> -  size_t headings_size;
> -  int ix;
> +  gdb_assert (spops != NULL);
>  
> -  gdb_assert (p != NULL);
> +  std::vector<struct info_probe_column> headings
> +    = spops->gen_info_probes_table_header ();
>  
> -  if (p->gen_info_probes_table_header == NULL
> -      && p->gen_info_probes_table_values == NULL)
> -    return;
> -
> -  gdb_assert (p->gen_info_probes_table_header != NULL
> -	      && p->gen_info_probes_table_values != NULL);
> -
> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
> -  p->gen_info_probes_table_header (&headings);
> -
> -  headings_size = VEC_length (info_probe_column_s, headings);
> -
> -  for (ix = 0;
> -       VEC_iterate (info_probe_column_s, headings, ix, column);
> -       ++ix)
> +  for (const struct info_probe_column &column : headings)
>      {
> -      size_t size_max = strlen (column->print_name);
> +      size_t size_max = strlen (column.print_name);
>  
>        for (const bound_probe &probe : probes)
>  	{
>  	  /* `probe_fields' refers to the values of each new field that this
>  	     probe will display.  */
> -	  VEC (const_char_ptr) *probe_fields = NULL;
> -	  struct cleanup *c2;
> -	  const char *val;
> -	  int kx;
>  
> -	  if (probe.probe->pops != p)
> +	  if (probe.prob->get_static_ops () != spops)
>  	    continue;
>  
> -	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
> -	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
> +  	  std::vector<const char *> probe_fields

There are spaces before the tab in this line.

Thanks,

Simon

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-22 20:39     ` Simon Marchi
@ 2017-11-22 22:36       ` Sergio Durigan Junior
  2017-11-23  0:01         ` Simon Marchi
  0 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-22 22:36 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches, Simon Marchi

On Wednesday, November 22 2017, Simon Marchi wrote:

> On 2017-11-15 11:37 PM, Sergio Durigan Junior wrote:
>> Changes from v1:
>> 
>> - Remove emit_info_probes_extra_fields method.
>> 
>> - Make gen_info_* methods return the vector directly.  Modify code
>>   accordingly.
>> 
>> - Cleanup unused variables.
>> 
>> - Make can_evaluate_arguments return bool.
>> 
>> - Make get_name and get_provider return a const std::string &.  Modify
>>   code accordingly.
>> 
>> - Move can_enable method from 'class probe' to 'class
>>   static_probe_ops'.
>> 
>> - Use const references when iterating on vector of objects.
>> 
>> This patch converts the generic probe interface (gdb/probe.[ch]) to
>> C++, and also performs some cleanups that were on my TODO list for a
>> while.
>> 
>> The main changes were the conversion of 'struct probe' to 'class
>> probe', and 'struct probe_ops' to 'class static_probe_ops'.  The
>> former now contains all the "dynamic", generic methods that act on a
>> probe + the generic data related to it; the latter encapsulates a
>> bunch of "static" methods that relate to the probe type, but not to a
>> specific probe itself.
>> 
>> I've had to do a few renamings (e.g., on 'struct bound_probe' the
>> field is called 'probe *prob' now, instead of 'struct probe *probe')
>> because GCC was complaining about naming the field using the same name
>> as the class.  Nothing major, though.  Generally speaking, the logic
>> behind and the design behind the code are the same.
>> 
>> Even though I'm sending a series of patches, they need to be tested
>> and committed as a single unit, because of inter-dependencies.  But it
>> should be easier to review in separate logical units.
>> 
>> I've regtested this patch on BuildBot, no regressions found.
>
> Hi Sergio,

Hey Simon,

Thanks for the review.

> I've looked at it (the series) quickly, and it looks good to me.  Personally,
> for comparing std::string with char*, I would use the form
>
>   str != char_ptr
>
> rather than
>
>   str.compare (char_ptr) != 0
>
> since I find it more readable, but I don't really mind.

You're right, it's better.  I'll replace that in my code.

> One whitespace comment below.
>
>> @@ -334,56 +358,33 @@ compare_probes (const bound_probe &a, const bound_probe &b)
>>  
>>  static void
>>  gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
>> -			      const struct probe_ops *p)
>> +			      const static_probe_ops *spops)
>>  {
>>    /* `headings' refers to the names of the columns when printing `info
>>       probes'.  */
>> -  VEC (info_probe_column_s) *headings = NULL;
>> -  struct cleanup *c;
>> -  info_probe_column_s *column;
>> -  size_t headings_size;
>> -  int ix;
>> +  gdb_assert (spops != NULL);
>>  
>> -  gdb_assert (p != NULL);
>> +  std::vector<struct info_probe_column> headings
>> +    = spops->gen_info_probes_table_header ();
>>  
>> -  if (p->gen_info_probes_table_header == NULL
>> -      && p->gen_info_probes_table_values == NULL)
>> -    return;
>> -
>> -  gdb_assert (p->gen_info_probes_table_header != NULL
>> -	      && p->gen_info_probes_table_values != NULL);
>> -
>> -  c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
>> -  p->gen_info_probes_table_header (&headings);
>> -
>> -  headings_size = VEC_length (info_probe_column_s, headings);
>> -
>> -  for (ix = 0;
>> -       VEC_iterate (info_probe_column_s, headings, ix, column);
>> -       ++ix)
>> +  for (const struct info_probe_column &column : headings)
>>      {
>> -      size_t size_max = strlen (column->print_name);
>> +      size_t size_max = strlen (column.print_name);
>>  
>>        for (const bound_probe &probe : probes)
>>  	{
>>  	  /* `probe_fields' refers to the values of each new field that this
>>  	     probe will display.  */
>> -	  VEC (const_char_ptr) *probe_fields = NULL;
>> -	  struct cleanup *c2;
>> -	  const char *val;
>> -	  int kx;
>>  
>> -	  if (probe.probe->pops != p)
>> +	  if (probe.prob->get_static_ops () != spops)
>>  	    continue;
>>  
>> -	  c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
>> -	  p->gen_info_probes_table_values (probe.probe, &probe_fields);
>> +  	  std::vector<const char *> probe_fields
>
> There are spaces before the tab in this line.

Thanks for catching that.  Fixed.

Is it OK to push after these changes, or do you want me to submit a v2?

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-22 22:36       ` Sergio Durigan Junior
@ 2017-11-23  0:01         ` Simon Marchi
  2017-11-23  0:15           ` Sergio Durigan Junior
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Marchi @ 2017-11-23  0:01 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Simon Marchi, GDB Patches

On 2017-11-22 17:36, Sergio Durigan Junior wrote:
> Thanks for catching that.  Fixed.
> 
> Is it OK to push after these changes, or do you want me to submit a v2?
> 
> Thanks,

I guess you mean v3?  You can push with that fixed.

Simon

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-23  0:01         ` Simon Marchi
@ 2017-11-23  0:15           ` Sergio Durigan Junior
  2017-11-23  0:33             ` Sergio Durigan Junior
  0 siblings, 1 reply; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-23  0:15 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Simon Marchi, GDB Patches

On Wednesday, November 22 2017, Simon Marchi wrote:

> On 2017-11-22 17:36, Sergio Durigan Junior wrote:
>> Thanks for catching that.  Fixed.
>>
>> Is it OK to push after these changes, or do you want me to submit a v2?
>>
>> Thanks,
>
> I guess you mean v3?  You can push with that fixed.

We're already at v2!  Woot!

Pushed:

935676c92feb5f35e4634ef58c20ffdfd0979b07
0e9ae10f5f97824067365af4813b843973297573
9c23b42ffa67b866cd7562c1d8caed70db5d6840

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/3] Convert generic probe interface to C++ (and perform some cleanups)
  2017-11-23  0:15           ` Sergio Durigan Junior
@ 2017-11-23  0:33             ` Sergio Durigan Junior
  0 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-23  0:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Simon Marchi, GDB Patches

On Wednesday, November 22 2017, I wrote:

> On Wednesday, November 22 2017, Simon Marchi wrote:
>
>> On 2017-11-22 17:36, Sergio Durigan Junior wrote:
>>> Thanks for catching that.  Fixed.
>>>
>>> Is it OK to push after these changes, or do you want me to submit a v2?
>>>
>>> Thanks,
>>
>> I guess you mean v3?  You can push with that fixed.
>
> We're already at v2!  Woot!
>
> Pushed:
>
> 935676c92feb5f35e4634ef58c20ffdfd0979b07
> 0e9ae10f5f97824067365af4813b843973297573
> 9c23b42ffa67b866cd7562c1d8caed70db5d6840

... and a mistake has been made.  *sigh*

I should have committed the three patches together as one, but I forgot
and pushed them separated.  I am sorry for the high number of breakage
e-mails that we will receive in the following minutes, and also for the
mistake, which will impact the ability to bisect our tree.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
  2017-11-13 17:53 [PATCH " Sergio Durigan Junior
@ 2017-11-13 18:02 ` Sergio Durigan Junior
  0 siblings, 0 replies; 23+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 18:02 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch converts the SystemTap probe
interface (gdb/stap-probe.[ch]) to C++, and also performs some
cleanups that were on my TODO list for a while.

The main changes were the conversion of 'struct stap_probe' to 'class
stap_probe', and a new 'class stap_static_probe_ops' to replace the
use of 'stap_probe_ops'.  Both classes implement the virtual methods
exported by their parents, 'class probe' and 'class static_probe_ops',
respectively.  I believe it's now a bit simpler to understand the
logic behind the stap-probe interface.

There are several helper functions used to parse parts of a stap
probe, and since they are generic and don't need to know about the
probe they're working on, I decided to leave them as simple static
functions (instead of e.g. converting them to class methods).

I've also converted a few uses of "VEC" to "std::vector", which makes
the code simpler and easier to maintain.  And, as usual, some cleanups
here and there.

Even though I'm sending a series of patches, they need to be tested
and committed as a single unit, because of inter-dependencies.  But it
should be easier to review in separate logical units.

I've regtested this patch on BuildBot, no regressions found.

gdb/ChangeLog:
2017-11-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (struct probe_ops stap_probe_ops): Delete
	variable.
	(stap_probe_arg_s): Delete type and VEC.
	(struct stap_probe): Delete.  Replace by...
	(class stap_static_probe_ops): ...this and...
	(class stap_probe): ...this.  Rename variables to add 'm_'
	prefix.  Do not use 'union' for arguments anymore.
	(stap_get_expected_argument_type): Receive probe name instead
	of 'struct stap_probe'.  Adjust code.
	(stap_parse_probe_arguments): Rename to...
	(stap_probe::parse_arguments): ...this.  Adjust code to
	reflect change.
	(stap_get_probe_address): Rename to...
	(stap_probe::get_relocated_address): ...this.  Adjust code
	to reflect change.
	(stap_get_probe_argument_count): Rename to...
	(stap_probe::get_argument_count): ...this.  Adjust code
	to reflect change.
	(stap_get_arg): Rename to...
	(stap_probe::get_arg_by_number'): ...this. Adjust code to
	reflect change.
	(can_evaluate_probe_arguments): Rename to...
	(stap_probe::can_evaluate_arguments): ...this.  Adjust code
	to reflect change.
	(stap_evaluate_probe_argument): Rename to...
	(stap_probe::evaluate_argument): ...this.  Adjust code
	to reflect change.
	(stap_compile_to_ax): Rename to...
	(stap_probe::compile_to_ax): ...this.  Adjust code to
	reflect change.
	(stap_probe_destroy): Delete.
	(stap_modify_semaphore): Adjust comment.
	(stap_set_semaphore): Rename to...
	(stap_probe::set_semaphore): ...this.  Adjust code to reflect
	change.
	(stap_clear_semaphore): Rename to...
	(stap_probe::clear_semaphore): ...this.  Adjust code to
	reflect	change.
	(stap_probe::get_static_ops): New method.
	(handle_stap_probe): Adjust code to create instance of
	'stap_probe'.
	(stap_get_probes): Rename to...
	(stap_static_probe_ops::get_probes): ...this.  Adjust code to
	reflect change.
	(stap_probe_is_linespec): Rename to...
	(stap_static_probe_ops::is_linespec): ...this.  Adjust code to
	reflect change.
	(stap_type_name): Rename to...
	(stap_static_probe_ops::type_name): ...this.  Adjust code to
	reflect change.
	(stap_static_probe_ops::emit_info_probes_extra_fields): New
	method.
	(stap_gen_info_probes_table_header): Rename to...
	(stap_static_probe_ops::gen_info_probes_table_header):
	...this.  Adjust code to reflect change.
	(stap_gen_info_probes_table_values): Rename to...
	(stap_probe::gen_info_probes_table_values): ...this.  Adjust
	code to reflect change.
	(struct probe_ops stap_probe_ops): Delete.
	(info_probes_stap_command): Use 'info_probes_for_spops'
	instead of 'info_probes_for_ops'.
	(_initialize_stap_probe): Use 'all_static_probe_ops' instead
	of 'all_probe_ops'.
---
 gdb/stap-probe.c | 478 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 244 insertions(+), 234 deletions(-)

diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 6fa0d20280..c169ffc488 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -45,10 +45,6 @@
 
 #define STAP_BASE_SECTION_NAME ".stapsdt.base"
 
-/* Forward declaration. */
-
-extern const struct probe_ops stap_probe_ops;
-
 /* Should we display debug information for the probe's argument expression
    parsing?  */
 
@@ -95,32 +91,135 @@ struct stap_probe_arg
   struct expression *aexpr;
 };
 
-typedef struct stap_probe_arg stap_probe_arg_s;
-DEF_VEC_O (stap_probe_arg_s);
+/* Class that implements the static probe methods for "stap" probes.  */
 
-struct stap_probe
+class stap_static_probe_ops : public static_probe_ops
 {
-  /* Generic information about the probe.  This shall be the first element
-     of this struct, in order to maintain binary compatibility with the
-     `struct probe' and be able to fully abstract it.  */
-  struct probe p;
+public:
+  /* See probe.h.  */
+  bool is_linespec (const char **linespecp) const override;
+
+  /* See probe.h.  */
+  void get_probes (std::vector<probe *> *probesp,
+		   struct objfile *objfile) const override;
+
+  /* See probe.h.  */
+  const char *type_name () const override;
+
+  /* See probe.h.  */
+  bool emit_info_probes_extra_fields () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_header
+    (std::vector<struct info_probe_column> *heads) const override;
+};
+
+/* SystemTap static_probe_ops.  */
+
+const stap_static_probe_ops stap_static_probe_ops;
 
+class stap_probe : public probe
+{
+public:
+  /* Constructor for stap_probe.  */
+  stap_probe (std::string &&name_, std::string &&provider_, CORE_ADDR address_,
+	      struct gdbarch *arch_, CORE_ADDR sem_addr, const char *args_text)
+    : probe (std::move (name_), std::move (provider_), address_, arch_),
+      m_sem_addr (sem_addr),
+      m_have_parsed_args (false), m_unparsed_args_text (args_text)
+  {}
+
+  /* Destructor for stap_probe.  */
+  ~stap_probe ()
+  {
+    if (m_have_parsed_args)
+      for (struct stap_probe_arg arg : m_parsed_args)
+	xfree (arg.aexpr);
+  }
+
+  /* See probe.h.  */
+  CORE_ADDR get_relocated_address (struct objfile *objfile) override;
+
+  /* See probe.h.  */
+  unsigned get_argument_count (struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  int can_evaluate_arguments () const override;
+
+  /* See probe.h.  */
+  struct value *evaluate_argument (unsigned n,
+				   struct frame_info *frame) override;
+
+  /* See probe.h.  */
+  void compile_to_ax (struct agent_expr *aexpr,
+		      struct axs_value *axs_value,
+		      unsigned n) override;
+
+  /* See probe.h.  */
+  void set_semaphore (struct objfile *objfile,
+		      struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  void clear_semaphore (struct objfile *objfile,
+			struct gdbarch *gdbarch) override;
+
+  /* See probe.h.  */
+  const static_probe_ops *get_static_ops () const override;
+
+  /* See probe.h.  */
+  void gen_info_probes_table_values
+    (std::vector<const char *> *values) const override;
+
+  /* Return argument N of probe.
+
+     If the probe's arguments have not been parsed yet, parse them.  If
+     there are no arguments, throw an exception (error).  Otherwise,
+     return the requested argument.  */
+  struct stap_probe_arg *get_arg_by_number (unsigned n,
+					    struct gdbarch *gdbarch)
+  {
+    if (!m_have_parsed_args)
+      this->parse_arguments (gdbarch);
+
+    gdb_assert (m_have_parsed_args);
+    if (m_parsed_args.empty ())
+      internal_error (__FILE__, __LINE__,
+		      _("Probe '%s' apparently does not have arguments, but \n"
+			"GDB is requesting its argument number %u anyway.  "
+			"This should not happen.  Please report this bug."),
+		      this->get_name (), n);
+
+    return &m_parsed_args[n];
+  }
+
+  /* Function which parses an argument string from the probe,
+     correctly splitting the arguments and storing their information
+     in properly ways.
+
+     Consider the following argument string (x86 syntax):
+
+     `4@%eax 4@$10'
+
+     We have two arguments, `%eax' and `$10', both with 32-bit
+     unsigned bitness.  This function basically handles them, properly
+     filling some structures with this information.  */
+  void parse_arguments (struct gdbarch *gdbarch);
+
+private:
   /* If the probe has a semaphore associated, then this is the value of
      it, relative to SECT_OFF_DATA.  */
-  CORE_ADDR sem_addr;
+  CORE_ADDR m_sem_addr;
 
-  /* One if the arguments have been parsed.  */
-  unsigned int args_parsed : 1;
+  /* True if the arguments have been parsed.  */
+  bool m_have_parsed_args;
 
-  union
-    {
-      const char *text;
+  /* The text version of the probe's arguments, unparsed.  */
+  const char *m_unparsed_args_text;
 
-      /* Information about each argument.  This is an array of `stap_probe_arg',
-	 with each entry representing one argument.  */
-      VEC (stap_probe_arg_s) *vec;
-    }
-  args_u;
+  /* Information about each argument.  This is an array of `stap_probe_arg',
+     with each entry representing one argument.  This is only valid if
+     M_ARGS_PARSED is true.  */
+  std::vector<struct stap_probe_arg> m_parsed_args;
 };
 
 /* When parsing the arguments, we have to establish different precedences
@@ -326,7 +425,7 @@ stap_get_opcode (const char **s)
 static struct type *
 stap_get_expected_argument_type (struct gdbarch *gdbarch,
 				 enum stap_arg_bitness b,
-				 const struct stap_probe *probe)
+				 const char *probe_name)
 {
   switch (b)
     {
@@ -361,8 +460,7 @@ stap_get_expected_argument_type (struct gdbarch *gdbarch,
       return builtin_type (gdbarch)->builtin_uint64;
 
     default:
-      error (_("Undefined bitness for probe '%s'."),
-	     probe->p.name);
+      error (_("Undefined bitness for probe '%s'."), probe_name);
       break;
     }
 }
@@ -1081,26 +1179,16 @@ stap_parse_argument (const char **arg, struct type *atype,
   return p.pstate.expout;
 }
 
-/* Function which parses an argument string from PROBE, correctly splitting
-   the arguments and storing their information in properly ways.
+/* Implementation of 'parse_probe_arguments' method.  */
 
-   Consider the following argument string (x86 syntax):
-
-   `4@%eax 4@$10'
-
-   We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
-   This function basically handles them, properly filling some structures with
-   this information.  */
-
-static void
-stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
+void
+stap_probe::parse_arguments (struct gdbarch *gdbarch)
 {
   const char *cur;
 
-  gdb_assert (!probe->args_parsed);
-  cur = probe->args_u.text;
-  probe->args_parsed = 1;
-  probe->args_u.vec = NULL;
+  gdb_assert (!m_have_parsed_args);
+  cur = m_unparsed_args_text;
+  m_have_parsed_args = true;
 
   if (cur == NULL || *cur == '\0' || *cur == ':')
     return;
@@ -1159,7 +1247,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 		/* We have an error, because we don't expect anything
 		   except 1, 2, 4 and 8.  */
 		warning (_("unrecognized bitness %s%c' for probe `%s'"),
-			 got_minus ? "`-" : "`", *cur, probe->p.name);
+			 got_minus ? "`-" : "`", *cur, this->get_name ());
 		return;
 	      }
 	    }
@@ -1173,7 +1261,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
 	arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
 
       arg.atype = stap_get_expected_argument_type (gdbarch, arg.bitness,
-						   probe);
+						   this->get_name ());
 
       expr = stap_parse_argument (&cur, arg.atype, gdbarch);
 
@@ -1191,35 +1279,31 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
       /* Start it over again.  */
       cur = skip_spaces (cur);
 
-      VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
+      m_parsed_args.push_back (arg);
     }
 }
 
-/* Implementation of the get_probe_address method.  */
+/* Implementation of the get_relocated_address method.  */
 
-static CORE_ADDR
-stap_get_probe_address (struct probe *probe, struct objfile *objfile)
+CORE_ADDR
+stap_probe::get_relocated_address (struct objfile *objfile)
 {
-  return probe->address + ANOFFSET (objfile->section_offsets,
-				    SECT_OFF_DATA (objfile));
+  return this->get_address () + ANOFFSET (objfile->section_offsets,
+					  SECT_OFF_DATA (objfile));
 }
 
 /* Given PROBE, returns the number of arguments present in that probe's
    argument string.  */
 
-static unsigned
-stap_get_probe_argument_count (struct probe *probe_generic,
-			       struct frame_info *frame)
+unsigned
+stap_probe::get_argument_count (struct frame_info *frame)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (!probe->args_parsed)
+  if (!m_have_parsed_args)
     {
-      if (can_evaluate_probe_arguments (probe_generic))
-	stap_parse_probe_arguments (probe, gdbarch);
+      if (this->can_evaluate_arguments ())
+	this->parse_arguments (gdbarch);
       else
 	{
 	  static int have_warned_stap_incomplete = 0;
@@ -1234,13 +1318,12 @@ stap_get_probe_argument_count (struct probe *probe_generic,
 	    }
 
 	  /* Marking the arguments as "already parsed".  */
-	  probe->args_u.vec = NULL;
-	  probe->args_parsed = 1;
+	  m_have_parsed_args = true;
 	}
     }
 
-  gdb_assert (probe->args_parsed);
-  return VEC_length (stap_probe_arg_s, probe->args_u.vec);
+  gdb_assert (m_have_parsed_args);
+  return m_parsed_args.size ();
 }
 
 /* Return 1 if OP is a valid operator inside a probe argument, or zero
@@ -1279,36 +1362,12 @@ stap_is_operator (const char *op)
   return ret;
 }
 
-/* Return argument N of probe PROBE.
-
-   If the probe's arguments have not been parsed yet, parse them.  If
-   there are no arguments, throw an exception (error).  Otherwise,
-   return the requested argument.  */
-
-static struct stap_probe_arg *
-stap_get_arg (struct stap_probe *probe, unsigned n, struct gdbarch *gdbarch)
-{
-  if (!probe->args_parsed)
-    stap_parse_probe_arguments (probe, gdbarch);
-
-  gdb_assert (probe->args_parsed);
-  if (probe->args_u.vec == NULL)
-    internal_error (__FILE__, __LINE__,
-		    _("Probe '%s' apparently does not have arguments, but \n"
-		      "GDB is requesting its argument number %u anyway.  "
-		      "This should not happen.  Please report this bug."),
-		    probe->p.name, n);
-
-  return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
-}
-
-/* Implement the `can_evaluate_probe_arguments' method of probe_ops.  */
+/* Implement the `can_evaluate_arguments' method.  */
 
-static int
-stap_can_evaluate_probe_arguments (struct probe *probe_generic)
+int
+stap_probe::can_evaluate_arguments () const
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = stap_probe->p.arch;
+  struct gdbarch *gdbarch = this->get_gdbarch ();
 
   /* For SystemTap probes, we have to guarantee that the method
      stap_is_single_operand is defined on gdbarch.  If it is not, then it
@@ -1319,35 +1378,28 @@ stap_can_evaluate_probe_arguments (struct probe *probe_generic)
 /* Evaluate the probe's argument N (indexed from 0), returning a value
    corresponding to it.  Assertion is thrown if N does not exist.  */
 
-static struct value *
-stap_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
-			      struct frame_info *frame)
+struct value *
+stap_probe::evaluate_argument (unsigned n, struct frame_info *frame)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch = get_frame_arch (frame);
   struct stap_probe_arg *arg;
   int pos = 0;
+  struct gdbarch *gdbarch = get_frame_arch (frame);
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, gdbarch);
+  arg = this->get_arg_by_number (n, gdbarch);
   return evaluate_subexp_standard (arg->atype, arg->aexpr, &pos, EVAL_NORMAL);
 }
 
 /* Compile the probe's argument N (indexed from 0) to agent expression.
    Assertion is thrown if N does not exist.  */
 
-static void
-stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
-		    struct axs_value *value, unsigned n)
+void
+stap_probe::compile_to_ax (struct agent_expr *expr, struct axs_value *value,
+			   unsigned n)
 {
-  struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
   struct stap_probe_arg *arg;
   union exp_element *pc;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  arg = stap_get_arg (stap_probe, n, expr->gdbarch);
+  arg = this->get_arg_by_number (n, expr->gdbarch);
 
   pc = arg->aexpr->elts;
   gen_expr (arg->aexpr, &pc, expr, value);
@@ -1355,35 +1407,12 @@ stap_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
   require_rvalue (expr, value);
   value->type = arg->atype;
 }
-
-/* Destroy (free) the data related to PROBE.  PROBE memory itself is not feed
-   as it is allocated on an obstack.  */
-
-static void
-stap_probe_destroy (struct probe *probe_generic)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  if (probe->args_parsed)
-    {
-      struct stap_probe_arg *arg;
-      int ix;
-
-      for (ix = 0; VEC_iterate (stap_probe_arg_s, probe->args_u.vec, ix, arg);
-	   ++ix)
-	xfree (arg->aexpr);
-      VEC_free (stap_probe_arg_s, probe->args_u.vec);
-    }
-}
-
 \f
 
 /* Set or clear a SystemTap semaphore.  ADDRESS is the semaphore's
-   address.  SET is zero if the semaphore should be cleared, or one
-   if it should be set.  This is a helper function for `stap_semaphore_down'
-   and `stap_semaphore_up'.  */
+   address.  SET is zero if the semaphore should be cleared, or one if
+   it should be set.  This is a helper function for
+   'stap_probe::set_semaphore' and 'stap_probe::clear_semaphore'.  */
 
 static void
 stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
@@ -1419,43 +1448,58 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
     warning (_("Could not write the value of a SystemTap semaphore."));
 }
 
-/* Set a SystemTap semaphore.  SEM is the semaphore's address.  Semaphores
-   act as reference counters, so calls to this function must be paired with
-   calls to `stap_semaphore_down'.
+/* Implementation of the 'set_semaphore' method.
 
-   This function and `stap_semaphore_down' race with another tool changing
-   the probes, but that is too rare to care.  */
+   SystemTap semaphores act as reference counters, so calls to this
+   function must be paired with calls to 'clear_semaphore'.
 
-static void
-stap_set_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		    struct gdbarch *gdbarch)
+   This function and 'clear_semaphore' race with another tool
+   changing the probes, but that is too rare to care.  */
+
+void
+stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   CORE_ADDR addr;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  addr = (probe->sem_addr
+  addr = (m_sem_addr
 	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
   stap_modify_semaphore (addr, 1, gdbarch);
 }
 
-/* Clear a SystemTap semaphore.  SEM is the semaphore's address.  */
+/* Implementation of the 'clear_semaphore' method.  */
 
-static void
-stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile,
-		      struct gdbarch *gdbarch)
+void
+stap_probe::clear_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
 {
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
   CORE_ADDR addr;
 
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  addr = (probe->sem_addr
+  addr = (m_sem_addr
 	  + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)));
   stap_modify_semaphore (addr, 0, gdbarch);
 }
 
+/* Implementation of the 'get_static_ops' method.  */
+
+const static_probe_ops *
+stap_probe::get_static_ops () const
+{
+  return &stap_static_probe_ops;
+}
+
+/* Implementation of the 'gen_info_probes_table_values' method.  */
+
+void
+stap_probe::gen_info_probes_table_values
+  (std::vector<const char *> *values) const
+{
+  const char *val = NULL;
+
+  if (m_sem_addr != 0)
+    val = print_core_address (this->get_gdbarch (), m_sem_addr);
+
+  values->push_back (val);
+}
+
 /* Helper function that parses the information contained in a
    SystemTap's probe.  Basically, the information consists in:
 
@@ -1478,21 +1522,14 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   int size = bfd_get_arch_size (abfd) / 8;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
-  CORE_ADDR base_ref;
-  const char *probe_args = NULL;
-  struct stap_probe *ret;
-
-  ret = XOBNEW (&objfile->per_bfd->storage_obstack, struct stap_probe);
-  ret->p.pops = &stap_probe_ops;
-  ret->p.arch = gdbarch;
 
   /* Provider and the name of the probe.  */
-  ret->p.provider = (char *) &el->data[3 * size];
-  ret->p.name = ((const char *)
-		 memchr (ret->p.provider, '\0',
-			 (char *) el->data + el->size - ret->p.provider));
+  const char *provider = (const char *) &el->data[3 * size];
+  const char *name = ((const char *)
+		      memchr (provider, '\0',
+			      (char *) el->data + el->size - provider));
   /* Making sure there is a name.  */
-  if (ret->p.name == NULL)
+  if (name == NULL)
     {
       complaint (&symfile_complaints, _("corrupt probe name when "
 					"reading `%s'"),
@@ -1503,32 +1540,32 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
   else
-    ++ret->p.name;
+    ++name;
 
   /* Retrieving the probe's address.  */
-  ret->p.address = extract_typed_address (&el->data[0], ptr_type);
+  CORE_ADDR address = extract_typed_address (&el->data[0], ptr_type);
 
   /* Link-time sh_addr of `.stapsdt.base' section.  */
-  base_ref = extract_typed_address (&el->data[size], ptr_type);
+  CORE_ADDR base_ref = extract_typed_address (&el->data[size], ptr_type);
 
   /* Semaphore address.  */
-  ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
+  CORE_ADDR sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
 
-  ret->p.address += base - base_ref;
-  if (ret->sem_addr != 0)
-    ret->sem_addr += base - base_ref;
+  address += base - base_ref;
+  if (sem_addr != 0)
+    sem_addr += base - base_ref;
 
   /* Arguments.  We can only extract the argument format if there is a valid
      name for this probe.  */
-  probe_args = ((const char*)
-		memchr (ret->p.name, '\0',
-			(char *) el->data + el->size - ret->p.name));
+  const char *probe_args = ((const char*)
+			    memchr (name, '\0',
+				    (char *) el->data + el->size - name));
 
   if (probe_args != NULL)
     ++probe_args;
 
   if (probe_args == NULL
-      || (memchr (probe_args, '\0', (char *) el->data + el->size - ret->p.name)
+      || (memchr (probe_args, '\0', (char *) el->data + el->size - name)
 	  != el->data + el->size - 1))
     {
       complaint (&symfile_complaints, _("corrupt probe argument when "
@@ -1539,11 +1576,11 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       return;
     }
 
-  ret->args_parsed = 0;
-  ret->args_u.text = probe_args;
+  stap_probe *ret = new stap_probe (std::string (name), std::string (provider),
+				    address, gdbarch, sem_addr, probe_args);
 
   /* Successfully created probe.  */
-  probesp->push_back ((struct probe *) ret);
+  probesp->push_back (ret);
 }
 
 /* Helper function which tries to find the base address of the SystemTap
@@ -1584,11 +1621,21 @@ get_stap_base_address (bfd *obfd, bfd_vma *base)
   return 1;
 }
 
-/* Helper function for `elf_get_probes', which gathers information about all
-   SystemTap probes from OBJFILE.  */
+/* Implementation of the 'is_linespec' method.  */
 
-static void
-stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
+bool
+stap_static_probe_ops::is_linespec (const char **linespecp) const
+{
+  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+
+  return probe_is_linespec_by_keyword (linespecp, keywords);
+}
+
+/* Implementation of the 'get_probes' method.  */
+
+void
+stap_static_probe_ops::get_probes (std::vector<probe *> *probesp,
+				   struct objfile *objfile) const
 {
   /* If we are here, then this is the first time we are parsing the
      SystemTap probe's information.  We basically have to count how many
@@ -1640,83 +1687,46 @@ stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile)
 
 /* Implementation of the type_name method.  */
 
-static const char *
-stap_type_name (struct probe *probe)
+const char *
+stap_static_probe_ops::type_name () const
 {
-  gdb_assert (probe->pops == &stap_probe_ops);
   return "stap";
 }
 
-static int
-stap_probe_is_linespec (const char **linespecp)
-{
-  static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
+/* Implementation of the 'emit_info_probes_extra_fields' method.  */
 
-  return probe_is_linespec_by_keyword (linespecp, keywords);
+bool
+stap_static_probe_ops::emit_info_probes_extra_fields () const
+{
+  return true;
 }
 
-static void
-stap_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
+/* Implementation of the 'gen_info_probes_table_header' method.  */
+
+void
+stap_static_probe_ops::gen_info_probes_table_header
+  (std::vector<struct info_probe_column> *heads) const
 {
-  info_probe_column_s stap_probe_column;
+  struct info_probe_column stap_probe_column;
 
   stap_probe_column.field_name = "semaphore";
   stap_probe_column.print_name = _("Semaphore");
 
-  VEC_safe_push (info_probe_column_s, *heads, &stap_probe_column);
-}
-
-static void
-stap_gen_info_probes_table_values (struct probe *probe_generic,
-				   VEC (const_char_ptr) **ret)
-{
-  struct stap_probe *probe = (struct stap_probe *) probe_generic;
-  struct gdbarch *gdbarch;
-  const char *val = NULL;
-
-  gdb_assert (probe_generic->pops == &stap_probe_ops);
-
-  gdbarch = probe->p.arch;
-
-  if (probe->sem_addr != 0)
-    val = print_core_address (gdbarch, probe->sem_addr);
-
-  VEC_safe_push (const_char_ptr, *ret, val);
+  heads->push_back (stap_probe_column);
 }
 
-/* SystemTap probe_ops.  */
-
-const struct probe_ops stap_probe_ops =
-{
-  stap_probe_is_linespec,
-  stap_get_probes,
-  stap_get_probe_address,
-  stap_get_probe_argument_count,
-  stap_can_evaluate_probe_arguments,
-  stap_evaluate_probe_argument,
-  stap_compile_to_ax,
-  stap_set_semaphore,
-  stap_clear_semaphore,
-  stap_probe_destroy,
-  stap_type_name,
-  stap_gen_info_probes_table_header,
-  stap_gen_info_probes_table_values,
-  NULL,  /* enable_probe  */
-  NULL   /* disable_probe  */
-};
-
 /* Implementation of the `info probes stap' command.  */
 
 static void
 info_probes_stap_command (const char *arg, int from_tty)
 {
-  info_probes_for_ops (arg, from_tty, &stap_probe_ops);
+  info_probes_for_spops (arg, from_tty, &stap_static_probe_ops);
 }
 
 void
 _initialize_stap_probe (void)
 {
-  all_probe_ops.push_back (&stap_probe_ops);
+  all_static_probe_ops.push_back (&stap_static_probe_ops);
 
   add_setshow_zuinteger_cmd ("stap-expression", class_maintenance,
 			     &stap_expression_debug,
-- 
2.13.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2017-11-23  0:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 17:59 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
2017-11-13 17:59 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
2017-11-15  3:58   ` Simon Marchi
2017-11-15 22:49     ` Sergio Durigan Junior
2017-11-13 17:59 ` [PATCH 1/3] Convert generic " Sergio Durigan Junior
2017-11-15  2:52   ` Simon Marchi
2017-11-15  3:25     ` Simon Marchi
2017-11-15  6:15       ` Sergio Durigan Junior
2017-11-15  6:12     ` Sergio Durigan Junior
2017-11-13 17:59 ` [PATCH 3/3] Convert DTrace " Sergio Durigan Junior
2017-11-15  4:40   ` Simon Marchi
2017-11-16  4:11     ` Sergio Durigan Junior
2017-11-16  4:37 ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
2017-11-16  4:38   ` [PATCH v2 2/3] Convert SystemTap probe interface " Sergio Durigan Junior
2017-11-16  4:38   ` [PATCH v2 3/3] Convert DTrace " Sergio Durigan Junior
2017-11-16  4:38   ` [PATCH v2 1/3] Convert generic " Sergio Durigan Junior
2017-11-22 20:39     ` Simon Marchi
2017-11-22 22:36       ` Sergio Durigan Junior
2017-11-23  0:01         ` Simon Marchi
2017-11-23  0:15           ` Sergio Durigan Junior
2017-11-23  0:33             ` Sergio Durigan Junior
2017-11-21 16:25   ` [PATCH v2 0/3] Convert probe interfaces " Sergio Durigan Junior
  -- strict thread matches above, loose matches on Subject: below --
2017-11-13 17:53 [PATCH " Sergio Durigan Junior
2017-11-13 18:02 ` [PATCH 2/3] Convert SystemTap probe interface " Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).