1 //===-- ProcessMessage.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessMessage_H_
11 #define liblldb_ProcessMessage_H_
13 #include "CrashReason.h"
18 #include "lldb/lldb-defines.h"
19 #include "lldb/lldb-types.h"
21 class ProcessMessage {
23 /// The type of signal this message can correspond to.
30 eSignalDeliveredMessage,
40 : m_tid(LLDB_INVALID_PROCESS_ID), m_kind(eInvalidMessage),
41 m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0),
44 Kind GetKind() const { return m_kind; }
46 lldb::tid_t GetTID() const { return m_tid; }
48 /// Indicates that the process @p pid has successfully attached.
49 static ProcessMessage Attach(lldb::pid_t pid) {
50 return ProcessMessage(pid, eAttachMessage);
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);
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);
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);
69 /// Indicates that the thread @p tid encountered a trace point.
70 static ProcessMessage Trace(lldb::tid_t tid) {
71 return ProcessMessage(tid, eTraceMessage);
74 /// Indicates that the thread @p tid encountered a break point.
75 static ProcessMessage Break(lldb::tid_t tid) {
76 return ProcessMessage(tid, eBreakpointMessage);
79 static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) {
80 return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr);
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;
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);
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);
102 /// Indicates that the thread @p pid has exec'd.
103 static ProcessMessage Exec(lldb::tid_t tid) {
104 return ProcessMessage(tid, eExecMessage);
107 int GetExitStatus() const {
108 assert(GetKind() == eExitMessage || GetKind() == eLimboMessage);
112 int GetSignal() const {
113 assert(GetKind() == eSignalMessage || GetKind() == eCrashMessage ||
114 GetKind() == eSignalDeliveredMessage);
118 int GetStopStatus() const {
119 assert(GetKind() == eSignalMessage);
123 CrashReason GetCrashReason() const {
124 assert(GetKind() == eCrashMessage);
125 return m_crash_reason;
128 lldb::addr_t GetFaultAddress() const {
129 assert(GetKind() == eCrashMessage);
133 lldb::addr_t GetHWAddress() const {
134 assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage);
138 lldb::tid_t GetChildTID() const {
139 assert(GetKind() == eNewThreadMessage);
143 const char *PrintCrashReason() const;
145 const char *PrintKind() const;
147 static const char *PrintKind(Kind);
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) {}
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) {}
163 CrashReason m_crash_reason;
166 lldb::tid_t m_child_tid;
169 #endif // #ifndef liblldb_ProcessMessage_H_