Add translations for various sub-directories
[binutils-gdb.git] / gdbserver / gdbthread.h
blobd7b5bc3e1538bde8eafd0f3253706924d7330a21
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), m_process (process), m_target_data (target_data)
34 ~thread_info ()
36 free_register_cache (m_regcache);
39 /* Return the process owning this thread. */
40 process_info *process () const
41 { return m_process; }
43 struct regcache *regcache ()
44 { return m_regcache; }
46 void set_regcache (struct regcache *regcache)
47 { m_regcache = regcache; }
49 void *target_data ()
50 { return m_target_data; }
52 /* The id of this thread. */
53 ptid_t id;
55 /* The last resume GDB requested on this thread. */
56 enum resume_kind last_resume_kind = resume_continue;
58 /* The last wait status reported for this thread. */
59 struct target_waitstatus last_status;
61 /* True if LAST_STATUS hasn't been reported to GDB yet. */
62 int status_pending_p = 0;
64 /* Given `while-stepping', a thread may be collecting data for more
65 than one tracepoint simultaneously. E.g.:
67 ff0001 INSN1 <-- TP1, while-stepping 10 collect $regs
68 ff0002 INSN2
69 ff0003 INSN3 <-- TP2, collect $regs
70 ff0004 INSN4 <-- TP3, while-stepping 10 collect $regs
71 ff0005 INSN5
73 Notice that when instruction INSN5 is reached, the while-stepping
74 actions of both TP1 and TP3 are still being collected, and that TP2
75 had been collected meanwhile. The whole range of ff0001-ff0005
76 should be single-stepped, due to at least TP1's while-stepping
77 action covering the whole range.
79 On the other hand, the same tracepoint with a while-stepping action
80 may be hit by more than one thread simultaneously, hence we can't
81 keep the current step count in the tracepoint itself.
83 This is the head of the list of the states of `while-stepping'
84 tracepoint actions this thread is now collecting; NULL if empty.
85 Each item in the list holds the current step of the while-stepping
86 action. */
87 struct wstep_state *while_stepping = nullptr;
89 /* Branch trace target information for this thread. */
90 struct btrace_target_info *btrace = nullptr;
92 /* Thread options GDB requested with QThreadOptions. */
93 gdb_thread_options thread_options = 0;
95 private:
96 process_info *m_process;
97 struct regcache *m_regcache = nullptr;
98 void *m_target_data;
101 /* Return a pointer to the first thread, or NULL if there isn't one. */
103 thread_info *get_first_thread (void);
105 thread_info *find_thread_ptid (ptid_t ptid);
107 /* Find any thread of the PID process. Returns NULL if none is
108 found. */
109 thread_info *find_any_thread_of_pid (int pid);
111 /* Find the first thread for which FUNC returns true. Return NULL if no thread
112 satisfying FUNC is found. */
114 thread_info *find_thread (gdb::function_view<bool (thread_info *)> func);
116 /* Like the above, but only consider threads with pid PID. */
118 thread_info *find_thread (int pid,
119 gdb::function_view<bool (thread_info *)> func);
121 /* Find the first thread that matches FILTER for which FUNC returns true.
122 Return NULL if no thread satisfying these conditions is found. */
124 thread_info *find_thread (ptid_t filter,
125 gdb::function_view<bool (thread_info *)> func);
127 /* Invoke FUNC for each thread. */
129 void for_each_thread (gdb::function_view<void (thread_info *)> func);
131 /* Like the above, but only consider threads matching PTID. */
133 void for_each_thread
134 (ptid_t ptid, gdb::function_view<void (thread_info *)> func);
136 /* Find a random thread that matches PTID and for which FUNC (THREAD)
137 returns true. If no entry is found then return nullptr. */
139 thread_info *find_thread_in_random
140 (gdb::function_view<bool (thread_info *)> func);
142 /* Like the above, but only consider threads matching PTID. */
144 thread_info *find_thread_in_random
145 (ptid_t ptid, gdb::function_view<bool (thread_info *)> func);
147 /* Switch the current thread. */
149 void switch_to_thread (thread_info *thread);
151 /* Save/restore current thread. */
153 class scoped_restore_current_thread
155 public:
156 scoped_restore_current_thread ();
157 ~scoped_restore_current_thread ();
159 DISABLE_COPY_AND_ASSIGN (scoped_restore_current_thread);
161 /* Cancel restoring on scope exit. */
162 void dont_restore () { m_dont_restore = true; }
164 private:
165 bool m_dont_restore = false;
166 process_info *m_process;
167 thread_info *m_thread;
170 #endif /* GDBSERVER_GDBTHREAD_H */