Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 1 | //===-- MachException.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Created by Greg Clayton on 6/18/07. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 13 | #ifndef __MachException_h__ |
| 14 | #define __MachException_h__ |
| 15 | |
| 16 | #include <mach/mach.h> |
| 17 | #include <vector> |
| 18 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Host/Debug.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 20 | #include "lldb/lldb-private-forward.h" |
| 21 | #include "lldb/lldb-types.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | namespace lldb_private { |
| 24 | namespace process_darwin { |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | typedef union MachMessageTag { |
| 27 | mach_msg_header_t hdr; |
| 28 | char data[1024]; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 29 | } MachMessage; |
| 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | class MachException { |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 32 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | struct PortInfo { |
| 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; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 41 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 42 | Status Save(task_t task); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 43 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 44 | Status Restore(task_t task); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | struct Data { |
| 48 | task_t task_port; |
| 49 | thread_t thread_port; |
| 50 | exception_type_t exc_type; |
| 51 | std::vector<mach_exception_data_type_t> exc_data; |
| 52 | Data() |
| 53 | : task_port(TASK_NULL), thread_port(THREAD_NULL), exc_type(0), |
| 54 | exc_data() {} |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | void Clear() { |
| 57 | task_port = TASK_NULL; |
| 58 | thread_port = THREAD_NULL; |
| 59 | exc_type = 0; |
| 60 | exc_data.clear(); |
| 61 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | bool IsValid() const { |
| 64 | return task_port != TASK_NULL && thread_port != THREAD_NULL && |
| 65 | exc_type != 0; |
| 66 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 67 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | // Return the SoftSignal for this MachException data, or zero if there is |
| 69 | // none |
| 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]); |
| 74 | return 0; |
| 75 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | bool IsBreakpoint() const { |
| 78 | return (exc_type == EXC_BREAKPOINT || |
| 79 | ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1)); |
| 80 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | bool GetStopInfo(ThreadStopInfo *stop_info, const UnixSignals &signals, |
| 83 | Stream &stream) const; |
| 84 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | struct Message { |
| 87 | MachMessage exc_msg; |
| 88 | MachMessage reply_msg; |
| 89 | Data state; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 90 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | Message() : state() { |
| 92 | memset(&exc_msg, 0, sizeof(exc_msg)); |
| 93 | memset(&reply_msg, 0, sizeof(reply_msg)); |
| 94 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | bool CatchExceptionRaise(task_t task); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 97 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 98 | Status Reply(::pid_t inferior_pid, task_t inferior_task, int signal); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 99 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 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); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 103 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | void Dump(Stream &stream) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 105 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | typedef std::vector<Message> collection; |
| 107 | typedef collection::iterator iterator; |
| 108 | typedef collection::const_iterator const_iterator; |
| 109 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | enum { |
| 112 | e_actionForward, // Forward signal to inferior process |
| 113 | e_actionStop, // Stop when this signal is received |
| 114 | }; |
| 115 | struct Action { |
| 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 |
| 121 | // empty to ignore |
| 122 | // exc_data value for |
| 123 | // exception |
| 124 | std::vector<mach_exception_data_type_t> exc_data_value; // Value to compare |
| 125 | // to exception data |
| 126 | // after masking, or |
| 127 | // empty to ignore |
| 128 | // exc_data value |
| 129 | // for exception |
| 130 | uint8_t flags; // Action flags describing what to do with the exception |
| 131 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | static const char *Name(exception_type_t exc_type); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace process_darwin |
| 137 | } // namespace lldb_private |
| 138 | |
| 139 | #endif |