From 814cf43a1f16157fcbe2c662f567d064393a0fcb Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 30 Apr 2019 23:47:54 -0600 Subject: Convert probes to type-safe registry API This changes the probes code in elfread.c to use the type-safe registry API. While doing this, I saw that the caller of get_probes owns the probes, so I went through the code and changed the vectors to store unique_ptrs, making the ownership relationship more clear. gdb/ChangeLog 2019-05-08 Tom Tromey * symfile.h (struct sym_probe_fns) : Change type. * symfile-debug.c (debug_sym_get_probes): Change type. * stap-probe.c (handle_stap_probe): (stap_static_probe_ops::get_probes): Change type. * probe.h (class static_probe_ops) : Change type. * probe.c (class any_static_probe_ops) : Change type. (parse_probes_in_pspace): Update. (find_probes_in_objfile, find_probe_by_pc, collect_probes): Update. (any_static_probe_ops::get_probes): Change type. * elfread.c (elfread_data): New typedef. (probe_key): Change type. (elf_get_probes): Likewise. Update. (probe_key_free): Remove. (_initialize_elfread): Update. * dtrace-probe.c (class dtrace_static_probe_ops) : Change type. (dtrace_process_dof_probe, dtrace_process_dof) (dtrace_static_probe_ops::get_probe): Change type. --- gdb/probe.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'gdb/probe.c') diff --git a/gdb/probe.c b/gdb/probe.c index b9337a9..7bc75d8 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -47,7 +47,7 @@ public: bool is_linespec (const char **linespecp) const override; /* See probe.h. */ - void get_probes (std::vector *probesp, + void get_probes (std::vector> *probesp, struct objfile *objfile) const override; /* See probe.h. */ @@ -84,10 +84,10 @@ parse_probes_in_pspace (const static_probe_ops *spops, objfile_namestr) != 0) continue; - const std::vector &probes + const std::vector> &probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - for (probe *p : probes) + for (auto &p : probes) { if (spops != &any_static_probe_ops && p->get_static_ops () != spops) continue; @@ -103,7 +103,7 @@ parse_probes_in_pspace (const static_probe_ops *spops, sal.explicit_pc = 1; sal.section = find_pc_overlay (sal.pc); sal.pspace = search_pspace; - sal.prob = p; + sal.prob = p.get (); sal.objfile = objfile; result->push_back (std::move (sal)); @@ -223,9 +223,9 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider, if (!objfile->sf || !objfile->sf->sym_probe_fns) return result; - const std::vector &probes + const std::vector> &probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - for (probe *p : probes) + for (auto &p : probes) { if (p->get_provider () != provider) continue; @@ -233,7 +233,7 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider, if (p->get_name () != name) continue; - result.push_back (p); + result.push_back (p.get ()); } return result; @@ -256,13 +256,13 @@ find_probe_by_pc (CORE_ADDR pc) continue; /* If this proves too inefficient, we can replace with a hash. */ - const std::vector &probes + const std::vector> &probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - for (probe *p : probes) + for (auto &p : probes) if (p->get_relocated_address (objfile) == pc) { result.objfile = objfile; - result.prob = p; + result.prob = p.get (); return result; } } @@ -305,10 +305,10 @@ collect_probes (const std::string &objname, const std::string &provider, continue; } - const std::vector &probes + const std::vector> &probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - for (probe *p : probes) + for (auto &p : probes) { if (spops != &any_static_probe_ops && p->get_static_ops () != spops) continue; @@ -321,7 +321,7 @@ collect_probes (const std::string &objname, const std::string &provider, && probe_pat->exec (p->get_name ().c_str (), 0, NULL, 0) != 0) continue; - result.emplace_back (p, objfile); + result.emplace_back (p.get (), objfile); } } @@ -750,7 +750,7 @@ any_static_probe_ops::is_linespec (const char **linespecp) const /* Implementation of 'get_probes' method. */ void -any_static_probe_ops::get_probes (std::vector *probesp, +any_static_probe_ops::get_probes (std::vector> *probesp, struct objfile *objfile) const { /* No probes can be provided by this dummy backend. */ -- cgit v1.1