xref: /src/contrib/llvm-project/lldb/source/Utility/State.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1cfca06d7SDimitry Andric //===-- State.cpp ---------------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
994994d37SDimitry Andric #include "lldb/Utility/State.h"
10f034231aSEd Maste 
11f034231aSEd Maste using namespace lldb;
12f034231aSEd Maste using namespace lldb_private;
13f034231aSEd Maste 
StateAsCString(StateType state)1414f1b3e8SDimitry Andric const char *lldb_private::StateAsCString(StateType state) {
1514f1b3e8SDimitry Andric   switch (state) {
1614f1b3e8SDimitry Andric   case eStateInvalid:
1714f1b3e8SDimitry Andric     return "invalid";
1814f1b3e8SDimitry Andric   case eStateUnloaded:
1914f1b3e8SDimitry Andric     return "unloaded";
2014f1b3e8SDimitry Andric   case eStateConnected:
2114f1b3e8SDimitry Andric     return "connected";
2214f1b3e8SDimitry Andric   case eStateAttaching:
2314f1b3e8SDimitry Andric     return "attaching";
2414f1b3e8SDimitry Andric   case eStateLaunching:
2514f1b3e8SDimitry Andric     return "launching";
2614f1b3e8SDimitry Andric   case eStateStopped:
2714f1b3e8SDimitry Andric     return "stopped";
2814f1b3e8SDimitry Andric   case eStateRunning:
2914f1b3e8SDimitry Andric     return "running";
3014f1b3e8SDimitry Andric   case eStateStepping:
3114f1b3e8SDimitry Andric     return "stepping";
3214f1b3e8SDimitry Andric   case eStateCrashed:
3314f1b3e8SDimitry Andric     return "crashed";
3414f1b3e8SDimitry Andric   case eStateDetached:
3514f1b3e8SDimitry Andric     return "detached";
3614f1b3e8SDimitry Andric   case eStateExited:
3714f1b3e8SDimitry Andric     return "exited";
3814f1b3e8SDimitry Andric   case eStateSuspended:
3914f1b3e8SDimitry Andric     return "suspended";
40f034231aSEd Maste   }
4174a628f7SDimitry Andric   return "unknown";
42f034231aSEd Maste }
43f034231aSEd Maste 
GetPermissionsAsCString(uint32_t permissions)4414f1b3e8SDimitry Andric const char *lldb_private::GetPermissionsAsCString(uint32_t permissions) {
4514f1b3e8SDimitry Andric   switch (permissions) {
4614f1b3e8SDimitry Andric   case 0:
4714f1b3e8SDimitry Andric     return "---";
4814f1b3e8SDimitry Andric   case ePermissionsWritable:
4914f1b3e8SDimitry Andric     return "-w-";
5014f1b3e8SDimitry Andric   case ePermissionsReadable:
5114f1b3e8SDimitry Andric     return "r--";
5214f1b3e8SDimitry Andric   case ePermissionsExecutable:
5314f1b3e8SDimitry Andric     return "--x";
5414f1b3e8SDimitry Andric   case ePermissionsReadable | ePermissionsWritable:
5514f1b3e8SDimitry Andric     return "rw-";
5614f1b3e8SDimitry Andric   case ePermissionsReadable | ePermissionsExecutable:
5714f1b3e8SDimitry Andric     return "r-x";
5814f1b3e8SDimitry Andric   case ePermissionsWritable | ePermissionsExecutable:
5914f1b3e8SDimitry Andric     return "-wx";
6014f1b3e8SDimitry Andric   case ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable:
6114f1b3e8SDimitry Andric     return "rwx";
62f034231aSEd Maste   default:
63f034231aSEd Maste     break;
64f034231aSEd Maste   }
65f034231aSEd Maste   return "???";
66f034231aSEd Maste }
67f034231aSEd Maste 
StateIsRunningState(StateType state)6814f1b3e8SDimitry Andric bool lldb_private::StateIsRunningState(StateType state) {
6914f1b3e8SDimitry Andric   switch (state) {
70f034231aSEd Maste   case eStateAttaching:
71f034231aSEd Maste   case eStateLaunching:
72f034231aSEd Maste   case eStateRunning:
73f034231aSEd Maste   case eStateStepping:
74f034231aSEd Maste     return true;
75f034231aSEd Maste 
76f034231aSEd Maste   case eStateConnected:
77f034231aSEd Maste   case eStateDetached:
78f034231aSEd Maste   case eStateInvalid:
79f034231aSEd Maste   case eStateUnloaded:
80f034231aSEd Maste   case eStateStopped:
81f034231aSEd Maste   case eStateCrashed:
82f034231aSEd Maste   case eStateExited:
83f034231aSEd Maste   case eStateSuspended:
84f034231aSEd Maste     break;
85f034231aSEd Maste   }
86f034231aSEd Maste   return false;
87f034231aSEd Maste }
88f034231aSEd Maste 
StateIsStoppedState(StateType state,bool must_exist)8914f1b3e8SDimitry Andric bool lldb_private::StateIsStoppedState(StateType state, bool must_exist) {
9014f1b3e8SDimitry Andric   switch (state) {
91f034231aSEd Maste   case eStateInvalid:
92f034231aSEd Maste   case eStateConnected:
93f034231aSEd Maste   case eStateAttaching:
94f034231aSEd Maste   case eStateLaunching:
95f034231aSEd Maste   case eStateRunning:
96f034231aSEd Maste   case eStateStepping:
97f034231aSEd Maste   case eStateDetached:
98f034231aSEd Maste     break;
99f034231aSEd Maste 
100f034231aSEd Maste   case eStateUnloaded:
101f034231aSEd Maste   case eStateExited:
102f034231aSEd Maste     return !must_exist;
103f034231aSEd Maste 
104f034231aSEd Maste   case eStateStopped:
105f034231aSEd Maste   case eStateCrashed:
106f034231aSEd Maste   case eStateSuspended:
107f034231aSEd Maste     return true;
108f034231aSEd Maste   }
109f034231aSEd Maste   return false;
110f034231aSEd Maste }
111