• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_LIBPANDABASE_PBASE_OS_DFX_OPTION_H
17 #define PANDA_LIBPANDABASE_PBASE_OS_DFX_OPTION_H
18 
19 #include "macros.h"
20 
21 #include <cstdint>
22 #include <string>
23 
24 namespace ark::os::dfx_option {
25 
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27 #define DFX_OPTION_ELEM(D, NAME, STR) D(NAME, DfxOptionHandler::DfxOptionId::NAME##_ID, STR)
28 
29 #ifdef PANDA_TARGET_UNIX
30 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
31 #define DFX_OPTION_LIST(D)                                       \
32     DFX_OPTION_ELEM(D, COMPILER_NULLCHECK, "compiler-nullcheck") \
33     DFX_OPTION_ELEM(D, REFERENCE_DUMP, "reference-dump")         \
34     DFX_OPTION_ELEM(D, SIGNAL_CATCHER, "signal-catcher")         \
35     DFX_OPTION_ELEM(D, SIGNAL_HANDLER, "signal-handler")         \
36     DFX_OPTION_ELEM(D, ARK_SIGQUIT, "sigquit")                   \
37     DFX_OPTION_ELEM(D, ARK_SIGUSR1, "sigusr1")                   \
38     DFX_OPTION_ELEM(D, ARK_SIGUSR2, "sigusr2")                   \
39     DFX_OPTION_ELEM(D, MOBILE_LOG, "mobile-log")                 \
40     DFX_OPTION_ELEM(D, DFXLOG, "dfx-log")                        \
41     DFX_OPTION_ELEM(D, HUNG_UPDATE, "hung-update")               \
42     DFX_OPTION_ELEM(D, END_FLAG, "end-flag")
43 #else
44 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
45 #define DFX_OPTION_LIST(D)                               \
46     DFX_OPTION_ELEM(D, REFERENCE_DUMP, "reference-dump") \
47     DFX_OPTION_ELEM(D, DFXLOG, "dfx-log")                \
48     DFX_OPTION_ELEM(D, END_FLAG, "end-flag")
49 #endif  // PANDA_TARGET_UNIX
50 
51 class DfxOptionHandler {
52 public:
53     enum DfxOptionId : uint8_t {
54 #ifdef PANDA_TARGET_UNIX
55         COMPILER_NULLCHECK_ID,
56         SIGNAL_CATCHER_ID,
57         SIGNAL_HANDLER_ID,
58         ARK_SIGQUIT_ID,
59         ARK_SIGUSR1_ID,
60         ARK_SIGUSR2_ID,
61         MOBILE_LOG_ID,
62         HUNG_UPDATE_ID,
63 #endif  // PANDA_TARGET_UNIX
64         REFERENCE_DUMP_ID,
65         DFXLOG_ID,
66         END_FLAG_ID,
67     };
68 
69     enum DfxOption : uint8_t {
70 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
71 #define D(e, v, str) e = (v),
72         DFX_OPTION_LIST(D)
73 #undef D
74     };
75 
76     static bool IsInOptionList(const std::string &s);
77 
78     static DfxOption DfxOptionFromString(const std::string &s);
79 
80     static std::string StringFromDfxOption(DfxOptionHandler::DfxOption dfxOption);
81 };
82 
83 }  // namespace ark::os::dfx_option
84 #endif  // PANDA_LIBPANDABASE_PBASE_OS_DFX_OPTION_H
85