From patchwork Fri May 3 23:12:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32515 Received: (qmail 130420 invoked by alias); 3 May 2019 23:12:40 -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 130255 invoked by uid 89); 3 May 2019 23:12:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 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=Objects X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:36 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 8038433F18C6 for ; Fri, 3 May 2019 18:12:35 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM3hZYgUYTGMMhM3hdon5; Fri, 03 May 2019 18:12:35 -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=zO/dvf4hZxitLN9Cxa1KcB1nSLIyMarH3BmP+OW4aK0=; b=L96h8w3Qzzv5pRiRQJCA70Gfse 4m/PHLaXBwdc8GrshX8oDBcvpJUvI5uEez0tQkonRENOpaCYoBAwTvnpsS+PbLFwBy2jFVjsxYoTo Me+EiSyQN0fk4myTSepTVEp+E; 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 1hMhM3-003AAO-AE; Fri, 03 May 2019 18:12:35 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 08/31] Convert auto-load.c to type-safe registry API Date: Fri, 3 May 2019 17:12:08 -0600 Message-Id: <20190503231231.8954-9-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes auto-load.c to use the type-safe registry API. It also changes a couple of types to "bool", removing uses of "FALSE". 2019-04-22 Tom Tromey * auto-load.c (struct auto_load_pspace_info): Add destructor and initializers. : Now bool. (auto_load_pspace_data): Change type. (~auto_load_pspace_info): Rename from auto_load_pspace_data_cleanup. (get_auto_load_pspace_data, init_loaded_scripts_info) (clear_section_scripts, maybe_print_unsupported_script_warning) (maybe_print_script_not_found_warning, _initialize_auto_load): Update. --- gdb/ChangeLog | 14 ++++++++++++ gdb/auto-load.c | 60 ++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index ae7a189dc04..6833c21323a 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -527,18 +527,21 @@ For more information about this security protection see the\n\ struct auto_load_pspace_info { + auto_load_pspace_info () = default; + ~auto_load_pspace_info (); + /* For each program space we keep track of loaded scripts, both when specified as file names and as scripts to be executed directly. */ - struct htab *loaded_script_files; - struct htab *loaded_script_texts; + struct htab *loaded_script_files = nullptr; + struct htab *loaded_script_texts = nullptr; /* Non-zero if we've issued the warning about an auto-load script not being supported. We only want to issue this warning once. */ - int unsupported_script_warning_printed; + bool unsupported_script_warning_printed = false; /* Non-zero if we've issued the warning about an auto-load script not being found. We only want to issue this warning once. */ - int script_not_found_warning_printed; + bool script_not_found_warning_printed = false; }; /* Objects of this type are stored in the loaded_script hash table. */ @@ -559,18 +562,15 @@ struct loaded_script }; /* Per-program-space data key. */ -static const struct program_space_data *auto_load_pspace_data; +static const struct program_space_key + auto_load_pspace_data; -static void -auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg) +auto_load_pspace_info::~auto_load_pspace_info () { - struct auto_load_pspace_info *info = (struct auto_load_pspace_info *) arg; - - if (info->loaded_script_files) - htab_delete (info->loaded_script_files); - if (info->loaded_script_texts) - htab_delete (info->loaded_script_texts); - xfree (info); + if (loaded_script_files) + htab_delete (loaded_script_files); + if (loaded_script_texts) + htab_delete (loaded_script_texts); } /* Get the current autoload data. If none is found yet, add it now. This @@ -581,13 +581,9 @@ get_auto_load_pspace_data (struct program_space *pspace) { struct auto_load_pspace_info *info; - info = ((struct auto_load_pspace_info *) - program_space_data (pspace, auto_load_pspace_data)); + info = auto_load_pspace_data.get (pspace); if (info == NULL) - { - info = XCNEW (struct auto_load_pspace_info); - set_program_space_data (pspace, auto_load_pspace_data, info); - } + info = auto_load_pspace_data.emplace (pspace); return info; } @@ -632,8 +628,8 @@ init_loaded_scripts_info (struct auto_load_pspace_info *pspace_info) eq_loaded_script_entry, xfree); - pspace_info->unsupported_script_warning_printed = FALSE; - pspace_info->script_not_found_warning_printed = FALSE; + pspace_info->unsupported_script_warning_printed = false; + pspace_info->script_not_found_warning_printed = false; } /* Wrapper on get_auto_load_pspace_data to also allocate the hash table @@ -747,17 +743,9 @@ clear_section_scripts (void) struct program_space *pspace = current_program_space; struct auto_load_pspace_info *info; - info = ((struct auto_load_pspace_info *) - program_space_data (pspace, auto_load_pspace_data)); + info = auto_load_pspace_data.get (pspace); if (info != NULL && info->loaded_script_files != NULL) - { - htab_delete (info->loaded_script_files); - htab_delete (info->loaded_script_texts); - info->loaded_script_files = NULL; - info->loaded_script_texts = NULL; - info->unsupported_script_warning_printed = FALSE; - info->script_not_found_warning_printed = FALSE; - } + auto_load_pspace_data.clear (pspace); } /* Look for the auto-load script in LANGUAGE associated with OBJFILE where @@ -1386,7 +1374,7 @@ of file %s.\n\ Use `info auto-load %s-scripts [REGEXP]' to list them."), offset, section_name, objfile_name (objfile), ext_lang_name (language)); - pspace_info->unsupported_script_warning_printed = 1; + pspace_info->unsupported_script_warning_printed = true; } } @@ -1408,7 +1396,7 @@ of file %s.\n\ Use `info auto-load %s-scripts [REGEXP]' to list them."), offset, section_name, objfile_name (objfile), ext_lang_name (language)); - pspace_info->script_not_found_warning_printed = 1; + pspace_info->script_not_found_warning_printed = true; } } @@ -1538,10 +1526,6 @@ _initialize_auto_load (void) char *guile_name_help; const char *suffix; - auto_load_pspace_data - = register_program_space_data_with_cleanup (NULL, - auto_load_pspace_data_cleanup); - gdb::observers::new_objfile.attach (auto_load_new_objfile); add_setshow_boolean_cmd ("gdb-scripts", class_support,