DebugServer2
Loading...
Searching...
No Matches
Stringify.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Base.h"
14#include "DebugServer2/Constants.h"
15#include "DebugServer2/Target/ThreadBase.h"
16#include "DebugServer2/Types.h"
17
18namespace ds2 {
19namespace Utils {
20
21class Stringify {
22public:
23 static char const *Error(ErrorCode error);
24 static char const *ThreadState(Target::ThreadBase::State state);
25 static char const *StopEvent(StopInfo::Event event);
26 static char const *StopReason(StopInfo::Reason reason);
27
28#if defined(OS_POSIX)
29 static char const *Errno(int error);
30 static char const *WaitStatus(int status);
31 static char const *Signal(int signal);
32 static char const *SignalCode(int signal, int code);
33 static char const *PTraceCommand(int code);
34#elif defined(OS_WIN32)
35 static char const *WSAError(DWORD error);
36 static char const *DebugEvent(DWORD event);
37 static char const *ExceptionCode(DWORD code);
38#endif
39};
40} // namespace Utils
41} // namespace ds2
42
43// Private stuff used by implementation functions.
44#if defined(STRINGIFY_H_INTERNAL)
45#include "DebugServer2/Utils/Log.h"
46#include "DebugServer2/Utils/String.h"
47
48#if defined(OS_DARWIN)
49#define ATT_TLS __thread
50#elif defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_WIN32)
51#define ATT_TLS thread_local
52#else
53#error "Target not supported."
54#endif
55
56#define DO_STRINGIFY(VALUE) \
57 case VALUE: \
58 return #VALUE;
59
60#define DO_STRINGIFY_ALIAS(VALUE, NAME) \
61 case VALUE: \
62 return #NAME;
63
64#define DO_DEFAULT(MESSAGE, VALUE) \
65 default: \
66 do { \
67 DS2LOG(Warning, MESSAGE ": %#lx", (unsigned long)VALUE); \
68 static ATT_TLS char tmp[20]; \
69 ds2::Utils::SNPrintf(tmp, sizeof(tmp), "%#lx", (unsigned long)VALUE); \
70 return tmp; \
71 } while (0);
72#endif
Definition Stringify.h:21