1e509ee18Sopenharmony_ci/* 2e509ee18Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License. 5e509ee18Sopenharmony_ci * You may obtain a copy of the License at 6e509ee18Sopenharmony_ci * 7e509ee18Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e509ee18Sopenharmony_ci * 9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and 13e509ee18Sopenharmony_ci * limitations under the License. 14e509ee18Sopenharmony_ci */ 15e509ee18Sopenharmony_ci// Taken from panda-tools/panda-debugger/debugger 16e509ee18Sopenharmony_ci 17e509ee18Sopenharmony_ci#include "test/utils/test_extractor.h" 18e509ee18Sopenharmony_ci 19e509ee18Sopenharmony_ci#include "libpandabase/utils/leb128.h" 20e509ee18Sopenharmony_ci#include "libpandabase/utils/utf.h" 21e509ee18Sopenharmony_ci#include "libpandafile/class_data_accessor-inl.h" 22e509ee18Sopenharmony_ci#include "libpandafile/code_data_accessor-inl.h" 23e509ee18Sopenharmony_ci#include "libpandafile/debug_data_accessor-inl.h" 24e509ee18Sopenharmony_ci#include "libpandafile/helpers.h" 25e509ee18Sopenharmony_ci#include "libpandafile/method_data_accessor-inl.h" 26e509ee18Sopenharmony_ci#include "libpandafile/proto_data_accessor-inl.h" 27e509ee18Sopenharmony_ci 28e509ee18Sopenharmony_cinamespace panda::ecmascript::tooling::test { 29e509ee18Sopenharmony_cistd::pair<EntityId, uint32_t> TestExtractor::GetBreakpointAddress(const SourceLocation &sourceLocation) 30e509ee18Sopenharmony_ci{ 31e509ee18Sopenharmony_ci EntityId retId = EntityId(); 32e509ee18Sopenharmony_ci uint32_t retOffset = 0; 33e509ee18Sopenharmony_ci auto callbackFunc = [&retId, &retOffset](const JSPtLocation &jsLocation) -> bool { 34e509ee18Sopenharmony_ci retId = jsLocation.GetMethodId(); 35e509ee18Sopenharmony_ci retOffset = jsLocation.GetBytecodeOffset(); 36e509ee18Sopenharmony_ci return true; 37e509ee18Sopenharmony_ci }; 38e509ee18Sopenharmony_ci std::unordered_set<std::string> recordName {}; 39e509ee18Sopenharmony_ci MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName); 40e509ee18Sopenharmony_ci return {retId, retOffset}; 41e509ee18Sopenharmony_ci} 42e509ee18Sopenharmony_ci 43e509ee18Sopenharmony_ciSourceLocation TestExtractor::GetSourceLocation(const JSPandaFile *file, EntityId methodId, uint32_t bytecodeOffset) 44e509ee18Sopenharmony_ci{ 45e509ee18Sopenharmony_ci SourceLocation location {file, 0, 0}; 46e509ee18Sopenharmony_ci auto callbackLineFunc = [&location](int32_t line) -> bool { 47e509ee18Sopenharmony_ci location.line = line; 48e509ee18Sopenharmony_ci return true; 49e509ee18Sopenharmony_ci }; 50e509ee18Sopenharmony_ci auto callbackColumnFunc = [&location](int32_t column) -> bool { 51e509ee18Sopenharmony_ci location.column = column; 52e509ee18Sopenharmony_ci return true; 53e509ee18Sopenharmony_ci }; 54e509ee18Sopenharmony_ci MatchLineWithOffset(callbackLineFunc, methodId, bytecodeOffset); 55e509ee18Sopenharmony_ci MatchColumnWithOffset(callbackColumnFunc, methodId, bytecodeOffset); 56e509ee18Sopenharmony_ci return location; 57e509ee18Sopenharmony_ci} 58e509ee18Sopenharmony_ci} // namespace panda::ecmascript::tooling::test 59