From 0782db848b52ecaf29e13d9f12a2c7cfabec2bdb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 12 Sep 2017 14:15:23 +0200 Subject: [PATCH] probe: Replace VEC(probe_ops_cp) with std::vector This patch replaces the usage of VEC to store pointers to probe_ops with an std::vector. The sole usage of that vector type is one global variable that holds the ops for the various kinds of probes, so this is pretty straightforward (no allocation/deallocation issues). gdb/ChangeLog: * probe.h (probe_ops_cp): Remove typedef. (DEF_VEC_P (probe_ops_cp)): Remove. (all_probe_ops): Change type to std::vector. * probe.c (info_probes_for_ops): Adjust to vector change. (probe_linespec_to_ops): Likewise. (all_probe_ops): Change type to std::vector. (_initialize_probe): Adjust to vector change. * dtrace-probe.c (_initialize_dtrace_probe): Likewise. * elfread.c (elf_get_probes): Likewise. * stap-probe.c (_initialize_stap_probe): Likewise. --- gdb/ChangeLog | 13 +++++++++++++ gdb/dtrace-probe.c | 2 +- gdb/elfread.c | 7 ++----- gdb/probe.c | 29 ++++++++--------------------- gdb/probe.h | 4 +--- gdb/stap-probe.c | 2 +- 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b5fe2e28303..3905a510fea 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2017-09-12 Simon Marchi + + * probe.h (probe_ops_cp): Remove typedef. + (DEF_VEC_P (probe_ops_cp)): Remove. + (all_probe_ops): Change type to std::vector. + * probe.c (info_probes_for_ops): Adjust to vector change. + (probe_linespec_to_ops): Likewise. + (all_probe_ops): Change type to std::vector. + (_initialize_probe): Adjust to vector change. + * dtrace-probe.c (_initialize_dtrace_probe): Likewise. + * elfread.c (elf_get_probes): Likewise. + * stap-probe.c (_initialize_stap_probe): Likewise. + 2017-09-12 Simon Marchi * probe.h (struct bound_probe): Define constructors. diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index f9209ece1a5..5a4daa3c6be 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -912,7 +912,7 @@ info_probes_dtrace_command (char *arg, int from_tty) void _initialize_dtrace_probe (void) { - VEC_safe_push (probe_ops_cp, all_probe_ops, &dtrace_probe_ops); + all_probe_ops.push_back (&dtrace_probe_ops); add_cmd ("dtrace", class_info, info_probes_dtrace_command, _("\ diff --git a/gdb/elfread.c b/gdb/elfread.c index 8a648656695..436d9b5b4ac 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1319,15 +1319,12 @@ elf_get_probes (struct objfile *objfile) if (probes_per_bfd == NULL) { - int ix; - const struct probe_ops *probe_ops; probes_per_bfd = new std::vector; /* Here we try to gather information about all types of probes from the objfile. */ - for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); - ix++) - probe_ops->get_probes (probes_per_bfd, objfile); + for (const probe_ops *ops : all_probe_ops) + ops->get_probes (probes_per_bfd, objfile); set_bfd_data (objfile->obfd, probe_key, probes_per_bfd); } diff --git a/gdb/probe.c b/gdb/probe.c index 36211eae41d..f44d25dbd3f 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -565,9 +565,6 @@ info_probes_for_ops (const char *arg, int from_tty, if (pops == NULL) { - const struct probe_ops *po; - int ix; - /* 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 @@ -578,7 +575,7 @@ info_probes_for_ops (const char *arg, int from_tty, that number. But note that we ignore the probe_ops for which no probes are defined with the given search criteria. */ - for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) + for (const probe_ops *po : all_probe_ops) if (exists_probe_with_pops (probes, po)) ui_out_extra_fields += get_number_extra_fields (po); } @@ -616,13 +613,10 @@ info_probes_for_ops (const char *arg, int from_tty, if (pops == NULL) { - const struct probe_ops *po; - int ix; - /* 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 (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) + for (const probe_ops *po : all_probe_ops) if (exists_probe_with_pops (probes, po)) gen_ui_out_table_header_info (probes, po); } @@ -647,11 +641,7 @@ info_probes_for_ops (const char *arg, int from_tty, if (pops == NULL) { - const struct probe_ops *po; - int ix; - - for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); - ++ix) + 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)) @@ -816,12 +806,9 @@ probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n) const struct probe_ops * probe_linespec_to_ops (const char **linespecp) { - int ix; - const struct probe_ops *probe_ops; - - for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++) - if (probe_ops->is_linespec (linespecp)) - return probe_ops; + for (const probe_ops *ops : all_probe_ops) + if (ops->is_linespec (linespecp)) + return ops; return NULL; } @@ -980,12 +967,12 @@ static const struct internalvar_funcs probe_funcs = }; -VEC (probe_ops_cp) *all_probe_ops; +std::vector all_probe_ops; void _initialize_probe (void) { - VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any); + all_probe_ops.push_back (&probe_ops_any); create_internalvar_type_lazy ("_probe_argc", &probe_funcs, (void *) (uintptr_t) -1); diff --git a/gdb/probe.h b/gdb/probe.h index 3248dc85a1e..1b3916602ad 100644 --- a/gdb/probe.h +++ b/gdb/probe.h @@ -160,9 +160,7 @@ struct probe_ops /* Definition of a vector of probe_ops. */ -typedef const struct probe_ops *probe_ops_cp; -DEF_VEC_P (probe_ops_cp); -extern VEC (probe_ops_cp) *all_probe_ops; +extern std::vector all_probe_ops; /* The probe_ops associated with the generic probe. */ diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index a65fc7ec635..61eb8e42072 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -1716,7 +1716,7 @@ info_probes_stap_command (char *arg, int from_tty) void _initialize_stap_probe (void) { - VEC_safe_push (probe_ops_cp, all_probe_ops, &stap_probe_ops); + all_probe_ops.push_back (&stap_probe_ops); add_setshow_zuinteger_cmd ("stap-expression", class_maintenance, &stap_expression_debug, -- 2.30.2