From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id F34A23858406 for ; Tue, 18 Jan 2022 04:09:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F34A23858406 X-ASG-Debug-ID: 1642478978-0c856e06ab131c60001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 7VTDdi0oayGgRKfx (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 17 Jan 2022 23:09:38 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 808D7441D66; Mon, 17 Jan 2022 23:09:38 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH v2 3/9] gdb: replace inferior::waiting_for_vfork_done with inferior::thread_waiting_for_vfork_done Date: Mon, 17 Jan 2022 23:09:31 -0500 X-ASG-Orig-Subj: [PATCH v2 3/9] gdb: replace inferior::waiting_for_vfork_done with inferior::thread_waiting_for_vfork_done Message-Id: <20220118040937.730282-4-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118040937.730282-1-simon.marchi@polymtl.ca> References: <20220118040937.730282-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1642478978 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 4689 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.95404 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-15.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 18 Jan 2022 04:09:50 -0000 The inferior::waiting_for_vfork_done flag indicates that some thread in that inferior is waiting for a vfork-done event. Subsequent patches will need to know which thread is waiting for that event. I think there is a latent buglet in that waiting_for_vfork_done is currently not reset on inferior exec or exit. I could imagine that if a thread in the parent process calls exec or exit while another thread of the parent process is waiting for its vfork child to exec or exit, we could end up with inferior::waiting_for_vfork_done without a thread actually waiting for a vfork-done event anymore. And since that flag is checked in resume_1, things could misbehave there. Since the new field points to a thread_info object, and those are destroyed on exec or exit, it could be worse now since we could try to access freed memory, if thread_waiting_for_vfork_done were to point to a stale thread_info. To avoid this, clear the field in infrun_inferior_exit and infrun_inferior_execd. Change-Id: I31b847278613a49ba03fc4915f74d9ceb228fdce --- gdb/inferior.h | 8 ++++---- gdb/infrun.c | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gdb/inferior.h b/gdb/inferior.h index ec0fb6e8b16c..7b82703f1470 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -531,10 +531,10 @@ class inferior : public refcounted_object, exits or execs. */ bool pending_detach = false; - /* True if this inferior is a vfork parent waiting for a vfork child - not under our control to be done with the shared memory region, - either by exiting or execing. */ - bool waiting_for_vfork_done = false; + /* If non-nullptr, points to a thread that called vfork and is now waiting + for a vfork child not under our control to be done with the shared memory + region, either by exiting or execing. */ + thread_info *thread_waiting_for_vfork_done = nullptr; /* True if we're in the process of detaching from this inferior. */ bool detaching = false; diff --git a/gdb/infrun.c b/gdb/infrun.c index 46e14d720cce..40b4bdd73130 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -507,7 +507,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \ insert breakpoints, so that we can debug it. A subsequent child exec or exit is enough to know when does the child stops using the parent's address space. */ - parent_inf->waiting_for_vfork_done = detach_fork; + parent_inf->thread_waiting_for_vfork_done + = detach_fork ? inferior_thread () : nullptr; parent_inf->pspace->breakpoints_not_allowed = detach_fork; } } @@ -639,7 +640,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ child_inf->pending_detach = 0; parent_inf->vfork_child = child_inf; parent_inf->pending_detach = detach_fork; - parent_inf->waiting_for_vfork_done = 0; + parent_inf->thread_waiting_for_vfork_done = nullptr; } else if (detach_fork) { @@ -1484,6 +1485,7 @@ static void infrun_inferior_exit (struct inferior *inf) { inf->displaced_step_state.reset (); + inf->thread_waiting_for_vfork_done = nullptr; } static void @@ -1502,6 +1504,8 @@ infrun_inferior_execd (inferior *inf) one in progress at the time of the exec, it must have been the exec'ing thread. */ clear_step_over_info (); + + inf->thread_waiting_for_vfork_done = nullptr; } /* If ON, and the architecture supports it, GDB will use displaced @@ -2254,7 +2258,7 @@ resume_1 (enum gdb_signal sig) /* Depends on stepped_breakpoint. */ step = currently_stepping (tp); - if (current_inferior ()->waiting_for_vfork_done) + if (current_inferior ()->thread_waiting_for_vfork_done != nullptr) { /* Don't try to single-step a vfork parent that is waiting for the child to get out of the shared memory region (by exec'ing @@ -2374,7 +2378,7 @@ resume_1 (enum gdb_signal sig) && use_displaced_stepping (tp) && !step_over_info_valid_p () && sig == GDB_SIGNAL_0 - && !current_inferior ()->waiting_for_vfork_done) + && current_inferior ()->thread_waiting_for_vfork_done == nullptr) { displaced_step_prepare_status prepare_status = displaced_step_prepare (tp); @@ -5618,7 +5622,7 @@ handle_inferior_event (struct execution_control_state *ecs) context_switch (ecs); - current_inferior ()->waiting_for_vfork_done = 0; + current_inferior ()->thread_waiting_for_vfork_done = nullptr; current_inferior ()->pspace->breakpoints_not_allowed = 0; if (handle_stop_requested (ecs)) -- 2.34.1