Commit | Line | Data |
---|---|---|
a80b95ba | 1 | /* Common things used by the various darwin files |
61baf725 | 2 | Copyright (C) 1995-2017 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 TG |
16 | |
17 | #ifndef __DARWIN_NAT_H__ | |
18 | #define __DARWIN_NAT_H__ | |
19 | ||
20 | #include <mach/mach.h> | |
a80b95ba | 21 | |
a80b95ba TG |
22 | /* Describe the mach exception handling state for a task. This state is saved |
23 | before being changed and restored when a process is detached. | |
24 | For more information on these fields see task_get_exception_ports manual | |
25 | page. */ | |
26 | struct darwin_exception_info | |
27 | { | |
28 | /* Exceptions handled by the port. */ | |
089354bb | 29 | exception_mask_t masks[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
30 | |
31 | /* Ports receiving exception messages. */ | |
089354bb | 32 | mach_port_t ports[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
33 | |
34 | /* Type of messages sent. */ | |
089354bb | 35 | exception_behavior_t behaviors[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
36 | |
37 | /* Type of state to be sent. */ | |
089354bb | 38 | thread_state_flavor_t flavors[EXC_TYPES_COUNT] {}; |
a80b95ba TG |
39 | |
40 | /* Number of elements set. */ | |
089354bb | 41 | mach_msg_type_number_t count = 0; |
a80b95ba | 42 | }; |
a80b95ba | 43 | |
bb00b29d | 44 | struct darwin_exception_msg |
a80b95ba | 45 | { |
bb00b29d TG |
46 | mach_msg_header_t header; |
47 | ||
48 | /* Thread and task taking the exception. */ | |
49 | mach_port_t thread_port; | |
50 | mach_port_t task_port; | |
51 | ||
52 | /* Type of the exception. */ | |
53 | exception_type_t ex_type; | |
54 | ||
55 | /* Machine dependent details. */ | |
56 | mach_msg_type_number_t data_count; | |
57 | integer_t ex_data[2]; | |
58 | }; | |
59 | ||
637fd620 TG |
60 | enum darwin_msg_state |
61 | { | |
62 | /* The thread is running. */ | |
63 | DARWIN_RUNNING, | |
64 | ||
65 | /* The thread is stopped. */ | |
66 | DARWIN_STOPPED, | |
67 | ||
68 | /* The thread has sent a message and waits for a reply. */ | |
69 | DARWIN_MESSAGE | |
70 | }; | |
bb00b29d TG |
71 | |
72 | struct private_thread_info | |
73 | { | |
74 | /* The thread port from a GDB point of view. */ | |
75 | thread_t gdb_port; | |
76 | ||
77 | /* The thread port from the inferior point of view. Not to be used inside | |
78 | gdb except for get_ada_task_ptid. */ | |
79 | thread_t inf_port; | |
80 | ||
81 | /* Current message state. | |
82 | If the kernel has sent a message it expects a reply and the inferior | |
83 | can't be killed before. */ | |
84 | enum darwin_msg_state msg_state; | |
85 | ||
86 | /* True if this thread is single-stepped. */ | |
87 | unsigned char single_step; | |
a80b95ba | 88 | |
bb00b29d TG |
89 | /* True if a signal was manually sent to the thread. */ |
90 | unsigned char signaled; | |
91 | ||
92 | /* The last exception received. */ | |
93 | struct darwin_exception_msg event; | |
94 | }; | |
95 | typedef struct private_thread_info darwin_thread_t; | |
96 | ||
bb00b29d | 97 | /* Describe an inferior. */ |
089354bb | 98 | struct darwin_inferior : public private_inferior |
bb00b29d | 99 | { |
a80b95ba | 100 | /* Corresponding task port. */ |
089354bb | 101 | task_t task = 0; |
a80b95ba | 102 | |
bb00b29d TG |
103 | /* Port which will receive the dead-name notification for the task port. |
104 | This is used to detect the death of the task. */ | |
089354bb | 105 | mach_port_t notify_port = 0; |
a80b95ba TG |
106 | |
107 | /* Initial exception handling. */ | |
108 | darwin_exception_info exception_info; | |
109 | ||
bb00b29d | 110 | /* Number of messages that have been received but not yet replied. */ |
089354bb | 111 | unsigned int pending_messages = 0; |
bb00b29d TG |
112 | |
113 | /* Set if inferior is not controlled by ptrace(2) but through Mach. */ | |
089354bb | 114 | bool no_ptrace = false; |
bb00b29d TG |
115 | |
116 | /* True if this task is suspended. */ | |
089354bb | 117 | bool suspended = false; |
bb00b29d | 118 | |
a80b95ba | 119 | /* Sorted vector of known threads. */ |
089354bb | 120 | std::vector<darwin_thread_t *> threads; |
a80b95ba | 121 | }; |
089354bb SM |
122 | |
123 | /* Return the darwin_inferior attached to INF. */ | |
124 | ||
125 | static inline darwin_inferior * | |
126 | get_darwin_inferior (inferior *inf) | |
127 | { | |
128 | return static_cast<darwin_inferior *> (inf->priv.get ()); | |
129 | } | |
a80b95ba TG |
130 | |
131 | /* Exception port. */ | |
132 | extern mach_port_t darwin_ex_port; | |
133 | ||
a80b95ba TG |
134 | /* Port set. */ |
135 | extern mach_port_t darwin_port_set; | |
136 | ||
137 | /* A copy of mach_host_self (). */ | |
138 | extern mach_port_t darwin_host_self; | |
139 | ||
df049a58 DE |
140 | /* FUNCTION_NAME is defined in common-utils.h (or not). */ |
141 | #ifdef FUNCTION_NAME | |
a80b95ba | 142 | #define MACH_CHECK_ERROR(ret) \ |
df049a58 | 143 | mach_check_error (ret, __FILE__, __LINE__, FUNCTION_NAME) |
a80b95ba TG |
144 | #else |
145 | #define MACH_CHECK_ERROR(ret) \ | |
146 | mach_check_error (ret, __FILE__, __LINE__, "??") | |
147 | #endif | |
148 | ||
149 | extern void mach_check_error (kern_return_t ret, const char *file, | |
150 | unsigned int line, const char *func); | |
151 | ||
152 | void darwin_set_sstep (thread_t thread, int enable); | |
153 | ||
154 | /* This one is called in darwin-nat.c, but needs to be provided by the | |
155 | platform specific nat code. It allows each platform to add platform specific | |
156 | stuff to the darwin_ops. */ | |
157 | extern void darwin_complete_target (struct target_ops *target); | |
158 | ||
159 | void darwin_check_osabi (darwin_inferior *inf, thread_t thread); | |
160 | ||
161 | #endif /* __DARWIN_NAT_H__ */ |