• 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 <string>
22 
23 #include <berberis/base/macros.h>
24 
25 #include "byte_input_stream.h"
26 #include "string_offset_table.h"
27 #include "string_table.h"
28 
29 namespace nogrod {
30 
31 class DwarfContext {
32  public:
DwarfContext(ByteInputStream * dwarf_info_stream,StringTable * debug_str_table,std::optional<StringOffsetTable> string_offset_table)33   DwarfContext(ByteInputStream* dwarf_info_stream,
34                StringTable* debug_str_table,
35                std::optional<StringOffsetTable> string_offset_table)
36       : dwarf_info_stream_{dwarf_info_stream},
37         debug_str_table_{debug_str_table},
38         string_offset_table_{std::move(string_offset_table)} {}
39 
40   DwarfContext(const DwarfContext&) = delete;
41   const DwarfContext& operator=(const DwarfContext&) = delete;
42   DwarfContext(DwarfContext&&) = delete;
43   DwarfContext& operator=(DwarfContext&&) = delete;
44 
debug_str_table()45   [[nodiscard]] const StringTable* debug_str_table() const { return debug_str_table_; }
string_offset_table()46   [[nodiscard]] const std::optional<StringOffsetTable>& string_offset_table() const {
47     return string_offset_table_;
48   }
49 
info_stream()50   [[nodiscard]] ByteInputStream* info_stream() { return dwarf_info_stream_; }
51 
str_offsets_base()52   [[nodiscard]] std::optional<uint64_t> str_offsets_base() const { return str_offsets_base_; }
53 
54   // DW_AT_str_offsets_base may be defined in Compilation Unit, in which case we set it here.
SetStrOffsetsBase(uint64_t str_offsets_base)55   void SetStrOffsetsBase(uint64_t str_offsets_base) { str_offsets_base_ = str_offsets_base; }
56   // DW_AT_str_offsets_base is reset once new compilation unit starts
ResetStrOffsetsBase()57   void ResetStrOffsetsBase() { str_offsets_base_.reset(); }
58 
59  private:
60   ByteInputStream* dwarf_info_stream_;
61   StringTable* debug_str_table_;
62   std::optional<StringOffsetTable> string_offset_table_;
63   std::optional<uint64_t> str_offsets_base_{};
64 };
65 
66 }  // namespace nogrod
67 #endif  // NOGROD_DWARF_CONTEXT_
68