From patchwork Fri May 3 23:12:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32526 Received: (qmail 774 invoked by alias); 3 May 2019 23:12:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 131067 invoked by uid 89); 3 May 2019 23:12:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_JMF_BL, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=objfiles X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:39 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 0C66E12549F for ; Fri, 3 May 2019 18:12:38 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM6htJyl2PzOMhM6hMXb3; Fri, 03 May 2019 18:12:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4zvsK6p3rUoMn0yOoPWYsufRv0R+9O7REo2caO7D4xk=; b=UaQyH+jwaoLv6x4mR+mCY5pj1T 1UmV11rZONEcscvPfffuyRuRMh8IJX+5htnDikSdPHW78h5i+FHPEh4Wj9TGZatinwMIHatC5vQQC 5/lcdYwFmiUlksVKGDPiTJiW/; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:37502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMhM5-003AAO-Qb; Fri, 03 May 2019 18:12:37 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 17/31] Convert probes to type-safe registry API Date: Fri, 3 May 2019 17:12:17 -0600 Message-Id: <20190503231231.8954-18-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> 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. 2019-05-03 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/ChangeLog | 22 ++++++++++++++++++++++ gdb/dtrace-probe.c | 14 ++++++++------ gdb/elfread.c | 32 ++++++++------------------------ gdb/probe.c | 28 ++++++++++++++-------------- gdb/probe.h | 2 +- gdb/stap-probe.c | 12 +++++++----- gdb/symfile-debug.c | 4 ++-- gdb/symfile.h | 3 ++- 8 files changed, 64 insertions(+), 53 deletions(-) diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index a51f35800ab..52973784e9a 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -81,7 +81,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. */ @@ -380,7 +380,7 @@ struct dtrace_dof_probe static void dtrace_process_dof_probe (struct objfile *objfile, struct gdbarch *gdbarch, - std::vector *probesp, + std::vector> *probesp, struct dtrace_dof_hdr *dof, struct dtrace_dof_probe *probe, struct dtrace_dof_provider *provider, @@ -507,7 +507,7 @@ dtrace_process_dof_probe (struct objfile *objfile, std::move (enablers_copy)); /* Successfully created probe. */ - probesp->push_back (ret); + probesp->emplace_back (ret); } } @@ -518,7 +518,8 @@ dtrace_process_dof_probe (struct objfile *objfile, static void dtrace_process_dof (asection *sect, struct objfile *objfile, - std::vector *probesp, struct dtrace_dof_hdr *dof) + std::vector> *probesp, + struct dtrace_dof_hdr *dof) { struct gdbarch *gdbarch = get_objfile_arch (objfile); struct dtrace_dof_sect *section; @@ -833,8 +834,9 @@ dtrace_static_probe_ops::is_linespec (const char **linespecp) const /* Implementation of the get_probes method. */ void -dtrace_static_probe_ops::get_probes (std::vector *probesp, - struct objfile *objfile) const +dtrace_static_probe_ops::get_probes + (std::vector> *probesp, + struct objfile *objfile) const { bfd *abfd = objfile->obfd; asection *sect = NULL; diff --git a/gdb/elfread.c b/gdb/elfread.c index 55a16bb2f8e..deee6f0baab 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> elfread_data; + /* Per-BFD data for probe info. */ -static const struct bfd_data *probe_key = NULL; +static const struct bfd_key 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 & +static const elfread_data & elf_get_probes (struct objfile *objfile) { - std::vector *probes_per_bfd; - - /* Have we parsed this objfile's probes already? */ - probes_per_bfd = (std::vector *) 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; + 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 *probes = (std::vector *) 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 (); diff --git a/gdb/probe.c b/gdb/probe.c index b9337a9d19f..7bc75d8e879 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. */ diff --git a/gdb/probe.h b/gdb/probe.h index 2f665e3a658..5c83f494714 100644 --- a/gdb/probe.h +++ b/gdb/probe.h @@ -62,7 +62,7 @@ public: 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 *probes, + virtual void get_probes (std::vector> *probes, struct objfile *objfile) const = 0; /* Return a pointer to a name identifying the probe type. This is diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 24b2b78a903..e70940c4878 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -106,7 +106,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. */ @@ -1497,7 +1497,8 @@ stap_probe::gen_info_probes_table_values () const static void handle_stap_probe (struct objfile *objfile, struct sdt_note *el, - std::vector *probesp, CORE_ADDR base) + std::vector> *probesp, + CORE_ADDR base) { bfd *abfd = objfile->obfd; int size = bfd_get_arch_size (abfd) / 8; @@ -1561,7 +1562,7 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el, address, gdbarch, sem_addr, probe_args); /* Successfully created probe. */ - probesp->push_back (ret); + probesp->emplace_back (ret); } /* Helper function which tries to find the base address of the SystemTap @@ -1615,8 +1616,9 @@ stap_static_probe_ops::is_linespec (const char **linespecp) const /* Implementation of the 'get_probes' method. */ void -stap_static_probe_ops::get_probes (std::vector *probesp, - struct objfile *objfile) const +stap_static_probe_ops::get_probes + (std::vector> *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 diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 8266ecbabf0..0f9da66e536 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -382,13 +382,13 @@ static const struct quick_symbol_functions debug_sym_quick_functions = /* Debugging version of struct sym_probe_fns. */ -static const std::vector & +static const std::vector> & debug_sym_get_probes (struct objfile *objfile) { const struct debug_sym_fns_data *debug_data = symfile_debug_objfile_data_key.get (objfile); - const std::vector &retval + const std::vector> &retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); fprintf_filtered (gdb_stdlog, diff --git a/gdb/symfile.h b/gdb/symfile.h index a873dfe9451..daddd2e21ab 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -292,7 +292,8 @@ struct quick_symbol_functions struct sym_probe_fns { /* If non-NULL, return a reference to vector of probe objects. */ - const std::vector &(*sym_get_probes) (struct objfile *); + const std::vector> &(*sym_get_probes) + (struct objfile *); }; /* Structure to keep track of symbol reading functions for various