• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "breakpoint_private.h"
17 
18 #include "verification/debug/context/context.h"
19 
20 #include "verification/util/str.h"
21 
22 #include "verifier_messages.h"
23 
24 #include "utils/logger.h"
25 
26 namespace panda::verifier::debug {
27 
AddBreakpointConfig(const DebugManagedBrkCfg & cfg)28 void AddBreakpointConfig(const DebugManagedBrkCfg &cfg)
29 {
30     auto &managed_breakpoints = DebugContext::GetCurrent().ManagedBreakpoints;
31     managed_breakpoints.Config->operator[](cfg.NameHash).push_back(cfg);
32 }
33 
BreakpointMethodIdCalculationHandler(uint32_t class_hash,uint32_t name_hash,uint64_t id)34 void BreakpointMethodIdCalculationHandler([[maybe_unused]] uint32_t class_hash, uint32_t name_hash, uint64_t id)
35 {
36     auto &managed_breakpoints = DebugContext::GetCurrent().ManagedBreakpoints;
37     if (managed_breakpoints.Config->count(name_hash) > 0) {
38         for (const auto &cfg : managed_breakpoints.Config->at(name_hash)) {
39             LOG_VERIFIER_DEBUG_BREAKPOINT_SET_INFO(name_hash, id, cfg.Offset);
40             auto &breakpoint = managed_breakpoints.Breakpoint[static_cast<size_t>(cfg.Comp)];
41             breakpoint->operator[](id).insert(cfg.Offset);
42         }
43     }
44 }
45 
CheckManagedBreakpoint(Component component,uint64_t id,uint32_t offset)46 bool CheckManagedBreakpoint(Component component, uint64_t id, uint32_t offset)
47 {
48     auto &managed_breakpoints = DebugContext::GetCurrent().ManagedBreakpoints;
49     const auto &breakpoints = managed_breakpoints.Breakpoint[static_cast<size_t>(component)];
50     auto count = breakpoints->count(id);
51     if (count == 0) {
52         return false;
53     }
54     const auto offset_hit = breakpoints->at(id).count(offset);
55     return offset_hit > 0;
56 }
57 
ManagedBreakpointPresent(Component component,uint64_t id)58 bool ManagedBreakpointPresent(Component component, uint64_t id)
59 {
60     auto &managed_breakpoints = DebugContext::GetCurrent().ManagedBreakpoints;
61     const auto &breakpoints = managed_breakpoints.Breakpoint[static_cast<size_t>(component)];
62     return breakpoints->count(id) > 0;
63 }
64 
65 }  // namespace panda::verifier::debug
66