• 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_H
17 #define LIBPANDAFILE_DEBUG_DATA_ACCESSOR_H
18 
19 #include "file.h"
20 
21 #include "utils/span.h"
22 
23 namespace panda::panda_file {
24 
25 class DebugInfoDataAccessor {
26 public:
27     DebugInfoDataAccessor(const File &panda_file, File::EntityId debug_info_id);
28 
29     ~DebugInfoDataAccessor() = default;
30 
31     NO_COPY_SEMANTIC(DebugInfoDataAccessor);
32     NO_MOVE_SEMANTIC(DebugInfoDataAccessor);
33 
GetLineStart()34     uint32_t GetLineStart() const
35     {
36         return line_start_;
37     }
38 
GetNumParams()39     uint32_t GetNumParams() const
40     {
41         return num_params_;
42     }
43 
44     template <class Callback>
45     void EnumerateParameters(const Callback &cb);
46 
47     Span<const uint8_t> GetConstantPool();
48 
49     const uint8_t *GetLineNumberProgram();
50 
GetSize()51     size_t GetSize()
52     {
53         if (size_ == 0) {
54             SkipLineNumberProgram();
55         }
56 
57         return size_;
58     }
59 
GetPandaFile()60     const File &GetPandaFile() const
61     {
62         return panda_file_;
63     }
64 
GetDebugInfoId()65     File::EntityId GetDebugInfoId() const
66     {
67         return debug_info_id_;
68     }
69 
70 private:
71     void SkipParameters();
72 
73     void SkipConstantPool();
74 
75     void SkipLineNumberProgram();
76 
77     const File &panda_file_;
78     File::EntityId debug_info_id_;
79 
80     uint32_t line_start_;
81     uint32_t num_params_;
82     Span<const uint8_t> parameters_sp_ {nullptr, nullptr};
83     Span<const uint8_t> constant_pool_size_sp_ {nullptr, nullptr};
84     Span<const uint8_t> line_num_program_off_sp_ {nullptr, nullptr};
85 
86     size_t size_ {0};
87 };
88 
89 }  // namespace panda::panda_file
90 
91 #endif  // LIBPANDAFILE_DEBUG_DATA_ACCESSOR_H
92