1 //===-- MachException.h -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 6/18/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef __MachException_h__
14 #define __MachException_h__
16 #include <mach/mach.h>
19 #include "lldb/Host/Debug.h"
20 #include "lldb/lldb-private-forward.h"
21 #include "lldb/lldb-types.h"
23 namespace lldb_private {
24 namespace process_darwin {
26 typedef union MachMessageTag {
27 mach_msg_header_t hdr;
34 exception_mask_t mask; // the exception mask for this device which may be a
35 // subset of EXC_MASK_ALL...
36 exception_mask_t masks[EXC_TYPES_COUNT];
37 mach_port_t ports[EXC_TYPES_COUNT];
38 exception_behavior_t behaviors[EXC_TYPES_COUNT];
39 thread_state_flavor_t flavors[EXC_TYPES_COUNT];
40 mach_msg_type_number_t count;
42 Status Save(task_t task);
44 Status Restore(task_t task);
50 exception_type_t exc_type;
51 std::vector<mach_exception_data_type_t> exc_data;
53 : task_port(TASK_NULL), thread_port(THREAD_NULL), exc_type(0),
57 task_port = TASK_NULL;
58 thread_port = THREAD_NULL;
63 bool IsValid() const {
64 return task_port != TASK_NULL && thread_port != THREAD_NULL &&
68 // Return the SoftSignal for this MachException data, or zero if there is
70 int SoftSignal() const {
71 if (exc_type == EXC_SOFTWARE && exc_data.size() == 2 &&
72 exc_data[0] == EXC_SOFT_SIGNAL)
73 return static_cast<int>(exc_data[1]);
77 bool IsBreakpoint() const {
78 return (exc_type == EXC_BREAKPOINT ||
79 ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1));
82 bool GetStopInfo(ThreadStopInfo *stop_info, const UnixSignals &signals,
83 Stream &stream) const;
88 MachMessage reply_msg;
92 memset(&exc_msg, 0, sizeof(exc_msg));
93 memset(&reply_msg, 0, sizeof(reply_msg));
96 bool CatchExceptionRaise(task_t task);
98 Status Reply(::pid_t inferior_pid, task_t inferior_task, int signal);
100 Status Receive(mach_port_t receive_port, mach_msg_option_t options,
101 mach_msg_timeout_t timeout,
102 mach_port_t notify_port = MACH_PORT_NULL);
104 void Dump(Stream &stream) const;
106 typedef std::vector<Message> collection;
107 typedef collection::iterator iterator;
108 typedef collection::const_iterator const_iterator;
112 e_actionForward, // Forward signal to inferior process
113 e_actionStop, // Stop when this signal is received
116 task_t task_port; // Set to TASK_NULL for any TASK
117 thread_t thread_port; // Set to THREAD_NULL for any thread
118 exception_type_t exc_mask; // Mach exception mask to watch for
119 std::vector<mach_exception_data_type_t> exc_data_mask; // Mask to apply to
120 // exception data, or
122 // exc_data value for
124 std::vector<mach_exception_data_type_t> exc_data_value; // Value to compare
130 uint8_t flags; // Action flags describing what to do with the exception
133 static const char *Name(exception_type_t exc_type);
136 } // namespace process_darwin
137 } // namespace lldb_private