1 /* 2 * Copyright (c) 2021 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_OS_DFX_OPTION_H_ 17 #define PANDA_LIBPANDABASE_OS_DFX_OPTION_H_ 18 19 #include "macros.h" 20 21 #include <cstdint> 22 #include <string> 23 24 namespace panda::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, END_FLAG, "end-flag") 42 #else 43 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 44 #define DFX_OPTION_LIST(D) \ 45 DFX_OPTION_ELEM(D, DFXLOG, "dfx-log") \ 46 DFX_OPTION_ELEM(D, END_FLAG, "end-flag") 47 #endif // PANDA_TARGET_UNIX 48 49 class DfxOptionHandler { 50 public: 51 enum DfxOptionId : uint8_t { 52 #ifdef PANDA_TARGET_UNIX 53 COMPILER_NULLCHECK_ID, 54 REFERENCE_DUMP_ID, 55 SIGNAL_CATCHER_ID, 56 SIGNAL_HANDLER_ID, 57 ARK_SIGQUIT_ID, 58 ARK_SIGUSR1_ID, 59 ARK_SIGUSR2_ID, 60 MOBILE_LOG_ID, 61 #endif // PANDA_TARGET_UNIX 62 DFXLOG_ID, 63 END_FLAG_ID, 64 }; 65 66 enum DfxOption : uint8_t { 67 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 68 #define D(e, v, str) e = v, 69 DFX_OPTION_LIST(D) 70 #undef D 71 }; 72 73 static bool IsInOptionList(const std::string &s); 74 75 static DfxOption DfxOptionFromString(const std::string &s); 76 77 static std::string StringFromDfxOption(DfxOptionHandler::DfxOption dfx_option); 78 }; 79 80 } // namespace panda::os::dfx_option 81 82 #endif // PANDA_LIBPANDABASE_OS_DFX_OPTION_H_ 83