1//===-- DNBError.h ----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Created by Greg Clayton on 6/26/07.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBERROR_H
14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBERROR_H
15
16#include <cerrno>
17#include <cstdio>
18#include <mach/mach.h>
19#include <string>
20
21class DNBError {
22public:
23 typedef uint32_t ValueType;
24 enum FlavorType {
25 Generic = 0,
26 MachKernel = 1,
27 POSIX = 2
28#ifdef WITH_SPRINGBOARD
29 ,
30 SpringBoard = 3
31#endif
32#ifdef WITH_BKS
33 ,
34 BackBoard = 4
35#endif
36#ifdef WITH_FBS
37 ,
38 FrontBoard = 5
39#endif
40 };
41
42 explicit DNBError(ValueType err = 0, FlavorType flavor = Generic)
43 : m_err(err), m_flavor(flavor) {}
44
45 const char *AsString() const;
46 void Clear() {
47 m_err = 0;
48 m_flavor = Generic;
49 m_str.clear();
50 }
51 ValueType Status() const { return m_err; }
52 FlavorType Flavor() const { return m_flavor; }
53
54 ValueType operator=(kern_return_t err) {
55 m_err = err;
56 m_flavor = MachKernel;
57 m_str.clear();
58 return m_err;
59 }
60
61 void SetError(kern_return_t err) {
62 m_err = err;
63 m_flavor = MachKernel;
64 m_str.clear();
65 }
66
67 void SetErrorToErrno() {
68 m_err = errno;
69 m_flavor = POSIX;
70 m_str.clear();
71 }
72
73 void SetError(ValueType err, FlavorType flavor) {
74 m_err = err;
75 m_flavor = flavor;
76 m_str.clear();
77 }
78
79 // Generic errors can set their own string values
80 void SetErrorString(const char *err_str) {
81 if (err_str && err_str[0])
82 m_str = err_str;
83 else
84 m_str.clear();
85 }
86 bool Success() const { return m_err == 0; }
87 bool Fail() const { return m_err != 0; }
88 void LogThreadedIfError(const char *format, ...) const;
89 void LogThreaded(const char *format, ...) const;
90
91protected:
92 ValueType m_err;
93 FlavorType m_flavor;
94 mutable std::string m_str;
95};
96
97#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBERROR_H
98

source code of lldb/tools/debugserver/source/DNBError.h