From patchwork Tue Feb 6 17:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 85370 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA5863858415 for ; Tue, 6 Feb 2024 17:16:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id C2D433858427 for ; Tue, 6 Feb 2024 17:15:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2D433858427 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2D433858427 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707239719; cv=none; b=vrZQ8oNFjDHLkalYA9ldXZlX5ZXrpbf5sIscECUnYOKtmDi8jY4DfCktL4sW9CzlNuXhV3nnN6/7WAT6+mLWHk32tBFXj42leb5KmC4w8jtfO7Kpgq+Rdbt5OzNY4HJMDL0FPI7EvVd/OE30dJVmq4pHIWGLWsfa0LaBoxIz00k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707239719; c=relaxed/simple; bh=pgAJIduwhIu7TJDi0+W9umobh42mrDkN1LJJ+ZTguEU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=f5VfwKDSuwTwgMem6LXthHB0R7xE4kJUxXKjFob34Wp8Z3sbhnzm7eJg5fh7ThBSCTGHrJ1garO7jCEMq0N+EOp57M+ocE4h25avB00pN6NtZ+RomB3CbV4cyqKaKwMttNOp+CGW8bmSg+2z0Sw8h9X5vxzlwssPcflZHsY7Ufc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 3961A1E0C3; Tue, 6 Feb 2024 12:15:16 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/5] gdb: add inferior parameter to breakpoint_init_inferior Date: Tue, 6 Feb 2024 12:14:24 -0500 Message-ID: <20240206171514.119244-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240206171514.119244-1-simon.marchi@efficios.com> References: <20240206171514.119244-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3496.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org By inspection, I believe that breakpoint_init_inferior doesn't call anything that relies on the current program space or inferior. So, add an inferior parameter, to make the current inferior / program space references bubble up one level. Change-Id: Ib07b7a6d360e324f6ae1aa502dd314b8cce421b7 --- gdb/breakpoint.c | 22 +++++----------------- gdb/breakpoint.h | 12 +++++++++++- gdb/infcmd.c | 10 +++++----- gdb/infrun.c | 4 ++-- gdb/target.c | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d844ef7baf25..8d8e97400e37 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4226,33 +4226,21 @@ mark_breakpoints_out (program_space *pspace) bl->inserted = 0; } -/* Clear the "inserted" flag in all breakpoints and delete any - breakpoints which should go away between runs of the program. - - Plus other such housekeeping that has to be done for breakpoints - between runs. - - Note: this function gets called at the end of a run (by - generic_mourn_inferior) and when a run begins (by - init_wait_for_inferior). */ - - +/* See breakpoint.h. */ void -breakpoint_init_inferior (enum inf_context context) +breakpoint_init_inferior (inferior *inf, inf_context context) { - struct program_space *pspace = current_program_space; - /* If breakpoint locations are shared across processes, then there's nothing to do. */ - if (gdbarch_has_global_breakpoints (current_inferior ()->arch ())) + if (gdbarch_has_global_breakpoints (inf->arch ())) return; - mark_breakpoints_out (pspace); + mark_breakpoints_out (inf->pspace); for (breakpoint &b : all_breakpoints_safe ()) { - if (b.has_locations () && b.first_loc ().pspace != pspace) + if (b.has_locations () && b.first_loc ().pspace != inf->pspace) continue; switch (b.type) diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index e7bebed2725d..8530a7127945 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1515,7 +1515,17 @@ extern struct breakpoint *clone_momentary_breakpoint (struct breakpoint *bpkt); extern void set_ignore_count (int, int, int); -extern void breakpoint_init_inferior (enum inf_context); +/* Clear the "inserted" flag in all breakpoint locations of INF's program space + and delete any breakpoints which should go away between runs of the program. + + Plus other such housekeeping that has to be done for breakpoints + between runs. + + Note: this function gets called at the end of a run (by + generic_mourn_inferior) and when a run begins (by + init_wait_for_inferior). */ + +extern void breakpoint_init_inferior (inferior *inf, inf_context context); extern void breakpoint_auto_delete (bpstat *); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 54063b37beb8..4e17a6b06295 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2824,14 +2824,14 @@ detach_command (const char *args, int from_tty) /* Hold a strong reference to the target while (maybe) detaching the parent. Otherwise detaching could close the target. */ - auto target_ref - = target_ops_ref::new_reference (current_inferior ()->process_target ()); + inferior *inf = current_inferior (); + auto target_ref = target_ops_ref::new_reference (inf->process_target ()); /* Save this before detaching, since detaching may unpush the process_stratum target. */ bool was_non_stop_p = target_is_non_stop_p (); - target_detach (current_inferior (), from_tty); + target_detach (inf, from_tty); update_previous_thread (); @@ -2840,11 +2840,11 @@ detach_command (const char *args, int from_tty) this within target_detach because that is also used when following child forks, and in that case we will want to transfer breakpoints to the child, not delete them. */ - breakpoint_init_inferior (inf_exited); + breakpoint_init_inferior (inf, inf_exited); /* If the solist is global across inferiors, don't clear it when we detach from a single inferior. */ - if (!gdbarch_has_global_solist (current_inferior ()->arch ())) + if (!gdbarch_has_global_solist (inf->arch ())) no_shared_libraries (nullptr, from_tty); if (deprecated_detach_hook) diff --git a/gdb/infrun.c b/gdb/infrun.c index d00a98906d71..fa68ab8296e9 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1297,7 +1297,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target) /* We've followed the inferior through an exec. Therefore, the inferior has essentially been killed & reborn. */ - breakpoint_init_inferior (inf_execd); + breakpoint_init_inferior (current_inferior (), inf_execd); gdb::unique_xmalloc_ptr exec_file_host = exec_file_find (exec_file_target, nullptr); @@ -3819,7 +3819,7 @@ init_wait_for_inferior (void) { /* These are meaningless until the first time through wait_for_inferior. */ - breakpoint_init_inferior (inf_starting); + breakpoint_init_inferior (current_inferior (), inf_starting); clear_proceed_status (0); diff --git a/gdb/target.c b/gdb/target.c index e72e22da69a3..bbc1badc9e19 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3636,7 +3636,7 @@ generic_mourn_inferior (void) /* Note this wipes step-resume breakpoints, so needs to be done after exit_inferior, which ends up referencing the step-resume breakpoints through clear_thread_inferior_resources. */ - breakpoint_init_inferior (inf_exited); + breakpoint_init_inferior (inf, inf_exited); registers_changed ();