Debian Codegraph @

gdbserver/inferiors.h

raw
1 /* Inferior process information for the remote server for GDB.
2 Copyright (C) 1993-2025 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 GDBSERVER_INFERIORS_H
20 #define GDBSERVER_INFERIORS_H
21
22 #include "gdbsupport/owning_intrusive_list.h"
23 #include "gdbsupport/unordered_map.h"
24
25 #include "dll.h"
26
27 struct thread_info;
28 struct regcache;
29 struct target_desc;
30 struct sym_cache;
31 struct breakpoint;
32 struct raw_breakpoint;
33 struct fast_tracepoint_jump;
34 struct process_info_private;
35 struct process_info;
36
37 extern owning_intrusive_list<process_info> all_processes;
38
39 struct process_info : public intrusive_list_node<process_info>
40 {
41 process_info (int pid_, int attached_)
42 : pid (pid_), attached (attached_)
43 {}
44
45 /* This process' pid. */
46 int pid;
47
48 /* Nonzero if this child process was attached rather than
49 spawned. */
50 int attached;
51
52 /* True if GDB asked us to detach from this process, but we remained
53 attached anyway. */
54 int gdb_detached = 0;
55
56 /* The symbol cache. */
57 struct sym_cache *symbol_cache = NULL;
58
59 /* The list of memory breakpoints. */
60 struct breakpoint *breakpoints = NULL;
61
62 /* The list of raw memory breakpoints. */
63 struct raw_breakpoint *raw_breakpoints = NULL;
64
65 /* The list of installed fast tracepoints. */
66 struct fast_tracepoint_jump *fast_tracepoint_jumps = NULL;
67
68 /* The list of syscalls to report, or just a single element, ANY_SYSCALL,
69 for unfiltered syscall reporting. */
70 std::vector<int> syscalls_to_catch;
71
72 const struct target_desc *tdesc = NULL;
73
74 /* Private target data. */
75 struct process_info_private *priv = NULL;
76
77 /* DLLs that are loaded for this proc. */
78 std::list<dll_info> all_dlls;
79
80 /* Flag to mark that the DLL list has changed. */
81 bool dlls_changed = false;
82
83 /* True if the inferior is starting up (inside startup_inferior),
84 and we're nursing it along (through the shell) until it is ready
85 to execute its first instruction. Until that is done, we must
86 not access inferior memory or registers, as we haven't determined
87 the target architecture/description. */
88 bool starting_up = false;
89
90 /* Return a reference to the private thread list. */
91 owning_intrusive_list<thread_info> &thread_list ()
92 { return m_thread_list; }
93
94 /* Return the number of threads in this process. */
95 unsigned int thread_count () const
96 { return m_ptid_thread_map.size (); }
97
98 /* Return the thread with ptid PTID, or nullptr if no such thread is
99 found. */
100 thread_info *find_thread (ptid_t ptid);
101
102 /* Find the first thread for which FUNC returns true. Return nullptr if no
103 such thread is found. */
104 thread_info *find_thread (gdb::function_view<bool (thread_info *)> func);
105
106 /* Invoke FUNC for each thread. */
107 void for_each_thread (gdb::function_view<void (thread_info *)> func);
108
109 /* Add a thread with id ID to this process. */
110 thread_info *add_thread (ptid_t id, void *target_data);
111
112 /* Remove thread THREAD.
113
114 THREAD must be part of this process' thread list. */
115 void remove_thread (thread_info *thread);
116
117 private:
118 /* This processes' thread list, sorted by creation order. */
119 owning_intrusive_list<thread_info> m_thread_list;
120
121 /* A map of ptid_t to thread_info*, for average O(1) ptid_t lookup.
122 Exited threads do not appear in the map. */
123 gdb::unordered_map<ptid_t, thread_info *> m_ptid_thread_map;
124 };
125
126 /* Return a pointer to the current process. Note that the current
127 process may be non-null while the current thread (current_thread)
128 is null. */
129
130 struct process_info *current_process (void);
131
132 extern owning_intrusive_list<process_info> all_processes;
133
134 /* Invoke FUNC for each process. */
135
136 void for_each_process (gdb::function_view<void (process_info *)> func);
137
138 /* Find the first process for which FUNC returns true. Return NULL if no
139 process satisfying FUNC is found. */
140
141 process_info *find_process (gdb::function_view<bool (process_info *)> func);
142
143 extern thread_info *current_thread;
144
145 /* Return the first process in the processes list. */
146 struct process_info *get_first_process (void);
147
148 struct process_info *add_process (int pid, int attached);
149 void remove_process (struct process_info *process);
150 struct process_info *find_process_pid (int pid);
151 int have_started_inferiors_p (void);
152 int have_attached_inferiors_p (void);
153
154 /* Switch to a thread of PROC. */
155 void switch_to_process (process_info *proc);
156
157 /* Set the inferior current working directory. If CWD is empty, unset
158 the directory. */
159 void set_inferior_cwd (std::string cwd);
160
161 #endif /* GDBSERVER_INFERIORS_H */