/** * Copyright (c) 2025 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 "breakpoint.h" #include "debug_info_extractor.h" #include "error.h" #include "evaluation/evaluation_engine.h" namespace ark::tooling::inspector { bool Breakpoint::SetLocations(std::set &sourceFiles, const DebugInfoCache &debugCache, std::unordered_multimap &breakpointLocations) { locations_ = debugCache.GetBreakpointLocations(sourceFileFilter_, lineNumber_, sourceFiles); if (locations_.empty()) { LOG(WARNING, DEBUGGER) << "Pending breakpoint, 0 locations resolved currently, id = " << GetId(); return true; } for (auto &location : locations_) { breakpointLocations.emplace(location, GetId()); } Resolve(); return true; } void Breakpoint::TryResolveImpl(const panda_file::File &file, const panda_file::DebugInfoExtractor *debugInfo, std::unordered_multimap &breakpointLocations) { auto lineHandler = [this, &breakpointLocations](const auto &pandaFile, auto methodId, auto &entry) { if (entry.line == lineNumber_) { auto [it, _] = locations_.emplace(pandaFile.GetFilename().data(), methodId, entry.offset); breakpointLocations.emplace(*it, GetId()); Resolve(); // Must choose the first found bytecode location in each method return false; } // Continue search return true; }; for (const auto &methodId : debugInfo->GetMethodIdList()) { if (!sourceFileFilter_(debugInfo->GetSourceFile(methodId))) { continue; } auto &table = debugInfo->GetLineNumberTable(methodId); for (auto &entry : table) { if (!lineHandler(file, methodId, entry)) { break; } } } } } // namespace ark::tooling::inspector