From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UJHdIiQGlWL3SQkAWB0awg (envelope-from ) for ; Mon, 30 May 2022 14:00:04 -0400 Received: by simark.ca (Postfix, from userid 112) id 8A96D1E221; Mon, 30 May 2022 14:00:04 -0400 (EDT) Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=IFU0k1mk; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D01D71E143 for ; Mon, 30 May 2022 14:00:03 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 28A39384B433 for ; Mon, 30 May 2022 18:00:03 +0000 (GMT) Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id CD345385E017 for ; Mon, 30 May 2022 17:59:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CD345385E017 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 3271D1004819C for ; Mon, 30 May 2022 17:59:37 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id vjg0nYZRzQs3Cvjg1naLo8; Mon, 30 May 2022 17:59:37 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=A+Opg4aG c=1 sm=1 tr=0 ts=62950609 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oZkIemNP1mAA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=6aD4TWOwK04fp6Ee6PwA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=YSmkoSqnH+m5lns02utsiOZ1QntMoqEM7VdE6LN2zw4=; b=IFU0k1mkEeEw28am2JldxOLpRe X87QErlLjqrvyDI92CxiENXTc1wm5ReojOKWe5HEYH0auVVq5nrqWAyfSNHtnRde9VxuteBplO79c RzwO1u0DKShBw8dPh2ZeAy3cc; Received: from 71-211-158-194.hlrn.qwest.net ([71.211.158.194]:45630 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nvjg0-002OyG-KA; Mon, 30 May 2022 11:59:36 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 1/6] Change address_space to use new and delete Date: Mon, 30 May 2022 11:59:29 -0600 Message-Id: <20220530175934.3872892-2-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220530175934.3872892-1-tom@tromey.com> References: <20220530175934.3872892-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 71.211.158.194 X-Source-L: No X-Exim-ID: 1nvjg0-002OyG-KA X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-158-194.hlrn.qwest.net (prentzel.Home) [71.211.158.194]:45630 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This changes address_space to use new and delete, and makes some other small C++-ification changes as well, like changing address_space_num to be a method. This patch was needed for the subsequent patch to rewrite the registry system. --- gdb/infrun.c | 6 +++--- gdb/progspace.c | 38 ++++++++++++-------------------------- gdb/progspace.h | 22 ++++++++++++++-------- gdb/scoped-mock-context.h | 2 +- gdb/target-debug.h | 2 +- 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 02c98b50c8c..b1f98377cad 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -501,7 +501,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ } else { - child_inf->aspace = new_address_space (); + child_inf->aspace = new address_space (); child_inf->pspace = new program_space (child_inf->aspace); child_inf->removable = 1; clone_program_space (child_inf->pspace, parent_inf->pspace); @@ -573,7 +573,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ child_inf->aspace = parent_inf->aspace; child_inf->pspace = parent_inf->pspace; - parent_inf->aspace = new_address_space (); + parent_inf->aspace = new address_space (); parent_inf->pspace = new program_space (parent_inf->aspace); clone_program_space (parent_inf->pspace, child_inf->pspace); @@ -583,7 +583,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ } else { - child_inf->aspace = new_address_space (); + child_inf->aspace = new address_space (); child_inf->pspace = new program_space (child_inf->aspace); child_inf->removable = 1; child_inf->symfile_flags = SYMFILE_NO_READ; diff --git a/gdb/progspace.c b/gdb/progspace.c index 1ee4fe3f940..3232ea9ab01 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -57,16 +57,10 @@ DEFINE_REGISTRY (address_space, REGISTRY_ACCESS_FIELD) /* Create a new address space object, and add it to the list. */ -struct address_space * -new_address_space (void) +address_space::address_space () + : m_num (++highest_address_space_num) { - struct address_space *aspace; - - aspace = XCNEW (struct address_space); - aspace->num = ++highest_address_space_num; - address_space_alloc_data (aspace); - - return aspace; + address_space_alloc_data (this); } /* Maybe create a new address space object, and add it to the list, or @@ -84,20 +78,12 @@ maybe_new_address_space (void) return program_spaces[0]->aspace; } - return new_address_space (); -} - -static void -free_address_space (struct address_space *aspace) -{ - address_space_free_data (aspace); - xfree (aspace); + return new address_space (); } -int -address_space_num (struct address_space *aspace) +address_space::~address_space () { - return aspace->num; + address_space_free_data (this); } /* Start counting over from scratch. */ @@ -153,7 +139,7 @@ program_space::~program_space () locations for this pspace which we're tearing down. */ clear_symtab_users (SYMFILE_DEFER_BP_RESET); if (!gdbarch_has_shared_address_space (target_gdbarch ())) - free_address_space (this->aspace); + delete this->aspace; /* Discard any data modules have associated with the PSPACE. */ program_space_free_data (this); } @@ -411,17 +397,17 @@ update_address_spaces (void) if (shared_aspace) { - struct address_space *aspace = new_address_space (); + struct address_space *aspace = new address_space (); - free_address_space (current_program_space->aspace); + delete current_program_space->aspace; for (struct program_space *pspace : program_spaces) pspace->aspace = aspace; } else for (struct program_space *pspace : program_spaces) { - free_address_space (pspace->aspace); - pspace->aspace = new_address_space (); + delete pspace->aspace; + pspace->aspace = new address_space (); } for (inferior *inf : all_inferiors ()) @@ -459,5 +445,5 @@ initialize_progspace (void) modules have done that. Do this before initialize_current_architecture, because that accesses the ebfd of current_program_space. */ - current_program_space = new program_space (new_address_space ()); + current_program_space = new program_space (new address_space ()); } diff --git a/gdb/progspace.h b/gdb/progspace.h index 73beb7a4710..eff157b0dd3 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -385,10 +385,22 @@ struct program_space associating caches to each address space. */ struct address_space { - int num; + /* Create a new address space object, and add it to the list. */ + address_space (); + ~address_space (); + DISABLE_COPY_AND_ASSIGN (address_space); + + /* Returns the integer address space id of this address space. */ + int num () const + { + return m_num; + } /* Per aspace data-pointers required by other GDB modules. */ - REGISTRY_FIELDS; + REGISTRY_FIELDS {}; + +private: + int m_num; }; /* The list of all program spaces. There's always at least one. */ @@ -430,17 +442,11 @@ class scoped_restore_current_program_space program_space *m_saved_pspace; }; -/* Create a new address space object, and add it to the list. */ -extern struct address_space *new_address_space (void); - /* Maybe create a new address space object, and add it to the list, or return a pointer to an existing address space, in case inferiors share an address space. */ extern struct address_space *maybe_new_address_space (void); -/* Returns the integer address space id of ASPACE. */ -extern int address_space_num (struct address_space *aspace); - /* Update all program spaces matching to address spaces. The user may have created several program spaces, and loaded executables into them before connecting to the target interface that will create the diff --git a/gdb/scoped-mock-context.h b/gdb/scoped-mock-context.h index b91d43b1716..a9895303015 100644 --- a/gdb/scoped-mock-context.h +++ b/gdb/scoped-mock-context.h @@ -38,7 +38,7 @@ struct scoped_mock_context Target mock_target; ptid_t mock_ptid {1, 1}; - program_space mock_pspace {new_address_space ()}; + program_space mock_pspace {new address_space ()}; inferior mock_inferior {mock_ptid.pid ()}; thread_info mock_thread {&mock_inferior, mock_ptid}; diff --git a/gdb/target-debug.h b/gdb/target-debug.h index c2b1db1ce8e..ab89c0a5185 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -89,7 +89,7 @@ #define target_debug_print_LONGEST_p(X) \ target_debug_do_print (phex (*(X), 0)) #define target_debug_print_struct_address_space_p(X) \ - target_debug_do_print (plongest (address_space_num (X))) + target_debug_do_print (plongest ((X)->num ())) #define target_debug_print_struct_bp_target_info_p(X) \ target_debug_do_print (core_addr_to_string ((X)->placed_address)) #define target_debug_print_struct_expression_p(X) \ -- 2.34.1