1 /* Print in infix form a struct expression.
3 Copyright (C) 1986-2023 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/>. */
23 #include "expression.h"
26 #include "parser-defs.h"
27 #include "user-regs.h" /* For user_reg_map_regnum_to_name. */
32 #include "cli/cli-style.h"
39 /* Default name for the standard operator OPCODE (i.e., one defined in
40 the definition of enum exp_opcode). */
43 op_name (enum exp_opcode opcode
)
51 xsnprintf (buf
, sizeof (buf
), "<unknown %d>", opcode
);
57 #include "std-operator.def"
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
);
69 debug_exp (struct expression
*exp
)
71 exp
->op
->dump (gdb_stdlog
, 0);
72 gdb_flush (gdb_stdlog
);
79 dump_for_expression (struct ui_file
*stream
, int depth
, enum exp_opcode op
)
81 gdb_printf (stream
, _("%*sOperation: %s\n"), depth
, "", op_name (op
));
85 dump_for_expression (struct ui_file
*stream
, int depth
, const std::string
&str
)
87 gdb_printf (stream
, _("%*sString: %s\n"), depth
, "", str
.c_str ());
91 dump_for_expression (struct ui_file
*stream
, int depth
, struct type
*type
)
93 gdb_printf (stream
, _("%*sType: "), depth
, "");
94 type_print (type
, nullptr, stream
, 0);
95 gdb_printf (stream
, "\n");
99 dump_for_expression (struct ui_file
*stream
, int depth
, CORE_ADDR addr
)
101 gdb_printf (stream
, _("%*sConstant: %s\n"), depth
, "",
102 core_addr_to_string (addr
));
106 dump_for_expression (struct ui_file
*stream
, int depth
, internalvar
*ivar
)
108 gdb_printf (stream
, _("%*sInternalvar: $%s\n"), depth
, "",
109 internalvar_name (ivar
));
113 dump_for_expression (struct ui_file
*stream
, int depth
, symbol
*sym
)
115 gdb_printf (stream
, _("%*sSymbol: %s\n"), depth
, "",
120 dump_for_expression (struct ui_file
*stream
, int depth
,
121 bound_minimal_symbol msym
)
123 gdb_printf (stream
, _("%*sMinsym %s in objfile %s\n"), depth
, "",
124 msym
.minsym
->print_name (), objfile_name (msym
.objfile
));
128 dump_for_expression (struct ui_file
*stream
, int depth
, const block
*bl
)
130 gdb_printf (stream
, _("%*sBlock: %p\n"), depth
, "", bl
);
134 dump_for_expression (struct ui_file
*stream
, int depth
,
135 const block_symbol
&sym
)
137 gdb_printf (stream
, _("%*sBlock symbol:\n"), depth
, "");
138 dump_for_expression (stream
, depth
+ 1, sym
.symbol
);
139 dump_for_expression (stream
, depth
+ 1, sym
.block
);
143 dump_for_expression (struct ui_file
*stream
, int depth
,
144 type_instance_flags flags
)
146 gdb_printf (stream
, _("%*sType flags: "), depth
, "");
147 if (flags
& TYPE_INSTANCE_FLAG_CONST
)
148 gdb_puts ("const ", stream
);
149 if (flags
& TYPE_INSTANCE_FLAG_VOLATILE
)
150 gdb_puts ("volatile", stream
);
151 gdb_printf (stream
, "\n");
155 dump_for_expression (struct ui_file
*stream
, int depth
,
156 enum c_string_type_values flags
)
158 gdb_printf (stream
, _("%*sC string flags: "), depth
, "");
159 switch (flags
& ~C_CHAR
)
162 gdb_puts (_("wide "), stream
);
165 gdb_puts (_("u16 "), stream
);
168 gdb_puts (_("u32 "), stream
);
171 gdb_puts (_("ordinary "), stream
);
175 if ((flags
& C_CHAR
) != 0)
176 gdb_puts (_("char"), stream
);
178 gdb_puts (_("string"), stream
);
179 gdb_puts ("\n", stream
);
183 dump_for_expression (struct ui_file
*stream
, int depth
,
184 enum range_flag flags
)
186 gdb_printf (stream
, _("%*sRange:"), depth
, "");
187 if ((flags
& RANGE_LOW_BOUND_DEFAULT
) != 0)
188 gdb_puts (_("low-default "), stream
);
189 if ((flags
& RANGE_HIGH_BOUND_DEFAULT
) != 0)
190 gdb_puts (_("high-default "), stream
);
191 if ((flags
& RANGE_HIGH_BOUND_EXCLUSIVE
) != 0)
192 gdb_puts (_("high-exclusive "), stream
);
193 if ((flags
& RANGE_HAS_STRIDE
) != 0)
194 gdb_puts (_("has-stride"), stream
);
195 gdb_printf (stream
, "\n");
199 dump_for_expression (struct ui_file
*stream
, int depth
,
200 const std::unique_ptr
<ada_component
> &comp
)
202 comp
->dump (stream
, depth
);
206 float_const_operation::dump (struct ui_file
*stream
, int depth
) const
208 gdb_printf (stream
, _("%*sFloat: "), depth
, "");
209 print_floating (m_data
.data (), m_type
, stream
);
210 gdb_printf (stream
, "\n");
213 } /* namespace expr */