]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/expprint.c
gdb, gdbserver, gdbsupport: remove includes of early headers
[thirdparty/binutils-gdb.git] / gdb / expprint.c
CommitLineData
c906108c 1/* Print in infix form a struct expression.
1bac305b 2
1d506c26 3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
4de283e4 20#include "symtab.h"
d55e5aa6 21#include "gdbtypes.h"
4de283e4
TT
22#include "expression.h"
23#include "value.h"
c906108c
SS
24#include "language.h"
25#include "parser-defs.h"
ef0f16cc 26#include "user-regs.h"
82eeeb94 27#include "target.h"
4de283e4
TT
28#include "block.h"
29#include "objfiles.h"
79a45b7d 30#include "valprint.h"
7f6aba03 31#include "cli/cli-style.h"
de401988
TT
32#include "c-lang.h"
33#include "expop.h"
a88c4354 34#include "ada-exp.h"
4de283e4
TT
35
36#include <ctype.h>
c906108c 37
731d2cc1
TV
38/* Meant to be used in debug sessions, so don't export it in a header file. */
39extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
40
41/* Print EXP. */
42
43void
44ATTRIBUTE_USED
45debug_exp (struct expression *exp)
46{
ce6fcad8 47 exp->dump (gdb_stdlog);
731d2cc1
TV
48 gdb_flush (gdb_stdlog);
49}
50
de401988
TT
51namespace expr
52{
53
0671cc8b
TT
54bool
55check_objfile (const struct block *block, struct objfile *objfile)
56{
46baa3c6 57 return check_objfile (block->objfile (), objfile);
0671cc8b
TT
58}
59
de401988
TT
60void
61dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
62{
b785bb6d
TT
63 gdb_printf (stream, _("%*sOperation: "), depth, "");
64
65 switch (op)
66 {
67 default:
68 gdb_printf (stream, "<unknown %d>", op);
69 break;
70
71#define OP(name) \
72 case name: \
73 gdb_puts (#name, stream); \
74 break;
75#include "std-operator.def"
76#undef OP
77 }
78
79 gdb_puts ("\n", stream);
de401988
TT
80}
81
82void
83dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
84{
6cb06a8c 85 gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
de401988
TT
86}
87
88void
89dump_for_expression (struct ui_file *stream, int depth, struct type *type)
90{
6cb06a8c 91 gdb_printf (stream, _("%*sType: "), depth, "");
de401988 92 type_print (type, nullptr, stream, 0);
6cb06a8c 93 gdb_printf (stream, "\n");
de401988
TT
94}
95
96void
97dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
98{
6cb06a8c
TT
99 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
100 core_addr_to_string (addr));
de401988
TT
101}
102
5309ce2f
TT
103void
104dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val)
105{
106 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ());
107}
108
de401988
TT
109void
110dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
111{
6cb06a8c
TT
112 gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
113 internalvar_name (ivar));
de401988
TT
114}
115
116void
117dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
118{
6cb06a8c
TT
119 gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
120 sym->print_name ());
d66641b6 121 dump_for_expression (stream, depth + 1, sym->type ());
de401988
TT
122}
123
124void
9c79936b
TT
125dump_for_expression (struct ui_file *stream, int depth,
126 bound_minimal_symbol msym)
de401988 127{
6cb06a8c
TT
128 gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
129 msym.minsym->print_name (), objfile_name (msym.objfile));
de401988
TT
130}
131
132void
133dump_for_expression (struct ui_file *stream, int depth, const block *bl)
134{
6cb06a8c 135 gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
de401988
TT
136}
137
9e5e03df
TT
138void
139dump_for_expression (struct ui_file *stream, int depth,
140 const block_symbol &sym)
141{
6cb06a8c 142 gdb_printf (stream, _("%*sBlock symbol:\n"), depth, "");
9e5e03df
TT
143 dump_for_expression (stream, depth + 1, sym.symbol);
144 dump_for_expression (stream, depth + 1, sym.block);
145}
146
de401988
TT
147void
148dump_for_expression (struct ui_file *stream, int depth,
149 type_instance_flags flags)
150{
6cb06a8c 151 gdb_printf (stream, _("%*sType flags: "), depth, "");
de401988 152 if (flags & TYPE_INSTANCE_FLAG_CONST)
0426ad51 153 gdb_puts ("const ", stream);
de401988 154 if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
0426ad51 155 gdb_puts ("volatile", stream);
6cb06a8c 156 gdb_printf (stream, "\n");
de401988
TT
157}
158
159void
160dump_for_expression (struct ui_file *stream, int depth,
161 enum c_string_type_values flags)
162{
6cb06a8c 163 gdb_printf (stream, _("%*sC string flags: "), depth, "");
de401988
TT
164 switch (flags & ~C_CHAR)
165 {
166 case C_WIDE_STRING:
0426ad51 167 gdb_puts (_("wide "), stream);
de401988
TT
168 break;
169 case C_STRING_16:
0426ad51 170 gdb_puts (_("u16 "), stream);
de401988
TT
171 break;
172 case C_STRING_32:
0426ad51 173 gdb_puts (_("u32 "), stream);
de401988
TT
174 break;
175 default:
0426ad51 176 gdb_puts (_("ordinary "), stream);
de401988
TT
177 break;
178 }
179
180 if ((flags & C_CHAR) != 0)
0426ad51 181 gdb_puts (_("char"), stream);
de401988 182 else
0426ad51
TT
183 gdb_puts (_("string"), stream);
184 gdb_puts ("\n", stream);
de401988
TT
185}
186
de401988
TT
187void
188dump_for_expression (struct ui_file *stream, int depth,
189 enum range_flag flags)
190{
6cb06a8c 191 gdb_printf (stream, _("%*sRange:"), depth, "");
de401988 192 if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
0426ad51 193 gdb_puts (_("low-default "), stream);
de401988 194 if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
0426ad51 195 gdb_puts (_("high-default "), stream);
de401988 196 if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
0426ad51 197 gdb_puts (_("high-exclusive "), stream);
de401988 198 if ((flags & RANGE_HAS_STRIDE) != 0)
0426ad51 199 gdb_puts (_("has-stride"), stream);
6cb06a8c 200 gdb_printf (stream, "\n");
de401988
TT
201}
202
a88c4354
TT
203void
204dump_for_expression (struct ui_file *stream, int depth,
205 const std::unique_ptr<ada_component> &comp)
206{
207 comp->dump (stream, depth);
208}
209
cae26a0c
TT
210void
211float_const_operation::dump (struct ui_file *stream, int depth) const
212{
6cb06a8c 213 gdb_printf (stream, _("%*sFloat: "), depth, "");
cae26a0c 214 print_floating (m_data.data (), m_type, stream);
6cb06a8c 215 gdb_printf (stream, "\n");
cae26a0c
TT
216}
217
de401988 218} /* namespace expr */