19ed5b49cSJohnny Chen //===-- ProcessMessage.h ----------------------------------------*- C++ -*-===// 29ed5b49cSJohnny Chen // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 69ed5b49cSJohnny Chen // 79ed5b49cSJohnny Chen //===----------------------------------------------------------------------===// 89ed5b49cSJohnny Chen 99ed5b49cSJohnny Chen #ifndef liblldb_ProcessMessage_H_ 109ed5b49cSJohnny Chen #define liblldb_ProcessMessage_H_ 119ed5b49cSJohnny Chen 1228e57429SChaoren Lin #include "CrashReason.h" 1328e57429SChaoren Lin 149ed5b49cSJohnny Chen #include <cassert> 1528e57429SChaoren Lin #include <string> 169ed5b49cSJohnny Chen 179ed5b49cSJohnny Chen #include "lldb/lldb-defines.h" 189ed5b49cSJohnny Chen #include "lldb/lldb-types.h" 199ed5b49cSJohnny Chen 20b9c1b51eSKate Stone class ProcessMessage { 219ed5b49cSJohnny Chen public: 229ed5b49cSJohnny Chen /// The type of signal this message can correspond to. 23b9c1b51eSKate Stone enum Kind { 249ed5b49cSJohnny Chen eInvalidMessage, 25e544143fSEd Maste eAttachMessage, 269ed5b49cSJohnny Chen eExitMessage, 279ed5b49cSJohnny Chen eLimboMessage, 289ed5b49cSJohnny Chen eSignalMessage, 299ed5b49cSJohnny Chen eSignalDeliveredMessage, 309ed5b49cSJohnny Chen eTraceMessage, 319ed5b49cSJohnny Chen eBreakpointMessage, 32e9ea0da8SMatt Kopec eWatchpointMessage, 33650648faSMatt Kopec eCrashMessage, 34718be877SMatt Kopec eNewThreadMessage, 35718be877SMatt Kopec eExecMessage 369ed5b49cSJohnny Chen }; 379ed5b49cSJohnny Chen ProcessMessage()389ed5b49cSJohnny Chen ProcessMessage() 39b9c1b51eSKate Stone : m_tid(LLDB_INVALID_PROCESS_ID), m_kind(eInvalidMessage), 40b9c1b51eSKate Stone m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0), 419ed5b49cSJohnny Chen m_addr(0) {} 429ed5b49cSJohnny Chen GetKind()439ed5b49cSJohnny Chen Kind GetKind() const { return m_kind; } 449ed5b49cSJohnny Chen GetTID()459ed5b49cSJohnny Chen lldb::tid_t GetTID() const { return m_tid; } 469ed5b49cSJohnny Chen 47*f05b42e9SAdrian Prantl /// Indicates that the process \p pid has successfully attached. Attach(lldb::pid_t pid)48e544143fSEd Maste static ProcessMessage Attach(lldb::pid_t pid) { 49e544143fSEd Maste return ProcessMessage(pid, eAttachMessage); 50e544143fSEd Maste } 51e544143fSEd Maste 52*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid is about to exit with status \p status. Limbo(lldb::tid_t tid,int status)539ed5b49cSJohnny Chen static ProcessMessage Limbo(lldb::tid_t tid, int status) { 549ed5b49cSJohnny Chen return ProcessMessage(tid, eLimboMessage, status); 559ed5b49cSJohnny Chen } 569ed5b49cSJohnny Chen 57*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid had the signal \p signum delivered. Signal(lldb::tid_t tid,int signum)589ed5b49cSJohnny Chen static ProcessMessage Signal(lldb::tid_t tid, int signum) { 599ed5b49cSJohnny Chen return ProcessMessage(tid, eSignalMessage, signum); 609ed5b49cSJohnny Chen } 619ed5b49cSJohnny Chen 62*f05b42e9SAdrian Prantl /// Indicates that a signal \p signum generated by the debugging process was 63*f05b42e9SAdrian Prantl /// delivered to the thread \p tid. SignalDelivered(lldb::tid_t tid,int signum)649ed5b49cSJohnny Chen static ProcessMessage SignalDelivered(lldb::tid_t tid, int signum) { 659ed5b49cSJohnny Chen return ProcessMessage(tid, eSignalDeliveredMessage, signum); 669ed5b49cSJohnny Chen } 679ed5b49cSJohnny Chen 68*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid encountered a trace point. Trace(lldb::tid_t tid)699ed5b49cSJohnny Chen static ProcessMessage Trace(lldb::tid_t tid) { 709ed5b49cSJohnny Chen return ProcessMessage(tid, eTraceMessage); 719ed5b49cSJohnny Chen } 729ed5b49cSJohnny Chen 73*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid encountered a break point. Break(lldb::tid_t tid)749ed5b49cSJohnny Chen static ProcessMessage Break(lldb::tid_t tid) { 759ed5b49cSJohnny Chen return ProcessMessage(tid, eBreakpointMessage); 769ed5b49cSJohnny Chen } 779ed5b49cSJohnny Chen Watch(lldb::tid_t tid,lldb::addr_t wp_addr)78e9ea0da8SMatt Kopec static ProcessMessage Watch(lldb::tid_t tid, lldb::addr_t wp_addr) { 79e9ea0da8SMatt Kopec return ProcessMessage(tid, eWatchpointMessage, 0, wp_addr); 80e9ea0da8SMatt Kopec } 81e9ea0da8SMatt Kopec 82*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid crashed. Crash(lldb::pid_t pid,CrashReason reason,int signo,lldb::addr_t fault_addr)83b9c1b51eSKate Stone static ProcessMessage Crash(lldb::pid_t pid, CrashReason reason, int signo, 84b9c1b51eSKate Stone lldb::addr_t fault_addr) { 859ed5b49cSJohnny Chen ProcessMessage message(pid, eCrashMessage, signo, fault_addr); 869ed5b49cSJohnny Chen message.m_crash_reason = reason; 879ed5b49cSJohnny Chen return message; 889ed5b49cSJohnny Chen } 899ed5b49cSJohnny Chen 90*f05b42e9SAdrian Prantl /// Indicates that the thread \p child_tid was spawned. NewThread(lldb::tid_t parent_tid,lldb::tid_t child_tid)91b9c1b51eSKate Stone static ProcessMessage NewThread(lldb::tid_t parent_tid, 92b9c1b51eSKate Stone lldb::tid_t child_tid) { 93650648faSMatt Kopec return ProcessMessage(parent_tid, eNewThreadMessage, child_tid); 94650648faSMatt Kopec } 95650648faSMatt Kopec 96*f05b42e9SAdrian Prantl /// Indicates that the thread \p tid is about to exit with status \p status. Exit(lldb::tid_t tid,int status)9793132f50SAndrew Kaylor static ProcessMessage Exit(lldb::tid_t tid, int status) { 9893132f50SAndrew Kaylor return ProcessMessage(tid, eExitMessage, status); 9993132f50SAndrew Kaylor } 10093132f50SAndrew Kaylor 101*f05b42e9SAdrian Prantl /// Indicates that the thread \p pid has exec'd. Exec(lldb::tid_t tid)102718be877SMatt Kopec static ProcessMessage Exec(lldb::tid_t tid) { 103718be877SMatt Kopec return ProcessMessage(tid, eExecMessage); 104718be877SMatt Kopec } 105718be877SMatt Kopec GetExitStatus()1069ed5b49cSJohnny Chen int GetExitStatus() const { 1079ed5b49cSJohnny Chen assert(GetKind() == eExitMessage || GetKind() == eLimboMessage); 1089ed5b49cSJohnny Chen return m_status; 1099ed5b49cSJohnny Chen } 1109ed5b49cSJohnny Chen GetSignal()1119ed5b49cSJohnny Chen int GetSignal() const { 1129ed5b49cSJohnny Chen assert(GetKind() == eSignalMessage || GetKind() == eCrashMessage || 1139ed5b49cSJohnny Chen GetKind() == eSignalDeliveredMessage); 1149ed5b49cSJohnny Chen return m_status; 1159ed5b49cSJohnny Chen } 1169ed5b49cSJohnny Chen GetStopStatus()1179ed5b49cSJohnny Chen int GetStopStatus() const { 1189ed5b49cSJohnny Chen assert(GetKind() == eSignalMessage); 1199ed5b49cSJohnny Chen return m_status; 1209ed5b49cSJohnny Chen } 1219ed5b49cSJohnny Chen GetCrashReason()1229ed5b49cSJohnny Chen CrashReason GetCrashReason() const { 1239ed5b49cSJohnny Chen assert(GetKind() == eCrashMessage); 1249ed5b49cSJohnny Chen return m_crash_reason; 1259ed5b49cSJohnny Chen } 1269ed5b49cSJohnny Chen GetFaultAddress()1279ed5b49cSJohnny Chen lldb::addr_t GetFaultAddress() const { 1289ed5b49cSJohnny Chen assert(GetKind() == eCrashMessage); 1299ed5b49cSJohnny Chen return m_addr; 1309ed5b49cSJohnny Chen } 1319ed5b49cSJohnny Chen GetHWAddress()132e9ea0da8SMatt Kopec lldb::addr_t GetHWAddress() const { 13352c8476aSMatt Kopec assert(GetKind() == eWatchpointMessage || GetKind() == eTraceMessage); 134e9ea0da8SMatt Kopec return m_addr; 135e9ea0da8SMatt Kopec } 136e9ea0da8SMatt Kopec GetChildTID()137650648faSMatt Kopec lldb::tid_t GetChildTID() const { 138650648faSMatt Kopec assert(GetKind() == eNewThreadMessage); 139650648faSMatt Kopec return m_child_tid; 140650648faSMatt Kopec } 141650648faSMatt Kopec 142b9c1b51eSKate Stone const char *PrintCrashReason() const; 1439ed5b49cSJohnny Chen 144b9c1b51eSKate Stone const char *PrintKind() const; 1459ed5b49cSJohnny Chen 146b9c1b51eSKate Stone static const char *PrintKind(Kind); 1479ed5b49cSJohnny Chen 1489ed5b49cSJohnny Chen private: 149b9c1b51eSKate Stone ProcessMessage(lldb::tid_t tid, Kind kind, int status = 0, 150b9c1b51eSKate Stone lldb::addr_t addr = 0) m_tid(tid)151b9c1b51eSKate Stone : m_tid(tid), m_kind(kind), 152b9c1b51eSKate Stone m_crash_reason(CrashReason::eInvalidCrashReason), m_status(status), 153b9c1b51eSKate Stone m_addr(addr), m_child_tid(0) {} 154650648faSMatt Kopec ProcessMessage(lldb::tid_t tid,Kind kind,lldb::tid_t child_tid)155650648faSMatt Kopec ProcessMessage(lldb::tid_t tid, Kind kind, lldb::tid_t child_tid) 156b9c1b51eSKate Stone : m_tid(tid), m_kind(kind), 157b9c1b51eSKate Stone m_crash_reason(CrashReason::eInvalidCrashReason), m_status(0), 158b9c1b51eSKate Stone m_addr(0), m_child_tid(child_tid) {} 1599ed5b49cSJohnny Chen 1609ed5b49cSJohnny Chen lldb::tid_t m_tid; 1619ed5b49cSJohnny Chen Kind m_kind : 8; 16228e57429SChaoren Lin CrashReason m_crash_reason; 1639ed5b49cSJohnny Chen int m_status; 1649ed5b49cSJohnny Chen lldb::addr_t m_addr; 165650648faSMatt Kopec lldb::tid_t m_child_tid; 1669ed5b49cSJohnny Chen }; 1679ed5b49cSJohnny Chen 1689ed5b49cSJohnny Chen #endif // #ifndef liblldb_ProcessMessage_H_ 169