1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "expression.h"
25 #include "parser-defs.h"
26 #include "user-regs.h"
31 #include "cli/cli-style.h"
38 /* Meant to be used in debug sessions, so don't export it in a header file. */
39 extern void ATTRIBUTE_USED
debug_exp (struct expression
*exp
);
45 debug_exp (struct expression
*exp
)
47 exp
->dump (gdb_stdlog
);
48 gdb_flush (gdb_stdlog
);
55 check_objfile (const struct block
*block
, struct objfile
*objfile
)
57 return check_objfile (block
->objfile (), objfile
);
61 dump_for_expression (struct ui_file
*stream
, int depth
, enum exp_opcode op
)
63 gdb_printf (stream
, _("%*sOperation: "), depth
, "");
68 gdb_printf (stream
, "<unknown %d>", op
);
73 gdb_puts (#name, stream); \
75 #include "std-operator.def"
79 gdb_puts ("\n", stream
);
83 dump_for_expression (struct ui_file
*stream
, int depth
, const std::string
&str
)
85 gdb_printf (stream
, _("%*sString: %s\n"), depth
, "", str
.c_str ());
89 dump_for_expression (struct ui_file
*stream
, int depth
, struct type
*type
)
91 gdb_printf (stream
, _("%*sType: "), depth
, "");
92 type_print (type
, nullptr, stream
, 0);
93 gdb_printf (stream
, "\n");
97 dump_for_expression (struct ui_file
*stream
, int depth
, CORE_ADDR addr
)
99 gdb_printf (stream
, _("%*sConstant: %s\n"), depth
, "",
100 core_addr_to_string (addr
));
104 dump_for_expression (struct ui_file
*stream
, int depth
, const gdb_mpz
&val
)
106 gdb_printf (stream
, _("%*sConstant: %s\n"), depth
, "", val
.str ().c_str ());
110 dump_for_expression (struct ui_file
*stream
, int depth
, internalvar
*ivar
)
112 gdb_printf (stream
, _("%*sInternalvar: $%s\n"), depth
, "",
113 internalvar_name (ivar
));
117 dump_for_expression (struct ui_file
*stream
, int depth
, symbol
*sym
)
119 gdb_printf (stream
, _("%*sSymbol: %s\n"), depth
, "",
121 dump_for_expression (stream
, depth
+ 1, sym
->type ());
125 dump_for_expression (struct ui_file
*stream
, int depth
,
126 bound_minimal_symbol msym
)
128 gdb_printf (stream
, _("%*sMinsym %s in objfile %s\n"), depth
, "",
129 msym
.minsym
->print_name (), objfile_name (msym
.objfile
));
133 dump_for_expression (struct ui_file
*stream
, int depth
, const block
*bl
)
135 gdb_printf (stream
, _("%*sBlock: %p\n"), depth
, "", bl
);
139 dump_for_expression (struct ui_file
*stream
, int depth
,
140 const block_symbol
&sym
)
142 gdb_printf (stream
, _("%*sBlock symbol:\n"), depth
, "");
143 dump_for_expression (stream
, depth
+ 1, sym
.symbol
);
144 dump_for_expression (stream
, depth
+ 1, sym
.block
);
148 dump_for_expression (struct ui_file
*stream
, int depth
,
149 type_instance_flags flags
)
151 gdb_printf (stream
, _("%*sType flags: "), depth
, "");
152 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
153 gdb_puts ("const ", stream
);
154 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
155 gdb_puts ("volatile", stream
);
156 gdb_printf (stream
, "\n");
160 dump_for_expression (struct ui_file
*stream
, int depth
,
161 enum c_string_type_values flags
)
163 gdb_printf (stream
, _("%*sC string flags: "), depth
, "");
164 switch (flags
& ~C_CHAR
)
167 gdb_puts (_("wide "), stream
);
170 gdb_puts (_("u16 "), stream
);
173 gdb_puts (_("u32 "), stream
);
176 gdb_puts (_("ordinary "), stream
);
180 if ((flags
& C_CHAR
) != 0)
181 gdb_puts (_("char"), stream
);
183 gdb_puts (_("string"), stream
);
184 gdb_puts ("\n", stream
);
188 dump_for_expression (struct ui_file
*stream
, int depth
,
189 enum range_flag flags
)
191 gdb_printf (stream
, _("%*sRange:"), depth
, "");
192 if ((flags
& RANGE_LOW_BOUND_DEFAULT
) != 0)
193 gdb_puts (_("low-default "), stream
);
194 if ((flags
& RANGE_HIGH_BOUND_DEFAULT
) != 0)
195 gdb_puts (_("high-default "), stream
);
196 if ((flags
& RANGE_HIGH_BOUND_EXCLUSIVE
) != 0)
197 gdb_puts (_("high-exclusive "), stream
);
198 if ((flags
& RANGE_HAS_STRIDE
) != 0)
199 gdb_puts (_("has-stride"), stream
);
200 gdb_printf (stream
, "\n");
204 dump_for_expression (struct ui_file
*stream
, int depth
,
205 const std::unique_ptr
<ada_component
> &comp
)
207 comp
->dump (stream
, depth
);
211 float_const_operation::dump (struct ui_file
*stream
, int depth
) const
213 gdb_printf (stream
, _("%*sFloat: "), depth
, "");
214 print_floating (m_data
.data (), m_type
, stream
);
215 gdb_printf (stream
, "\n");
218 } /* namespace expr */