From patchwork Fri May 3 23:12:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32525 Received: (qmail 690 invoked by alias); 3 May 2019 23:12:46 -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 130844 invoked by uid 89); 3 May 2019 23:12:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Validity, validity X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.48.251) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:38 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 771364405 for ; Fri, 3 May 2019 18:12:37 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM5hcYPMdnCeMhM5hMCPs; Fri, 03 May 2019 18:12:37 -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=BoSOSe0KMcbWYCJ01w/GiQGvMkO1cUOWLULsZxcyWtk=; b=Tqkl86FpulCEgaISOwTaFvcfkv UVz4UuBNKWUHP4UoBE52Glu+02UuyE/AfenQcRD+OZWbLd8NGOqiWr+dpFWNvTK06PM8MuyVrbEsx NcbIblATT77kjUPOUvChc2qd9; 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-8x; Fri, 03 May 2019 18:12:37 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 15/31] Convert solib-svr4.c to type-safe registry API Date: Fri, 3 May 2019 17:12:15 -0600 Message-Id: <20190503231231.8954-16-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes solib-svr4y.c to use the type-safe registry API. 2019-04-30 Tom Tromey * solib-svr4.c (struct svr4_info): Add initializers and destructor. : Now an htab_up. (solib_svr4_pspace_data): Change type. (free_probes_table): Simplify. (~svr4_info): Rename from svr4_pspace_data_cleanup. (get_svr4_info, probes_table_htab_remove_objfile_probes) (probes_table_remove_objfile_probes, register_solib_event_probe) (solib_event_probe_at, svr4_update_solib_event_breakpoint) (_initialize_svr4_solib): Update. --- gdb/ChangeLog | 13 +++++++++ gdb/solib-svr4.c | 76 ++++++++++++++++++++---------------------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 2aa7b95ce6c..2828c96c683 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -322,53 +322,53 @@ lm_addr_check (const struct so_list *so, bfd *abfd) struct svr4_info { - CORE_ADDR debug_base; /* Base of dynamic linker structures. */ + svr4_info () = default; + ~svr4_info (); + + /* Base of dynamic linker structures. */ + CORE_ADDR debug_base = 0; /* Validity flag for debug_loader_offset. */ - int debug_loader_offset_p; + int debug_loader_offset_p = 0; /* Load address for the dynamic linker, inferred. */ - CORE_ADDR debug_loader_offset; + CORE_ADDR debug_loader_offset = 0; /* Name of the dynamic linker, valid if debug_loader_offset_p. */ - char *debug_loader_name; + char *debug_loader_name = nullptr; /* Load map address for the main executable. */ - CORE_ADDR main_lm_addr; + CORE_ADDR main_lm_addr = 0; - CORE_ADDR interp_text_sect_low; - CORE_ADDR interp_text_sect_high; - CORE_ADDR interp_plt_sect_low; - CORE_ADDR interp_plt_sect_high; + CORE_ADDR interp_text_sect_low = 0; + CORE_ADDR interp_text_sect_high = 0; + CORE_ADDR interp_plt_sect_low = 0; + CORE_ADDR interp_plt_sect_high = 0; /* Nonzero if the list of objects was last obtained from the target via qXfer:libraries-svr4:read. */ - int using_xfer; + int using_xfer = 0; /* 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->prob->address. */ - htab_t probes_table; + htab_up probes_table; /* List of objects loaded into the inferior, used by the probes- based interface. */ - struct so_list *solib_list; + struct so_list *solib_list = nullptr; }; /* Per-program-space data key. */ -static const struct program_space_data *solib_svr4_pspace_data; +static const struct program_space_key solib_svr4_pspace_data; /* Free the probes table. */ static void free_probes_table (struct svr4_info *info) { - if (info->probes_table == NULL) - return; - - htab_delete (info->probes_table); - info->probes_table = NULL; + info->probes_table.reset (nullptr); } /* Free the solib list. */ @@ -380,15 +380,9 @@ free_solib_list (struct svr4_info *info) info->solib_list = NULL; } -static void -svr4_pspace_data_cleanup (struct program_space *pspace, void *arg) +svr4_info::~svr4_info () { - struct svr4_info *info = (struct svr4_info *) arg; - - free_probes_table (info); - free_solib_list (info); - - xfree (info); + free_solib_list (this); } /* Get the svr4 data for program space PSPACE. If none is found yet, add it now. @@ -397,15 +391,11 @@ svr4_pspace_data_cleanup (struct program_space *pspace, void *arg) static struct svr4_info * get_svr4_info (program_space *pspace) { - struct svr4_info *info; + struct svr4_info *info = solib_svr4_pspace_data.get (pspace); - info = (struct svr4_info *) program_space_data (pspace, - solib_svr4_pspace_data); - if (info != NULL) - return info; + if (info == NULL) + info = solib_svr4_pspace_data.emplace (pspace); - info = XCNEW (struct svr4_info); - set_program_space_data (pspace, solib_svr4_pspace_data, info); return info; } @@ -1677,7 +1667,8 @@ probes_table_htab_remove_objfile_probes (void **slot, void *info) struct objfile *objfile = (struct objfile *) info; if (pa->objfile == objfile) - htab_clear_slot (get_svr4_info (objfile->pspace)->probes_table, slot); + htab_clear_slot (get_svr4_info (objfile->pspace)->probes_table.get (), + slot); return 1; } @@ -1689,7 +1680,7 @@ probes_table_remove_objfile_probes (struct objfile *objfile) { svr4_info *info = get_svr4_info (objfile->pspace); if (info->probes_table != nullptr) - htab_traverse_noresize (info->probes_table, + htab_traverse_noresize (info->probes_table.get (), probes_table_htab_remove_objfile_probes, objfile); } @@ -1706,12 +1697,12 @@ register_solib_event_probe (svr4_info *info, struct objfile *objfile, /* Create the probes table, if necessary. */ if (info->probes_table == NULL) - info->probes_table = htab_create_alloc (1, hash_probe_and_action, - equal_probe_and_action, - xfree, xcalloc, xfree); + info->probes_table.reset (htab_create_alloc (1, hash_probe_and_action, + equal_probe_and_action, + xfree, xcalloc, xfree)); lookup.address = address; - slot = htab_find_slot (info->probes_table, &lookup, INSERT); + slot = htab_find_slot (info->probes_table.get (), &lookup, INSERT); gdb_assert (*slot == HTAB_EMPTY_ENTRY); pa = XCNEW (struct probe_and_action); @@ -1734,7 +1725,7 @@ solib_event_probe_at (struct svr4_info *info, CORE_ADDR address) void **slot; lookup.address = address; - slot = htab_find_slot (info->probes_table, &lookup, NO_INSERT); + slot = htab_find_slot (info->probes_table.get (), &lookup, NO_INSERT); if (slot == NULL) return NULL; @@ -2012,8 +2003,7 @@ svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg) struct svr4_info *info; struct probe_and_action *pa; - info = ((struct svr4_info *) - program_space_data (loc->pspace, solib_svr4_pspace_data)); + info = solib_svr4_pspace_data.get (loc->pspace); if (info == NULL || info->probes_table == NULL) continue; @@ -3243,8 +3233,6 @@ void _initialize_svr4_solib (void) { solib_svr4_data = gdbarch_data_register_pre_init (solib_svr4_init); - solib_svr4_pspace_data - = register_program_space_data_with_cleanup (NULL, svr4_pspace_data_cleanup); svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses; svr4_so_ops.free_so = svr4_free_so;