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