blob: f932e9fff278997906f5850fc7b26f1eb4f45765 [file] [log] [blame]
Johnny Chen9ed5b492012-01-05 21:48:15 +00001//===-- 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 Lin28e57422015-02-03 01:51:25 +000013#include "CrashReason.h"
14
Johnny Chen9ed5b492012-01-05 21:48:15 +000015#include <cassert>
Chaoren Lin28e57422015-02-03 01:51:25 +000016#include <string>
Johnny Chen9ed5b492012-01-05 21:48:15 +000017
18#include "lldb/lldb-defines.h"
19#include "lldb/lldb-types.h"
20
21class ProcessMessage
22{
23public:
24
25 /// The type of signal this message can correspond to.
26 enum Kind
27 {
28 eInvalidMessage,
Ed Mastee5441432013-09-03 23:55:30 +000029 eAttachMessage,
Johnny Chen9ed5b492012-01-05 21:48:15 +000030 eExitMessage,
31 eLimboMessage,
32 eSignalMessage,
33 eSignalDeliveredMessage,
34 eTraceMessage,
35 eBreakpointMessage,
Matt Kopece9ea0da2013-05-07 19:29:28 +000036 eWatchpointMessage,
Matt Kopec650648f2013-01-08 16:30:18 +000037 eCrashMessage,
Matt Kopec718be872013-10-09 19:39:55 +000038 eNewThreadMessage,
39 eExecMessage
Johnny Chen9ed5b492012-01-05 21:48:15 +000040 };
41
Johnny Chen9ed5b492012-01-05 21:48:15 +000042 ProcessMessage()
43 : m_tid(LLDB_INVALID_PROCESS_ID),
44 m_kind(eInvalidMessage),
Chaoren Lin28e57422015-02-03 01:51:25 +000045 m_crash_reason(CrashReason::eInvalidCrashReason),
Johnny Chen9ed5b492012-01-05 21:48:15 +000046 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 Mastee5441432013-09-03 23:55:30 +000053 /// 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 Chen9ed5b492012-01-05 21:48:15 +000058 /// 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 Kopece9ea0da2013-05-07 19:29:28 +000084 static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) {
85 return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr);
86 }
87
Johnny Chen9ed5b492012-01-05 21:48:15 +000088 /// 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 Kaylor93132f52013-05-28 23:04:25 +000096 /// Indicates that the thread @p child_tid was spawned.
Matt Kopec650648f2013-01-08 16:30:18 +000097 static ProcessMessage NewThread(lldb::tid_t parent_tid, lldb::tid_t child_tid) {
98 return ProcessMessage(parent_tid, eNewThreadMessage, child_tid);
99 }
100
Andrew Kaylor93132f52013-05-28 23:04:25 +0000101 /// 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 Kopec718be872013-10-09 19:39:55 +0000106 /// 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 Chen9ed5b492012-01-05 21:48:15 +0000111 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 Kopece9ea0da2013-05-07 19:29:28 +0000137 lldb::addr_t GetHWAddress() const {
Matt Kopec52c84762013-05-08 16:52:34 +0000138 assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage);
Matt Kopece9ea0da2013-05-07 19:29:28 +0000139 return m_addr;
140 }
141
Matt Kopec650648f2013-01-08 16:30:18 +0000142 lldb::tid_t GetChildTID() const {
143 assert(GetKind() == eNewThreadMessage);
144 return m_child_tid;
145 }
146
Johnny Chen9ed5b492012-01-05 21:48:15 +0000147 const char *
148 PrintCrashReason() const;
149
Johnny Chen9ed5b492012-01-05 21:48:15 +0000150 const char *
151 PrintKind() const;
152
153 static const char *
154 PrintKind(Kind);
155
156private:
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 Lin28e57422015-02-03 01:51:25 +0000161 m_crash_reason(CrashReason::eInvalidCrashReason),
Johnny Chen9ed5b492012-01-05 21:48:15 +0000162 m_status(status),
Matt Kopec650648f2013-01-08 16:30:18 +0000163 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 Lin28e57422015-02-03 01:51:25 +0000169 m_crash_reason(CrashReason::eInvalidCrashReason),
Matt Kopec650648f2013-01-08 16:30:18 +0000170 m_status(0),
171 m_addr(0),
172 m_child_tid(child_tid) { }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000173
174 lldb::tid_t m_tid;
175 Kind m_kind : 8;
Chaoren Lin28e57422015-02-03 01:51:25 +0000176 CrashReason m_crash_reason;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000177 int m_status;
178 lldb::addr_t m_addr;
Matt Kopec650648f2013-01-08 16:30:18 +0000179 lldb::tid_t m_child_tid;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000180};
181
182#endif // #ifndef liblldb_ProcessMessage_H_