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