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