gdbserver: Use std::list for all_processes
[external/binutils.git] / gdb / gdbserver / gdbthread.h
1 /* Multi-thread control defs for remote server for GDB.
2    Copyright (C) 1993-2017 Free Software Foundation, Inc.
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
22 #include "common-gdbthread.h"
23 #include "inferiors.h"
24
25 struct btrace_target_info;
26 struct regcache;
27
28 struct thread_info
29 {
30   /* This must appear first.  See inferiors.h.
31      The list iterator functions assume it.  */
32   struct inferior_list_entry entry;
33
34   void *target_data;
35   struct regcache *regcache_data;
36
37   /* The last resume GDB requested on this thread.  */
38   enum resume_kind last_resume_kind;
39
40   /* The last wait status reported for this thread.  */
41   struct target_waitstatus last_status;
42
43   /* True if LAST_STATUS hasn't been reported to GDB yet.  */
44   int status_pending_p;
45
46   /* Given `while-stepping', a thread may be collecting data for more
47      than one tracepoint simultaneously.  E.g.:
48
49     ff0001  INSN1 <-- TP1, while-stepping 10 collect $regs
50     ff0002  INSN2
51     ff0003  INSN3 <-- TP2, collect $regs
52     ff0004  INSN4 <-- TP3, while-stepping 10 collect $regs
53     ff0005  INSN5
54
55    Notice that when instruction INSN5 is reached, the while-stepping
56    actions of both TP1 and TP3 are still being collected, and that TP2
57    had been collected meanwhile.  The whole range of ff0001-ff0005
58    should be single-stepped, due to at least TP1's while-stepping
59    action covering the whole range.
60
61    On the other hand, the same tracepoint with a while-stepping action
62    may be hit by more than one thread simultaneously, hence we can't
63    keep the current step count in the tracepoint itself.
64
65    This is the head of the list of the states of `while-stepping'
66    tracepoint actions this thread is now collecting; NULL if empty.
67    Each item in the list holds the current step of the while-stepping
68    action.  */
69   struct wstep_state *while_stepping;
70
71   /* Branch trace target information for this thread.  */
72   struct btrace_target_info *btrace;
73 };
74
75 extern struct inferior_list all_threads;
76
77 void remove_thread (struct thread_info *thread);
78 struct thread_info *add_thread (ptid_t ptid, void *target_data);
79
80 struct thread_info *get_first_thread (void);
81
82 struct thread_info *find_thread_ptid (ptid_t ptid);
83
84 /* Find any thread of the PID process.  Returns NULL if none is
85    found.  */
86 struct thread_info *find_any_thread_of_pid (int pid);
87
88 /* Get current thread ID (Linux task ID).  */
89 #define current_ptid (current_thread->entry.id)
90
91 /* Get the ptid of THREAD.  */
92
93 static inline ptid_t
94 ptid_of (const thread_info *thread)
95 {
96   return thread->entry.id;
97 }
98
99 /* Get the pid of THREAD.  */
100
101 static inline int
102 pid_of (const thread_info *thread)
103 {
104   return thread->entry.id.pid ();
105 }
106
107 /* Get the lwp of THREAD.  */
108
109 static inline long
110 lwpid_of (const thread_info *thread)
111 {
112   return thread->entry.id.lwp ();
113 }
114
115 /* Create a cleanup to restore current_thread.  */
116 struct cleanup *make_cleanup_restore_current_thread (void);
117
118 #endif /* GDB_THREAD_H */