From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uNA/MpcW0mAtYAAAWB0awg (envelope-from ) for ; Tue, 22 Jun 2021 12:57:59 -0400 Received: by simark.ca (Postfix, from userid 112) id CB89E1F1F2; Tue, 22 Jun 2021 12:57:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4B4D41E54D for ; Tue, 22 Jun 2021 12:57:59 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1F6E3943417 for ; Tue, 22 Jun 2021 16:57:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1F6E3943417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624381079; bh=/qyYkp5DfXyFdNOZvb6I1I2MsRDc+c+Fp+KFiISwabk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=u2TpxehoCgHHTIlQalDjNPf7EijbQi/6gB+/8jchhsFVXWzPjWIC53SMTBLq9ppOW wJb1At8VW5vHARyEmXhbEWRBRlJIilZ7fmgY8GA4Kwgo+AaKDAeMbFAZWCJVxZKYur pqURPIaiK1LO2Bl1qo4rL+iMOSWNlKQPya7GImsA= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id DE9063857426 for ; Tue, 22 Jun 2021 16:57:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE9063857426 X-ASG-Debug-ID: 1624381026-0c856e67e2169e550001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id m4PAy3KGXqvZY9c5 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Jun 2021 12:57:07 -0400 (EDT) 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 84331441D68; Tue, 22 Jun 2021 12:57:06 -0400 (EDT) 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 05/11] gdb: add setter / getter for thread_info resumed state Date: Tue, 22 Jun 2021 12:56:58 -0400 X-ASG-Orig-Subj: [PATCH 05/11] gdb: add setter / getter for thread_info resumed state Message-Id: <20210622165704.2404007-6-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210622165704.2404007-1-simon.marchi@polymtl.ca> References: <20210622165704.2404007-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: 1624381027 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 10434 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.90826 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" A following patch will want to do things when a thread's resumed state changes. Make the `resumed` field private (renamed to `m_resumed`) and add a getter and a setter for it. The following patch in question will therefore be able to add some code to the setter. gdb/ChangeLog: * gdbthread.h (struct thread_info) : Rename to... : This. Change all uses to use the resumed and set_resumed methods. : New methods. Change-Id: I360c48cc55a036503174313261ce4e757d795319 --- gdb/breakpoint.c | 3 +-- gdb/gdbthread.h | 23 +++++++++++++++-------- gdb/infrun.c | 44 ++++++++++++++++++++++---------------------- gdb/remote.c | 2 +- gdb/thread.c | 2 +- 5 files changed, 40 insertions(+), 34 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 7d7e299ad5ff..73d2b536b35d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -406,8 +406,7 @@ breakpoints_should_be_inserted_now (void) /* Don't remove breakpoints yet if, even though all threads are stopped, we still have events to process. */ for (thread_info *tp : all_non_exited_threads ()) - if (tp->resumed - && tp->suspend.waitstatus_pending_p) + if (tp->resumed () && tp->suspend.waitstatus_pending_p) return 1; } return 0; diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 54c097206d16..2f3d85d34eaa 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -293,14 +293,11 @@ class thread_info : public refcounted_object, thread is off and running. */ bool executing = false; - /* True if this thread is resumed from infrun's perspective. - Note that a thread can be marked both as not-executing and - resumed at the same time. This happens if we try to resume a - thread that has a wait status pending. We shouldn't let the - thread really run until that wait status has been processed, but - we should not process that wait status if we didn't try to let - the thread run. */ - bool resumed = false; + bool resumed () const + { return m_resumed; } + + void set_resumed (bool resumed) + { m_resumed = resumed; } /* Frontend view of the thread state. Note that the THREAD_RUNNING/ THREAD_STOPPED states are different from EXECUTING. When the @@ -393,6 +390,16 @@ class thread_info : public refcounted_object, /* Displaced-step state for this thread. */ displaced_step_thread_state displaced_step_state; + +private: + /* True if this thread is resumed from infrun's perspective. + Note that a thread can be marked both as not-executing and + resumed at the same time. This happens if we try to resume a + thread that has a wait status pending. We shouldn't let the + thread really run until that wait status has been processed, but + we should not process that wait status if we didn't try to let + the thread run. */ + bool m_resumed = false; }; /* A gdb::ref_ptr pointer to a thread_info. */ diff --git a/gdb/infrun.c b/gdb/infrun.c index fcd0f4e10ced..450e6177cb89 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1920,7 +1920,7 @@ start_step_over (void) } if (tp->control.trap_expected - || tp->resumed + || tp->resumed () || tp->executing) { internal_error (__FILE__, __LINE__, @@ -1928,7 +1928,7 @@ start_step_over (void) "trap_expected=%d, resumed=%d, executing=%d\n", target_pid_to_str (tp->ptid).c_str (), tp->control.trap_expected, - tp->resumed, + tp->resumed (), tp->executing); } @@ -1953,7 +1953,7 @@ start_step_over (void) /* If the thread's step over could not be initiated because no buffers were available, it was re-added to the global step over chain. */ - if (tp->resumed) + if (tp->resumed ()) { infrun_debug_printf ("[%s] was resumed.", target_pid_to_str (tp->ptid).c_str ()); @@ -2220,7 +2220,7 @@ resume_1 (enum gdb_signal sig) currently_stepping (tp)); tp->inf->process_target ()->threads_executing = true; - tp->resumed = true; + tp->set_resumed (true); /* FIXME: What should we do if we are supposed to resume this thread with a signal? Maybe we should maintain a queue of @@ -2342,7 +2342,7 @@ resume_1 (enum gdb_signal sig) resume_ptid = internal_resume_ptid (user_step); do_target_resume (resume_ptid, false, GDB_SIGNAL_0); - tp->resumed = true; + tp->set_resumed (true); return; } } @@ -2551,7 +2551,7 @@ resume_1 (enum gdb_signal sig) } do_target_resume (resume_ptid, step, sig); - tp->resumed = true; + tp->set_resumed (true); } /* Resume the inferior. SIG is the signal to give the inferior @@ -2803,7 +2803,7 @@ maybe_set_commit_resumed_all_targets () resuming more threads. */ bool has_thread_with_pending_status = false; for (thread_info *thread : all_non_exited_threads (proc_target)) - if (thread->resumed && thread->suspend.waitstatus_pending_p) + if (thread->resumed () && thread->suspend.waitstatus_pending_p) { has_thread_with_pending_status = true; break; @@ -3238,7 +3238,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) continue; } - if (tp->resumed) + if (tp->resumed ()) { infrun_debug_printf ("[%s] resumed", target_pid_to_str (tp->ptid).c_str ()); @@ -3263,7 +3263,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) error (_("Command aborted.")); } } - else if (!cur_thr->resumed && !thread_is_in_step_over_chain (cur_thr)) + else if (!cur_thr->resumed () && !thread_is_in_step_over_chain (cur_thr)) { /* The thread wasn't started, and isn't queued, run it now. */ reset_ecs (ecs, cur_thr); @@ -3408,7 +3408,7 @@ infrun_thread_stop_requested (ptid_t ptid) /* Otherwise we can process the (new) pending event now. Set it so this pending event is considered by do_target_wait. */ - tp->resumed = true; + tp->set_resumed (true); } } @@ -3505,7 +3505,7 @@ random_pending_event_thread (inferior *inf, ptid_t waiton_ptid) auto has_event = [&] (thread_info *tp) { return (tp->ptid.matches (waiton_ptid) - && tp->resumed + && tp->resumed () && tp->suspend.waitstatus_pending_p); }; @@ -3852,7 +3852,7 @@ prepare_for_detach (void) } } else - thr->resumed = false; + thr->set_resumed (false); } } @@ -4893,7 +4893,7 @@ handle_one (const wait_one_event &event) t->stop_requested = 0; t->executing = 0; - t->resumed = false; + t->set_resumed (false); t->control.may_range_step = 0; /* This may be the first time we see the inferior report @@ -5063,7 +5063,7 @@ stop_all_threads (void) /* The thread may be not executing, but still be resumed with a pending status to process. */ - t->resumed = false; + t->set_resumed (false); } } @@ -5808,7 +5808,7 @@ restart_threads (struct thread_info *event_thread) continue; } - if (tp->resumed) + if (tp->resumed ()) { infrun_debug_printf ("restart threads: [%s] resumed", target_pid_to_str (tp->ptid).c_str ()); @@ -5820,7 +5820,7 @@ restart_threads (struct thread_info *event_thread) { infrun_debug_printf ("restart threads: [%s] needs step-over", target_pid_to_str (tp->ptid).c_str ()); - gdb_assert (!tp->resumed); + gdb_assert (!tp->resumed ()); continue; } @@ -5829,7 +5829,7 @@ restart_threads (struct thread_info *event_thread) { infrun_debug_printf ("restart threads: [%s] has pending status", target_pid_to_str (tp->ptid).c_str ()); - tp->resumed = true; + tp->set_resumed (true); continue; } @@ -5873,7 +5873,7 @@ static int resumed_thread_with_pending_status (struct thread_info *tp, void *arg) { - return (tp->resumed + return (tp->resumed () && tp->suspend.waitstatus_pending_p); } @@ -5959,7 +5959,7 @@ finish_step_over (struct execution_control_state *ecs) /* This was cleared early, by handle_inferior_event. Set it so this pending event is considered by do_target_wait. */ - tp->resumed = true; + tp->set_resumed (true); gdb_assert (!tp->executing); @@ -7519,7 +7519,7 @@ restart_after_all_stop_detach (process_stratum_target *proc_target) /* If we have a pending event to process, skip resuming the target and go straight to processing it. */ - if (thr->resumed && thr->suspend.waitstatus_pending_p) + if (thr->resumed () && thr->suspend.waitstatus_pending_p) return; } @@ -7624,7 +7624,7 @@ keep_going_stepped_thread (struct thread_info *tp) get_frame_address_space (frame), tp->suspend.stop_pc); - tp->resumed = true; + tp->set_resumed (true); resume_ptid = internal_resume_ptid (tp->control.stepping_command); do_target_resume (resume_ptid, false, GDB_SIGNAL_0); } @@ -8039,7 +8039,7 @@ static void keep_going_pass_signal (struct execution_control_state *ecs) { gdb_assert (ecs->event_thread->ptid == inferior_ptid); - gdb_assert (!ecs->event_thread->resumed); + gdb_assert (!ecs->event_thread->resumed ()); /* Save the pc before execution, to compare with pc after stop. */ ecs->event_thread->prev_pc diff --git a/gdb/remote.c b/gdb/remote.c index 22933eeaeec6..f08616be9b67 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8132,7 +8132,7 @@ static ptid_t first_remote_resumed_thread (remote_target *target) { for (thread_info *tp : all_non_exited_threads (target, minus_one_ptid)) - if (tp->resumed) + if (tp->resumed ()) return tp->ptid; return null_ptid; } diff --git a/gdb/thread.c b/gdb/thread.c index 925ed96c3d83..c6c63b742db4 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -708,7 +708,7 @@ void set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed) { for (thread_info *tp : all_non_exited_threads (targ, ptid)) - tp->resumed = resumed; + tp->set_resumed (resumed); } /* Helper for set_running, that marks one thread either running or -- 2.32.0