From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway23.websitewelcome.com (gateway23.websitewelcome.com [192.185.49.218]) by sourceware.org (Postfix) with ESMTPS id EBF3F3857C57 for ; Sun, 9 Aug 2020 13:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EBF3F3857C57 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 27690DC2 for ; Sun, 9 Aug 2020 08:53:03 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4ll0kddgVOIGp4ll0kN6SV; Sun, 09 Aug 2020 08:53:03 -0500 X-Authority-Reason: nr=8 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=6TRiQVy2lBBa4eYCIBQtO0SFcRdap8lDYbhXLby7LCs=; b=BUF2Ihd1fF2EG1s40U7zaLCOCh cwBpKu6u/Ie4GI3LV8WUm1HfgP0TcUG95d8I1j5aSkPO512o4VgVKBTTZTBDdTexiBFSjT7ju3X7d j4zG/XCSzmTRy7JPE1+ob+Xa1; Received: from 75-166-101-103.hlrn.qwest.net ([75.166.101.103]:56058 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1k4lkz-0022sH-HL; Sun, 09 Aug 2020 07:53:01 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/6] Introduce and use compile_module_up Date: Sun, 9 Aug 2020 07:52:55 -0600 Message-Id: <20200809135258.8207-4-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200809135258.8207-1-tom@tromey.com> References: <20200809135258.8207-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.101.103 X-Source-L: No X-Exim-ID: 1k4lkz-0022sH-HL X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-101-103.hlrn.qwest.net (bapiya.Home) [75.166.101.103]:56058 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Aug 2020 13:53:06 -0000 This introduces compile_module_up, a unique pointer for compile_module, and changes a few spots to use it. gdb/ChangeLog 2020-08-08 Tom Tromey * compile/compile.c (eval_compile_command): Update. * compile/compile-object-run.h (compile_object_run): Take a compile_module_up. * compile/compile-object-run.c (compile_object_run): Take a compile_module_up. * compile/compile-object-load.h (struct compile_module): Add constructor, destructor. (compile_module_up): New typedef. (compile_object_load): Return compile_object_up. * compile/compile-object-load.c (compile_object_load): Return compile_module_up. --- gdb/ChangeLog | 14 ++++++++++++++ gdb/compile/compile-object-load.c | 5 ++--- gdb/compile/compile-object-load.h | 12 +++++++++++- gdb/compile/compile-object-run.c | 4 +--- gdb/compile/compile-object-run.h | 2 +- gdb/compile/compile.c | 7 +++---- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 2f416079025..dff10fe94f4 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -582,7 +582,7 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base) COMPILE_I_PRINT_ADDRESS_SCOPE when COMPILE_I_PRINT_VALUE_SCOPE should have been used instead. */ -struct compile_module * +compile_module_up compile_object_load (const compile_file_names &file_names, enum compile_i_scope_types scope, void *scope_data) { @@ -594,7 +594,6 @@ compile_object_load (const compile_file_names &file_names, long storage_needed; asymbol **symbol_table, **symp; long number_of_symbols, missing_symbols; - struct compile_module *retval; struct type *regs_type, *out_value_type = NULL; char **matching; struct objfile *objfile; @@ -790,7 +789,7 @@ compile_object_load (const compile_file_names &file_names, paddress (target_gdbarch (), out_value_addr)); } - retval = XNEW (struct compile_module); + compile_module_up retval (new struct compile_module); retval->objfile = objfile_holder.release (); retval->source_file = xstrdup (file_names.source_file ()); retval->func_sym = func_sym; diff --git a/gdb/compile/compile-object-load.h b/gdb/compile/compile-object-load.h index c4adc719141..9def29ebc9b 100644 --- a/gdb/compile/compile-object-load.h +++ b/gdb/compile/compile-object-load.h @@ -46,6 +46,13 @@ struct munmap_list struct compile_module { + compile_module () = default; + + DISABLE_COPY_AND_ASSIGN (compile_module); + + compile_module &operator= (compile_module &&other) = default; + compile_module (compile_module &&other) = default; + /* objfile for the compiled module. */ struct objfile *objfile; @@ -77,7 +84,10 @@ struct compile_module struct munmap_list *munmap_list_head; }; -extern struct compile_module *compile_object_load +/* A unique pointer for a compile_module. */ +typedef std::unique_ptr compile_module_up; + +extern compile_module_up compile_object_load (const compile_file_names &fnames, enum compile_i_scope_types scope, void *scope_data); diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c index 4a18655d488..5a680a6723f 100644 --- a/gdb/compile/compile-object-run.c +++ b/gdb/compile/compile-object-run.c @@ -121,7 +121,7 @@ do_module_cleanup (void *arg, int registers_valid) longer touch MODULE's memory after this function has been called. */ void -compile_object_run (struct compile_module *module) +compile_object_run (compile_module_up &&module) { struct value *func_val; struct do_module_cleanup *data; @@ -142,8 +142,6 @@ compile_object_run (struct compile_module *module) data->munmap_list_head = module->munmap_list_head; xfree (module->source_file); - xfree (module); - module = NULL; try { diff --git a/gdb/compile/compile-object-run.h b/gdb/compile/compile-object-run.h index 9311d02c379..45375db654f 100644 --- a/gdb/compile/compile-object-run.h +++ b/gdb/compile/compile-object-run.h @@ -19,6 +19,6 @@ #include "compile-object-load.h" -extern void compile_object_run (struct compile_module *module); +extern void compile_object_run (compile_module_up &&module); #endif /* COMPILE_COMPILE_OBJECT_RUN_H */ diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 0c29a0476e7..0f830f6db71 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -820,14 +820,13 @@ void eval_compile_command (struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data) { - struct compile_module *compile_module; - compile_file_names fnames = compile_to_object (cmd, cmd_string, scope); gdb::unlinker object_remover (fnames.object_file ()); gdb::unlinker source_remover (fnames.source_file ()); - compile_module = compile_object_load (fnames, scope, scope_data); + compile_module_up compile_module = compile_object_load (fnames, scope, + scope_data); if (compile_module == NULL) { gdb_assert (scope == COMPILE_I_PRINT_ADDRESS_SCOPE); @@ -840,7 +839,7 @@ eval_compile_command (struct command_line *cmd, const char *cmd_string, source_remover.keep (); object_remover.keep (); - compile_object_run (compile_module); + compile_object_run (std::move (compile_module)); } /* See compile/compile-internal.h. */ -- 2.17.2