]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/darwin-nat.h
Sort includes for files gdb/[a-f]*.[chyl].
[thirdparty/binutils-gdb.git] / gdb / darwin-nat.h
1 /* Common things used by the various darwin files
2 Copyright (C) 1995-2019 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef DARWIN_NAT_H
18 #define DARWIN_NAT_H
19
20 #include <mach/mach.h>
21
22 /* Local non-gdb includes. */
23 #include "gdbthread.h"
24 #include "inf-child.h"
25
26 /* This needs to be overridden by the platform specific nat code. */
27
28 class darwin_nat_target : public inf_child_target
29 {
30 void create_inferior (const char *exec_file,
31 const std::string &allargs,
32 char **env, int from_tty) override;
33
34 void attach (const char *, int) override;
35
36 void detach (inferior *, int) override;
37
38 ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
39
40 void mourn_inferior () override;
41
42 void kill () override;
43
44 void interrupt () override;
45
46 void resume (ptid_t, int , enum gdb_signal) override;
47
48 bool thread_alive (ptid_t ptid) override;
49
50 std::string pid_to_str (ptid_t) override;
51
52 char *pid_to_exec_file (int pid) override;
53
54 enum target_xfer_status xfer_partial (enum target_object object,
55 const char *annex,
56 gdb_byte *readbuf,
57 const gdb_byte *writebuf,
58 ULONGEST offset, ULONGEST len,
59 ULONGEST *xfered_len) override;
60
61 bool supports_multi_process () override;
62
63 ptid_t get_ada_task_ptid (long lwp, long thread) override;
64 };
65
66 /* Describe the mach exception handling state for a task. This state is saved
67 before being changed and restored when a process is detached.
68 For more information on these fields see task_get_exception_ports manual
69 page. */
70 struct darwin_exception_info
71 {
72 /* Exceptions handled by the port. */
73 exception_mask_t masks[EXC_TYPES_COUNT] {};
74
75 /* Ports receiving exception messages. */
76 mach_port_t ports[EXC_TYPES_COUNT] {};
77
78 /* Type of messages sent. */
79 exception_behavior_t behaviors[EXC_TYPES_COUNT] {};
80
81 /* Type of state to be sent. */
82 thread_state_flavor_t flavors[EXC_TYPES_COUNT] {};
83
84 /* Number of elements set. */
85 mach_msg_type_number_t count = 0;
86 };
87
88 struct darwin_exception_msg
89 {
90 mach_msg_header_t header;
91
92 /* Thread and task taking the exception. */
93 mach_port_t thread_port;
94 mach_port_t task_port;
95
96 /* Type of the exception. */
97 exception_type_t ex_type;
98
99 /* Machine dependent details. */
100 mach_msg_type_number_t data_count;
101 integer_t ex_data[2];
102 };
103
104 enum darwin_msg_state
105 {
106 /* The thread is running. */
107 DARWIN_RUNNING,
108
109 /* The thread is stopped. */
110 DARWIN_STOPPED,
111
112 /* The thread has sent a message and waits for a reply. */
113 DARWIN_MESSAGE
114 };
115
116 struct darwin_thread_info : public private_thread_info
117 {
118 /* The thread port from a GDB point of view. */
119 thread_t gdb_port = 0;
120
121 /* The thread port from the inferior point of view. Not to be used inside
122 gdb except for get_ada_task_ptid. */
123 thread_t inf_port = 0;
124
125 /* Current message state.
126 If the kernel has sent a message it expects a reply and the inferior
127 can't be killed before. */
128 enum darwin_msg_state msg_state = DARWIN_RUNNING;
129
130 /* True if this thread is single-stepped. */
131 bool single_step = false;
132
133 /* True if a signal was manually sent to the thread. */
134 bool signaled = false;
135
136 /* The last exception received. */
137 struct darwin_exception_msg event {};
138 };
139 typedef struct darwin_thread_info darwin_thread_t;
140
141 static inline darwin_thread_info *
142 get_darwin_thread_info (class thread_info *thread)
143 {
144 return static_cast<darwin_thread_info *> (thread->priv.get ());
145 }
146
147 /* Describe an inferior. */
148 struct darwin_inferior : public private_inferior
149 {
150 /* Corresponding task port. */
151 task_t task = 0;
152
153 /* Port which will receive the dead-name notification for the task port.
154 This is used to detect the death of the task. */
155 mach_port_t notify_port = 0;
156
157 /* Initial exception handling. */
158 darwin_exception_info exception_info;
159
160 /* Number of messages that have been received but not yet replied. */
161 unsigned int pending_messages = 0;
162
163 /* Set if inferior is not controlled by ptrace(2) but through Mach. */
164 bool no_ptrace = false;
165
166 /* True if this task is suspended. */
167 bool suspended = false;
168
169 /* Sorted vector of known threads. */
170 std::vector<darwin_thread_t *> threads;
171 };
172
173 /* Return the darwin_inferior attached to INF. */
174
175 static inline darwin_inferior *
176 get_darwin_inferior (inferior *inf)
177 {
178 return static_cast<darwin_inferior *> (inf->priv.get ());
179 }
180
181 /* Exception port. */
182 extern mach_port_t darwin_ex_port;
183
184 /* Port set. */
185 extern mach_port_t darwin_port_set;
186
187 /* A copy of mach_host_self (). */
188 extern mach_port_t darwin_host_self;
189
190 /* FUNCTION_NAME is defined in common-utils.h (or not). */
191 #ifdef FUNCTION_NAME
192 #define MACH_CHECK_ERROR(ret) \
193 mach_check_error (ret, __FILE__, __LINE__, FUNCTION_NAME)
194 #else
195 #define MACH_CHECK_ERROR(ret) \
196 mach_check_error (ret, __FILE__, __LINE__, "??")
197 #endif
198
199 extern void mach_check_error (kern_return_t ret, const char *file,
200 unsigned int line, const char *func);
201
202 void darwin_set_sstep (thread_t thread, int enable);
203
204 void darwin_check_osabi (darwin_inferior *inf, thread_t thread);
205
206 #endif /* DARWIN_NAT_H */