From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 981E9388202D for ; Tue, 4 Jul 2023 15:25:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 981E9388202D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688484301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oQTmSJB6yE9pazcaB5S7O4Ys4XRbLL+IxBugOmpYAS8=; b=LKD2DjUAZWHEbLxA1mLEeDHBoOCb1VqC/8u5+PmgpYBhtE5c/PtMXJ7ZokNmrMVryo3JKC BFsmZGS2A52AHgltOHJd+00N2q4jnk48Xmy0AU59elMaJecFPHBSdsV/HPx+elHDt1BBVk rPJ0xvHef/jLWtyLd0v6XAV6/l+OAIw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-5jijvETpPgKD5mvFuC4Q0Q-1; Tue, 04 Jul 2023 11:25:00 -0400 X-MC-Unique: 5jijvETpPgKD5mvFuC4Q0Q-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3fa8d203eccso24968065e9.1 for ; Tue, 04 Jul 2023 08:25:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688484299; x=1691076299; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oQTmSJB6yE9pazcaB5S7O4Ys4XRbLL+IxBugOmpYAS8=; b=iKAm5UhwkuMJHj1205Ku0qB90o6gy7mhqAqFAmQNFwR+ErJuTbWzHFicglof2FjbAi a6BLoQWvQCaUwNYxivQQPuOmi7G4a2dienzUYBEUC6jndzSKjPhClUAsKqEQ+7slKzHj TLi1zG7hBJvnL27QD2PYNVjGh3R8vPgULNT5ytyjkALX20qe4dckhZePKL1wKnbKjwOY xJkdKMZnNvgtvOAnNyLlbJAJYEk0NZGaAeBupZkV8uNjMDDSyW5KBuaWlpNk4Hk3M9fw 2SDPaCv1JWQK9Vol+c5MMY0m8L/pGl3JtH0HHxEqzuNxkXn9bDiJNW/2GzcCMaebkr3V 3b5Q== X-Gm-Message-State: AC+VfDxOxc+r3Yz13HOsBantXtkuBZsHde4FSRssixZBuNle6+ngSsu8 kdBryXhlt5klKjWbCaTtrvARH5JNrsKcfvVw2FVfow8P8dsCgS3w1lUEOtEvbP1mIdAk64dFjGJ eIfSp1D9PZ14LaEEG2hsFdA== X-Received: by 2002:a05:600c:4196:b0:3fa:ef97:1fa5 with SMTP id p22-20020a05600c419600b003faef971fa5mr17508589wmh.6.1688484299178; Tue, 04 Jul 2023 08:24:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GX1DDbGDzbGdd8SUyuDlCkYAK6L8Me6ZdjGapfXaWwzez1x5HMZJXQDO4+SG9ZQ7hiP7XfA== X-Received: by 2002:a05:600c:4196:b0:3fa:ef97:1fa5 with SMTP id p22-20020a05600c419600b003faef971fa5mr17508568wmh.6.1688484298838; Tue, 04 Jul 2023 08:24:58 -0700 (PDT) Received: from localhost (2.72.115.87.dyn.plus.net. [87.115.72.2]) by smtp.gmail.com with ESMTPSA id u12-20020a05600c00cc00b003fbc681c8d1sm13184222wmm.36.2023.07.04.08.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:24:58 -0700 (PDT) From: Andrew Burgess To: "Aktemur, Tankut Baris" , "gdb-patches@sourceware.org" Cc: Mihails Strasuns , "Schimpe, Christina" Subject: RE: [PATCH 4/8] gdb, infrun: refactor part of `proceed` into separate function In-Reply-To: References: Date: Tue, 04 Jul 2023 16:24:57 +0100 Message-ID: <87cz17lmwm.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: "Aktemur, Tankut Baris" writes: > On Thursday, June 22, 2023 3:17 PM, Andrew Burgess wrote: >> From: Mihails Strasuns >> >> Split the thread resuming code from proceed into new function >> proceed_resume_thread_checked. >> >> Co-Authored-By: Christina Schimpe >> --- >> gdb/infrun.c | 148 +++++++++++++++++++++++++++------------------------ >> 1 file changed, 79 insertions(+), 69 deletions(-) >> >> diff --git a/gdb/infrun.c b/gdb/infrun.c >> index 5b0257076f0..b10b7c59652 100644 >> --- a/gdb/infrun.c >> +++ b/gdb/infrun.c >> @@ -3268,6 +3268,82 @@ check_multi_target_resumption (process_stratum_target *resume_target) >> } >> } >> >> +/* Helper function for `proceed`. Check if thread TP is suitable for >> + resuming, and, if it is, switch to the thread and call >> + `keep_going_pass_signal`. If TP is not suitable for resuming then this >> + function will just return without switching threads. */ >> + >> +static void >> +proceed_resume_thread_checked (thread_info *tp) >> +{ >> + if (!tp->inf->has_execution ()) >> + { >> + infrun_debug_printf ("[%s] target has no execution", >> + tp->ptid.to_string ().c_str ()); >> + return; >> + } >> + >> + if (tp->resumed ()) >> + { >> + infrun_debug_printf ("[%s] resumed", >> + tp->ptid.to_string ().c_str ()); >> + gdb_assert (tp->executing () || tp->has_pending_waitstatus ()); >> + return; >> + } >> + >> + if (thread_is_in_step_over_chain (tp)) >> + { >> + infrun_debug_printf ("[%s] needs step-over", >> + tp->ptid.to_string ().c_str ()); >> + return; >> + } >> + >> + /* When handling a vfork GDB removes all breakpoints from the program >> + space in which the vfork is being handled, as such we must take care >> + not to resume any thread other than the vfork parent -- resuming the >> + vfork parent allows GDB to receive and handle the 'vfork done' >> + event. */ >> + if (tp->inf->thread_waiting_for_vfork_done != nullptr) >> + { >> + if (target_is_non_stop_p ()) >> + { >> + /* For non-stop targets, regardless of whether GDB is using >> + all-stop or non-stop mode, threads are controlled >> + individually. >> + >> + When a thread is handling a vfork, breakpoints are removed >> + from the inferior (well, program space in fact), so it is >> + critical that we don't try to resume any thread other than the >> + vfork parent. */ >> + if (tp != tp->inf->thread_waiting_for_vfork_done) >> + { >> + infrun_debug_printf ("[%s] thread %s of this inferior is " >> + "waiting for vfork-done", >> + tp->ptid.to_string ().c_str (), >> + tp->inf->thread_waiting_for_vfork_done >> + ->ptid.to_string ().c_str ()); >> + return; >> + } >> + } >> + else >> + { >> + /* For all-stop targets, when we attempt to resume the inferior, >> + we will in fact only resume the vfork parent thread, this is >> + handled in internal_resume_ptid, as such, there is nothing >> + more that needs doing here. */ > > I wonder if here we should do > > gdb_assert (tp == tp->inf->thread_waiting_for_vfork_done); > That's a good idea. I've also updated the comment within this else block as the current text doesn't really cover why this assert holds. I've posted a V2 with this change. Thanks, Andrew > -Baris > >> + } >> + } >> + >> + infrun_debug_printf ("resuming %s", >> + tp->ptid.to_string ().c_str ()); >> + >> + execution_control_state ecs (tp); >> + switch_to_thread (tp); >> + keep_going_pass_signal (&ecs); >> + if (!ecs.wait_some_more) >> + error (_("Command aborted.")); >> +} >> + >> /* Basic routine for continuing the program in various fashions. >> >> ADDR is the address to resume at, or -1 for resume where stopped. >> @@ -3456,77 +3532,11 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) >> resume_ptid)) >> { >> switch_to_thread_no_regs (tp); >> - >> - if (!tp->inf->has_execution ()) >> - { >> - infrun_debug_printf ("[%s] target has no execution", >> - tp->ptid.to_string ().c_str ()); >> - continue; >> - } >> - >> - if (tp->resumed ()) >> - { >> - infrun_debug_printf ("[%s] resumed", >> - tp->ptid.to_string ().c_str ()); >> - gdb_assert (tp->executing () || tp->has_pending_waitstatus ()); >> - continue; >> - } >> - >> - if (thread_is_in_step_over_chain (tp)) >> - { >> - infrun_debug_printf ("[%s] needs step-over", >> - tp->ptid.to_string ().c_str ()); >> - continue; >> - } >> - >> - /* If a thread of that inferior is waiting for a vfork-done >> - (for a detached vfork child to exec or exit), breakpoints are >> - removed. We must not resume any thread of that inferior, other >> - than the one waiting for the vfork-done. */ >> - if (tp->inf->thread_waiting_for_vfork_done != nullptr >> - && tp != tp->inf->thread_waiting_for_vfork_done) >> - { >> - infrun_debug_printf ("[%s] another thread of this inferior is " >> - "waiting for vfork-done", >> - tp->ptid.to_string ().c_str ()); >> - continue; >> - } >> - >> - infrun_debug_printf ("resuming %s", >> - tp->ptid.to_string ().c_str ()); >> - >> - execution_control_state ecs (tp); >> - switch_to_thread (tp); >> - keep_going_pass_signal (&ecs); >> - if (!ecs.wait_some_more) >> - error (_("Command aborted.")); >> - } >> - } >> - else if (!cur_thr->resumed () >> - && !thread_is_in_step_over_chain (cur_thr)) >> - { >> - /* In non-stop mode, if a there exists a thread waiting for a vfork >> - then only allow that thread to resume (breakpoints are removed >> - from an inferior when handling a vfork). >> - >> - We check target_is_non_stop_p here rather than just checking the >> - non-stop flag, though these are equivalent (all-stop on a >> - non-stop target was handled in a previous block, so at this >> - point, if target_is_non_stop_p then GDB must be running on >> - non-stop mode). By using target_is_non_stop_p it will be easier >> - to merge this block with the previous in a later commit. */ >> - if (!(target_is_non_stop_p () >> - && cur_thr->inf->thread_waiting_for_vfork_done != nullptr >> - && cur_thr->inf->thread_waiting_for_vfork_done != cur_thr)) >> - { >> - /* The thread wasn't started, and isn't queued, run it now. */ >> - execution_control_state ecs (cur_thr); >> - switch_to_thread (cur_thr); >> - keep_going_pass_signal (&ecs); >> - if (!ecs.wait_some_more) >> - error (_("Command aborted.")); >> + proceed_resume_thread_checked (tp); >> } >> } >> + else >> + proceed_resume_thread_checked (cur_thr); >> >> disable_commit_resumed.reset_and_commit (); >> } >> -- >> 2.25.4 > > Intel Deutschland GmbH > Registered Address: Am Campeon 10, 85579 Neubiberg, Germany > Tel: +49 89 99 8853-0, www.intel.de > Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva > Chairperson of the Supervisory Board: Nicole Lau > Registered Office: Munich > Commercial Register: Amtsgericht Muenchen HRB 186928