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 LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHEXCEPTION_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHEXCEPTION_H
16 #include <mach/mach.h>
22 typedef union MachMessageTag
{
23 mach_msg_header_t hdr
;
30 exception_mask_t mask
; // the exception mask for this device which may be a
31 // subset of EXC_MASK_ALL...
32 exception_mask_t masks
[EXC_TYPES_COUNT
];
33 mach_port_t ports
[EXC_TYPES_COUNT
];
34 exception_behavior_t behaviors
[EXC_TYPES_COUNT
];
35 thread_state_flavor_t flavors
[EXC_TYPES_COUNT
];
36 mach_msg_type_number_t count
;
38 kern_return_t
Save(task_t task
);
39 kern_return_t
Restore(task_t task
);
45 exception_type_t exc_type
;
46 std::vector
<mach_exception_data_type_t
> exc_data
;
48 : task_port(TASK_NULL
), thread_port(THREAD_NULL
), exc_type(0),
52 task_port
= TASK_NULL
;
53 thread_port
= THREAD_NULL
;
57 bool IsValid() const {
58 return task_port
!= TASK_NULL
&& thread_port
!= THREAD_NULL
&&
61 // Return the SoftSignal for this MachException data, or zero if there is
63 int SoftSignal() const {
64 if (exc_type
== EXC_SOFTWARE
&& exc_data
.size() == 2 &&
65 exc_data
[0] == EXC_SOFT_SIGNAL
)
66 return static_cast<int>(exc_data
[1]);
69 bool IsBreakpoint() const {
70 return (exc_type
== EXC_BREAKPOINT
||
71 ((exc_type
== EXC_SOFTWARE
) && exc_data
[0] == 1));
73 void AppendExceptionData(mach_exception_data_t Data
,
74 mach_msg_type_number_t Count
) {
75 mach_exception_data_type_t Buf
;
76 for (mach_msg_type_number_t i
= 0; i
< Count
; ++i
) {
77 // Perform an unaligned copy.
78 memcpy(&Buf
, Data
+ i
, sizeof(mach_exception_data_type_t
));
79 exc_data
.push_back(Buf
);
83 void DumpStopReason() const;
84 bool GetStopInfo(struct DNBThreadStopInfo
*stop_info
) const;
89 MachMessage reply_msg
;
93 memset(&exc_msg
, 0, sizeof(exc_msg
));
94 memset(&reply_msg
, 0, sizeof(reply_msg
));
96 bool CatchExceptionRaise(task_t task
);
98 kern_return_t
Reply(MachProcess
*process
, int signal
);
99 kern_return_t
Receive(mach_port_t receive_port
, mach_msg_option_t options
,
100 mach_msg_timeout_t timeout
,
101 mach_port_t notify_port
= MACH_PORT_NULL
);
103 typedef std::vector
<Message
> collection
;
104 typedef collection::iterator iterator
;
105 typedef collection::const_iterator const_iterator
;
109 e_actionForward
, // Forward signal to inferior process
110 e_actionStop
, // Stop when this signal is received
113 task_t task_port
; // Set to TASK_NULL for any TASK
114 thread_t thread_port
; // Set to THREAD_NULL for any thread
115 exception_type_t exc_mask
; // Mach exception mask to watch for
116 std::vector
<mach_exception_data_type_t
> exc_data_mask
; // Mask to apply to
117 // exception data, or
119 // exc_data value for
121 std::vector
<mach_exception_data_type_t
> exc_data_value
; // Value to compare
127 uint8_t flags
; // Action flags describing what to do with the exception
129 static const char *Name(exception_type_t exc_type
);