blob: c3d8e95a6c4318cb19fc78a2783de4dbe44bf85a [file] [log] [blame]
Johnny Chen9ed5b492012-01-05 21:48:15 +00001//===-- ProcessMessage.h ----------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Johnny Chen9ed5b492012-01-05 21:48:15 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_ProcessMessage_H_
10#define liblldb_ProcessMessage_H_
11
Chaoren Lin28e57422015-02-03 01:51:25 +000012#include "CrashReason.h"
13
Johnny Chen9ed5b492012-01-05 21:48:15 +000014#include <cassert>
Chaoren Lin28e57422015-02-03 01:51:25 +000015#include <string>
Johnny Chen9ed5b492012-01-05 21:48:15 +000016
17#include "lldb/lldb-defines.h"
18#include "lldb/lldb-types.h"
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020class ProcessMessage {
Johnny Chen9ed5b492012-01-05 21:48:15 +000021public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000022 /// The type of signal this message can correspond to.
23 enum Kind {
24 eInvalidMessage,
25 eAttachMessage,
26 eExitMessage,
27 eLimboMessage,
28 eSignalMessage,
29 eSignalDeliveredMessage,
30 eTraceMessage,
31 eBreakpointMessage,
32 eWatchpointMessage,
33 eCrashMessage,
34 eNewThreadMessage,
35 eExecMessage
36 };
Johnny Chen9ed5b492012-01-05 21:48:15 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 ProcessMessage()
39 : m_tid(LLDB_INVALID_PROCESS_ID), m_kind(eInvalidMessage),
40 m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0),
41 m_addr(0) {}
Johnny Chen9ed5b492012-01-05 21:48:15 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 Kind GetKind() const { return m_kind; }
Johnny Chen9ed5b492012-01-05 21:48:15 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 lldb::tid_t GetTID() const { return m_tid; }
Johnny Chen9ed5b492012-01-05 21:48:15 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 /// Indicates that the process @p pid has successfully attached.
48 static ProcessMessage Attach(lldb::pid_t pid) {
49 return ProcessMessage(pid, eAttachMessage);
50 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 /// Indicates that the thread @p tid is about to exit with status @p status.
53 static ProcessMessage Limbo(lldb::tid_t tid, int status) {
54 return ProcessMessage(tid, eLimboMessage, status);
55 }
Ed Mastee5441432013-09-03 23:55:30 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 /// Indicates that the thread @p tid had the signal @p signum delivered.
58 static ProcessMessage Signal(lldb::tid_t tid, int signum) {
59 return ProcessMessage(tid, eSignalMessage, signum);
60 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 /// Indicates that a signal @p signum generated by the debugging process was
63 /// delivered to the thread @p tid.
64 static ProcessMessage SignalDelivered(lldb::tid_t tid, int signum) {
65 return ProcessMessage(tid, eSignalDeliveredMessage, signum);
66 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 /// Indicates that the thread @p tid encountered a trace point.
69 static ProcessMessage Trace(lldb::tid_t tid) {
70 return ProcessMessage(tid, eTraceMessage);
71 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 /// Indicates that the thread @p tid encountered a break point.
74 static ProcessMessage Break(lldb::tid_t tid) {
75 return ProcessMessage(tid, eBreakpointMessage);
76 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) {
79 return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr);
80 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 /// Indicates that the thread @p tid crashed.
83 static ProcessMessage Crash(lldb::pid_t pid, CrashReason reason, int signo,
84 lldb::addr_t fault_addr) {
85 ProcessMessage message(pid, eCrashMessage, signo, fault_addr);
86 message.m_crash_reason = reason;
87 return message;
88 }
Matt Kopece9ea0da2013-05-07 19:29:28 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 /// Indicates that the thread @p child_tid was spawned.
91 static ProcessMessage NewThread(lldb::tid_t parent_tid,
92 lldb::tid_t child_tid) {
93 return ProcessMessage(parent_tid, eNewThreadMessage, child_tid);
94 }
Johnny Chen9ed5b492012-01-05 21:48:15 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 /// Indicates that the thread @p tid is about to exit with status @p status.
97 static ProcessMessage Exit(lldb::tid_t tid, int status) {
98 return ProcessMessage(tid, eExitMessage, status);
99 }
Matt Kopec650648f2013-01-08 16:30:18 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 /// Indicates that the thread @p pid has exec'd.
102 static ProcessMessage Exec(lldb::tid_t tid) {
103 return ProcessMessage(tid, eExecMessage);
104 }
Andrew Kaylor93132f52013-05-28 23:04:25 +0000105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 int GetExitStatus() const {
107 assert(GetKind() == eExitMessage || GetKind() == eLimboMessage);
108 return m_status;
109 }
Matt Kopec718be872013-10-09 19:39:55 +0000110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 int GetSignal() const {
112 assert(GetKind() == eSignalMessage || GetKind() == eCrashMessage ||
113 GetKind() == eSignalDeliveredMessage);
114 return m_status;
115 }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 int GetStopStatus() const {
118 assert(GetKind() == eSignalMessage);
119 return m_status;
120 }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 CrashReason GetCrashReason() const {
123 assert(GetKind() == eCrashMessage);
124 return m_crash_reason;
125 }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000126
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127 lldb::addr_t GetFaultAddress() const {
128 assert(GetKind() == eCrashMessage);
129 return m_addr;
130 }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 lldb::addr_t GetHWAddress() const {
133 assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage);
134 return m_addr;
135 }
Johnny Chen9ed5b492012-01-05 21:48:15 +0000136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 lldb::tid_t GetChildTID() const {
138 assert(GetKind() == eNewThreadMessage);
139 return m_child_tid;
140 }
Matt Kopece9ea0da2013-05-07 19:29:28 +0000141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142 const char *PrintCrashReason() const;
Matt Kopec650648f2013-01-08 16:30:18 +0000143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 const char *PrintKind() const;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146 static const char *PrintKind(Kind);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000147
148private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000149 ProcessMessage(lldb::tid_t tid, Kind kind, int status = 0,
150 lldb::addr_t addr = 0)
151 : m_tid(tid), m_kind(kind),
152 m_crash_reason(CrashReason::eInvalidCrashReason), m_status(status),
153 m_addr(addr), m_child_tid(0) {}
Matt Kopec650648f2013-01-08 16:30:18 +0000154
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 ProcessMessage(lldb::tid_t tid, Kind kind, lldb::tid_t child_tid)
156 : m_tid(tid), m_kind(kind),
157 m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0),
158 m_addr(0), m_child_tid(child_tid) {}
Johnny Chen9ed5b492012-01-05 21:48:15 +0000159
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160 lldb::tid_t m_tid;
161 Kind m_kind : 8;
162 CrashReason m_crash_reason;
163 int m_status;
164 lldb::addr_t m_addr;
165 lldb::tid_t m_child_tid;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000166};
167
168#endif // #ifndef liblldb_ProcessMessage_H_