| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #pragma once |
| |
| #include <stdint.h> |
| |
| #include "garnet/bin/zxdb/symbols/type.h" |
| |
| namespace zxdb { |
| |
| // A DWARF "base type" is a compiler built-in primitive type like an |
| // integer. The file will include a definition for something named "int" that |
| // is defined as being a signed integer of 4 bytes, etc. |
| class BaseType final : public Type { |
| public: |
| // These are the DWARF base type encodings. The integer value of each is the |
| // constant from the DWARF spec for that value. This isn't an enum because |
| // the value is an integer that can include ranges of user-defined values. |
| // |
| // The DWARF list encompasses some types not generated by our toolchain, |
| // and that other values can appear in symbols. Code is not expected to |
| // handle every one of these values. To make it clear which values we handle, |
| // the irrelevant values are removed. But code should not assume that only |
| // these values might ever appear. |
| static constexpr int kBaseTypeNone = 0x00; // Means uninitialized. |
| static constexpr int kBaseTypeAddress = 0x01; |
| static constexpr int kBaseTypeBoolean = 0x02; |
| static constexpr int kBaseTypeFloat = 0x04; |
| static constexpr int kBaseTypeSigned = 0x05; |
| static constexpr int kBaseTypeSignedChar = 0x06; |
| static constexpr int kBaseTypeUnsigned = 0x07; |
| static constexpr int kBaseTypeUnsignedChar = 0x08; |
| static constexpr int kBaseTypeUTF = 0x10; // Byte size defines encoding. |
| |
| // Symbol overrides. |
| const BaseType* AsBaseType() const final; |
| |
| // Returns one of kBaseType* or possibly something else if the language is |
| // new or unusual. Don't handle, but also don't crash on unexpected values. |
| int base_type() const { return base_type_; } |
| void set_base_type(int type) { base_type_ = type; } |
| |
| // Bitfield support. |
| uint32_t bit_size() const { return bit_size_; } |
| void set_bit_size(uint32_t bs) { bit_size_ = bs; } |
| |
| // DWARF defines the bit offset as the "number of bits from the beginning of |
| // the containing entity to the beginning of the data member." The bit size |
| // will be 0 for non-bitfields. |
| uint32_t bit_offset() const { return bit_offset_; } |
| void set_bit_offset(uint32_t bo) { bit_offset_ = bo; } |
| |
| private: |
| FRIEND_REF_COUNTED_THREAD_SAFE(BaseType); |
| FRIEND_MAKE_REF_COUNTED(BaseType); |
| |
| BaseType(); |
| BaseType(int base_type, int byte_size, const std::string& name); |
| ~BaseType(); |
| |
| int base_type_ = kBaseTypeNone; |
| int bit_size_ = 0; |
| int bit_offset_ = 0; |
| }; |
| |
| } // namespace zxdb |