Files
ark_js_runtime/ecmascript/tooling/test/utils/test_extractor.cpp
T
zhuguanghui123 495985a93b Funtions MatchWithOffset and callbackFunc split to two functions.Search separately by row and column.
variable extracted: methodId,offset

  Issue:https://gitee.com/openharmony/ark_js_runtime/issues/I53JD6?from=project-issue

Signed-off-by: zhuguanghui123 <zhuguanghui9@huawei.com>
Change-Id: I4951f10f17fe2af756b336e56e61033ea7fab689
2022-04-28 13:30:51 +08:00

58 lines
2.1 KiB
C++

/*
* Copyright (c) 2021 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.
*/
// Taken from panda-tools/panda-debugger/debugger
#include "ecmascript/tooling/test/utils/test_extractor.h"
#include "libpandabase/utils/leb128.h"
#include "libpandabase/utils/utf.h"
#include "libpandafile/class_data_accessor-inl.h"
#include "libpandafile/code_data_accessor-inl.h"
#include "libpandafile/debug_data_accessor-inl.h"
#include "libpandafile/helpers.h"
#include "libpandafile/method_data_accessor-inl.h"
#include "libpandafile/proto_data_accessor-inl.h"
namespace panda::ecmascript::tooling::test {
std::pair<EntityId, uint32_t> TestExtractor::GetBreakpointAddress(const SourceLocation &sourceLocation)
{
EntityId retId = EntityId();
uint32_t retOffset = 0;
auto callbackFunc = [&retId, &retOffset](File::EntityId id, uint32_t offset) -> bool {
retId = id;
retOffset = offset;
return true;
};
MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column);
return {retId, retOffset};
}
SourceLocation TestExtractor::GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset)
{
SourceLocation location {GetSourceFile(methodId), 0, 0};
auto callbackLineFunc = [&location](int32_t line) -> bool {
location.line = line;
return true;
};
auto callbackColumnFunc = [&location](int32_t column) -> bool {
location.column = column;
return true;
};
MatchLineWithOffset(callbackLineFunc, methodId, bytecodeOffset);
MatchColumnWithOffset(callbackColumnFunc, methodId, bytecodeOffset);
return location;
}
} // namespace panda::ecmascript::tooling::test