Commit | Line | Data |
---|---|---|
a80b95ba | 1 | /* Common things used by the various darwin files |
42a4f53d | 2 | Copyright (C) 1995-2019 Free Software Foundation, Inc. |
a80b95ba TG |
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 | |
47d48711 | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a80b95ba | 16 | |
1a5c2598 TT |
17 | #ifndef DARWIN_NAT_H |
18 | #define DARWIN_NAT_H | |
a80b95ba TG |
19 | |
20 | #include <mach/mach.h> | |
d55e5aa6 TT |
21 | |
22 | /* Local non-gdb includes. */ | |
7aabaf9d | 23 | #include "gdbthread.h" |
d55e5aa6 | 24 | #include "inf-child.h" |
a80b95ba | 25 | |
f6ac5f3d PA |
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, | |
da05d921 | 32 | char **env, int from_tty) override; |
f6ac5f3d PA |
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 | ||
57810aa7 | 48 | bool thread_alive (ptid_t ptid) override; |
f6ac5f3d | 49 | |
a068643d | 50 | std::string pid_to_str (ptid_t) override; |
f6ac5f3d PA |
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 | ||
57810aa7 | 61 | bool supports_multi_process () override; |
f6ac5f3d PA |
62 | |
63 | ptid_t get_ada_task_ptid (long lwp, long thread) override; | |
64 | }; | |
65 | ||
a80b95ba TG |
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. */ | |
089354bb | 73 | exception_mask_t masks[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
74 | |
75 | /* Ports receiving exception messages. */ | |
089354bb | 76 | mach_port_t ports[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
77 | |
78 | /* Type of messages sent. */ | |
089354bb | 79 | exception_behavior_t behaviors[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
80 | |
81 | /* Type of state to be sent. */ | |
089354bb | 82 | thread_state_flavor_t flavors[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
83 | |
84 | /* Number of elements set. */ | |
089354bb | 85 | mach_msg_type_number_t count = 0; |
a80b95ba | 86 | }; |
a80b95ba | 87 | |
bb00b29d | 88 | struct darwin_exception_msg |
a80b95ba | 89 | { |
bb00b29d TG |
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 | ||
637fd620 TG |
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 | }; | |
bb00b29d | 115 | |
7aabaf9d | 116 | struct darwin_thread_info : public private_thread_info |
bb00b29d TG |
117 | { |
118 | /* The thread port from a GDB point of view. */ | |
de1ec836 | 119 | thread_t gdb_port = 0; |
bb00b29d TG |
120 | |
121 | /* The thread port from the inferior point of view. Not to be used inside | |
122 | gdb except for get_ada_task_ptid. */ | |
de1ec836 | 123 | thread_t inf_port = 0; |
bb00b29d TG |
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. */ | |
de1ec836 | 128 | enum darwin_msg_state msg_state = DARWIN_RUNNING; |
bb00b29d TG |
129 | |
130 | /* True if this thread is single-stepped. */ | |
de1ec836 | 131 | bool single_step = false; |
a80b95ba | 132 | |
bb00b29d | 133 | /* True if a signal was manually sent to the thread. */ |
de1ec836 | 134 | bool signaled = false; |
bb00b29d TG |
135 | |
136 | /* The last exception received. */ | |
de1ec836 | 137 | struct darwin_exception_msg event {}; |
bb00b29d | 138 | }; |
7aabaf9d SM |
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 | } | |
bb00b29d | 146 | |
bb00b29d | 147 | /* Describe an inferior. */ |
089354bb | 148 | struct darwin_inferior : public private_inferior |
bb00b29d | 149 | { |
a80b95ba | 150 | /* Corresponding task port. */ |
089354bb | 151 | task_t task = 0; |
a80b95ba | 152 | |
bb00b29d TG |
153 | /* Port which will receive the dead-name notification for the task port. |
154 | This is used to detect the death of the task. */ | |
089354bb | 155 | mach_port_t notify_port = 0; |
a80b95ba TG |
156 | |
157 | /* Initial exception handling. */ | |
158 | darwin_exception_info exception_info; | |
159 | ||
bb00b29d | 160 | /* Number of messages that have been received but not yet replied. */ |
089354bb | 161 | unsigned int pending_messages = 0; |
bb00b29d TG |
162 | |
163 | /* Set if inferior is not controlled by ptrace(2) but through Mach. */ | |
089354bb | 164 | bool no_ptrace = false; |
bb00b29d TG |
165 | |
166 | /* True if this task is suspended. */ | |
089354bb | 167 | bool suspended = false; |
bb00b29d | 168 | |
a80b95ba | 169 | /* Sorted vector of known threads. */ |
089354bb | 170 | std::vector<darwin_thread_t *> threads; |
a80b95ba | 171 | }; |
089354bb SM |
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 | } | |
a80b95ba TG |
180 | |
181 | /* Exception port. */ | |
182 | extern mach_port_t darwin_ex_port; | |
183 | ||
a80b95ba TG |
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 | ||
df049a58 DE |
190 | /* FUNCTION_NAME is defined in common-utils.h (or not). */ |
191 | #ifdef FUNCTION_NAME | |
a80b95ba | 192 | #define MACH_CHECK_ERROR(ret) \ |
df049a58 | 193 | mach_check_error (ret, __FILE__, __LINE__, FUNCTION_NAME) |
a80b95ba TG |
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 | ||
a80b95ba TG |
204 | void darwin_check_osabi (darwin_inferior *inf, thread_t thread); |
205 | ||
1a5c2598 | 206 | #endif /* DARWIN_NAT_H */ |