1 /**
2 * Copyright (c) 2021-2022 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 #include "verification/config/process/config_process.h"
17 #include "verification/config/options/method_group_parser.h"
18 #include "verification/util/parser/parser.h"
19
20 #include "verifier_messages.h"
21
22 #include "runtime/include/mem/panda_string.h"
23
24 #include "literal_parser.h"
25
26 #include "runtime/include/method.h"
27 #include "runtime/include/runtime.h"
28
29 #include "utils/logger.h"
30
31 #include <string>
32 #include <cstring>
33 #include <cstdint>
34 #include <unordered_map>
35
36 #include <type_traits>
37
38 namespace panda::verifier::debug {
39
40 using panda::parser::parser;
41 using panda::verifier::config::Section;
42
RegisterConfigHandlerMethodGroups()43 void RegisterConfigHandlerMethodGroups()
44 {
45 static const auto CONFIG_DEBUG_METHOD_GROUPS_VERIFIER_OPTIONS = [](const Section §ion) {
46 auto &runtime = *Runtime::GetCurrent();
47 auto &verif_options = runtime.GetVerificationOptions();
48
49 for (const auto &item : section.items) {
50 struct Context {
51 PandaString group;
52 PandaString options;
53 };
54
55 using p = parser<Context, const char, const char *>;
56 const auto WS = p::of_charset(" \t");
57
58 const auto GROUP_HANDLER = [](Context &c, PandaString &&group) {
59 c.group = std::move(group);
60 return true;
61 };
62
63 const auto OPTIONS_HANDLER = [](Context &c, PandaString &&options) {
64 c.options = std::move(options);
65 return true;
66 };
67
68 const auto LINE = ~WS >> MethodGroupParser<p>(GROUP_HANDLER) >> WS >> LiteralParser<p>(OPTIONS_HANDLER) >>
69 ~WS >> p::end();
70
71 const char *start = item.c_str();
72 const char *end = item.c_str() + item.length(); // NOLINT
73
74 Context ctx;
75
76 if (!LINE(ctx, start, end)) {
77 LOG(DEBUG, VERIFIER) << " Error: cannot parse config line '" << item << "'";
78 return false;
79 }
80
81 if (!verif_options.Debug.GetMethodOptions().AddOptionsForGroup(ctx.group, ctx.options)) {
82 LOG(DEBUG, VERIFIER) << " Error: cannot set options for method group '" << ctx.group << "', options '"
83 << ctx.options << "'";
84 return false;
85 }
86
87 LOG(DEBUG, VERIFIER) << " Set options for method group '" << ctx.group << "' : '" << ctx.options << "'";
88 }
89
90 return true;
91 };
92
93 config::RegisterConfigHandler("config.debug.method_groups.verifier.options",
94 CONFIG_DEBUG_METHOD_GROUPS_VERIFIER_OPTIONS);
95 }
96
97 } // namespace panda::verifier::debug
98