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
28 namespace panda::ecmascript::tooling::test {
GetBreakpointAddress(const SourceLocation & sourceLocation)29 std::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 MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", "");
39 return {retId, retOffset};
40 }
41
GetSourceLocation(const JSPandaFile * file,EntityId methodId,uint32_t bytecodeOffset)42 SourceLocation TestExtractor::GetSourceLocation(const JSPandaFile *file, EntityId methodId, uint32_t bytecodeOffset)
43 {
44 SourceLocation location {file, 0, 0};
45 auto callbackLineFunc = [&location](int32_t line) -> bool {
46 location.line = line;
47 return true;
48 };
49 auto callbackColumnFunc = [&location](int32_t column) -> bool {
50 location.column = column;
51 return true;
52 };
53 MatchLineWithOffset(callbackLineFunc, methodId, bytecodeOffset);
54 MatchColumnWithOffset(callbackColumnFunc, methodId, bytecodeOffset);
55 return location;
56 }
57 } // namespace panda::ecmascript::tooling::test
58