GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/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" /* For user_reg_map_regnum_to_name. */
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/* Default name for the standard operator OPCODE (i.e., one defined in
40 the definition of enum exp_opcode). */
41
42const char *
43op_name (enum exp_opcode opcode)
44{
45 switch (opcode)
46 {
47 default:
48 {
49 static char buf[30];
50
51 xsnprintf (buf, sizeof (buf), "<unknown %d>", opcode);
52 return buf;
53 }
54#define OP(name) \
55 case name: \
56 return #name ;
57#include "std-operator.def"
58#undef OP
59 }
60}
61
62/* Meant to be used in debug sessions, so don't export it in a header file. */
63extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
64
65/* Print EXP. */
66
67void
68ATTRIBUTE_USED
69debug_exp (struct expression *exp)
70{
71 exp->op->dump (gdb_stdlog, 0);
73}
74
75namespace expr
76{
77
78void
79dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
80{
81 gdb_printf (stream, _("%*sOperation: %s\n"), depth, "", op_name (op));
82}
83
84void
85dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
86{
87 gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
88}
89
90void
91dump_for_expression (struct ui_file *stream, int depth, struct type *type)
92{
93 gdb_printf (stream, _("%*sType: "), depth, "");
94 type_print (type, nullptr, stream, 0);
95 gdb_printf (stream, "\n");
96}
97
98void
99dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
100{
101 gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
102 core_addr_to_string (addr));
103}
104
105void
106dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
107{
108 gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
109 internalvar_name (ivar));
110}
111
112void
113dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
114{
115 gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
116 sym->print_name ());
117}
118
119void
120dump_for_expression (struct ui_file *stream, int depth,
122{
123 gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
124 msym.minsym->print_name (), objfile_name (msym.objfile));
125}
126
127void
128dump_for_expression (struct ui_file *stream, int depth, const block *bl)
129{
130 gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
131}
132
133void
134dump_for_expression (struct ui_file *stream, int depth,
135 const block_symbol &sym)
136{
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);
140}
141
142void
143dump_for_expression (struct ui_file *stream, int depth,
144 type_instance_flags flags)
145{
146 gdb_printf (stream, _("%*sType flags: "), depth, "");
148 gdb_puts ("const ", stream);
150 gdb_puts ("volatile", stream);
151 gdb_printf (stream, "\n");
152}
153
154void
155dump_for_expression (struct ui_file *stream, int depth,
157{
158 gdb_printf (stream, _("%*sC string flags: "), depth, "");
159 switch (flags & ~C_CHAR)
160 {
161 case C_WIDE_STRING:
162 gdb_puts (_("wide "), stream);
163 break;
164 case C_STRING_16:
165 gdb_puts (_("u16 "), stream);
166 break;
167 case C_STRING_32:
168 gdb_puts (_("u32 "), stream);
169 break;
170 default:
171 gdb_puts (_("ordinary "), stream);
172 break;
173 }
174
175 if ((flags & C_CHAR) != 0)
176 gdb_puts (_("char"), stream);
177 else
178 gdb_puts (_("string"), stream);
179 gdb_puts ("\n", stream);
180}
181
182void
183dump_for_expression (struct ui_file *stream, int depth,
184 enum range_flag flags)
185{
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);
192 gdb_puts (_("high-exclusive "), stream);
193 if ((flags & RANGE_HAS_STRIDE) != 0)
194 gdb_puts (_("has-stride"), stream);
195 gdb_printf (stream, "\n");
196}
197
198void
199dump_for_expression (struct ui_file *stream, int depth,
200 const std::unique_ptr<ada_component> &comp)
201{
202 comp->dump (stream, depth);
203}
204
205void
206float_const_operation::dump (struct ui_file *stream, int depth) const
207{
208 gdb_printf (stream, _("%*sFloat: "), depth, "");
209 print_floating (m_data.data (), m_type, stream);
210 gdb_printf (stream, "\n");
211}
212
213} /* namespace expr */
c_string_type_values
Definition: c-lang.h:38
@ C_WIDE_STRING
Definition: c-lang.h:42
@ C_STRING_16
Definition: c-lang.h:44
@ C_CHAR
Definition: c-lang.h:50
@ C_STRING_32
Definition: c-lang.h:46
void dump(struct ui_file *stream, int depth) const override
Definition: expprint.c:206
struct type * m_type
Definition: expop.h:582
const char * op_name(enum exp_opcode opcode)
Definition: expprint.c:43
void ATTRIBUTE_USED debug_exp(struct expression *exp)
Definition: expprint.c:69
exp_opcode
Definition: expression.h:44
range_flag
Definition: expression.h:293
@ RANGE_LOW_BOUND_DEFAULT
Definition: expression.h:299
@ RANGE_HIGH_BOUND_EXCLUSIVE
Definition: expression.h:305
@ RANGE_HIGH_BOUND_DEFAULT
Definition: expression.h:302
@ RANGE_HAS_STRIDE
Definition: expression.h:308
@ TYPE_INSTANCE_FLAG_CONST
Definition: gdbtypes.h:113
@ TYPE_INSTANCE_FLAG_VOLATILE
Definition: gdbtypes.h:114
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:1862
Definition: ada-exp.h:80
static void dump_for_expression(struct ui_file *stream, int depth, const operation_up &op)
Definition: expop.h:311
const char * objfile_name(const struct objfile *objfile)
Definition: objfiles.c:1308
const struct block * block
Definition: symtab.h:1498
struct symbol * symbol
Definition: symtab.h:1494
Definition: block.h:109
struct objfile * objfile
Definition: minsyms.h:54
struct minimal_symbol * minsym
Definition: minsyms.h:49
expr::operation_up op
Definition: expression.h:226
const char * print_name() const
Definition: symtab.h:474
Definition: gdbtypes.h:922
void type_print(struct type *type, const char *varstring, struct ui_file *stream, int show)
Definition: typeprint.c:391
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition: utils.c:1865
void gdb_flush(struct ui_file *stream)
Definition: utils.c:1477
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1788
#define gdb_stdlog
Definition: utils.h:196
void print_floating(const gdb_byte *valaddr, struct type *type, struct ui_file *stream)
Definition: valprint.c:1373
const char * internalvar_name(const struct internalvar *var)
Definition: value.c:2520