1 //===-- State.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 LLDB_UTILITY_STATE_H 11 #define LLDB_UTILITY_STATE_H 12 13 #include "lldb/lldb-enumerations.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Support/FormatProviders.h" 16 #include "llvm/Support/raw_ostream.h" 17 #include <cstdint> 18 19 namespace lldb_private { 20 21 //------------------------------------------------------------------ 22 /// Converts a StateType to a C string. 23 /// 24 /// @param[in] state 25 /// The StateType object to convert. 26 /// 27 /// @return 28 /// A NULL terminated C string that describes \a state. The 29 /// returned string comes from constant string buffers and does 30 /// not need to be freed. 31 //------------------------------------------------------------------ 32 const char *StateAsCString(lldb::StateType state); 33 34 //------------------------------------------------------------------ 35 /// Check if a state represents a state where the process or thread 36 /// is running. 37 /// 38 /// @param[in] state 39 /// The StateType enumeration value 40 /// 41 /// @return 42 /// \b true if the state represents a process or thread state 43 /// where the process or thread is running, \b false otherwise. 44 //------------------------------------------------------------------ 45 bool StateIsRunningState(lldb::StateType state); 46 47 //------------------------------------------------------------------ 48 /// Check if a state represents a state where the process or thread 49 /// is stopped. Stopped can mean stopped when the process is still 50 /// around, or stopped when the process has exited or doesn't exist 51 /// yet. The \a must_exist argument tells us which of these cases is 52 /// desired. 53 /// 54 /// @param[in] state 55 /// The StateType enumeration value 56 /// 57 /// @param[in] must_exist 58 /// A boolean that indicates the thread must also be alive 59 /// so states like unloaded or exited won't return true. 60 /// 61 /// @return 62 /// \b true if the state represents a process or thread state 63 /// where the process or thread is stopped. If \a must_exist is 64 /// \b true, then the process can't be exited or unloaded, 65 /// otherwise exited and unloaded or other states where the 66 /// process no longer exists are considered to be stopped. 67 //------------------------------------------------------------------ 68 bool StateIsStoppedState(lldb::StateType state, bool must_exist); 69 70 const char *GetPermissionsAsCString(uint32_t permissions); 71 72 } // namespace lldb_private 73 74 namespace llvm { 75 template <> struct format_provider<lldb::StateType> { 76 static void format(const lldb::StateType &state, raw_ostream &Stream, 77 StringRef Style) { 78 Stream << lldb_private::StateAsCString(state); 79 } 80 }; 81 } // namespace llvm 82 83 #endif // LLDB_UTILITY_STATE_H 84