• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NOGROD_DWARF_CONTEXT_
18 #define NOGROD_DWARF_CONTEXT_
19 
20 #include <cstdint>
21 #include <optional>
22 #include <string>
23 
24 #include <berberis/base/macros.h>
25 
26 #include "byte_input_stream.h"
27 #include "string_offset_table.h"
28 #include "string_table.h"
29 
30 namespace nogrod {
31 
32 class DwarfContext {
33  public:
DwarfContext(ByteInputStream * dwarf_info_stream,const StringTable * debug_str_table,const std::optional<StringOffsetTable> & string_offset_table)34   DwarfContext(ByteInputStream* dwarf_info_stream,
35                const StringTable* debug_str_table,
36                const std::optional<StringOffsetTable>& string_offset_table)
37       : dwarf_info_stream_{dwarf_info_stream},
38         debug_str_table_{debug_str_table},
39         string_offset_table_{string_offset_table} {}
40 
41   DwarfContext(const DwarfContext&) = delete;
42   const DwarfContext& operator=(const DwarfContext&) = delete;
43   DwarfContext(DwarfContext&&) = delete;
44   DwarfContext& operator=(DwarfContext&&) = delete;
45 
debug_str_table()46   [[nodiscard]] const StringTable* debug_str_table() const { return debug_str_table_; }
string_offset_table()47   [[nodiscard]] const std::optional<StringOffsetTable>& string_offset_table() const {
48     return string_offset_table_;
49   }
50 
info_stream()51   [[nodiscard]] ByteInputStream* info_stream() { return dwarf_info_stream_; }
52 
str_offsets_base()53   [[nodiscard]] std::optional<uint64_t> str_offsets_base() const { return str_offsets_base_; }
54 
55   // DW_AT_str_offsets_base may be defined in Compilation Unit, in which case we set it here.
SetStrOffsetsBase(uint64_t str_offsets_base)56   void SetStrOffsetsBase(uint64_t str_offsets_base) { str_offsets_base_ = str_offsets_base; }
57   // DW_AT_str_offsets_base is reset once new compilation unit starts
ResetStrOffsetsBase()58   void ResetStrOffsetsBase() { str_offsets_base_.reset(); }
59 
60  private:
61   ByteInputStream* dwarf_info_stream_;
62   const StringTable* debug_str_table_;
63   const std::optional<StringOffsetTable>& string_offset_table_;
64   std::optional<uint64_t> str_offsets_base_{};
65 };
66 
67 }  // namespace nogrod
68 #endif  // NOGROD_DWARF_CONTEXT_
69