1 //===-- ProcessMessage.h ----------------------------------------*- C++ -*-===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ProcessMessage_H_
10 #define liblldb_ProcessMessage_H_
12 #include "CrashReason.h"
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-types.h"
20 class ProcessMessage {
22 /// The type of signal this message can correspond to.
29 eSignalDeliveredMessage,
39 : m_tid(LLDB_INVALID_PROCESS_ID), m_kind(eInvalidMessage),
40 m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0),
43 Kind GetKind() const { return m_kind; }
45 lldb::tid_t GetTID() const { return m_tid; }
47 /// Indicates that the process \p pid has successfully attached.
48 static ProcessMessage Attach(lldb::pid_t pid) {
49 return ProcessMessage(pid, eAttachMessage);
52 /// 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);
57 /// 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);
62 /// 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);
68 /// Indicates that the thread \p tid encountered a trace point.
69 static ProcessMessage Trace(lldb::tid_t tid) {
70 return ProcessMessage(tid, eTraceMessage);
73 /// Indicates that the thread \p tid encountered a break point.
74 static ProcessMessage Break(lldb::tid_t tid) {
75 return ProcessMessage(tid, eBreakpointMessage);
78 static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) {
79 return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr);
82 /// 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;
90 /// 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);
96 /// 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);
101 /// Indicates that the thread \p pid has exec'd.
102 static ProcessMessage Exec(lldb::tid_t tid) {
103 return ProcessMessage(tid, eExecMessage);
106 int GetExitStatus() const {
107 assert(GetKind() == eExitMessage || GetKind() == eLimboMessage);
111 int GetSignal() const {
112 assert(GetKind() == eSignalMessage || GetKind() == eCrashMessage ||
113 GetKind() == eSignalDeliveredMessage);
117 int GetStopStatus() const {
118 assert(GetKind() == eSignalMessage);
122 CrashReason GetCrashReason() const {
123 assert(GetKind() == eCrashMessage);
124 return m_crash_reason;
127 lldb::addr_t GetFaultAddress() const {
128 assert(GetKind() == eCrashMessage);
132 lldb::addr_t GetHWAddress() const {
133 assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage);
137 lldb::tid_t GetChildTID() const {
138 assert(GetKind() == eNewThreadMessage);
142 const char *PrintCrashReason() const;
144 const char *PrintKind() const;
146 static const char *PrintKind(Kind);
149 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) {}
155 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) {}
162 CrashReason m_crash_reason;
165 lldb::tid_t m_child_tid;
168 #endif // #ifndef liblldb_ProcessMessage_H_