| 1 | /* Language independent support for printing types for GDB, the GNU debugger. |
| 2 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef TYPEPRINT_H |
| 20 | #define TYPEPRINT_H |
| 21 | |
| 22 | #include "gdb_obstack.h" |
| 23 | |
| 24 | enum language; |
| 25 | struct ui_file; |
| 26 | struct typedef_hash_table; |
| 27 | struct ext_lang_type_printers; |
| 28 | |
| 29 | struct print_offset_data |
| 30 | { |
| 31 | /* The offset to be applied to bitpos when PRINT_OFFSETS is true. |
| 32 | This is needed for when we are printing nested structs and want |
| 33 | to make sure that the printed offset for each field carries over |
| 34 | the offset of the outter struct. */ |
| 35 | unsigned int offset_bitpos = 0; |
| 36 | |
| 37 | /* END_BITPOS is the one-past-the-end bit position of the previous |
| 38 | field (where we expect the current field to be if there is no |
| 39 | hole). */ |
| 40 | unsigned int end_bitpos = 0; |
| 41 | |
| 42 | /* Print information about field at index FIELD_IDX of the struct type |
| 43 | TYPE and update this object. |
| 44 | |
| 45 | If the field is static, it simply prints the correct number of |
| 46 | spaces. |
| 47 | |
| 48 | The output is strongly based on pahole(1). */ |
| 49 | void update (struct type *type, unsigned int field_idx, |
| 50 | struct ui_file *stream); |
| 51 | |
| 52 | /* Call when all fields have been printed. This will print |
| 53 | information about any padding that may exist. LEVEL is the |
| 54 | desired indentation level. */ |
| 55 | void finish (struct type *type, int level, struct ui_file *stream); |
| 56 | |
| 57 | /* When printing the offsets of a struct and its fields (i.e., |
| 58 | 'ptype /o'; type_print_options::print_offsets), we use this many |
| 59 | characters when printing the offset information at the beginning |
| 60 | of the line. This is needed in order to generate the correct |
| 61 | amount of whitespaces when no offset info should be printed for a |
| 62 | certain field. */ |
| 63 | static const int indentation; |
| 64 | |
| 65 | private: |
| 66 | |
| 67 | /* Helper function for ptype/o implementation that prints |
| 68 | information about a hole, if necessary. STREAM is where to |
| 69 | print. BITPOS is the bitpos of the current field. FOR_WHAT is a |
| 70 | string describing the purpose of the hole. */ |
| 71 | |
| 72 | void maybe_print_hole (struct ui_file *stream, unsigned int bitpos, |
| 73 | const char *for_what); |
| 74 | }; |
| 75 | |
| 76 | struct type_print_options |
| 77 | { |
| 78 | /* True means that no special printing flags should apply. */ |
| 79 | unsigned int raw : 1; |
| 80 | |
| 81 | /* True means print methods in a class. */ |
| 82 | unsigned int print_methods : 1; |
| 83 | |
| 84 | /* True means print typedefs in a class. */ |
| 85 | unsigned int print_typedefs : 1; |
| 86 | |
| 87 | /* True means to print offsets, a la 'pahole'. */ |
| 88 | unsigned int print_offsets : 1; |
| 89 | |
| 90 | /* The number of nested type definitions to print. -1 == all. */ |
| 91 | int print_nested_type_limit; |
| 92 | |
| 93 | /* If not NULL, a local typedef hash table used when printing a |
| 94 | type. */ |
| 95 | typedef_hash_table *local_typedefs; |
| 96 | |
| 97 | /* If not NULL, a global typedef hash table used when printing a |
| 98 | type. */ |
| 99 | typedef_hash_table *global_typedefs; |
| 100 | |
| 101 | /* The list of type printers associated with the global typedef |
| 102 | table. This is intentionally opaque. */ |
| 103 | struct ext_lang_type_printers *global_printers; |
| 104 | }; |
| 105 | |
| 106 | extern const struct type_print_options type_print_raw_options; |
| 107 | |
| 108 | /* A hash table holding typedef_field objects. This is more |
| 109 | complicated than an ordinary hash because it must also track the |
| 110 | lifetime of some -- but not all -- of the contained objects. */ |
| 111 | |
| 112 | class typedef_hash_table |
| 113 | { |
| 114 | public: |
| 115 | |
| 116 | /* Create a new typedef-lookup hash table. */ |
| 117 | typedef_hash_table (); |
| 118 | |
| 119 | ~typedef_hash_table (); |
| 120 | |
| 121 | /* Copy a typedef hash. */ |
| 122 | typedef_hash_table (const typedef_hash_table &); |
| 123 | |
| 124 | typedef_hash_table &operator= (const typedef_hash_table &) = delete; |
| 125 | |
| 126 | /* Add typedefs from T to the hash table TABLE. */ |
| 127 | void recursively_update (struct type *); |
| 128 | |
| 129 | /* Add template parameters from T to the typedef hash TABLE. */ |
| 130 | void add_template_parameters (struct type *t); |
| 131 | |
| 132 | /* Look up the type T in the typedef hash tables contained in FLAGS. |
| 133 | The local table is searched first, then the global table (either |
| 134 | table can be NULL, in which case it is skipped). If T is in a |
| 135 | table, return its short (class-relative) typedef name. Otherwise |
| 136 | return NULL. */ |
| 137 | static const char *find_typedef (const struct type_print_options *flags, |
| 138 | struct type *t); |
| 139 | |
| 140 | private: |
| 141 | |
| 142 | static const char *find_global_typedef (const struct type_print_options *flags, |
| 143 | struct type *t); |
| 144 | |
| 145 | |
| 146 | /* The actual hash table. */ |
| 147 | htab_t m_table; |
| 148 | |
| 149 | /* Storage for typedef_field objects that must be synthesized. */ |
| 150 | auto_obstack m_storage; |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | void print_type_scalar (struct type * type, LONGEST, struct ui_file *); |
| 155 | |
| 156 | void c_type_print_args (struct type *, struct ui_file *, int, enum language, |
| 157 | const struct type_print_options *); |
| 158 | |
| 159 | /* Print <unknown return type> to stream STREAM. */ |
| 160 | |
| 161 | void type_print_unknown_return_type (struct ui_file *stream); |
| 162 | |
| 163 | /* Throw an error indicating that the user tried to use a symbol that |
| 164 | has unknown type. SYM_PRINT_NAME is the name of the symbol, to be |
| 165 | included in the error message. */ |
| 166 | extern void error_unknown_type (const char *sym_print_name); |
| 167 | |
| 168 | extern void val_print_not_allocated (struct ui_file *stream); |
| 169 | |
| 170 | extern void val_print_not_associated (struct ui_file *stream); |
| 171 | |
| 172 | #endif |