Automatic date update in version.in
[binutils-gdb.git] / gdbserver / gdbthread.h
blob11ab7f49adbfbd24a6f292f155a0e4e4180d33c0
1 /* Multi-thread control defs for remote server for GDB.
2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef GDBSERVER_GDBTHREAD_H
20 #define GDBSERVER_GDBTHREAD_H
22 #include "gdbsupport/function-view.h"
23 #include "gdbsupport/intrusive_list.h"
25 struct btrace_target_info;
26 struct regcache;
28 struct thread_info : public intrusive_list_node<thread_info>
30 thread_info (ptid_t id, process_info *process, void *target_data)
31 : id (id), target_data (target_data), m_process (process)
34 ~thread_info ()
36 free_register_cache (this->regcache_data);
39 /* Return the process owning this thread. */
40 process_info *process () const
41 { return m_process; }
43 /* The id of this thread. */
44 ptid_t id;
46 void *target_data;
47 struct regcache *regcache_data = nullptr;
49 /* The last resume GDB requested on this thread. */
50 enum resume_kind last_resume_kind = resume_continue;
52 /* The last wait status reported for this thread. */
53 struct target_waitstatus last_status;
55 /* True if LAST_STATUS hasn't been reported to GDB yet. */
56 int status_pending_p = 0;
58 /* Given `while-stepping', a thread may be collecting data for more
59 than one tracepoint simultaneously. E.g.:
61 ff0001 INSN1 <-- TP1, while-stepping 10 collect $regs
62 ff0002 INSN2
63 ff0003 INSN3 <-- TP2, collect $regs
64 ff0004 INSN4 <-- TP3, while-stepping 10 collect $regs
65 ff0005 INSN5
67 Notice that when instruction INSN5 is reached, the while-stepping
68 actions of both TP1 and TP3 are still being collected, and that TP2
69 had been collected meanwhile. The whole range of ff0001-ff0005
70 should be single-stepped, due to at least TP1's while-stepping
71 action covering the whole range.
73 On the other hand, the same tracepoint with a while-stepping action
74 may be hit by more than one thread simultaneously, hence we can't
75 keep the current step count in the tracepoint itself.
77 This is the head of the list of the states of `while-stepping'
78 tracepoint actions this thread is now collecting; NULL if empty.
79 Each item in the list holds the current step of the while-stepping
80 action. */
81 struct wstep_state *while_stepping = nullptr;
83 /* Branch trace target information for this thread. */
84 struct btrace_target_info *btrace = nullptr;
86 /* Thread options GDB requested with QThreadOptions. */
87 gdb_thread_options thread_options = 0;
89 private:
90 process_info *m_process;
93 /* Return a pointer to the first thread, or NULL if there isn't one. */
95 struct thread_info *get_first_thread (void);
97 struct thread_info *find_thread_ptid (ptid_t ptid);
99 /* Find any thread of the PID process. Returns NULL if none is
100 found. */
101 struct thread_info *find_any_thread_of_pid (int pid);
103 /* Find the first thread for which FUNC returns true. Return NULL if no thread
104 satisfying FUNC is found. */
106 thread_info *find_thread (gdb::function_view<bool (thread_info *)> func);
108 /* Like the above, but only consider threads with pid PID. */
110 thread_info *find_thread (int pid,
111 gdb::function_view<bool (thread_info *)> func);
113 /* Find the first thread that matches FILTER for which FUNC returns true.
114 Return NULL if no thread satisfying these conditions is found. */
116 thread_info *find_thread (ptid_t filter,
117 gdb::function_view<bool (thread_info *)> func);
119 /* Invoke FUNC for each thread. */
121 void for_each_thread (gdb::function_view<void (thread_info *)> func);
123 /* Like the above, but only consider threads matching PTID. */
125 void for_each_thread
126 (ptid_t ptid, gdb::function_view<void (thread_info *)> func);
128 /* Find a random thread that matches PTID and for which FUNC (THREAD)
129 returns true. If no entry is found then return nullptr. */
131 thread_info *find_thread_in_random
132 (gdb::function_view<bool (thread_info *)> func);
134 /* Like the above, but only consider threads matching PTID. */
136 thread_info *find_thread_in_random
137 (ptid_t ptid, gdb::function_view<bool (thread_info *)> func);
139 /* Switch the current thread. */
141 void switch_to_thread (thread_info *thread);
143 /* Save/restore current thread. */
145 class scoped_restore_current_thread
147 public:
148 scoped_restore_current_thread ();
149 ~scoped_restore_current_thread ();
151 DISABLE_COPY_AND_ASSIGN (scoped_restore_current_thread);
153 /* Cancel restoring on scope exit. */
154 void dont_restore () { m_dont_restore = true; }
156 private:
157 bool m_dont_restore = false;
158 process_info *m_process;
159 thread_info *m_thread;
162 #endif /* GDBSERVER_GDBTHREAD_H */