1343181Sdim//===-- State.h -------------------------------------------------*- C++ -*-===//
2343181Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6343181Sdim//
7343181Sdim//===----------------------------------------------------------------------===//
8343181Sdim
9343181Sdim#ifndef LLDB_UTILITY_STATE_H
10343181Sdim#define LLDB_UTILITY_STATE_H
11343181Sdim
12343181Sdim#include "lldb/lldb-enumerations.h"
13343181Sdim#include "llvm/ADT/StringRef.h"
14343181Sdim#include "llvm/Support/FormatProviders.h"
15343181Sdim#include "llvm/Support/raw_ostream.h"
16343181Sdim#include <cstdint>
17343181Sdim
18343181Sdimnamespace lldb_private {
19343181Sdim
20343181Sdim/// Converts a StateType to a C string.
21343181Sdim///
22353358Sdim/// \param[in] state
23343181Sdim///     The StateType object to convert.
24343181Sdim///
25353358Sdim/// \return
26343181Sdim///     A NULL terminated C string that describes \a state. The
27343181Sdim///     returned string comes from constant string buffers and does
28343181Sdim///     not need to be freed.
29343181Sdimconst char *StateAsCString(lldb::StateType state);
30343181Sdim
31343181Sdim/// Check if a state represents a state where the process or thread
32343181Sdim/// is running.
33343181Sdim///
34353358Sdim/// \param[in] state
35343181Sdim///     The StateType enumeration value
36343181Sdim///
37353358Sdim/// \return
38343181Sdim///     \b true if the state represents a process or thread state
39343181Sdim///     where the process or thread is running, \b false otherwise.
40343181Sdimbool StateIsRunningState(lldb::StateType state);
41343181Sdim
42343181Sdim/// Check if a state represents a state where the process or thread
43343181Sdim/// is stopped. Stopped can mean stopped when the process is still
44343181Sdim/// around, or stopped when the process has exited or doesn't exist
45343181Sdim/// yet. The \a must_exist argument tells us which of these cases is
46343181Sdim/// desired.
47343181Sdim///
48353358Sdim/// \param[in] state
49343181Sdim///     The StateType enumeration value
50343181Sdim///
51353358Sdim/// \param[in] must_exist
52343181Sdim///     A boolean that indicates the thread must also be alive
53343181Sdim///     so states like unloaded or exited won't return true.
54343181Sdim///
55353358Sdim/// \return
56343181Sdim///     \b true if the state represents a process or thread state
57343181Sdim///     where the process or thread is stopped. If \a must_exist is
58343181Sdim///     \b true, then the process can't be exited or unloaded,
59343181Sdim///     otherwise exited and unloaded or other states where the
60343181Sdim///     process no longer exists are considered to be stopped.
61343181Sdimbool StateIsStoppedState(lldb::StateType state, bool must_exist);
62343181Sdim
63343181Sdimconst char *GetPermissionsAsCString(uint32_t permissions);
64343181Sdim
65343181Sdim} // namespace lldb_private
66343181Sdim
67343181Sdimnamespace llvm {
68343181Sdimtemplate <> struct format_provider<lldb::StateType> {
69343181Sdim  static void format(const lldb::StateType &state, raw_ostream &Stream,
70343181Sdim                     StringRef Style) {
71343181Sdim    Stream << lldb_private::StateAsCString(state);
72343181Sdim  }
73343181Sdim};
74343181Sdim} // namespace llvm
75343181Sdim
76343181Sdim#endif // LLDB_UTILITY_STATE_H
77