• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 #ifndef LIBPANDAFILE_DEBUG_DATA_ACCESSOR_INL_H
17 #define LIBPANDAFILE_DEBUG_DATA_ACCESSOR_INL_H
18 
19 #include "debug_data_accessor.h"
20 #include "helpers.h"
21 
22 namespace panda::panda_file {
23 
24 template <class Callback>
EnumerateParameters(const Callback & cb)25 inline void DebugInfoDataAccessor::EnumerateParameters(const Callback &cb)
26 {
27     auto sp = parameters_sp_;
28 
29     for (size_t i = 0; i < num_params_; i++) {
30         File::EntityId id(helpers::ReadULeb128(&sp));
31         cb(id);
32     }
33 
34     constant_pool_size_sp_ = sp;
35 }
36 
SkipParameters()37 inline void DebugInfoDataAccessor::SkipParameters()
38 {
39     EnumerateParameters([](File::EntityId /* unused */) {});
40 }
41 
GetConstantPool()42 inline Span<const uint8_t> DebugInfoDataAccessor::GetConstantPool()
43 {
44     if (constant_pool_size_sp_.data() == nullptr) {
45         SkipParameters();
46     }
47 
48     auto sp = constant_pool_size_sp_;
49 
50     uint32_t size = helpers::ReadULeb128(&sp);
51     line_num_program_off_sp_ = sp.SubSpan(size);
52 
53     return sp.First(size);
54 }
55 
SkipConstantPool()56 inline void DebugInfoDataAccessor::SkipConstantPool()
57 {
58     GetConstantPool();
59 }
60 
GetLineNumberProgram()61 inline const uint8_t *DebugInfoDataAccessor::GetLineNumberProgram()
62 {
63     if (line_num_program_off_sp_.data() == nullptr) {
64         SkipConstantPool();
65     }
66 
67     auto sp = line_num_program_off_sp_;
68     uint32_t index = helpers::ReadULeb128(&sp);
69     auto line_num_program_id = panda_file_.ResolveLineNumberProgramIndex(index);
70 
71     size_ = panda_file_.GetIdFromPointer(sp.data()).GetOffset() - debug_info_id_.GetOffset();
72 
73     return panda_file_.GetSpanFromId(line_num_program_id).data();
74 }
75 
SkipLineNumberProgram()76 inline void DebugInfoDataAccessor::SkipLineNumberProgram()
77 {
78     GetLineNumberProgram();
79 }
80 
81 }  // namespace panda::panda_file
82 
83 #endif  // LIBPANDAFILE_DEBUG_DATA_ACCESSOR_INL_H
84