/** * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "whitelist_private.h" #include "verification/config/context/context.h" #include "utils/logger.h" namespace panda::verifier::debug { bool InWhitelist(WhitelistKind kind, uint64_t id) { auto &whitelist = DebugContext::GetCurrent().Whitelist; return whitelist.isNotEmpty && whitelist.Id[static_cast(kind)]->count(id) > 0; } void AddWhitelistMethodConfig(WhitelistKind kind, const PandaString &name) { auto &whitelist = DebugContext::GetCurrent().Whitelist; whitelist.Names[static_cast(kind)].push_back(name); whitelist.isNotEmpty = true; } void DebugContext::InsertIntoWhitelist(const PandaString &name, bool isClassName, Method::UniqId id) { auto kindsToAdd = isClassName ? std::initializer_list {WhitelistKind::CLASS} : std::initializer_list {WhitelistKind::METHOD, WhitelistKind::METHOD_CALL}; for (auto kind : kindsToAdd) { auto k = static_cast(kind); auto &ids = Whitelist.Id[k]; auto &names = Whitelist.Names[k]; if (std::find(names.begin(), names.end(), name) != names.end()) { ids->insert(id); LOG(DEBUG, VERIFIER) << "Method with " << (isClassName ? "class " : "") << "name " << name << ", id 0x" << std::hex << id << " was added to whitelist"; } } } } // namespace panda::verifier::debug