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