diff options
author | Tom Tromey <tom@tromey.com> | 2019-04-30 23:47:54 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-05-08 16:01:51 -0600 |
commit | 814cf43a1f16157fcbe2c662f567d064393a0fcb (patch) | |
tree | 66d0d0c948fdf020cd7a31849db9edc26ea138ac /gdb/elfread.c | |
parent | 02dc647ed65b1429b9af4986ed467f90fbe0c33b (diff) | |
download | gdb-814cf43a1f16157fcbe2c662f567d064393a0fcb.zip gdb-814cf43a1f16157fcbe2c662f567d064393a0fcb.tar.gz gdb-814cf43a1f16157fcbe2c662f567d064393a0fcb.tar.bz2 |
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 <tom@tromey.com>
* symfile.h (struct sym_probe_fns) <sym_get_probes>: 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) <get_probes>: Change type.
* probe.c (class any_static_probe_ops) <get_probes>: 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) <get_probes>:
Change type.
(dtrace_process_dof_probe, dtrace_process_dof)
(dtrace_static_probe_ops::get_probe): Change type.
Diffstat (limited to 'gdb/elfread.c')
-rw-r--r-- | gdb/elfread.c | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/gdb/elfread.c b/gdb/elfread.c index 55a16bb..deee6f0 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -64,9 +64,13 @@ struct elfinfo asection *mdebugsect; /* Section pointer for .mdebug section */ }; +/* Type for per-BFD data. */ + +typedef std::vector<std::unique_ptr<probe>> elfread_data; + /* Per-BFD data for probe info. */ -static const struct bfd_data *probe_key = NULL; +static const struct bfd_key<elfread_data> probe_key; /* Minimal symbols located at the GOT entries for .plt - that is the real pointer where the given entry will jump to. It gets updated by the real @@ -1347,43 +1351,24 @@ elf_symfile_init (struct objfile *objfile) /* Implementation of `sym_get_probes', as documented in symfile.h. */ -static const std::vector<probe *> & +static const elfread_data & elf_get_probes (struct objfile *objfile) { - std::vector<probe *> *probes_per_bfd; - - /* Have we parsed this objfile's probes already? */ - probes_per_bfd = (std::vector<probe *> *) bfd_data (objfile->obfd, probe_key); + elfread_data *probes_per_bfd = probe_key.get (objfile->obfd); if (probes_per_bfd == NULL) { - probes_per_bfd = new std::vector<probe *>; + probes_per_bfd = probe_key.emplace (objfile->obfd); /* Here we try to gather information about all types of probes from the objfile. */ 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); } return *probes_per_bfd; } -/* Helper function used to free the space allocated for storing SystemTap - probe information. */ - -static void -probe_key_free (bfd *abfd, void *d) -{ - std::vector<probe *> *probes = (std::vector<probe *> *) d; - - for (probe *p : *probes) - delete p; - - delete probes; -} - /* Implementation `sym_probe_fns', as documented in symfile.h. */ @@ -1475,7 +1460,6 @@ static const struct gnu_ifunc_fns elf_gnu_ifunc_fns = void _initialize_elfread (void) { - probe_key = register_bfd_data_with_cleanup (NULL, probe_key_free); add_symtab_fns (bfd_target_elf_flavour, &elf_sym_fns); elf_objfile_gnu_ifunc_cache_data = register_objfile_data (); |