Home | History | Annotate | Download | only in Core
      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 
     17 using namespace lldb;
     18 using namespace lldb_private;
     19 
     20 const char *
     21 lldb_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 
     43 const char *
     44 lldb_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 
     67 bool
     68 lldb_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         break;
     87     }
     88     return false;
     89 }
     90 
     91 bool
     92 lldb_private::StateIsStoppedState (StateType state, bool must_exist)
     93 {
     94     switch (state)
     95     {
     96     case eStateInvalid:
     97     case eStateConnected:
     98     case eStateAttaching:
     99     case eStateLaunching:
    100     case eStateRunning:
    101     case eStateStepping:
    102     case eStateDetached:
    103         break;
    104 
    105     case eStateUnloaded:
    106     case eStateExited:
    107         return !must_exist;
    108 
    109     case eStateStopped:
    110     case eStateCrashed:
    111     case eStateSuspended:
    112         return true;
    113     }
    114     return false;
    115 }
    116