attr.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
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 #ifndef BLOATY_DWARF_ATTR_H_
16 #define BLOATY_DWARF_ATTR_H_
17 
18 #include <cstdint>
19 
20 #include "absl/strings/string_view.h"
21 #include "absl/types/optional.h"
22 
23 namespace bloaty {
24 namespace dwarf {
25 
26 class CU;
27 
28 class AttrValue {
29  public:
31 
32  AttrValue(const AttrValue &) = default;
33  AttrValue &operator=(const AttrValue &) = default;
34 
35  uint16_t form() const { return form_; }
36 
37  bool IsUint() const {
39  }
40 
41  bool IsString() const {
43  }
44 
45  // Attempts to coerce to uint, returning nullopt if this is not possible.
46  absl::optional<uint64_t> ToUint(const CU& cu) const;
47 
48  // REQUIRES: IsUint().
49  uint64_t GetUint(const CU& cu) const;
50 
51  // REQUIRES: IsString().
52  absl::string_view GetString(const CU& cu) const;
53 
54  private:
56  : uint_(val), form_(form), type_(Type::kUint) {}
58  : string_(val), form_(form), type_(Type::kString) {}
59 
60  // We delay the resolution of indirect strings and addresses, both to avoid
61  // unnecessary work and because they may depend on base values that occur
62  // after them in the sequence of attributes, eg.
63  //
64  // $ dwarfdump -i bloaty
65  // COMPILE_UNIT<header overall offset = 0x00000000>:
66  // < 0><0x0000000c> DW_TAG_compile_unit
67  // DW_AT_producer (indexed string: 0x00000000)Debian clang version 11.0.1-2
68  // DW_AT_language DW_LANG_C_plus_plus_14
69  // DW_AT_name (indexed string: 0x00000001)../src/main.cc
70  // DW_AT_str_offsets_base 0x00000008
71  //
72  // Note that DW_AT_name comes before DW_AT_str_offset_base, but the latter
73  // value is required to resolve the name attribute.
74  enum class Type {
75  kUint,
76  kString,
79  };
80 
81  Type type() const { return type_; }
82 
84  AttrValue ret(form, val);
85  ret.type_ = Type::kUnresolvedUint;
86  return ret;
87  }
88 
90  AttrValue ret(form, val);
92  return ret;
93  }
94 
95  union {
98  };
99 
102 
103  template <class D>
106  template <class D>
107  static absl::string_view ReadIndirectString(const CU& cu,
109  static absl::string_view ResolveIndirectString(const CU& cu, uint64_t ofs);
110 
112  uint64_t ResolveIndirectAddress(const CU& cu) const;
113 };
114 
115 } // namespace dwarf
116 } // namespace bloaty
117 
118 #endif
bloaty::dwarf::AttrValue::ReadIndirectString
static absl::string_view ReadIndirectString(const CU &cu, absl::string_view *data)
bloaty
Definition: bloaty.cc:69
bloaty::dwarf::AttrValue::AttrValue
AttrValue(uint16_t form, uint64_t val)
Definition: attr.h:55
bloaty::dwarf::AttrValue::GetUint
uint64_t GetUint(const CU &cu) const
Definition: attr.cc:44
bloaty::dwarf::AttrValue::IsUint
bool IsUint() const
Definition: attr.h:37
bloaty::dwarf::AttrValue::form_
uint16_t form_
Definition: attr.h:100
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
bloaty::dwarf::AttrValue::Type::kUint
@ kUint
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
bloaty::dwarf::AttrValue::UnresolvedUint
static AttrValue UnresolvedUint(uint16_t form, uint64_t val)
Definition: attr.h:83
bloaty::dwarf::AttrValue::ResolveIndirectAddress
uint64_t ResolveIndirectAddress(const CU &cu) const
Definition: attr.cc:101
Type
Definition: bloaty/third_party/protobuf/src/google/protobuf/type.pb.h:182
bloaty::dwarf::CU
Definition: debug_info.h:241
bloaty::dwarf::AttrValue::operator=
AttrValue & operator=(const AttrValue &)=default
bloaty::dwarf::AttrValue::Type::kString
@ kString
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
absl::optional< uint64_t >
bloaty::dwarf::AttrValue::AttrValue
AttrValue(const AttrValue &)=default
bloaty::dwarf::AttrValue::form
uint16_t form() const
Definition: attr.h:35
bloaty::dwarf::AttrValue::uint_
uint64_t uint_
Definition: attr.h:96
bloaty::dwarf::AttrValue::ParseAttr
static AttrValue ParseAttr(const CU &cu, uint8_t form, absl::string_view *data)
Definition: attr.cc:105
bloaty::dwarf::AttrValue::Type::kUnresolvedUint
@ kUnresolvedUint
bloaty::dwarf::AttrValue::ResolveDoubleIndirectString
absl::string_view ResolveDoubleIndirectString(const CU &cu) const
Definition: attr.cc:85
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
bloaty::dwarf::AttrValue::AttrValue
AttrValue(uint16_t form, absl::string_view val)
Definition: attr.h:57
bloaty::dwarf::AttrValue::GetString
absl::string_view GetString(const CU &cu) const
Definition: attr.cc:53
bloaty::dwarf::AttrValue::ReadVariableBlock
static absl::string_view ReadVariableBlock(absl::string_view *data)
Definition: attr.cc:68
bloaty::dwarf::AttrValue::Type::kUnresolvedString
@ kUnresolvedString
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
bloaty::dwarf::AttrValue::type
Type type() const
Definition: attr.h:81
bloaty::dwarf::AttrValue::ResolveIndirectString
static absl::string_view ResolveIndirectString(const CU &cu, uint64_t ofs)
Definition: attr.cc:73
bloaty::dwarf::AttrValue::ReadBlock
static absl::string_view ReadBlock(absl::string_view *data)
bloaty::dwarf::AttrValue::string_
absl::string_view string_
Definition: attr.h:97
bloaty::dwarf::AttrValue::ToUint
absl::optional< uint64_t > ToUint(const CU &cu) const
Definition: attr.cc:28
bloaty::dwarf::AttrValue::type_
Type type_
Definition: attr.h:101
bloaty::dwarf::AttrValue::IsString
bool IsString() const
Definition: attr.h:41
bloaty::dwarf::AttrValue
Definition: attr.h:28
bloaty::dwarf::AttrValue::UnresolvedString
static AttrValue UnresolvedString(uint16_t form, uint64_t val)
Definition: attr.h:89


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35