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// Taken from panda-tools/panda-debugger/debugger 16 17#include "test/utils/test_extractor.h" 18 19#include "libpandabase/utils/leb128.h" 20#include "libpandabase/utils/utf.h" 21#include "libpandafile/class_data_accessor-inl.h" 22#include "libpandafile/code_data_accessor-inl.h" 23#include "libpandafile/debug_data_accessor-inl.h" 24#include "libpandafile/helpers.h" 25#include "libpandafile/method_data_accessor-inl.h" 26#include "libpandafile/proto_data_accessor-inl.h" 27 28namespace panda::ecmascript::tooling::test { 29std::pair<EntityId, uint32_t> TestExtractor::GetBreakpointAddress(const SourceLocation &sourceLocation) 30{ 31 EntityId retId = EntityId(); 32 uint32_t retOffset = 0; 33 auto callbackFunc = [&retId, &retOffset](const JSPtLocation &jsLocation) -> bool { 34 retId = jsLocation.GetMethodId(); 35 retOffset = jsLocation.GetBytecodeOffset(); 36 return true; 37 }; 38 std::unordered_set<std::string> recordName {}; 39 MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName); 40 return {retId, retOffset}; 41} 42 43SourceLocation TestExtractor::GetSourceLocation(const JSPandaFile *file, EntityId methodId, uint32_t bytecodeOffset) 44{ 45 SourceLocation location {file, 0, 0}; 46 auto callbackLineFunc = [&location](int32_t line) -> bool { 47 location.line = line; 48 return true; 49 }; 50 auto callbackColumnFunc = [&location](int32_t column) -> bool { 51 location.column = column; 52 return true; 53 }; 54 MatchLineWithOffset(callbackLineFunc, methodId, bytecodeOffset); 55 MatchColumnWithOffset(callbackColumnFunc, methodId, bytecodeOffset); 56 return location; 57} 58} // namespace panda::ecmascript::tooling::test 59