• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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.h"
17 
18 #include "debug_info_extractor.h"
19 #include "error.h"
20 #include "evaluation/evaluation_engine.h"
21 
22 namespace ark::tooling::inspector {
23 
SetLocations(std::set<std::string_view> & sourceFiles,const DebugInfoCache & debugCache,std::unordered_multimap<PtLocation,BreakpointId,HashLocation> & breakpointLocations)24 bool Breakpoint::SetLocations(std::set<std::string_view> &sourceFiles, const DebugInfoCache &debugCache,
25                               std::unordered_multimap<PtLocation, BreakpointId, HashLocation> &breakpointLocations)
26 {
27     locations_ = debugCache.GetBreakpointLocations(sourceFileFilter_, lineNumber_, sourceFiles);
28     if (locations_.empty()) {
29         LOG(WARNING, DEBUGGER) << "Pending breakpoint, 0 locations resolved currently, id = " << GetId();
30         return true;
31     }
32 
33     for (auto &location : locations_) {
34         breakpointLocations.emplace(location, GetId());
35     }
36     Resolve();
37     return true;
38 }
39 
TryResolveImpl(const panda_file::File & file,const panda_file::DebugInfoExtractor * debugInfo,std::unordered_multimap<PtLocation,BreakpointId,HashLocation> & breakpointLocations)40 void Breakpoint::TryResolveImpl(const panda_file::File &file, const panda_file::DebugInfoExtractor *debugInfo,
41                                 std::unordered_multimap<PtLocation, BreakpointId, HashLocation> &breakpointLocations)
42 {
43     auto lineHandler = [this, &breakpointLocations](const auto &pandaFile, auto methodId, auto &entry) {
44         if (entry.line == lineNumber_) {
45             auto [it, _] = locations_.emplace(pandaFile.GetFilename().data(), methodId, entry.offset);
46             breakpointLocations.emplace(*it, GetId());
47             Resolve();
48             // Must choose the first found bytecode location in each method
49             return false;
50         }
51         // Continue search
52         return true;
53     };
54 
55     for (const auto &methodId : debugInfo->GetMethodIdList()) {
56         if (!sourceFileFilter_(debugInfo->GetSourceFile(methodId))) {
57             continue;
58         }
59 
60         auto &table = debugInfo->GetLineNumberTable(methodId);
61         for (auto &entry : table) {
62             if (!lineHandler(file, methodId, entry)) {
63                 break;
64             }
65         }
66     }
67 }
68 
69 }  // namespace ark::tooling::inspector
70