cris: Check UNDEFWEAK_NO_DYNAMIC_RELOC
[deliverable/binutils-gdb.git] / gdb / gdbserver / gdbthread.h
CommitLineData
623b6bdf 1/* Multi-thread control defs for remote server for GDB.
61baf725 2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
623b6bdf
YQ
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19#ifndef GDB_THREAD_H
20#define GDB_THREAD_H
21
75352e28 22#include "common-gdbthread.h"
6a6bbd9d 23#include "inferiors.h"
623b6bdf 24
9c80ecd6
SM
25#include <list>
26
9accd112 27struct btrace_target_info;
a44892be 28struct regcache;
9accd112 29
623b6bdf
YQ
30struct thread_info
31{
9c80ecd6
SM
32 /* The id of this thread. */
33 ptid_t id;
80894984 34
623b6bdf 35 void *target_data;
a44892be 36 struct regcache *regcache_data;
623b6bdf
YQ
37
38 /* The last resume GDB requested on this thread. */
39 enum resume_kind last_resume_kind;
40
41 /* The last wait status reported for this thread. */
42 struct target_waitstatus last_status;
43
b7ea362b
PA
44 /* True if LAST_STATUS hasn't been reported to GDB yet. */
45 int status_pending_p;
46
623b6bdf
YQ
47 /* Given `while-stepping', a thread may be collecting data for more
48 than one tracepoint simultaneously. E.g.:
49
50 ff0001 INSN1 <-- TP1, while-stepping 10 collect $regs
51 ff0002 INSN2
52 ff0003 INSN3 <-- TP2, collect $regs
53 ff0004 INSN4 <-- TP3, while-stepping 10 collect $regs
54 ff0005 INSN5
55
56 Notice that when instruction INSN5 is reached, the while-stepping
57 actions of both TP1 and TP3 are still being collected, and that TP2
58 had been collected meanwhile. The whole range of ff0001-ff0005
59 should be single-stepped, due to at least TP1's while-stepping
60 action covering the whole range.
61
62 On the other hand, the same tracepoint with a while-stepping action
63 may be hit by more than one thread simultaneously, hence we can't
64 keep the current step count in the tracepoint itself.
65
66 This is the head of the list of the states of `while-stepping'
67 tracepoint actions this thread is now collecting; NULL if empty.
68 Each item in the list holds the current step of the while-stepping
69 action. */
70 struct wstep_state *while_stepping;
9accd112
MM
71
72 /* Branch trace target information for this thread. */
73 struct btrace_target_info *btrace;
623b6bdf
YQ
74};
75
9c80ecd6 76extern std::list<thread_info *> all_threads;
623b6bdf
YQ
77
78void remove_thread (struct thread_info *thread);
f7667f0d 79struct thread_info *add_thread (ptid_t ptid, void *target_data);
623b6bdf 80
9c80ecd6
SM
81/* Return a pointer to the first thread, or NULL if there isn't one. */
82
649ebbca
DE
83struct thread_info *get_first_thread (void);
84
623b6bdf 85struct thread_info *find_thread_ptid (ptid_t ptid);
623b6bdf 86
34c65914
PA
87/* Find any thread of the PID process. Returns NULL if none is
88 found. */
89struct thread_info *find_any_thread_of_pid (int pid);
90
9c80ecd6
SM
91/* Find the first thread for which FUNC returns true. Return NULL if no thread
92 satisfying FUNC is found. */
93
94template <typename Func>
95static thread_info *
96find_thread (Func func)
97{
98 std::list<thread_info *>::iterator next, cur = all_threads.begin ();
99
100 while (cur != all_threads.end ())
101 {
102 next = cur;
103 next++;
104
105 if (func (*cur))
106 return *cur;
107
108 cur = next;
109 }
110
111 return NULL;
112}
113
114/* Invoke FUNC for each thread. */
115
116template <typename Func>
117static void
118for_each_thread (Func func)
119{
120 std::list<thread_info *>::iterator next, cur = all_threads.begin ();
121
122 while (cur != all_threads.end ())
123 {
124 next = cur;
125 next++;
126 func (*cur);
127 cur = next;
128 }
129}
130
131/* Find the a random thread for which FUNC (THREAD) returns true. If
132 no entry is found then return NULL. */
133
134template <typename Func>
135static thread_info *
136find_thread_in_random (Func func)
137{
138 int count = 0;
139 int random_selector;
140
141 /* First count how many interesting entries we have. */
142 for_each_thread ([&] (thread_info *thread) {
143 if (func (thread))
144 count++;
145 });
146
147 if (count == 0)
148 return NULL;
149
150 /* Now randomly pick an entry out of those. */
151 random_selector = (int)
152 ((count * (double) rand ()) / (RAND_MAX + 1.0));
153
154 thread_info *thread = find_thread ([&] (thread_info *thread) {
155 return func (thread) && (random_selector-- == 0);
156 });
157
158 gdb_assert (thread != NULL);
159
160 return thread;
161}
162
fbd5db48 163/* Get current thread ID (Linux task ID). */
9c80ecd6 164#define current_ptid (current_thread->id)
f5a02773 165
9179355e
SM
166/* Get the ptid of THREAD. */
167
168static inline ptid_t
169ptid_of (const thread_info *thread)
170{
9c80ecd6 171 return thread->id;
9179355e
SM
172}
173
174/* Get the pid of THREAD. */
175
176static inline int
177pid_of (const thread_info *thread)
178{
9c80ecd6 179 return thread->id.pid ();
9179355e
SM
180}
181
182/* Get the lwp of THREAD. */
183
184static inline long
185lwpid_of (const thread_info *thread)
186{
9c80ecd6 187 return thread->id.lwp ();
9179355e
SM
188}
189
984a2c04
YQ
190/* Create a cleanup to restore current_thread. */
191struct cleanup *make_cleanup_restore_current_thread (void);
192
623b6bdf 193#endif /* GDB_THREAD_H */
This page took 0.445614 seconds and 4 git commands to generate.