98 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// Created by Greg Clayton on 6/26/07.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBERROR_H14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBERROR_H15 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 = 228#ifdef WITH_SPRINGBOARD29 ,30 SpringBoard = 331#endif32#ifdef WITH_BKS33 ,34 BackBoard = 435#endif36#ifdef WITH_FBS37 ,38 FrontBoard = 539#endif40 };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 values80 void SetErrorString(const char *err_str) {81 if (err_str && err_str[0])82 m_str = err_str;83 else84 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_H98