Remove path name from test case
[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"
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 /* Meant to be used in debug sessions, so don't export it in a header file. */
40 extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
41
42 /* Print EXP. */
43
44 void
45 ATTRIBUTE_USED
46 debug_exp (struct expression *exp)
47 {
48 exp->dump (gdb_stdlog);
49 gdb_flush (gdb_stdlog);
50 }
51
52 namespace expr
53 {
54
55 bool
56 check_objfile (const struct block *block, struct objfile *objfile)
57 {
58 return check_objfile (block->objfile (), objfile);
59 }
60
61 void
62 dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
63 {
64 gdb_printf (stream, _("%*sOperation: "), depth, "");
65
66 switch (op)
67 {
68 default:
69 gdb_printf (stream, "<unknown %d>", op);
70 break;
71
72 #define OP(name) \
73 case name: \
74 gdb_puts (#name, stream); \
75 break;
76 #include "std-operator.def"
77 #undef OP
78 }
79
80 gdb_puts ("\n", stream);
81 }
82
83 void
84 dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
85 {
86 gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
87 }
88
89 void
90 dump_for_expression (struct ui_file *stream, int depth, struct type *type)
91 {
92 gdb_printf (stream, _("%*sType: "), depth, "");
93 type_print (type, nullptr, stream, 0);
94 gdb_printf (stream, "\n");
95 }
96
97 void
98 dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
99 {
100 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
101 core_addr_to_string (addr));
102 }
103
104 void
105 dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val)
106 {
107 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ());
108 }
109
110 void
111 dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
112 {
113 gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
114 internalvar_name (ivar));
115 }
116
117 void
118 dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
119 {
120 gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
121 sym->print_name ());
122 dump_for_expression (stream, depth + 1, sym->type ());
123 }
124
125 void
126 dump_for_expression (struct ui_file *stream, int depth,
127 bound_minimal_symbol msym)
128 {
129 gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
130 msym.minsym->print_name (), objfile_name (msym.objfile));
131 }
132
133 void
134 dump_for_expression (struct ui_file *stream, int depth, const block *bl)
135 {
136 gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
137 }
138
139 void
140 dump_for_expression (struct ui_file *stream, int depth,
141 const block_symbol &sym)
142 {
143 gdb_printf (stream, _("%*sBlock symbol:\n"), depth, "");
144 dump_for_expression (stream, depth + 1, sym.symbol);
145 dump_for_expression (stream, depth + 1, sym.block);
146 }
147
148 void
149 dump_for_expression (struct ui_file *stream, int depth,
150 type_instance_flags flags)
151 {
152 gdb_printf (stream, _("%*sType flags: "), depth, "");
153 if (flags & TYPE_INSTANCE_FLAG_CONST)
154 gdb_puts ("const ", stream);
155 if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
156 gdb_puts ("volatile", stream);
157 gdb_printf (stream, "\n");
158 }
159
160 void
161 dump_for_expression (struct ui_file *stream, int depth,
162 enum c_string_type_values flags)
163 {
164 gdb_printf (stream, _("%*sC string flags: "), depth, "");
165 switch (flags & ~C_CHAR)
166 {
167 case C_WIDE_STRING:
168 gdb_puts (_("wide "), stream);
169 break;
170 case C_STRING_16:
171 gdb_puts (_("u16 "), stream);
172 break;
173 case C_STRING_32:
174 gdb_puts (_("u32 "), stream);
175 break;
176 default:
177 gdb_puts (_("ordinary "), stream);
178 break;
179 }
180
181 if ((flags & C_CHAR) != 0)
182 gdb_puts (_("char"), stream);
183 else
184 gdb_puts (_("string"), stream);
185 gdb_puts ("\n", stream);
186 }
187
188 void
189 dump_for_expression (struct ui_file *stream, int depth,
190 enum range_flag flags)
191 {
192 gdb_printf (stream, _("%*sRange:"), depth, "");
193 if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
194 gdb_puts (_("low-default "), stream);
195 if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
196 gdb_puts (_("high-default "), stream);
197 if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
198 gdb_puts (_("high-exclusive "), stream);
199 if ((flags & RANGE_HAS_STRIDE) != 0)
200 gdb_puts (_("has-stride"), stream);
201 gdb_printf (stream, "\n");
202 }
203
204 void
205 dump_for_expression (struct ui_file *stream, int depth,
206 const std::unique_ptr<ada_component> &comp)
207 {
208 comp->dump (stream, depth);
209 }
210
211 void
212 float_const_operation::dump (struct ui_file *stream, int depth) const
213 {
214 gdb_printf (stream, _("%*sFloat: "), depth, "");
215 print_floating (m_data.data (), m_type, stream);
216 gdb_printf (stream, "\n");
217 }
218
219 } /* namespace expr */