1 /* Common things used by the various darwin files
2 Copyright (C) 1995-2019 Free Software Foundation, Inc.
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.
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.
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/>. */
20 #include <mach/mach.h>
22 /* Local non-gdb includes. */
23 #include "gdbthread.h"
24 #include "inf-child.h"
26 /* This needs to be overridden by the platform specific nat code. */
28 class darwin_nat_target
: public inf_child_target
30 void create_inferior (const char *exec_file
,
31 const std::string
&allargs
,
32 char **env
, int from_tty
) override
;
34 void attach (const char *, int) override
;
36 void detach (inferior
*, int) override
;
38 ptid_t
wait (ptid_t
, struct target_waitstatus
*, int) override
;
40 void mourn_inferior () override
;
42 void kill () override
;
44 void interrupt () override
;
46 void resume (ptid_t
, int , enum gdb_signal
) override
;
48 bool thread_alive (ptid_t ptid
) override
;
50 std::string
pid_to_str (ptid_t
) override
;
52 char *pid_to_exec_file (int pid
) override
;
54 enum target_xfer_status
xfer_partial (enum target_object object
,
57 const gdb_byte
*writebuf
,
58 ULONGEST offset
, ULONGEST len
,
59 ULONGEST
*xfered_len
) override
;
61 bool supports_multi_process () override
;
63 ptid_t
get_ada_task_ptid (long lwp
, long thread
) override
;
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
70 struct darwin_exception_info
72 /* Exceptions handled by the port. */
73 exception_mask_t masks
[EXC_TYPES_COUNT
] {};
75 /* Ports receiving exception messages. */
76 mach_port_t ports
[EXC_TYPES_COUNT
] {};
78 /* Type of messages sent. */
79 exception_behavior_t behaviors
[EXC_TYPES_COUNT
] {};
81 /* Type of state to be sent. */
82 thread_state_flavor_t flavors
[EXC_TYPES_COUNT
] {};
84 /* Number of elements set. */
85 mach_msg_type_number_t count
= 0;
88 struct darwin_exception_msg
90 mach_msg_header_t header
;
92 /* Thread and task taking the exception. */
93 mach_port_t thread_port
;
94 mach_port_t task_port
;
96 /* Type of the exception. */
97 exception_type_t ex_type
;
99 /* Machine dependent details. */
100 mach_msg_type_number_t data_count
;
101 integer_t ex_data
[2];
104 enum darwin_msg_state
106 /* The thread is running. */
109 /* The thread is stopped. */
112 /* The thread has sent a message and waits for a reply. */
116 struct darwin_thread_info
: public private_thread_info
118 /* The thread port from a GDB point of view. */
119 thread_t gdb_port
= 0;
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;
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
;
130 /* True if this thread is single-stepped. */
131 bool single_step
= false;
133 /* True if a signal was manually sent to the thread. */
134 bool signaled
= false;
136 /* The last exception received. */
137 struct darwin_exception_msg event
{};
139 typedef struct darwin_thread_info darwin_thread_t
;
141 static inline darwin_thread_info
*
142 get_darwin_thread_info (class thread_info
*thread
)
144 return static_cast<darwin_thread_info
*> (thread
->priv
.get ());
147 /* Describe an inferior. */
148 struct darwin_inferior
: public private_inferior
150 /* Corresponding task port. */
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;
157 /* Initial exception handling. */
158 darwin_exception_info exception_info
;
160 /* Number of messages that have been received but not yet replied. */
161 unsigned int pending_messages
= 0;
163 /* Set if inferior is not controlled by ptrace(2) but through Mach. */
164 bool no_ptrace
= false;
166 /* True if this task is suspended. */
167 bool suspended
= false;
169 /* Sorted vector of known threads. */
170 std::vector
<darwin_thread_t
*> threads
;
173 /* Return the darwin_inferior attached to INF. */
175 static inline darwin_inferior
*
176 get_darwin_inferior (inferior
*inf
)
178 return static_cast<darwin_inferior
*> (inf
->priv
.get ());
181 /* Exception port. */
182 extern mach_port_t darwin_ex_port
;
185 extern mach_port_t darwin_port_set
;
187 /* A copy of mach_host_self (). */
188 extern mach_port_t darwin_host_self
;
190 /* FUNCTION_NAME is defined in common-utils.h (or not). */
192 #define MACH_CHECK_ERROR(ret) \
193 mach_check_error (ret, __FILE__, __LINE__, FUNCTION_NAME)
195 #define MACH_CHECK_ERROR(ret) \
196 mach_check_error (ret, __FILE__, __LINE__, "??")
199 extern void mach_check_error (kern_return_t ret
, const char *file
,
200 unsigned int line
, const char *func
);
202 void darwin_set_sstep (thread_t thread
, int enable
);
204 void darwin_check_osabi (darwin_inferior
*inf
, thread_t thread
);
206 #endif /* DARWIN_NAT_H */