1*80814287SRaphael Isemann //===-- State.cpp ---------------------------------------------------------===// 2d821c997SPavel Labath // 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 6d821c997SPavel Labath // 7d821c997SPavel Labath //===----------------------------------------------------------------------===// 8d821c997SPavel Labath 9d821c997SPavel Labath #include "lldb/Utility/State.h" 10d821c997SPavel Labath 11d821c997SPavel Labath using namespace lldb; 12d821c997SPavel Labath using namespace lldb_private; 13d821c997SPavel Labath StateAsCString(StateType state)14d821c997SPavel Labathconst char *lldb_private::StateAsCString(StateType state) { 15d821c997SPavel Labath switch (state) { 16d821c997SPavel Labath case eStateInvalid: 17d821c997SPavel Labath return "invalid"; 18d821c997SPavel Labath case eStateUnloaded: 19d821c997SPavel Labath return "unloaded"; 20d821c997SPavel Labath case eStateConnected: 21d821c997SPavel Labath return "connected"; 22d821c997SPavel Labath case eStateAttaching: 23d821c997SPavel Labath return "attaching"; 24d821c997SPavel Labath case eStateLaunching: 25d821c997SPavel Labath return "launching"; 26d821c997SPavel Labath case eStateStopped: 27d821c997SPavel Labath return "stopped"; 28d821c997SPavel Labath case eStateRunning: 29d821c997SPavel Labath return "running"; 30d821c997SPavel Labath case eStateStepping: 31d821c997SPavel Labath return "stepping"; 32d821c997SPavel Labath case eStateCrashed: 33d821c997SPavel Labath return "crashed"; 34d821c997SPavel Labath case eStateDetached: 35d821c997SPavel Labath return "detached"; 36d821c997SPavel Labath case eStateExited: 37d821c997SPavel Labath return "exited"; 38d821c997SPavel Labath case eStateSuspended: 39d821c997SPavel Labath return "suspended"; 40d821c997SPavel Labath } 41d821c997SPavel Labath return "unknown"; 42d821c997SPavel Labath } 43d821c997SPavel Labath GetPermissionsAsCString(uint32_t permissions)44d821c997SPavel Labathconst char *lldb_private::GetPermissionsAsCString(uint32_t permissions) { 45d821c997SPavel Labath switch (permissions) { 46d821c997SPavel Labath case 0: 47d821c997SPavel Labath return "---"; 48d821c997SPavel Labath case ePermissionsWritable: 49d821c997SPavel Labath return "-w-"; 50d821c997SPavel Labath case ePermissionsReadable: 51d821c997SPavel Labath return "r--"; 52d821c997SPavel Labath case ePermissionsExecutable: 53d821c997SPavel Labath return "--x"; 54d821c997SPavel Labath case ePermissionsReadable | ePermissionsWritable: 55d821c997SPavel Labath return "rw-"; 56d821c997SPavel Labath case ePermissionsReadable | ePermissionsExecutable: 57d821c997SPavel Labath return "r-x"; 58d821c997SPavel Labath case ePermissionsWritable | ePermissionsExecutable: 59d821c997SPavel Labath return "-wx"; 60d821c997SPavel Labath case ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable: 61d821c997SPavel Labath return "rwx"; 62d821c997SPavel Labath default: 63d821c997SPavel Labath break; 64d821c997SPavel Labath } 65d821c997SPavel Labath return "???"; 66d821c997SPavel Labath } 67d821c997SPavel Labath StateIsRunningState(StateType state)68d821c997SPavel Labathbool lldb_private::StateIsRunningState(StateType state) { 69d821c997SPavel Labath switch (state) { 70d821c997SPavel Labath case eStateAttaching: 71d821c997SPavel Labath case eStateLaunching: 72d821c997SPavel Labath case eStateRunning: 73d821c997SPavel Labath case eStateStepping: 74d821c997SPavel Labath return true; 75d821c997SPavel Labath 76d821c997SPavel Labath case eStateConnected: 77d821c997SPavel Labath case eStateDetached: 78d821c997SPavel Labath case eStateInvalid: 79d821c997SPavel Labath case eStateUnloaded: 80d821c997SPavel Labath case eStateStopped: 81d821c997SPavel Labath case eStateCrashed: 82d821c997SPavel Labath case eStateExited: 83d821c997SPavel Labath case eStateSuspended: 84d821c997SPavel Labath break; 85d821c997SPavel Labath } 86d821c997SPavel Labath return false; 87d821c997SPavel Labath } 88d821c997SPavel Labath StateIsStoppedState(StateType state,bool must_exist)89d821c997SPavel Labathbool lldb_private::StateIsStoppedState(StateType state, bool must_exist) { 90d821c997SPavel Labath switch (state) { 91d821c997SPavel Labath case eStateInvalid: 92d821c997SPavel Labath case eStateConnected: 93d821c997SPavel Labath case eStateAttaching: 94d821c997SPavel Labath case eStateLaunching: 95d821c997SPavel Labath case eStateRunning: 96d821c997SPavel Labath case eStateStepping: 97d821c997SPavel Labath case eStateDetached: 98d821c997SPavel Labath break; 99d821c997SPavel Labath 100d821c997SPavel Labath case eStateUnloaded: 101d821c997SPavel Labath case eStateExited: 102d821c997SPavel Labath return !must_exist; 103d821c997SPavel Labath 104d821c997SPavel Labath case eStateStopped: 105d821c997SPavel Labath case eStateCrashed: 106d821c997SPavel Labath case eStateSuspended: 107d821c997SPavel Labath return true; 108d821c997SPavel Labath } 109d821c997SPavel Labath return false; 110d821c997SPavel Labath } 111