1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999-2019 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/>. */
25 /* Local non-gdb includes. */
27 #include "cli/cli-style.h"
28 #include "completer.h"
29 #include "readline/readline.h"
32 /* These are the CLI output functions */
34 /* Mark beginning of a table */
37 cli_ui_out::do_table_begin (int nbrofcols
, int nr_rows
, const char *tblid
)
40 m_suppress_output
= true;
42 /* Only the table suppresses the output and, fortunately, a table
43 is not a recursive data structure. */
44 gdb_assert (!m_suppress_output
);
47 /* Mark beginning of a table body */
50 cli_ui_out::do_table_body ()
52 if (m_suppress_output
)
55 /* first, close the table header line */
59 /* Mark end of a table */
62 cli_ui_out::do_table_end ()
64 m_suppress_output
= false;
67 /* Specify table header */
70 cli_ui_out::do_table_header (int width
, ui_align alignment
,
71 const std::string
&col_name
,
72 const std::string
&col_hdr
)
74 if (m_suppress_output
)
77 do_field_string (0, width
, alignment
, 0, col_hdr
.c_str (),
78 ui_out_style_kind::DEFAULT
);
81 /* Mark beginning of a list */
84 cli_ui_out::do_begin (ui_out_type type
, const char *id
)
88 /* Mark end of a list */
91 cli_ui_out::do_end (ui_out_type type
)
95 /* output an int field */
98 cli_ui_out::do_field_int (int fldno
, int width
, ui_align alignment
,
99 const char *fldname
, int value
)
101 if (m_suppress_output
)
104 std::string str
= string_printf ("%d", value
);
106 do_field_string (fldno
, width
, alignment
, fldname
, str
.c_str (),
107 ui_out_style_kind::DEFAULT
);
110 /* used to omit a field */
113 cli_ui_out::do_field_skip (int fldno
, int width
, ui_align alignment
,
116 if (m_suppress_output
)
119 do_field_string (fldno
, width
, alignment
, fldname
, "",
120 ui_out_style_kind::DEFAULT
);
123 /* other specific cli_field_* end up here so alignment and field
124 separators are both handled by cli_field_string */
127 cli_ui_out::do_field_string (int fldno
, int width
, ui_align align
,
128 const char *fldname
, const char *string
,
129 ui_out_style_kind style
)
134 if (m_suppress_output
)
137 if ((align
!= ui_noalign
) && string
)
139 before
= width
- strlen (string
);
144 if (align
== ui_right
)
146 else if (align
== ui_left
)
165 ui_file_style fstyle
;
168 case ui_out_style_kind::DEFAULT
:
171 case ui_out_style_kind::FILE:
173 fstyle
= file_name_style
.style ();
175 case ui_out_style_kind::FUNCTION
:
176 fstyle
= function_name_style
.style ();
178 case ui_out_style_kind::VARIABLE
:
179 fstyle
= variable_name_style
.style ();
181 case ui_out_style_kind::ADDRESS
:
182 fstyle
= address_style
.style ();
185 gdb_assert_not_reached ("missing case");
187 fputs_styled (string
, fstyle
, m_streams
.back ());
193 if (align
!= ui_noalign
)
197 /* Output field containing ARGS using printf formatting in FORMAT. */
200 cli_ui_out::do_field_fmt (int fldno
, int width
, ui_align align
,
201 const char *fldname
, const char *format
,
204 if (m_suppress_output
)
207 std::string str
= string_vprintf (format
, args
);
209 do_field_string (fldno
, width
, align
, fldname
, str
.c_str (),
210 ui_out_style_kind::DEFAULT
);
214 cli_ui_out::do_spaces (int numspaces
)
216 if (m_suppress_output
)
219 print_spaces_filtered (numspaces
, m_streams
.back ());
223 cli_ui_out::do_text (const char *string
)
225 if (m_suppress_output
)
228 fputs_filtered (string
, m_streams
.back ());
232 cli_ui_out::do_message (const char *format
, va_list args
)
234 if (m_suppress_output
)
237 vfprintf_unfiltered (m_streams
.back (), format
, args
);
241 cli_ui_out::do_wrap_hint (const char *identstring
)
243 if (m_suppress_output
)
246 wrap_here (identstring
);
250 cli_ui_out::do_flush ()
252 gdb_flush (m_streams
.back ());
255 /* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
256 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
257 output stream; it is an internal error if it does not exist. */
260 cli_ui_out::do_redirect (ui_file
*outstream
)
262 if (outstream
!= NULL
)
263 m_streams
.push_back (outstream
);
265 m_streams
.pop_back ();
268 /* local functions */
271 cli_ui_out::field_separator ()
273 fputc_filtered (' ', m_streams
.back ());
276 /* Constructor for cli_ui_out. */
278 cli_ui_out::cli_ui_out (ui_file
*stream
, ui_out_flags flags
)
280 m_suppress_output (false)
282 gdb_assert (stream
!= NULL
);
284 m_streams
.push_back (stream
);
287 cli_ui_out::~cli_ui_out ()
291 /* Initialize private members at startup. */
294 cli_out_new (struct ui_file
*stream
)
296 return new cli_ui_out (stream
, ui_source_list
);
300 cli_ui_out::set_stream (struct ui_file
*stream
)
304 old
= m_streams
.back ();
305 m_streams
.back () = stream
;
310 /* CLI interface to display tab-completion matches. */
312 /* CLI version of displayer.crlf. */
315 cli_mld_crlf (const struct match_list_displayer
*displayer
)
320 /* CLI version of displayer.putch. */
323 cli_mld_putch (const struct match_list_displayer
*displayer
, int ch
)
325 putc (ch
, rl_outstream
);
328 /* CLI version of displayer.puts. */
331 cli_mld_puts (const struct match_list_displayer
*displayer
, const char *s
)
333 fputs (s
, rl_outstream
);
336 /* CLI version of displayer.flush. */
339 cli_mld_flush (const struct match_list_displayer
*displayer
)
341 fflush (rl_outstream
);
344 EXTERN_C
void _rl_erase_entire_line (void);
346 /* CLI version of displayer.erase_entire_line. */
349 cli_mld_erase_entire_line (const struct match_list_displayer
*displayer
)
351 _rl_erase_entire_line ();
354 /* CLI version of displayer.beep. */
357 cli_mld_beep (const struct match_list_displayer
*displayer
)
362 /* CLI version of displayer.read_key. */
365 cli_mld_read_key (const struct match_list_displayer
*displayer
)
367 return rl_read_key ();
370 /* CLI version of rl_completion_display_matches_hook.
371 See gdb_display_match_list for a description of the arguments. */
374 cli_display_match_list (char **matches
, int len
, int max
)
376 struct match_list_displayer displayer
;
378 rl_get_screen_size (&displayer
.height
, &displayer
.width
);
379 displayer
.crlf
= cli_mld_crlf
;
380 displayer
.putch
= cli_mld_putch
;
381 displayer
.puts
= cli_mld_puts
;
382 displayer
.flush
= cli_mld_flush
;
383 displayer
.erase_entire_line
= cli_mld_erase_entire_line
;
384 displayer
.beep
= cli_mld_beep
;
385 displayer
.read_key
= cli_mld_read_key
;
387 gdb_display_match_list (matches
, len
, max
, &displayer
);
388 rl_forced_update_display ();