blob: 80497dd77b87045e6b6846484eaeac3eb8e0161d [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- State.cpp -----------------------------------------------*- 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// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
14#include "lldb/Core/State.h"
Eli Friedman88966972010-06-09 08:50:27 +000015#include <stdio.h>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016
17using namespace lldb;
18using namespace lldb_private;
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020const char *lldb_private::StateAsCString(StateType state) {
21 switch (state) {
22 case eStateInvalid:
23 return "invalid";
24 case eStateUnloaded:
25 return "unloaded";
26 case eStateConnected:
27 return "connected";
28 case eStateAttaching:
29 return "attaching";
30 case eStateLaunching:
31 return "launching";
32 case eStateStopped:
33 return "stopped";
34 case eStateRunning:
35 return "running";
36 case eStateStepping:
37 return "stepping";
38 case eStateCrashed:
39 return "crashed";
40 case eStateDetached:
41 return "detached";
42 case eStateExited:
43 return "exited";
44 case eStateSuspended:
45 return "suspended";
46 }
47 static char unknown_state_string[64];
48 snprintf(unknown_state_string, sizeof(unknown_state_string), "StateType = %i",
49 state);
50 return unknown_state_string;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053const char *lldb_private::GetPermissionsAsCString(uint32_t permissions) {
54 switch (permissions) {
55 case 0:
56 return "---";
57 case ePermissionsWritable:
58 return "-w-";
59 case ePermissionsReadable:
60 return "r--";
61 case ePermissionsExecutable:
62 return "--x";
63 case ePermissionsReadable | ePermissionsWritable:
64 return "rw-";
65 case ePermissionsReadable | ePermissionsExecutable:
66 return "r-x";
67 case ePermissionsWritable | ePermissionsExecutable:
68 return "-wx";
69 case ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable:
70 return "rwx";
71 default:
72 break;
73 }
74 return "???";
Greg Claytond495c532011-05-17 03:37:42 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077bool lldb_private::StateIsRunningState(StateType state) {
78 switch (state) {
79 case eStateAttaching:
80 case eStateLaunching:
81 case eStateRunning:
82 case eStateStepping:
83 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 case eStateConnected:
86 case eStateDetached:
87 case eStateInvalid:
88 case eStateUnloaded:
89 case eStateStopped:
90 case eStateCrashed:
91 case eStateExited:
92 case eStateSuspended:
93 break;
94 }
95 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096}
97
Kate Stoneb9c1b512016-09-06 20:57:50 +000098bool lldb_private::StateIsStoppedState(StateType state, bool must_exist) {
99 switch (state) {
100 case eStateInvalid:
101 case eStateConnected:
102 case eStateAttaching:
103 case eStateLaunching:
104 case eStateRunning:
105 case eStateStepping:
106 case eStateDetached:
107 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 case eStateUnloaded:
110 case eStateExited:
111 return !must_exist;
Greg Clayton2637f822011-11-17 01:23:07 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 case eStateStopped:
114 case eStateCrashed:
115 case eStateSuspended:
116 return true;
117 }
118 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119}