1 /* Output generating routines for GDB.
3 Copyright (C) 1999-2017 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
8 This file is part of GDB.
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
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "common/enum-flags.h"
34 /* the current ui_out */
36 /* FIXME: This should not be a global but something passed down from main.c
38 extern struct ui_out **current_ui_current_uiout_ptr (void);
39 #define current_uiout (*current_ui_current_uiout_ptr ())
53 ui_source_list = (1 << 0),
56 DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
58 /* Prototypes for ui-out API. */
60 /* A result is a recursive data structure consisting of lists and
69 /* Compatibility wrappers. */
71 extern struct cleanup *make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
74 extern struct cleanup *make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
81 explicit ui_out (ui_out_flags flags = 0);
84 void push_level (ui_out_type type);
85 void pop_level (ui_out_type type);
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
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);
98 void begin (ui_out_type type, const char *id);
99 void end (ui_out_type type);
101 void field_int (const char *fldname, int value);
102 void field_fmt_int (int width, ui_align align, const char *fldname,
104 void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
106 void field_string (const char *fldname, const char *string);
107 void field_stream (const char *fldname, string_file &stream);
108 void field_skip (const char *fldname);
109 void field_fmt (const char *fldname, const char *format, ...)
110 ATTRIBUTE_PRINTF (3, 4);
112 void spaces (int numspaces);
113 void text (const char *string);
114 void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
115 void wrap_hint (const char *identstring);
119 /* Redirect the output of a ui_out object temporarily. */
120 void redirect (ui_file *outstream);
122 ui_out_flags test_flags (ui_out_flags mask);
124 /* HACK: Code in GDB is currently checking to see the type of ui_out
125 builder when determining which output to produce. This function is
126 a hack to encapsulate that test. Once GDB manages to separate the
127 CLI/MI from the core of GDB the problem should just go away .... */
129 bool is_mi_like_p ();
131 bool query_table_field (int colno, int *width, int *alignment,
132 const char **col_name);
136 virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
138 virtual void do_table_body () = 0;
139 virtual void do_table_end () = 0;
140 virtual void do_table_header (int width, ui_align align,
141 const std::string &col_name,
142 const std::string &col_hdr) = 0;
144 virtual void do_begin (ui_out_type type, const char *id) = 0;
145 virtual void do_end (ui_out_type type) = 0;
146 virtual void do_field_int (int fldno, int width, ui_align align,
147 const char *fldname, int value) = 0;
148 virtual void do_field_skip (int fldno, int width, ui_align align,
149 const char *fldname) = 0;
150 virtual void do_field_string (int fldno, int width, ui_align align,
151 const char *fldname, const char *string) = 0;
152 virtual void do_field_fmt (int fldno, int width, ui_align align,
153 const char *fldname, const char *format,
155 ATTRIBUTE_PRINTF (6,0) = 0;
156 virtual void do_spaces (int numspaces) = 0;
157 virtual void do_text (const char *string) = 0;
158 virtual void do_message (const char *format, va_list args)
159 ATTRIBUTE_PRINTF (2,0) = 0;
160 virtual void do_wrap_hint (const char *identstring) = 0;
161 virtual void do_flush () = 0;
162 virtual void do_redirect (struct ui_file *outstream) = 0;
164 /* Set as not MI-like by default. It is overridden in subclasses if
167 virtual bool do_is_mi_like_p ()
172 ui_out_flags m_flags;
174 /* Vector to store and track the ui-out levels. */
175 std::vector<std::unique_ptr<ui_out_level>> m_levels;
177 /* A table, if any. At present only a single table is supported. */
178 std::unique_ptr<ui_out_table> m_table_up;
180 void verify_field (int *fldno, int *width, ui_align *align);
183 ui_out_level *current_level () const;
186 /* This is similar to make_cleanup_ui_out_tuple_begin_end and
187 make_cleanup_ui_out_list_begin_end, but written as an RAII template
188 class. It takes the ui_out_type as a template parameter. Normally
189 this is used via the typedefs ui_out_emit_tuple and
191 template<ui_out_type Type>
192 class ui_out_emit_type
196 ui_out_emit_type (struct ui_out *uiout, const char *id)
199 uiout->begin (Type, id);
207 DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
211 struct ui_out *m_uiout;
214 typedef ui_out_emit_type<ui_out_type_tuple> ui_out_emit_tuple;
215 typedef ui_out_emit_type<ui_out_type_list> ui_out_emit_list;
217 /* Start a new table on construction, and end the table on
219 class ui_out_emit_table
223 ui_out_emit_table (struct ui_out *uiout, int nr_cols, int nr_rows,
227 m_uiout->table_begin (nr_cols, nr_rows, tblid);
230 ~ui_out_emit_table ()
232 m_uiout->table_end ();
235 ui_out_emit_table (const ui_out_emit_table &) = delete;
236 ui_out_emit_table &operator= (const ui_out_emit_table &) = delete;
240 struct ui_out *m_uiout;
243 /* On destruction, pop the last redirection by calling the uiout's
244 redirect method with a NULL parameter. */
245 class ui_out_redirect_pop
249 ui_out_redirect_pop (ui_out *uiout)
254 ~ui_out_redirect_pop ()
256 m_uiout->redirect (NULL);
259 ui_out_redirect_pop (const ui_out_redirect_pop &) = delete;
260 ui_out_redirect_pop &operator= (const ui_out_redirect_pop &) = delete;
263 struct ui_out *m_uiout;
266 #endif /* UI_OUT_H */