| 1 | /* DWARF attributes |
| 2 | |
| 3 | Copyright (C) 1994-2020 Free Software Foundation, Inc. |
| 4 | |
| 5 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, |
| 6 | Inc. with support from Florida State University (under contract |
| 7 | with the Ada Joint Program Office), and Silicon Graphics, Inc. |
| 8 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., |
| 9 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 |
| 10 | support. |
| 11 | |
| 12 | This file is part of GDB. |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or modify |
| 15 | it under the terms of the GNU General Public License as published by |
| 16 | the Free Software Foundation; either version 3 of the License, or |
| 17 | (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 26 | |
| 27 | #ifndef GDB_DWARF2_ATTRIBUTE_H |
| 28 | #define GDB_DWARF2_ATTRIBUTE_H |
| 29 | |
| 30 | #include "dwarf2.h" |
| 31 | #include "gdbtypes.h" |
| 32 | |
| 33 | /* Blocks are a bunch of untyped bytes. */ |
| 34 | struct dwarf_block |
| 35 | { |
| 36 | size_t size; |
| 37 | |
| 38 | /* Valid only if SIZE is not zero. */ |
| 39 | const gdb_byte *data; |
| 40 | }; |
| 41 | |
| 42 | /* Attributes have a name and a value. */ |
| 43 | struct attribute |
| 44 | { |
| 45 | /* Read the given attribute value as an address, taking the |
| 46 | attribute's form into account. */ |
| 47 | CORE_ADDR value_as_address () const; |
| 48 | |
| 49 | /* If the attribute has a string form, return the string value; |
| 50 | otherwise return NULL. */ |
| 51 | const char *value_as_string () const; |
| 52 | |
| 53 | /* Return non-zero if ATTR's value is a section offset --- classes |
| 54 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. |
| 55 | You may use DW_UNSND (attr) to retrieve such offsets. |
| 56 | |
| 57 | Section 7.5.4, "Attribute Encodings", explains that no attribute |
| 58 | may have a value that belongs to more than one of these classes; it |
| 59 | would be ambiguous if we did, because we use the same forms for all |
| 60 | of them. */ |
| 61 | |
| 62 | bool form_is_section_offset () const; |
| 63 | |
| 64 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
| 65 | zero otherwise. When this function returns true, you can apply |
| 66 | the constant_value method to it. |
| 67 | |
| 68 | However, note that for some attributes you must check |
| 69 | attr_form_is_section_offset before using this test. DW_FORM_data4 |
| 70 | and DW_FORM_data8 are members of both the constant class, and of |
| 71 | the classes that contain offsets into other debug sections |
| 72 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says |
| 73 | that, if an attribute's can be either a constant or one of the |
| 74 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be |
| 75 | taken as section offsets, not constants. |
| 76 | |
| 77 | DW_FORM_data16 is not considered as constant_value cannot handle |
| 78 | that. */ |
| 79 | |
| 80 | bool form_is_constant () const; |
| 81 | |
| 82 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
| 83 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ |
| 84 | |
| 85 | bool form_is_ref () const |
| 86 | { |
| 87 | return (form == DW_FORM_ref_addr |
| 88 | || form == DW_FORM_ref1 |
| 89 | || form == DW_FORM_ref2 |
| 90 | || form == DW_FORM_ref4 |
| 91 | || form == DW_FORM_ref8 |
| 92 | || form == DW_FORM_ref_udata |
| 93 | || form == DW_FORM_GNU_ref_alt); |
| 94 | } |
| 95 | |
| 96 | /* Check if the attribute's form is a DW_FORM_block* |
| 97 | if so return true else false. */ |
| 98 | |
| 99 | bool form_is_block () const; |
| 100 | |
| 101 | /* Return DIE offset of this attribute. Return 0 with complaint if |
| 102 | the attribute is not of the required kind. */ |
| 103 | |
| 104 | sect_offset get_ref_die_offset () const |
| 105 | { |
| 106 | if (form_is_ref ()) |
| 107 | return (sect_offset) u.unsnd; |
| 108 | get_ref_die_offset_complaint (); |
| 109 | return {}; |
| 110 | } |
| 111 | |
| 112 | /* Return the constant value held by this attribute. Return |
| 113 | DEFAULT_VALUE if the value held by the attribute is not |
| 114 | constant. */ |
| 115 | |
| 116 | LONGEST constant_value (int default_value) const; |
| 117 | |
| 118 | |
| 119 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 120 | ENUM_BITFIELD(dwarf_form) form : 15; |
| 121 | |
| 122 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This |
| 123 | field should be in u.str (existing only for DW_STRING) but it is kept |
| 124 | here for better struct attribute alignment. */ |
| 125 | unsigned int string_is_canonical : 1; |
| 126 | |
| 127 | union |
| 128 | { |
| 129 | const char *str; |
| 130 | struct dwarf_block *blk; |
| 131 | ULONGEST unsnd; |
| 132 | LONGEST snd; |
| 133 | CORE_ADDR addr; |
| 134 | ULONGEST signature; |
| 135 | } |
| 136 | u; |
| 137 | |
| 138 | private: |
| 139 | |
| 140 | /* Used by get_ref_die_offset to issue a complaint. */ |
| 141 | |
| 142 | void get_ref_die_offset_complaint () const; |
| 143 | }; |
| 144 | |
| 145 | /* Get at parts of an attribute structure. */ |
| 146 | |
| 147 | #define DW_STRING(attr) ((attr)->u.str) |
| 148 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
| 149 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
| 150 | #define DW_BLOCK(attr) ((attr)->u.blk) |
| 151 | #define DW_SND(attr) ((attr)->u.snd) |
| 152 | #define DW_ADDR(attr) ((attr)->u.addr) |
| 153 | #define DW_SIGNATURE(attr) ((attr)->u.signature) |
| 154 | |
| 155 | #endif /* GDB_DWARF2_ATTRIBUTE_H */ |