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 77C6F3858422 for ; Thu, 22 Jun 2023 13:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77C6F3858422 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=1687439868; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6SWbn0NZUddgs390w3UTeG/YppDkU38lVcfD4DHqmAo=; b=NCh9doXfpI3f27MnTk39oEclsqJccfI/l1eA9kva2IabvqzgQITFooBUHhWU3QdRmkOhH2 EkqRc0EVUGgwQDDOx9siwvsgCtEP7Pr2DarraO+Xa1NXmI8VbGXrdqEh6PMhnETSkZeQpv ibxvs84eiaKm2IYx5+UxwdVyZqzJfko= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-HkEMwWBNPySibFI-ZOOZxw-1; Thu, 22 Jun 2023 09:17:47 -0400 X-MC-Unique: HkEMwWBNPySibFI-ZOOZxw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2b1d8fa4629so57046751fa.0 for ; Thu, 22 Jun 2023 06:17:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687439865; x=1690031865; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6SWbn0NZUddgs390w3UTeG/YppDkU38lVcfD4DHqmAo=; b=BT5WmUm673DEQwABLukp56J6l8mQMmpkvZz9XlSUW9DecyGxPe3x4lE/jhuOBD8Xv4 Y3/DLLRRQondInuNkb86S4Gw8C1bb2vhqyB1cdfGw5dFsTXhWEOqrXMYbY/rNEmVoZXJ oAuxXFcQUMZMRKh2dak0+2Te8Gbla1WGfPoUDm0dY9hmgASkjtriH1F88ZifxKTTpdk2 oLdTNU6DWm/h9ZGFFZBAcQfrk9KEs9U1hM9E4nPhB9tgNJCiWC3AcAqGI7+fbQhpal6H aFS4vEbNoVQpUTH+kiT4f5cYqfVySbj+LCvpdkwKI7O0KHSVj7Yrq9bqlNh37AIhytLR Meew== X-Gm-Message-State: AC+VfDw97JMD2bFNrE2aHya68CXaWBkahpIKIAaqZSfVb3DZEApWZT9b RIZ67tRR6oJyVVL4OVv8aRJ1isfbgZ3A+8iYaWSeK8fZLyJIxEOL4ca9SJrvkts93lIukl/dw9+ X3I5+Kyf58zB92kKi8s4XqbtChHmTwq4pagCTTiQYLJw8mv3jG0wgxaVTo5gUlmBCguMFmiMRjT dzA8ypEg== X-Received: by 2002:a05:6512:3284:b0:4f8:692a:6492 with SMTP id p4-20020a056512328400b004f8692a6492mr9158609lfe.32.1687439865061; Thu, 22 Jun 2023 06:17:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Hm87YyX2UNugtgZLeBOiK2mkQOPWi8DnW9l04QA5xRU0BuF7FABHkNUQ3iQwJS6VOmceP2Q== X-Received: by 2002:a05:6512:3284:b0:4f8:692a:6492 with SMTP id p4-20020a056512328400b004f8692a6492mr9158461lfe.32.1687439860642; Thu, 22 Jun 2023 06:17:40 -0700 (PDT) Received: from localhost (2.72.115.87.dyn.plus.net. [87.115.72.2]) by smtp.gmail.com with ESMTPSA id y16-20020adfd090000000b003110dc7f408sm7017259wrh.41.2023.06.22.06.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 06:17:40 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Mihails Strasuns , Christina Schimpe Subject: [PATCH 4/8] gdb, infrun: refactor part of `proceed` into separate function Date: Thu, 22 Jun 2023 14:17:24 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 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_H5,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: 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. */ + } + } + + 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