* [PATCH 1/3] Convert generic probe interface to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
@ 2017-11-13 17:53 ` Sergio Durigan Junior
2017-11-13 17:53 ` [PATCH 1/2] Convert SystemTap " Sergio Durigan Junior
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:53 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] 10+ messages in thread
* [PATCH 1/2] Convert SystemTap probe interface to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
2017-11-13 17:53 ` [PATCH 1/3] Convert generic probe interface " Sergio Durigan Junior
@ 2017-11-13 17:53 ` Sergio Durigan Junior
2017-11-13 17:53 ` [PATCH 2/2] Convert DTrace " Sergio Durigan Junior
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:53 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] 10+ messages in thread
* [PATCH 2/2] Convert DTrace probe interface to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
2017-11-13 17:53 ` [PATCH 1/3] Convert generic probe interface " Sergio Durigan Junior
2017-11-13 17:53 ` [PATCH 1/2] Convert SystemTap " Sergio Durigan Junior
@ 2017-11-13 17:53 ` Sergio Durigan Junior
2017-11-13 17:58 ` [CANCEL] [PATCH 0/3] Convert probe interfaces " Sergio Durigan Junior
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:53 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] 10+ messages in thread
* [CANCEL] [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
` (2 preceding siblings ...)
2017-11-13 17:53 ` [PATCH 2/2] Convert DTrace " Sergio Durigan Junior
@ 2017-11-13 17:58 ` Sergio Durigan Junior
2017-11-13 18:02 ` [PATCH 3/3] Convert DTrace probe interface " Sergio Durigan Junior
2017-11-13 18:02 ` [PATCH 2/3] Convert SystemTap " Sergio Durigan Junior
5 siblings, 0 replies; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-13 17:58 UTC (permalink / raw)
To: GDB Patches
On Monday, November 13 2017, I wrote:
> 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.
Sorry, it seems my git-format-patch messed up and generated a lot of
patches on my source tree. Please, ignore this thread. I will resubmit
the patches in a new thread.
> 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.
--
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] 10+ messages in thread
* [PATCH 3/3] Convert DTrace probe interface to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
` (3 preceding siblings ...)
2017-11-13 17:58 ` [CANCEL] [PATCH 0/3] Convert probe interfaces " Sergio Durigan Junior
@ 2017-11-13 18:02 ` Sergio Durigan Junior
2017-11-13 18:02 ` [PATCH 2/3] Convert SystemTap " Sergio Durigan Junior
5 siblings, 0 replies; 10+ 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 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] 10+ messages in thread
* [PATCH 2/3] Convert SystemTap probe interface to C++ (and perform some cleanups)
2017-11-13 17:53 [PATCH 0/3] Convert probe interfaces to C++ (and perform some cleanups) Sergio Durigan Junior
` (4 preceding siblings ...)
2017-11-13 18:02 ` [PATCH 3/3] Convert DTrace probe interface " Sergio Durigan Junior
@ 2017-11-13 18:02 ` Sergio Durigan Junior
5 siblings, 0 replies; 10+ 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] 10+ messages in thread