GDB (xrefs)
Loading...
Searching...
No Matches
expprint.c
Go to the documentation of this file.
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. */
40extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
41
42/* Print EXP. */
43
44void
45ATTRIBUTE_USED
46debug_exp (struct expression *exp)
47{
48 exp->dump (gdb_stdlog);
50}
51
52namespace expr
53{
54
55bool
56check_objfile (const struct block *block, struct objfile *objfile)
57{
58 return check_objfile (block->objfile (), objfile);
59}
60
61void
62dump_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
83void
84dump_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
89void
90dump_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
97void
98dump_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
104void
105dump_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
110void
111dump_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
117void
118dump_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
125void
126dump_for_expression (struct ui_file *stream, int depth,
128{
129 gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
130 msym.minsym->print_name (), objfile_name (msym.objfile));
131}
132
133void
134dump_for_expression (struct ui_file *stream, int depth, const block *bl)
135{
136 gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
137}
138
139void
140dump_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
148void
149dump_for_expression (struct ui_file *stream, int depth,
150 type_instance_flags flags)
151{
152 gdb_printf (stream, _("%*sType flags: "), depth, "");
154 gdb_puts ("const ", stream);
156 gdb_puts ("volatile", stream);
157 gdb_printf (stream, "\n");
158}
159
160void
161dump_for_expression (struct ui_file *stream, int depth,
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
188void
189dump_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);
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
204void
205dump_for_expression (struct ui_file *stream, int depth,
206 const std::unique_ptr<ada_component> &comp)
207{
208 comp->dump (stream, depth);
209}
210
211void
212float_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 */
c_string_type_values
Definition c-lang.h:40
@ C_WIDE_STRING
Definition c-lang.h:44
@ C_STRING_16
Definition c-lang.h:46
@ C_CHAR
Definition c-lang.h:52
@ C_STRING_32
Definition c-lang.h:48
void dump(struct ui_file *stream, int depth) const override
Definition expprint.c:212
struct type * m_type
Definition expop.h:591
void ATTRIBUTE_USED debug_exp(struct expression *exp)
Definition expprint.c:46
exp_opcode
Definition expression.h:45
range_flag
Definition expression.h:370
@ RANGE_LOW_BOUND_DEFAULT
Definition expression.h:376
@ RANGE_HIGH_BOUND_EXCLUSIVE
Definition expression.h:382
@ RANGE_HIGH_BOUND_DEFAULT
Definition expression.h:379
@ RANGE_HAS_STRIDE
Definition expression.h:385
@ TYPE_INSTANCE_FLAG_CONST
Definition gdbtypes.h:96
@ TYPE_INSTANCE_FLAG_VOLATILE
Definition gdbtypes.h:97
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
Definition ada-exp.h:87
bool check_objfile(const std::unique_ptr< ada_component > &comp, struct objfile *objfile)
Definition ada-lang.c:9386
static void dump_for_expression(struct ui_file *stream, int depth, const operation_up &op)
Definition expop.h:309
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
const struct block * block
Definition symtab.h:1537
struct symbol * symbol
Definition symtab.h:1533
Definition block.h:109
struct objfile * objfile() const
Definition block.c:43
struct objfile * objfile
Definition minsyms.h:54
struct minimal_symbol * minsym
Definition minsyms.h:49
void dump(struct ui_file *stream)
Definition expression.h:213
std::string str() const
Definition gmp-utils.h:162
const char * print_name() const
Definition symtab.h:475
struct type * type() const
Definition symtab.h:1331
void type_print(struct type *type, const char *varstring, struct ui_file *stream, int show)
Definition typeprint.c:388
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void gdb_flush(struct ui_file *stream)
Definition utils.c:1498
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
#define gdb_stdlog
Definition utils.h:190
void print_floating(const gdb_byte *valaddr, struct type *type, struct ui_file *stream)
Definition valprint.c:1392
const char * internalvar_name(const struct internalvar *var)
Definition value.c:2287