From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id 77EDE3858D39 for ; Fri, 29 Dec 2023 10:42:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77EDE3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77EDE3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=134.134.136.126 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703846555; cv=none; b=Q8aOPFCW7aNnHPcj8W55IG/jUjeBNO6rDM/qLsg4Qf2VzC9A59OaezFvENP2b+kYYhmzfsTN4ukKy6qvo74M3vQLmUP8PMvZlcnihf2djenMdMiqHb8xbt/8fGut9OYxc5la6REbd613af/U4J6gViJgBR/eNNbpekbj/Mg4UTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703846555; c=relaxed/simple; bh=Pq7AKFZEU+3E0KI0BmwhTDNc9QO3aXOJrXAgmgmDlaM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=tKQ7Xavvh62+kh6zv1qpaGmCZiuNUWKB2UzNC7vXqepA/G9x+J7nrnb0J3Rbi5stwGbe56kglQ9+HqMlU7hUd/lq9atIzlrxn7Yv7kkIcgv7ZSuK6HFABNu8zEes0pChFF1F8HKDwtJGNeBc8tk0yA+KjCn5/lOcX+Snef5zsNY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703846553; x=1735382553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pq7AKFZEU+3E0KI0BmwhTDNc9QO3aXOJrXAgmgmDlaM=; b=DYAiYQ3TY/DBCwLCaohzaLVQhQg6cPAcVJC1ii0OH4iW6LLcyCbjb2Gp h2jsHdsbmSKkXIdP1qr8+1QLu+XLET1OHn9SjazauMvuuIg4r+wd6ryBL GUEhBhy2tbInHAfosx+Ah59G0DRWbgnrZB2NLEtwDUQsJgHWXVi8g4wk2 68b/voyc+c1GolFnr6rF/T/PJ39Fhb15q8PA6kP9fV4JO1MDAs56pTnX3 dgEw2YDUhu66NzyCmfJH0ssid+oE+4yFuBOOjnlB3483hS01YDAJrWC7F KOIQZ5RJTnt5QL0F1kBngbb37EQvgJawzFU0KRjRM4IUGkaGU+xGCfg83 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="381613088" X-IronPort-AV: E=Sophos;i="6.04,314,1695711600"; d="scan'208";a="381613088" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Dec 2023 02:42:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="755000241" X-IronPort-AV: E=Sophos;i="6.04,314,1695711600"; d="scan'208";a="755000241" Received: from unknown (HELO localhost) ([10.211.177.238]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Dec 2023 02:42:30 -0800 From: Natalia Saiapova To: gdb-patches@sourceware.org Cc: tankut.baris.aktemur@intel.com Subject: [PATCH 1/6] gdb: use schedlock_applies in user_visible_resume_ptid. Date: Fri, 29 Dec 2023 10:41:57 +0000 Message-Id: <20231229104202.7878-2-natalia.saiapova@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231229104202.7878-1-natalia.saiapova@intel.com> References: <20231229104202.7878-1-natalia.saiapova@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: This is a refactoring. The logic in user_visible_resume_ptid is very similar to schedlock_applies, but uses `step` parameter instead of `tp->control.stepping_command`. Refactor schedlock_applies logic into the following two methods: bool schedlock_applies_to_thread (thread_info *tp) and bool schedlock_applies (bool step) such that they share the logic. Update the call-sites accordingly, where we have only the thread, use the former, and where we have the bool step, use the latter. --- gdb/infrun.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 1d863896c40..e10bde94744 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -107,7 +107,9 @@ static bool start_step_over (void); static bool step_over_info_valid_p (void); -static bool schedlock_applies (struct thread_info *tp); +static bool schedlock_applies_to_thread (thread_info *tp); + +static bool schedlock_applies (bool step); /* Asynchronous signal handler registered as event loop source for when we have pending events ready to be passed to the core. */ @@ -1970,7 +1972,7 @@ any_thread_needs_target_thread_events (process_stratum_target *target, { for (thread_info *tp : all_non_exited_threads (target, resume_ptid)) if (displaced_step_in_progress_thread (tp) - || schedlock_applies (tp) + || schedlock_applies_to_thread (tp) || tp->thread_fsm () != nullptr) return true; return false; @@ -1983,7 +1985,7 @@ static void update_thread_events_after_step_over (thread_info *event_thread, const target_waitstatus &event_status) { - if (schedlock_applies (event_thread)) + if (schedlock_applies_to_thread (event_thread)) { /* If scheduler-locking applies, continue reporting thread-created/thread-cloned events. */ @@ -2383,6 +2385,9 @@ ptid_t user_visible_resume_ptid (int step) { ptid_t resume_ptid; + thread_info *tp = nullptr; + if (inferior_ptid != null_ptid) + tp = inferior_thread (); if (non_stop) { @@ -2390,20 +2395,12 @@ user_visible_resume_ptid (int step) individually. */ resume_ptid = inferior_ptid; } - else if ((scheduler_mode == schedlock_on) - || (scheduler_mode == schedlock_step && step)) + else if (schedlock_applies (step)) { /* User-settable 'scheduler' mode requires solo thread resume. */ resume_ptid = inferior_ptid; } - else if ((scheduler_mode == schedlock_replay) - && target_record_will_replay (minus_one_ptid, execution_direction)) - { - /* User-settable 'scheduler' mode requires solo thread resume in replay - mode. */ - resume_ptid = inferior_ptid; - } else if (!sched_multi && target_supports_multi_process ()) { /* Resume all threads of the current process (and none of other @@ -2574,7 +2571,7 @@ do_target_resume (ptid_t resume_ptid, bool step, enum gdb_signal sig) */ if (step_over_info_valid_p () || displaced_step_in_progress_thread (tp) - || schedlock_applies (tp)) + || schedlock_applies_to_thread (tp)) { gdb_thread_options options = GDB_THREAD_OPTION_CLONE | GDB_THREAD_OPTION_EXIT; @@ -3185,15 +3182,23 @@ thread_still_needs_step_over (struct thread_info *tp) return what; } +/* Returns true if scheduler locking applies to TP. */ + +static bool +schedlock_applies_to_thread (thread_info *tp) +{ + bool step = (tp != nullptr) && tp->control.stepping_command; + return schedlock_applies (step); +} + /* Returns true if scheduler locking applies. STEP indicates whether - we're about to do a step/next-like command to a thread. */ + we're about to do a step/next-like command. */ static bool -schedlock_applies (struct thread_info *tp) +schedlock_applies (bool step) { return (scheduler_mode == schedlock_on - || (scheduler_mode == schedlock_step - && tp->control.stepping_command) + || (scheduler_mode == schedlock_step && step) || (scheduler_mode == schedlock_replay && target_record_will_replay (minus_one_ptid, execution_direction))); @@ -3690,7 +3695,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) /* If scheduler locking applies, we can avoid iterating over all threads. */ - if (!non_stop && !schedlock_applies (cur_thr)) + if (!non_stop && !schedlock_applies_to_thread (cur_thr)) { for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid)) @@ -5938,7 +5943,7 @@ handle_thread_exited (execution_control_state *ecs) } inferior *inf = ecs->event_thread->inf; - bool slock_applies = schedlock_applies (ecs->event_thread); + bool slock_applies = schedlock_applies_to_thread (ecs->event_thread); delete_thread (ecs->event_thread); ecs->event_thread = nullptr; @@ -6377,7 +6382,7 @@ handle_inferior_event (struct execution_control_state *ecs) /* If resuming the child, mark it running. */ if ((ecs->ws.kind () == TARGET_WAITKIND_THREAD_CLONED - && !schedlock_applies (ecs->event_thread)) + && !schedlock_applies_to_thread (ecs->event_thread)) || (ecs->ws.kind () != TARGET_WAITKIND_THREAD_CLONED && (follow_child || (!detach_fork && (non_stop || sched_multi))))) @@ -6386,7 +6391,7 @@ handle_inferior_event (struct execution_control_state *ecs) /* In non-stop mode, also resume the other branch. */ if ((ecs->ws.kind () == TARGET_WAITKIND_THREAD_CLONED && target_is_non_stop_p () - && !schedlock_applies (ecs->event_thread)) + && !schedlock_applies_to_thread (ecs->event_thread)) || (ecs->ws.kind () != TARGET_WAITKIND_THREAD_CLONED && (!detach_fork && (non_stop || (sched_multi @@ -8249,7 +8254,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs) current thread is stepping. If some other thread not the event thread is stepping, then it must be that scheduler locking is not in effect. */ - if (schedlock_applies (ecs->event_thread)) + if (schedlock_applies_to_thread (ecs->event_thread)) return false; /* Otherwise, we no longer expect a trap in the current thread. -- 2.25.1 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