gdb/testsuite: Fix pretty-print.exp on big-endian platforms
[deliverable/binutils-gdb.git] / gdb / ui-out.h
CommitLineData
8b93c638 1/* Output generating routines for GDB.
bee0189a 2
42a4f53d 3 Copyright (C) 1999-2019 Free Software Foundation, Inc.
bee0189a 4
8b93c638
JM
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
22
23#ifndef UI_OUT_H
24#define UI_OUT_H 1
25
112e8700 26#include <vector>
bef721e2 27
268a13a5 28#include "gdbsupport/enum-flags.h"
8b93c638 29
112e8700
SM
30class ui_out_level;
31class ui_out_table;
e6e5e94c 32struct ui_file;
8b93c638
JM
33
34/* the current ui_out */
35
36/* FIXME: This should not be a global but something passed down from main.c
581e13c1 37 or top.c. */
b6dcde57
PA
38extern struct ui_out **current_ui_current_uiout_ptr (void);
39#define current_uiout (*current_ui_current_uiout_ptr ())
8b93c638
JM
40
41/* alignment enum */
42enum ui_align
43 {
44 ui_left = -1,
45 ui_center,
46 ui_right,
47 ui_noalign
48 };
49
50/* flags enum */
bef721e2 51enum ui_out_flag
13674803
SM
52{
53 ui_source_list = (1 << 0),
54 fix_multi_location_breakpoint_output = (1 << 1),
55};
8b93c638 56
bef721e2 57DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
8b93c638 58
581e13c1 59/* Prototypes for ui-out API. */
8b93c638 60
631ec795 61/* A result is a recursive data structure consisting of lists and
581e13c1 62 tuples. */
631ec795
AC
63
64enum ui_out_type
65 {
666547aa 66 ui_out_type_tuple,
631ec795
AC
67 ui_out_type_list
68 };
69
cbe56571
TT
70/* Possible kinds of styling. */
71
72enum class ui_out_style_kind
73{
74 /* The default (plain) style. */
75 DEFAULT,
76 /* File name. */
77 FILE,
78 /* Function name. */
80ae2043
TT
79 FUNCTION,
80 /* Variable name. */
35fb8261
TT
81 VARIABLE,
82 /* Address. */
83 ADDRESS
cbe56571
TT
84};
85
112e8700
SM
86class ui_out
87{
88 public:
89
90 explicit ui_out (ui_out_flags flags = 0);
91 virtual ~ui_out ();
92
93 void push_level (ui_out_type type);
94 void pop_level (ui_out_type type);
95
96 /* A table can be considered a special tuple/list combination with the
97 implied structure: ``table = { hdr = { header, ... } , body = [ {
98 field, ... }, ... ] }''. If NR_ROWS is negative then there is at
99 least one row. */
100
101 void table_begin (int nr_cols, int nr_rows, const std::string &tblid);
102 void table_header (int width, ui_align align, const std::string &col_name,
103 const std::string &col_hdr);
104 void table_body ();
105 void table_end ();
106
107 void begin (ui_out_type type, const char *id);
108 void end (ui_out_type type);
109
381befee
TT
110 void field_signed (const char *fldname, LONGEST value);
111 void field_fmt_signed (int width, ui_align align, const char *fldname,
112 LONGEST value);
113 /* Like field_signed, but print an unsigned value. */
1f77b012 114 void field_unsigned (const char *fldname, ULONGEST value);
112e8700
SM
115 void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
116 CORE_ADDR address);
cbe56571
TT
117 void field_string (const char *fldname, const char *string,
118 ui_out_style_kind style = ui_out_style_kind::DEFAULT);
6fb16ce6 119 void field_string (const char *fldname, const std::string &string);
cbe56571
TT
120 void field_stream (const char *fldname, string_file &stream,
121 ui_out_style_kind style = ui_out_style_kind::DEFAULT);
112e8700
SM
122 void field_skip (const char *fldname);
123 void field_fmt (const char *fldname, const char *format, ...)
124 ATTRIBUTE_PRINTF (3, 4);
125
126 void spaces (int numspaces);
127 void text (const char *string);
128 void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
129 void wrap_hint (const char *identstring);
130
131 void flush ();
132
133 /* Redirect the output of a ui_out object temporarily. */
7becfd03 134 void redirect (ui_file *outstream);
112e8700
SM
135
136 ui_out_flags test_flags (ui_out_flags mask);
137
138 /* HACK: Code in GDB is currently checking to see the type of ui_out
139 builder when determining which output to produce. This function is
140 a hack to encapsulate that test. Once GDB manages to separate the
141 CLI/MI from the core of GDB the problem should just go away .... */
142
4904c3c6 143 bool is_mi_like_p () const;
112e8700
SM
144
145 bool query_table_field (int colno, int *width, int *alignment,
146 const char **col_name);
147
046bebe1
TT
148 /* Return true if this stream is prepared to handle style
149 escapes. */
150 virtual bool can_emit_style_escape () const = 0;
151
112e8700
SM
152 protected:
153
154 virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
155 = 0;
156 virtual void do_table_body () = 0;
157 virtual void do_table_end () = 0;
158 virtual void do_table_header (int width, ui_align align,
159 const std::string &col_name,
160 const std::string &col_hdr) = 0;
161
162 virtual void do_begin (ui_out_type type, const char *id) = 0;
163 virtual void do_end (ui_out_type type) = 0;
381befee
TT
164 virtual void do_field_signed (int fldno, int width, ui_align align,
165 const char *fldname, LONGEST value) = 0;
1f77b012
TT
166 virtual void do_field_unsigned (int fldno, int width, ui_align align,
167 const char *fldname, ULONGEST value) = 0;
112e8700
SM
168 virtual void do_field_skip (int fldno, int width, ui_align align,
169 const char *fldname) = 0;
170 virtual void do_field_string (int fldno, int width, ui_align align,
cbe56571
TT
171 const char *fldname, const char *string,
172 ui_out_style_kind style) = 0;
112e8700
SM
173 virtual void do_field_fmt (int fldno, int width, ui_align align,
174 const char *fldname, const char *format,
175 va_list args)
176 ATTRIBUTE_PRINTF (6,0) = 0;
177 virtual void do_spaces (int numspaces) = 0;
178 virtual void do_text (const char *string) = 0;
179 virtual void do_message (const char *format, va_list args)
180 ATTRIBUTE_PRINTF (2,0) = 0;
181 virtual void do_wrap_hint (const char *identstring) = 0;
182 virtual void do_flush () = 0;
7becfd03 183 virtual void do_redirect (struct ui_file *outstream) = 0;
112e8700
SM
184
185 /* Set as not MI-like by default. It is overridden in subclasses if
186 necessary. */
187
4904c3c6 188 virtual bool do_is_mi_like_p () const
112e8700
SM
189 { return false; }
190
191 private:
192
193 ui_out_flags m_flags;
194
195 /* Vector to store and track the ui-out levels. */
196 std::vector<std::unique_ptr<ui_out_level>> m_levels;
197
198 /* A table, if any. At present only a single table is supported. */
199 std::unique_ptr<ui_out_table> m_table_up;
200
201 void verify_field (int *fldno, int *width, ui_align *align);
202
203 int level () const;
204 ui_out_level *current_level () const;
205};
0fac0b41 206
296bd123
TT
207/* Start a new tuple or list on construction, and end it on
208 destruction. Normally this is used via the typedefs
209 ui_out_emit_tuple and ui_out_emit_list. */
d4b0bb18
TT
210template<ui_out_type Type>
211class ui_out_emit_type
212{
213public:
214
215 ui_out_emit_type (struct ui_out *uiout, const char *id)
216 : m_uiout (uiout)
217 {
218 uiout->begin (Type, id);
219 }
220
221 ~ui_out_emit_type ()
222 {
223 m_uiout->end (Type);
224 }
225
d6541620 226 DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
d4b0bb18
TT
227
228private:
229
230 struct ui_out *m_uiout;
231};
232
233typedef ui_out_emit_type<ui_out_type_tuple> ui_out_emit_tuple;
234typedef ui_out_emit_type<ui_out_type_list> ui_out_emit_list;
235
dc9fe180
TT
236/* Start a new table on construction, and end the table on
237 destruction. */
4a2b031d
TT
238class ui_out_emit_table
239{
240public:
241
242 ui_out_emit_table (struct ui_out *uiout, int nr_cols, int nr_rows,
243 const char *tblid)
244 : m_uiout (uiout)
245 {
246 m_uiout->table_begin (nr_cols, nr_rows, tblid);
247 }
248
249 ~ui_out_emit_table ()
250 {
251 m_uiout->table_end ();
252 }
253
254 ui_out_emit_table (const ui_out_emit_table &) = delete;
255 ui_out_emit_table &operator= (const ui_out_emit_table &) = delete;
256
257private:
258
259 struct ui_out *m_uiout;
260};
261
ca5909c7
TT
262/* On destruction, pop the last redirection by calling the uiout's
263 redirect method with a NULL parameter. */
264class ui_out_redirect_pop
265{
266public:
267
268 ui_out_redirect_pop (ui_out *uiout)
269 : m_uiout (uiout)
270 {
271 }
272
273 ~ui_out_redirect_pop ()
274 {
275 m_uiout->redirect (NULL);
276 }
277
278 ui_out_redirect_pop (const ui_out_redirect_pop &) = delete;
279 ui_out_redirect_pop &operator= (const ui_out_redirect_pop &) = delete;
280
281private:
282 struct ui_out *m_uiout;
283};
284
8b93c638 285#endif /* UI_OUT_H */
This page took 2.060521 seconds and 4 git commands to generate.