Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 1 | //===-- ProcessMessage.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 | #ifndef liblldb_ProcessMessage_H_ |
| 11 | #define liblldb_ProcessMessage_H_ |
| 12 | |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 13 | #include "CrashReason.h" |
| 14 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 15 | #include <cassert> |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 16 | #include <string> |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 17 | |
| 18 | #include "lldb/lldb-defines.h" |
| 19 | #include "lldb/lldb-types.h" |
| 20 | |
| 21 | class ProcessMessage |
| 22 | { |
| 23 | public: |
| 24 | |
| 25 | /// The type of signal this message can correspond to. |
| 26 | enum Kind |
| 27 | { |
| 28 | eInvalidMessage, |
Ed Maste | e544143 | 2013-09-03 23:55:30 +0000 | [diff] [blame] | 29 | eAttachMessage, |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 30 | eExitMessage, |
| 31 | eLimboMessage, |
| 32 | eSignalMessage, |
| 33 | eSignalDeliveredMessage, |
| 34 | eTraceMessage, |
| 35 | eBreakpointMessage, |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 36 | eWatchpointMessage, |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 37 | eCrashMessage, |
Matt Kopec | 718be87 | 2013-10-09 19:39:55 +0000 | [diff] [blame] | 38 | eNewThreadMessage, |
| 39 | eExecMessage |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 42 | ProcessMessage() |
| 43 | : m_tid(LLDB_INVALID_PROCESS_ID), |
| 44 | m_kind(eInvalidMessage), |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 45 | m_crash_reason(CrashReason::eInvalidCrashReason), |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 46 | m_status(0), |
| 47 | m_addr(0) { } |
| 48 | |
| 49 | Kind GetKind() const { return m_kind; } |
| 50 | |
| 51 | lldb::tid_t GetTID() const { return m_tid; } |
| 52 | |
Ed Maste | e544143 | 2013-09-03 23:55:30 +0000 | [diff] [blame] | 53 | /// Indicates that the process @p pid has successfully attached. |
| 54 | static ProcessMessage Attach(lldb::pid_t pid) { |
| 55 | return ProcessMessage(pid, eAttachMessage); |
| 56 | } |
| 57 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 58 | /// Indicates that the thread @p tid is about to exit with status @p status. |
| 59 | static ProcessMessage Limbo(lldb::tid_t tid, int status) { |
| 60 | return ProcessMessage(tid, eLimboMessage, status); |
| 61 | } |
| 62 | |
| 63 | /// Indicates that the thread @p tid had the signal @p signum delivered. |
| 64 | static ProcessMessage Signal(lldb::tid_t tid, int signum) { |
| 65 | return ProcessMessage(tid, eSignalMessage, signum); |
| 66 | } |
| 67 | |
| 68 | /// Indicates that a signal @p signum generated by the debugging process was |
| 69 | /// delivered to the thread @p tid. |
| 70 | static ProcessMessage SignalDelivered(lldb::tid_t tid, int signum) { |
| 71 | return ProcessMessage(tid, eSignalDeliveredMessage, signum); |
| 72 | } |
| 73 | |
| 74 | /// Indicates that the thread @p tid encountered a trace point. |
| 75 | static ProcessMessage Trace(lldb::tid_t tid) { |
| 76 | return ProcessMessage(tid, eTraceMessage); |
| 77 | } |
| 78 | |
| 79 | /// Indicates that the thread @p tid encountered a break point. |
| 80 | static ProcessMessage Break(lldb::tid_t tid) { |
| 81 | return ProcessMessage(tid, eBreakpointMessage); |
| 82 | } |
| 83 | |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 84 | static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) { |
| 85 | return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr); |
| 86 | } |
| 87 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 88 | /// Indicates that the thread @p tid crashed. |
| 89 | static ProcessMessage Crash(lldb::pid_t pid, CrashReason reason, |
| 90 | int signo, lldb::addr_t fault_addr) { |
| 91 | ProcessMessage message(pid, eCrashMessage, signo, fault_addr); |
| 92 | message.m_crash_reason = reason; |
| 93 | return message; |
| 94 | } |
| 95 | |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 96 | /// Indicates that the thread @p child_tid was spawned. |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 97 | static ProcessMessage NewThread(lldb::tid_t parent_tid, lldb::tid_t child_tid) { |
| 98 | return ProcessMessage(parent_tid, eNewThreadMessage, child_tid); |
| 99 | } |
| 100 | |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 101 | /// Indicates that the thread @p tid is about to exit with status @p status. |
| 102 | static ProcessMessage Exit(lldb::tid_t tid, int status) { |
| 103 | return ProcessMessage(tid, eExitMessage, status); |
| 104 | } |
| 105 | |
Matt Kopec | 718be87 | 2013-10-09 19:39:55 +0000 | [diff] [blame] | 106 | /// Indicates that the thread @p pid has exec'd. |
| 107 | static ProcessMessage Exec(lldb::tid_t tid) { |
| 108 | return ProcessMessage(tid, eExecMessage); |
| 109 | } |
| 110 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 111 | int GetExitStatus() const { |
| 112 | assert(GetKind() == eExitMessage || GetKind() == eLimboMessage); |
| 113 | return m_status; |
| 114 | } |
| 115 | |
| 116 | int GetSignal() const { |
| 117 | assert(GetKind() == eSignalMessage || GetKind() == eCrashMessage || |
| 118 | GetKind() == eSignalDeliveredMessage); |
| 119 | return m_status; |
| 120 | } |
| 121 | |
| 122 | int GetStopStatus() const { |
| 123 | assert(GetKind() == eSignalMessage); |
| 124 | return m_status; |
| 125 | } |
| 126 | |
| 127 | CrashReason GetCrashReason() const { |
| 128 | assert(GetKind() == eCrashMessage); |
| 129 | return m_crash_reason; |
| 130 | } |
| 131 | |
| 132 | lldb::addr_t GetFaultAddress() const { |
| 133 | assert(GetKind() == eCrashMessage); |
| 134 | return m_addr; |
| 135 | } |
| 136 | |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 137 | lldb::addr_t GetHWAddress() const { |
Matt Kopec | 52c8476 | 2013-05-08 16:52:34 +0000 | [diff] [blame] | 138 | assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage); |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 139 | return m_addr; |
| 140 | } |
| 141 | |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 142 | lldb::tid_t GetChildTID() const { |
| 143 | assert(GetKind() == eNewThreadMessage); |
| 144 | return m_child_tid; |
| 145 | } |
| 146 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 147 | const char * |
| 148 | PrintCrashReason() const; |
| 149 | |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 150 | const char * |
| 151 | PrintKind() const; |
| 152 | |
| 153 | static const char * |
| 154 | PrintKind(Kind); |
| 155 | |
| 156 | private: |
| 157 | ProcessMessage(lldb::tid_t tid, Kind kind, |
| 158 | int status = 0, lldb::addr_t addr = 0) |
| 159 | : m_tid(tid), |
| 160 | m_kind(kind), |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 161 | m_crash_reason(CrashReason::eInvalidCrashReason), |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 162 | m_status(status), |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 163 | m_addr(addr), |
| 164 | m_child_tid(0) { } |
| 165 | |
| 166 | ProcessMessage(lldb::tid_t tid, Kind kind, lldb::tid_t child_tid) |
| 167 | : m_tid(tid), |
| 168 | m_kind(kind), |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 169 | m_crash_reason(CrashReason::eInvalidCrashReason), |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 170 | m_status(0), |
| 171 | m_addr(0), |
| 172 | m_child_tid(child_tid) { } |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 173 | |
| 174 | lldb::tid_t m_tid; |
| 175 | Kind m_kind : 8; |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 176 | CrashReason m_crash_reason; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 177 | int m_status; |
| 178 | lldb::addr_t m_addr; |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 179 | lldb::tid_t m_child_tid; |
Johnny Chen | 9ed5b49 | 2012-01-05 21:48:15 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | #endif // #ifndef liblldb_ProcessMessage_H_ |