Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 1 | //===-- MachException.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Created by Greg Clayton on 6/18/07. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 14 | #ifndef __MachException_h__ |
| 15 | #define __MachException_h__ |
| 16 | |
| 17 | #include <mach/mach.h> |
| 18 | #include <vector> |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 20 | #include "lldb/Host/Debug.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 21 | #include "lldb/lldb-private-forward.h" |
| 22 | #include "lldb/lldb-types.h" |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 23 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 24 | namespace lldb_private { |
| 25 | namespace process_darwin { |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 27 | typedef union MachMessageTag { |
| 28 | mach_msg_header_t hdr; |
| 29 | char data[1024]; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 30 | } MachMessage; |
| 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 32 | class MachException { |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 33 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 34 | struct PortInfo { |
| 35 | exception_mask_t mask; // the exception mask for this device which may be a |
| 36 | // subset of EXC_MASK_ALL... |
| 37 | exception_mask_t masks[EXC_TYPES_COUNT]; |
| 38 | mach_port_t ports[EXC_TYPES_COUNT]; |
| 39 | exception_behavior_t behaviors[EXC_TYPES_COUNT]; |
| 40 | thread_state_flavor_t flavors[EXC_TYPES_COUNT]; |
| 41 | mach_msg_type_number_t count; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 43 | Error Save(task_t task); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 45 | Error Restore(task_t task); |
| 46 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 48 | struct Data { |
| 49 | task_t task_port; |
| 50 | thread_t thread_port; |
| 51 | exception_type_t exc_type; |
| 52 | std::vector<mach_exception_data_type_t> exc_data; |
| 53 | Data() |
| 54 | : task_port(TASK_NULL), thread_port(THREAD_NULL), exc_type(0), |
| 55 | exc_data() {} |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 57 | void Clear() { |
| 58 | task_port = TASK_NULL; |
| 59 | thread_port = THREAD_NULL; |
| 60 | exc_type = 0; |
| 61 | exc_data.clear(); |
| 62 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 64 | bool IsValid() const { |
| 65 | return task_port != TASK_NULL && thread_port != THREAD_NULL && |
| 66 | exc_type != 0; |
| 67 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 69 | // Return the SoftSignal for this MachException data, or zero if there is |
| 70 | // none |
| 71 | int SoftSignal() const { |
| 72 | if (exc_type == EXC_SOFTWARE && exc_data.size() == 2 && |
| 73 | exc_data[0] == EXC_SOFT_SIGNAL) |
| 74 | return static_cast<int>(exc_data[1]); |
| 75 | return 0; |
| 76 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 78 | bool IsBreakpoint() const { |
| 79 | return (exc_type == EXC_BREAKPOINT || |
| 80 | ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1)); |
| 81 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 82 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 83 | bool GetStopInfo(ThreadStopInfo *stop_info, const UnixSignals &signals, |
| 84 | Stream &stream) const; |
| 85 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 86 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 87 | struct Message { |
| 88 | MachMessage exc_msg; |
| 89 | MachMessage reply_msg; |
| 90 | Data state; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 92 | Message() : state() { |
| 93 | memset(&exc_msg, 0, sizeof(exc_msg)); |
| 94 | memset(&reply_msg, 0, sizeof(reply_msg)); |
| 95 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 96 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 97 | bool CatchExceptionRaise(task_t task); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 99 | Error Reply(::pid_t inferior_pid, task_t inferior_task, int signal); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 101 | Error Receive(mach_port_t receive_port, mach_msg_option_t options, |
| 102 | mach_msg_timeout_t timeout, |
| 103 | mach_port_t notify_port = MACH_PORT_NULL); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 105 | void Dump(Stream &stream) const; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 107 | typedef std::vector<Message> collection; |
| 108 | typedef collection::iterator iterator; |
| 109 | typedef collection::const_iterator const_iterator; |
| 110 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 112 | enum { |
| 113 | e_actionForward, // Forward signal to inferior process |
| 114 | e_actionStop, // Stop when this signal is received |
| 115 | }; |
| 116 | struct Action { |
| 117 | task_t task_port; // Set to TASK_NULL for any TASK |
| 118 | thread_t thread_port; // Set to THREAD_NULL for any thread |
| 119 | exception_type_t exc_mask; // Mach exception mask to watch for |
| 120 | std::vector<mach_exception_data_type_t> exc_data_mask; // Mask to apply to |
| 121 | // exception data, or |
| 122 | // empty to ignore |
| 123 | // exc_data value for |
| 124 | // exception |
| 125 | std::vector<mach_exception_data_type_t> exc_data_value; // Value to compare |
| 126 | // to exception data |
| 127 | // after masking, or |
| 128 | // empty to ignore |
| 129 | // exc_data value |
| 130 | // for exception |
| 131 | uint8_t flags; // Action flags describing what to do with the exception |
| 132 | }; |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 134 | static const char *Name(exception_type_t exc_type); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // namespace process_darwin |
| 138 | } // namespace lldb_private |
| 139 | |
| 140 | #endif |