• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 
16 #include "debug_helpers.h"
17 
18 namespace ark::panda_file::debug_helpers {
19 
GetLineNumber(ark::panda_file::MethodDataAccessor mda,uint32_t bcOffset,const ark::panda_file::File * pandaDebugFile)20 size_t GetLineNumber(ark::panda_file::MethodDataAccessor mda, uint32_t bcOffset,
21                      const ark::panda_file::File *pandaDebugFile)
22 {
23     auto debugInfoId = mda.GetDebugInfoId();
24     if (!debugInfoId) {
25         return -1;
26     }
27 
28     ark::panda_file::DebugInfoDataAccessor dda(*pandaDebugFile, debugInfoId.value());
29     const uint8_t *program = dda.GetLineNumberProgram();
30 
31     ark::panda_file::LineProgramState state(*pandaDebugFile, ark::panda_file::File::EntityId(0), dda.GetLineStart(),
32                                             dda.GetConstantPool());
33 
34     BytecodeOffsetResolver resolver(&state, bcOffset);
35     ark::panda_file::LineNumberProgramProcessor<BytecodeOffsetResolver> programProcessor(program, &resolver);
36     programProcessor.Process();
37 
38     return resolver.GetLine();
39 }
40 
GetStringFromConstantPool(const File & pf,uint32_t offset)41 const char *GetStringFromConstantPool(const File &pf, uint32_t offset)
42 {
43     auto id = File::EntityId(offset);
44     ASSERT(id.IsValid());
45     return utf::Mutf8AsCString(pf.GetStringData(id).data);
46 }
47 
48 }  // namespace ark::panda_file::debug_helpers
49