pstore2
debug_line_section.hpp
Go to the documentation of this file.
1 //===- include/pstore/mcrepo/debug_line_section.hpp -------*- mode: C++ -*-===//
2 //* _ _ _ _ *
3 //* __| | ___| |__ _ _ __ _ | (_)_ __ ___ *
4 //* / _` |/ _ \ '_ \| | | |/ _` | | | | '_ \ / _ \ *
5 //* | (_| | __/ |_) | |_| | (_| | | | | | | | __/ *
6 //* \__,_|\___|_.__/ \__,_|\__, | |_|_|_| |_|\___| *
7 //* |___/ *
8 //* _ _ *
9 //* ___ ___ ___| |_(_) ___ _ __ *
10 //* / __|/ _ \/ __| __| |/ _ \| '_ \ *
11 //* \__ \ __/ (__| |_| | (_) | | | | *
12 //* |___/\___|\___|\__|_|\___/|_| |_| *
13 //* *
14 //===----------------------------------------------------------------------===//
15 //
16 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
17 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
18 // information.
19 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20 //
21 //===----------------------------------------------------------------------===//
24 
25 #ifndef PSTORE_MCREPO_DEBUG_LINE_SECTION_HPP
26 #define PSTORE_MCREPO_DEBUG_LINE_SECTION_HPP
27 
28 #include "pstore/core/address.hpp"
29 #include "pstore/core/index_types.hpp"
31 
32 namespace pstore {
33  namespace repo {
34 
35  // TODO: modeling the debug line section as a "generic_section plus an extent for the CU
36  // header" is expedient but we probably don't need to store the alignment or external fixup
37  // array.
39  public:
40  template <typename DataRange, typename IFixupRange, typename XFixupRange>
42  index::digest const & header_digest, extent<std::uint8_t> const & header_extent,
44  std::uint8_t align)
45  : header_digest_{header_digest}
46  , header_{header_extent}
47  , g_{src.data_range, src.ifixups_range, src.xfixups_range, align} {}
48 
49 
50  index::digest const & header_digest () const noexcept { return header_digest_; }
51  extent<std::uint8_t> const & header_extent () const noexcept { return header_; }
52  generic_section const & generic () const noexcept { return g_; }
53 
54  unsigned align () const noexcept { return g_.align (); }
55  // \returns The section's data payload.
56  container<std::uint8_t> payload () const { return g_.payload (); }
58  std::size_t size () const noexcept { return this->payload ().size (); }
59  container<internal_fixup> ifixups () const { return g_.ifixups (); }
60  container<external_fixup> xfixups () const { return g_.xfixups (); }
61 
63  std::size_t size_bytes () const {
64  return offsetof (debug_line_section, g_) + g_.size_bytes ();
65  }
66 
67  template <typename DataRange, typename IFixupRange, typename XFixupRange>
68  static std::size_t size_bytes (DataRange const & d, IFixupRange const & i,
69  XFixupRange const & x) {
70  return offsetof (debug_line_section, g_) + generic_section::size_bytes (d, i, x);
71  }
72 
73  template <typename DataRange, typename IFixupRange, typename XFixupRange>
74  static std::size_t
76  return size_bytes (src.data_range, src.ifixups_range, src.xfixups_range);
77  }
78 
79  private:
80  index::digest header_digest_;
81  extent<std::uint8_t> header_;
82  generic_section g_;
83  };
84  static_assert (std::is_standard_layout<debug_line_section>::value,
85  "debug_line_section must be standard-layout");
86  static_assert (alignof (debug_line_section) == 16,
87  "debug_line_section alignment must be 16");
88 
89 
90  template <>
91  inline unsigned section_alignment<pstore::repo::debug_line_section> (
92  pstore::repo::debug_line_section const & s) noexcept {
93  return s.align ();
94  }
95  template <>
96  inline std::uint64_t section_size<pstore::repo::debug_line_section> (
97  pstore::repo::debug_line_section const & s) noexcept {
98  return s.size ();
99  }
100 
101 
103  public:
106  section_content const * const sec)
107  : section_creation_dispatcher (section_kind::debug_line)
108  , header_digest_{header_digest}
109  , header_{header}
110  , section_{sec} {}
111 
113  debug_line_section_creation_dispatcher const &) = delete;
115  operator= (debug_line_section_creation_dispatcher const &) = delete;
116 
117  std::size_t size_bytes () const override;
118 
119  // Write the section data to the memory pointed to by \p out.
120  std::uint8_t * write (std::uint8_t * out) const final;
121 
122  private:
123  std::uintptr_t aligned_impl (std::uintptr_t in) const override;
124 
125  index::digest header_digest_;
126  extent<std::uint8_t> header_;
127  section_content const * const section_;
128  };
129 
130  template <>
133  };
134 
135  class debug_line_dispatcher final : public dispatcher {
136  public:
137  explicit constexpr debug_line_dispatcher (debug_line_section const & d) noexcept
138  : d_{d} {}
139  ~debug_line_dispatcher () noexcept final;
140 
141  std::size_t size_bytes () const final { return d_.size_bytes (); }
142  unsigned align () const final { return d_.align (); }
143  std::size_t size () const final { return d_.size (); }
144  container<internal_fixup> ifixups () const final { return d_.ifixups (); }
145  container<external_fixup> xfixups () const final { return d_.xfixups (); }
146  container<std::uint8_t> payload () const final { return d_.payload (); }
147 
148  private:
149  debug_line_section const & d_;
150  };
151 
152 
153  template <>
155  using type = debug_line_dispatcher;
156  };
157 
158  } // end namespace repo
159 } // end namespace pstore
160 
161 #endif // PSTORE_MCREPO_DEBUG_LINE_SECTION_HPP
Declares the generic section.
Definition: uint128.hpp:85
A simple wrapper around the elements of one of the three arrays that make up a section.
Definition: section.hpp:152
Definition: debug_line_section.hpp:38
Maps from the type of data that is associated with a fragment&#39;s section to a "dispatcher" subclass wh...
Definition: section.hpp:146
Describes the three members of a section as three pairs of iterators: one each for the data...
Definition: generic_section.hpp:187
This class is used to add virtual methods to a fragment&#39;s section.
Definition: section.hpp:195
Definition: debug_line_section.hpp:135
Definition: generic_section.hpp:177
An empty class used as the base type for all sections.
Definition: section.hpp:69
container< std::uint8_t > payload() const final
Return the data section stored in the object file.
Definition: debug_line_section.hpp:146
Maps from the type of data that is associated with a fragment&#39;s section to a "dispatcher" subclass wh...
Definition: section.hpp:214
std::size_t size_bytes() const
A group of member functions which return the number of bytes occupied by a fragment instance...
Definition: generic_section.cpp:83
Definition: nonpod2.cpp:40
Definition: generic_section.hpp:386
std::size_t size_bytes() const
Definition: debug_line_section.hpp:63
A section creation dispatcher is used to instantiate and construct each of a fragment&#39;s sections in p...
Definition: section.hpp:91
std::size_t size() const noexcept
Definition: debug_line_section.hpp:58
Definition: debug_line_section.hpp:102
The data store file header.
Definition: file_header.hpp:78