GDB (xrefs)
Loading...
Searching...
No Matches
typeprint.h
Go to the documentation of this file.
1/* Language independent support for printing types for GDB, the GNU debugger.
2 Copyright (C) 1986-2023 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 "gdbsupport/gdb_obstack.h"
23
24enum language;
25struct ui_file;
28
30{
31 /* True means that no special printing flags should apply. */
32 unsigned int raw : 1;
33
34 /* True means print methods in a class. */
35 unsigned int print_methods : 1;
36
37 /* True means print typedefs in a class. */
38 unsigned int print_typedefs : 1;
39
40 /* True means to print offsets, a la 'pahole'. */
41 unsigned int print_offsets : 1;
42
43 /* True means to print offsets in hex, otherwise use decimal. */
44 unsigned int print_in_hex : 1;
45
46 /* The number of nested type definitions to print. -1 == all. */
48
49 /* If not NULL, a local typedef hash table used when printing a
50 type. */
52
53 /* If not NULL, a global typedef hash table used when printing a
54 type. */
56
57 /* The list of type printers associated with the global typedef
58 table. This is intentionally opaque. */
60};
61
63{
64 /* Indicate if the offset an d size fields should be printed in decimal
65 (default) or hexadecimal. */
66 bool print_in_hex = false;
67
68 /* The offset to be applied to bitpos when PRINT_OFFSETS is true.
69 This is needed for when we are printing nested structs and want
70 to make sure that the printed offset for each field carries over
71 the offset of the outer struct. */
72 unsigned int offset_bitpos = 0;
73
74 /* END_BITPOS is the one-past-the-end bit position of the previous
75 field (where we expect the current field to be if there is no
76 hole). */
77 unsigned int end_bitpos = 0;
78
79 /* Print information about field at index FIELD_IDX of the struct type
80 TYPE and update this object.
81
82 If the field is static, it simply prints the correct number of
83 spaces.
84
85 The output is strongly based on pahole(1). */
86 void update (struct type *type, unsigned int field_idx,
87 struct ui_file *stream);
88
89 /* Call when all fields have been printed. This will print
90 information about any padding that may exist. LEVEL is the
91 desired indentation level. */
92 void finish (struct type *type, int level, struct ui_file *stream);
93
94 /* When printing the offsets of a struct and its fields (i.e.,
95 'ptype /o'; type_print_options::print_offsets), we use this many
96 characters when printing the offset information at the beginning
97 of the line. This is needed in order to generate the correct
98 amount of whitespaces when no offset info should be printed for a
99 certain field. */
100 static const int indentation;
101
102 explicit print_offset_data (const struct type_print_options *flags);
103
104private:
105
106 /* Helper function for ptype/o implementation that prints
107 information about a hole, if necessary. STREAM is where to
108 print. BITPOS is the bitpos of the current field. FOR_WHAT is a
109 string describing the purpose of the hole. */
110
111 void maybe_print_hole (struct ui_file *stream, unsigned int bitpos,
112 const char *for_what);
113};
114
116
117/* A hash table holding typedef_field objects. This is more
118 complicated than an ordinary hash because it must also track the
119 lifetime of some -- but not all -- of the contained objects. */
120
122{
123public:
124
125 /* Create a new typedef-lookup hash table. */
127
128 /* Copy a typedef hash. */
130
132
133 /* Add typedefs from T to the hash table TABLE. */
134 void recursively_update (struct type *);
135
136 /* Add template parameters from T to the typedef hash TABLE. */
137 void add_template_parameters (struct type *t);
138
139 /* Look up the type T in the typedef hash tables contained in FLAGS.
140 The local table is searched first, then the global table (either
141 table can be NULL, in which case it is skipped). If T is in a
142 table, return its short (class-relative) typedef name. Otherwise
143 return NULL. */
144 static const char *find_typedef (const struct type_print_options *flags,
145 struct type *t);
146
147private:
148
149 static const char *find_global_typedef (const struct type_print_options *flags,
150 struct type *t);
151
152
153 /* The actual hash table. */
154 htab_up m_table;
155
156 /* Storage for typedef_field objects that must be synthesized. */
157 auto_obstack m_storage;
158};
159
160
161void print_type_scalar (struct type * type, LONGEST, struct ui_file *);
162
163/* Assuming the TYPE is a fixed point type, print its type description
164 on STREAM. */
165
166void print_type_fixed_point (struct type *type, struct ui_file *stream);
167
168void c_type_print_args (struct type *, struct ui_file *, int, enum language,
169 const struct type_print_options *);
170
171/* Print <unknown return type> to stream STREAM. */
172
173void type_print_unknown_return_type (struct ui_file *stream);
174
175/* Throw an error indicating that the user tried to use a symbol that
176 has unknown type. SYM_PRINT_NAME is the name of the symbol, to be
177 included in the error message. */
178extern void error_unknown_type (const char *sym_print_name);
179
180extern void val_print_not_allocated (struct ui_file *stream);
181
182extern void val_print_not_associated (struct ui_file *stream);
183
184#endif
auto_obstack m_storage
Definition typeprint.h:157
void add_template_parameters(struct type *t)
Definition typeprint.c:247
static const char * find_global_typedef(const struct type_print_options *flags, struct type *t)
Definition typeprint.c:309
typedef_hash_table & operator=(const typedef_hash_table &)=delete
static const char * find_typedef(const struct type_print_options *flags, struct type *t)
Definition typeprint.c:349
void recursively_update(struct type *)
Definition typeprint.c:222
language
Definition defs.h:211
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
void update(struct type *type, unsigned int field_idx, struct ui_file *stream)
Definition typeprint.c:125
static const int indentation
Definition typeprint.h:100
void finish(struct type *type, int level, struct ui_file *stream)
Definition typeprint.c:184
unsigned int offset_bitpos
Definition typeprint.h:72
print_offset_data(const struct type_print_options *flags)
Definition typeprint.c:77
void maybe_print_hole(struct ui_file *stream, unsigned int bitpos, const char *for_what)
Definition typeprint.c:86
unsigned int end_bitpos
Definition typeprint.h:77
unsigned int print_in_hex
Definition typeprint.h:44
unsigned int print_offsets
Definition typeprint.h:41
unsigned int print_methods
Definition typeprint.h:35
unsigned int print_typedefs
Definition typeprint.h:38
unsigned int raw
Definition typeprint.h:32
int print_nested_type_limit
Definition typeprint.h:47
typedef_hash_table * global_typedefs
Definition typeprint.h:55
struct ext_lang_type_printers * global_printers
Definition typeprint.h:59
typedef_hash_table * local_typedefs
Definition typeprint.h:51
void c_type_print_args(struct type *, struct ui_file *, int, enum language, const struct type_print_options *)
void val_print_not_allocated(struct ui_file *stream)
Definition typeprint.c:898
void print_type_fixed_point(struct type *type, struct ui_file *stream)
Definition typeprint.c:693
const struct type_print_options type_print_raw_options
Definition typeprint.c:41
void val_print_not_associated(struct ui_file *stream)
Definition typeprint.c:906
void error_unknown_type(const char *sym_print_name)
Definition typeprint.c:427
void print_type_scalar(struct type *type, LONGEST, struct ui_file *)
Definition typeprint.c:616
void type_print_unknown_return_type(struct ui_file *stream)
Definition typeprint.c:418