Add type to expression dump of symbol
[binutils-gdb.git] / gdb / expprint.c
1 /* Print in infix form a struct expression.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "value.h"
25 #include "language.h"
26 #include "parser-defs.h"
27 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
28 #include "target.h"
29 #include "block.h"
30 #include "objfiles.h"
31 #include "valprint.h"
32 #include "cli/cli-style.h"
33 #include "c-lang.h"
34 #include "expop.h"
35 #include "ada-exp.h"
36
37 #include <ctype.h>
38
39 /* Default name for the standard operator OPCODE (i.e., one defined in
40 the definition of enum exp_opcode). */
41
42 const char *
43 op_name (enum exp_opcode opcode)
44 {
45 switch (opcode)
46 {
47 default:
48 {
49 static char buf[30];
50
51 xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode);
52 return buf;
53 }
54 #define OP(name) \
55 case name: \
56 return #name ;
57 #include "std-operator.def"
58 #undef OP
59 }
60 }
61
62 /* Meant to be used in debug sessions, so don't export it in a header file. */
63 extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
64
65 /* Print EXP. */
66
67 void
68 ATTRIBUTE_USED
69 debug_exp (struct expression *exp)
70 {
71 exp->dump (gdb_stdlog);
72 gdb_flush (gdb_stdlog);
73 }
74
75 namespace expr
76 {
77
78 void
79 dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
80 {
81 gdb_printf (stream, _("%*sOperation: %s\n"), depth, "", op_name (op));
82 }
83
84 void
85 dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
86 {
87 gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
88 }
89
90 void
91 dump_for_expression (struct ui_file *stream, int depth, struct type *type)
92 {
93 gdb_printf (stream, _("%*sType: "), depth, "");
94 type_print (type, nullptr, stream, 0);
95 gdb_printf (stream, "\n");
96 }
97
98 void
99 dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
100 {
101 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
102 core_addr_to_string (addr));
103 }
104
105 void
106 dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
107 {
108 gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
109 internalvar_name (ivar));
110 }
111
112 void
113 dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
114 {
115 gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
116 sym->print_name ());
117 dump_for_expression (stream, depth + 1, sym->type ());
118 }
119
120 void
121 dump_for_expression (struct ui_file *stream, int depth,
122 bound_minimal_symbol msym)
123 {
124 gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
125 msym.minsym->print_name (), objfile_name (msym.objfile));
126 }
127
128 void
129 dump_for_expression (struct ui_file *stream, int depth, const block *bl)
130 {
131 gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
132 }
133
134 void
135 dump_for_expression (struct ui_file *stream, int depth,
136 const block_symbol &sym)
137 {
138 gdb_printf (stream, _("%*sBlock symbol:\n"), depth, "");
139 dump_for_expression (stream, depth + 1, sym.symbol);
140 dump_for_expression (stream, depth + 1, sym.block);
141 }
142
143 void
144 dump_for_expression (struct ui_file *stream, int depth,
145 type_instance_flags flags)
146 {
147 gdb_printf (stream, _("%*sType flags: "), depth, "");
148 if (flags & TYPE_INSTANCE_FLAG_CONST)
149 gdb_puts ("const ", stream);
150 if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
151 gdb_puts ("volatile", stream);
152 gdb_printf (stream, "\n");
153 }
154
155 void
156 dump_for_expression (struct ui_file *stream, int depth,
157 enum c_string_type_values flags)
158 {
159 gdb_printf (stream, _("%*sC string flags: "), depth, "");
160 switch (flags & ~C_CHAR)
161 {
162 case C_WIDE_STRING:
163 gdb_puts (_("wide "), stream);
164 break;
165 case C_STRING_16:
166 gdb_puts (_("u16 "), stream);
167 break;
168 case C_STRING_32:
169 gdb_puts (_("u32 "), stream);
170 break;
171 default:
172 gdb_puts (_("ordinary "), stream);
173 break;
174 }
175
176 if ((flags & C_CHAR) != 0)
177 gdb_puts (_("char"), stream);
178 else
179 gdb_puts (_("string"), stream);
180 gdb_puts ("\n", stream);
181 }
182
183 void
184 dump_for_expression (struct ui_file *stream, int depth,
185 enum range_flag flags)
186 {
187 gdb_printf (stream, _("%*sRange:"), depth, "");
188 if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
189 gdb_puts (_("low-default "), stream);
190 if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
191 gdb_puts (_("high-default "), stream);
192 if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
193 gdb_puts (_("high-exclusive "), stream);
194 if ((flags & RANGE_HAS_STRIDE) != 0)
195 gdb_puts (_("has-stride"), stream);
196 gdb_printf (stream, "\n");
197 }
198
199 void
200 dump_for_expression (struct ui_file *stream, int depth,
201 const std::unique_ptr<ada_component> &comp)
202 {
203 comp->dump (stream, depth);
204 }
205
206 void
207 float_const_operation::dump (struct ui_file *stream, int depth) const
208 {
209 gdb_printf (stream, _("%*sFloat: "), depth, "");
210 print_floating (m_data.data (), m_type, stream);
211 gdb_printf (stream, "\n");
212 }
213
214 } /* namespace expr */