Make program_space::deleted_solibs a vector of std::string
[deliverable/binutils-gdb.git] / gdb / ui-out.h
CommitLineData
8b93c638 1/* Output generating routines for GDB.
bee0189a 2
e2882c85 3 Copyright (C) 1999-2018 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
112e8700 28#include "common/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
8b93c638 52 {
bef721e2 53 ui_source_list = (1 << 0),
8b93c638
JM
54 };
55
bef721e2 56DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
8b93c638 57
581e13c1 58/* Prototypes for ui-out API. */
8b93c638 59
631ec795 60/* A result is a recursive data structure consisting of lists and
581e13c1 61 tuples. */
631ec795
AC
62
63enum ui_out_type
64 {
666547aa 65 ui_out_type_tuple,
631ec795
AC
66 ui_out_type_list
67 };
68
6b28c186 69/* Compatibility wrappers. */
631ec795 70
6b28c186
AC
71extern struct cleanup *make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
72 const char *id);
666547aa 73
666547aa
AC
74extern struct cleanup *make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
75 const char *id);
e6e0bfab 76
112e8700
SM
77class ui_out
78{
79 public:
80
81 explicit ui_out (ui_out_flags flags = 0);
82 virtual ~ui_out ();
83
84 void push_level (ui_out_type type);
85 void pop_level (ui_out_type type);
86
87 /* A table can be considered a special tuple/list combination with the
88 implied structure: ``table = { hdr = { header, ... } , body = [ {
89 field, ... }, ... ] }''. If NR_ROWS is negative then there is at
90 least one row. */
91
92 void table_begin (int nr_cols, int nr_rows, const std::string &tblid);
93 void table_header (int width, ui_align align, const std::string &col_name,
94 const std::string &col_hdr);
95 void table_body ();
96 void table_end ();
97
98 void begin (ui_out_type type, const char *id);
99 void end (ui_out_type type);
100
101 void field_int (const char *fldname, int value);
102 void field_fmt_int (int width, ui_align align, const char *fldname,
103 int value);
104 void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
105 CORE_ADDR address);
106 void field_string (const char *fldname, const char *string);
6fb16ce6 107 void field_string (const char *fldname, const std::string &string);
d7e74731 108 void field_stream (const char *fldname, string_file &stream);
112e8700
SM
109 void field_skip (const char *fldname);
110 void field_fmt (const char *fldname, const char *format, ...)
111 ATTRIBUTE_PRINTF (3, 4);
112
113 void spaces (int numspaces);
114 void text (const char *string);
115 void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
116 void wrap_hint (const char *identstring);
117
118 void flush ();
119
120 /* Redirect the output of a ui_out object temporarily. */
7becfd03 121 void redirect (ui_file *outstream);
112e8700
SM
122
123 ui_out_flags test_flags (ui_out_flags mask);
124
125 /* HACK: Code in GDB is currently checking to see the type of ui_out
126 builder when determining which output to produce. This function is
127 a hack to encapsulate that test. Once GDB manages to separate the
128 CLI/MI from the core of GDB the problem should just go away .... */
129
130 bool is_mi_like_p ();
131
132 bool query_table_field (int colno, int *width, int *alignment,
133 const char **col_name);
134
135 protected:
136
137 virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
138 = 0;
139 virtual void do_table_body () = 0;
140 virtual void do_table_end () = 0;
141 virtual void do_table_header (int width, ui_align align,
142 const std::string &col_name,
143 const std::string &col_hdr) = 0;
144
145 virtual void do_begin (ui_out_type type, const char *id) = 0;
146 virtual void do_end (ui_out_type type) = 0;
147 virtual void do_field_int (int fldno, int width, ui_align align,
148 const char *fldname, int value) = 0;
149 virtual void do_field_skip (int fldno, int width, ui_align align,
150 const char *fldname) = 0;
151 virtual void do_field_string (int fldno, int width, ui_align align,
152 const char *fldname, const char *string) = 0;
153 virtual void do_field_fmt (int fldno, int width, ui_align align,
154 const char *fldname, const char *format,
155 va_list args)
156 ATTRIBUTE_PRINTF (6,0) = 0;
157 virtual void do_spaces (int numspaces) = 0;
158 virtual void do_text (const char *string) = 0;
159 virtual void do_message (const char *format, va_list args)
160 ATTRIBUTE_PRINTF (2,0) = 0;
161 virtual void do_wrap_hint (const char *identstring) = 0;
162 virtual void do_flush () = 0;
7becfd03 163 virtual void do_redirect (struct ui_file *outstream) = 0;
112e8700
SM
164
165 /* Set as not MI-like by default. It is overridden in subclasses if
166 necessary. */
167
168 virtual bool do_is_mi_like_p ()
169 { return false; }
170
171 private:
172
173 ui_out_flags m_flags;
174
175 /* Vector to store and track the ui-out levels. */
176 std::vector<std::unique_ptr<ui_out_level>> m_levels;
177
178 /* A table, if any. At present only a single table is supported. */
179 std::unique_ptr<ui_out_table> m_table_up;
180
181 void verify_field (int *fldno, int *width, ui_align *align);
182
183 int level () const;
184 ui_out_level *current_level () const;
185};
0fac0b41 186
d4b0bb18
TT
187/* This is similar to make_cleanup_ui_out_tuple_begin_end and
188 make_cleanup_ui_out_list_begin_end, but written as an RAII template
189 class. It takes the ui_out_type as a template parameter. Normally
190 this is used via the typedefs ui_out_emit_tuple and
191 ui_out_emit_list. */
192template<ui_out_type Type>
193class ui_out_emit_type
194{
195public:
196
197 ui_out_emit_type (struct ui_out *uiout, const char *id)
198 : m_uiout (uiout)
199 {
200 uiout->begin (Type, id);
201 }
202
203 ~ui_out_emit_type ()
204 {
205 m_uiout->end (Type);
206 }
207
d6541620 208 DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
d4b0bb18
TT
209
210private:
211
212 struct ui_out *m_uiout;
213};
214
215typedef ui_out_emit_type<ui_out_type_tuple> ui_out_emit_tuple;
216typedef ui_out_emit_type<ui_out_type_list> ui_out_emit_list;
217
dc9fe180
TT
218/* Start a new table on construction, and end the table on
219 destruction. */
4a2b031d
TT
220class ui_out_emit_table
221{
222public:
223
224 ui_out_emit_table (struct ui_out *uiout, int nr_cols, int nr_rows,
225 const char *tblid)
226 : m_uiout (uiout)
227 {
228 m_uiout->table_begin (nr_cols, nr_rows, tblid);
229 }
230
231 ~ui_out_emit_table ()
232 {
233 m_uiout->table_end ();
234 }
235
236 ui_out_emit_table (const ui_out_emit_table &) = delete;
237 ui_out_emit_table &operator= (const ui_out_emit_table &) = delete;
238
239private:
240
241 struct ui_out *m_uiout;
242};
243
ca5909c7
TT
244/* On destruction, pop the last redirection by calling the uiout's
245 redirect method with a NULL parameter. */
246class ui_out_redirect_pop
247{
248public:
249
250 ui_out_redirect_pop (ui_out *uiout)
251 : m_uiout (uiout)
252 {
253 }
254
255 ~ui_out_redirect_pop ()
256 {
257 m_uiout->redirect (NULL);
258 }
259
260 ui_out_redirect_pop (const ui_out_redirect_pop &) = delete;
261 ui_out_redirect_pop &operator= (const ui_out_redirect_pop &) = delete;
262
263private:
264 struct ui_out *m_uiout;
265};
266
8b93c638 267#endif /* UI_OUT_H */
This page took 2.015081 seconds and 4 git commands to generate.