Add symbol lookup cache.
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
32d0add0 3 Copyright (C) 1999-2015 Free Software Foundation, Inc.
349c5d5f 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#include "defs.h"
24#include "ui-out.h"
25#include "cli-out.h"
14dba4b4 26#include "vec.h"
8b93c638 27
0a8fce9a 28typedef struct cli_ui_out_data cli_out_data;
8b93c638 29
8b93c638
JM
30
31/* Prototypes for local functions */
32
02a45ac0 33static void cli_text (struct ui_out *uiout, const char *string);
8b93c638
JM
34
35static void field_separator (void);
36
e2e11a41
AC
37static void out_field_fmt (struct ui_out *uiout, int fldno,
38 const char *fldname,
a0b31db1 39 const char *format,...) ATTRIBUTE_PRINTF (4, 5);
8b93c638 40
17b2616c
PA
41/* The destructor. */
42
43static void
44cli_uiout_dtor (struct ui_out *ui_out)
45{
46 cli_out_data *data = ui_out_data (ui_out);
47
48 VEC_free (ui_filep, data->streams);
49 xfree (data);
50}
51
02a45ac0
PA
52/* These are the CLI output functions */
53
8b93c638
JM
54/* Mark beginning of a table */
55
02a45ac0 56static void
e2e11a41 57cli_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 58 int nr_rows,
e2e11a41 59 const char *tblid)
8b93c638 60{
1248ede2 61 cli_out_data *data = ui_out_data (uiout);
c5504eaf 62
698384cd
AC
63 if (nr_rows == 0)
64 data->suppress_output = 1;
65 else
ce2826aa 66 /* Only the table suppresses the output and, fortunately, a table
30fdc99f 67 is not a recursive data structure. */
698384cd 68 gdb_assert (data->suppress_output == 0);
8b93c638
JM
69}
70
71/* Mark beginning of a table body */
72
02a45ac0 73static void
fba45db2 74cli_table_body (struct ui_out *uiout)
8b93c638 75{
1248ede2 76 cli_out_data *data = ui_out_data (uiout);
c5504eaf 77
698384cd
AC
78 if (data->suppress_output)
79 return;
8b93c638
JM
80 /* first, close the table header line */
81 cli_text (uiout, "\n");
82}
83
84/* Mark end of a table */
85
02a45ac0 86static void
fba45db2 87cli_table_end (struct ui_out *uiout)
8b93c638 88{
1248ede2 89 cli_out_data *data = ui_out_data (uiout);
c5504eaf 90
698384cd 91 data->suppress_output = 0;
8b93c638
JM
92}
93
94/* Specify table header */
95
02a45ac0 96static void
fba45db2 97cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 98 const char *col_name,
e2e11a41 99 const char *colhdr)
8b93c638 100{
1248ede2 101 cli_out_data *data = ui_out_data (uiout);
c5504eaf 102
698384cd
AC
103 if (data->suppress_output)
104 return;
0a8fce9a
PA
105
106 /* Always go through the function pointer (virtual function call).
107 We may have been extended. */
108 uo_field_string (uiout, 0, width, alignment, 0, colhdr);
8b93c638
JM
109}
110
111/* Mark beginning of a list */
112
02a45ac0 113static void
631ec795
AC
114cli_begin (struct ui_out *uiout,
115 enum ui_out_type type,
116 int level,
117 const char *id)
8b93c638 118{
1248ede2 119 cli_out_data *data = ui_out_data (uiout);
c5504eaf 120
698384cd
AC
121 if (data->suppress_output)
122 return;
8b93c638
JM
123}
124
125/* Mark end of a list */
126
02a45ac0 127static void
631ec795
AC
128cli_end (struct ui_out *uiout,
129 enum ui_out_type type,
130 int level)
8b93c638 131{
1248ede2 132 cli_out_data *data = ui_out_data (uiout);
c5504eaf 133
698384cd
AC
134 if (data->suppress_output)
135 return;
8b93c638
JM
136}
137
138/* output an int field */
139
02a45ac0 140static void
fba45db2 141cli_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
142 enum ui_align alignment,
143 const char *fldname, int value)
8b93c638 144{
c5504eaf 145 char buffer[20]; /* FIXME: how many chars long a %d can become? */
1248ede2 146 cli_out_data *data = ui_out_data (uiout);
c5504eaf 147
698384cd
AC
148 if (data->suppress_output)
149 return;
08850b56 150 xsnprintf (buffer, sizeof (buffer), "%d", value);
0a8fce9a
PA
151
152 /* Always go through the function pointer (virtual function call).
153 We may have been extended. */
154 uo_field_string (uiout, fldno, width, alignment, fldname, buffer);
8b93c638
JM
155}
156
157/* used to ommit a field */
158
02a45ac0 159static void
fba45db2 160cli_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
161 enum ui_align alignment,
162 const char *fldname)
8b93c638 163{
1248ede2 164 cli_out_data *data = ui_out_data (uiout);
c5504eaf 165
698384cd
AC
166 if (data->suppress_output)
167 return;
0a8fce9a
PA
168
169 /* Always go through the function pointer (virtual function call).
170 We may have been extended. */
171 uo_field_string (uiout, fldno, width, alignment, fldname, "");
8b93c638
JM
172}
173
174/* other specific cli_field_* end up here so alignment and field
175 separators are both handled by cli_field_string */
176
02a45ac0 177static void
8b93c638
JM
178cli_field_string (struct ui_out *uiout,
179 int fldno,
180 int width,
55555bbc 181 enum ui_align align,
e2e11a41 182 const char *fldname,
8b93c638
JM
183 const char *string)
184{
185 int before = 0;
186 int after = 0;
1248ede2 187 cli_out_data *data = ui_out_data (uiout);
c5504eaf 188
698384cd
AC
189 if (data->suppress_output)
190 return;
191
8b93c638
JM
192 if ((align != ui_noalign) && string)
193 {
194 before = width - strlen (string);
195 if (before <= 0)
196 before = 0;
197 else
198 {
199 if (align == ui_right)
200 after = 0;
201 else if (align == ui_left)
202 {
203 after = before;
204 before = 0;
205 }
206 else
207 /* ui_center */
208 {
209 after = before / 2;
210 before -= after;
211 }
212 }
213 }
214
215 if (before)
216 ui_out_spaces (uiout, before);
217 if (string)
218 out_field_fmt (uiout, fldno, fldname, "%s", string);
219 if (after)
220 ui_out_spaces (uiout, after);
221
222 if (align != ui_noalign)
223 field_separator ();
224}
225
30fdc99f 226/* This is the only field function that does not align. */
8b93c638 227
a0b31db1 228static void ATTRIBUTE_PRINTF (6, 0)
8b93c638
JM
229cli_field_fmt (struct ui_out *uiout, int fldno,
230 int width, enum ui_align align,
e2e11a41
AC
231 const char *fldname,
232 const char *format,
233 va_list args)
8b93c638 234{
1248ede2 235 cli_out_data *data = ui_out_data (uiout);
14dba4b4 236 struct ui_file *stream;
c5504eaf 237
698384cd
AC
238 if (data->suppress_output)
239 return;
240
14dba4b4
JK
241 stream = VEC_last (ui_filep, data->streams);
242 vfprintf_filtered (stream, format, args);
8b93c638
JM
243
244 if (align != ui_noalign)
245 field_separator ();
246}
247
02a45ac0 248static void
fba45db2 249cli_spaces (struct ui_out *uiout, int numspaces)
8b93c638 250{
1248ede2 251 cli_out_data *data = ui_out_data (uiout);
14dba4b4 252 struct ui_file *stream;
c5504eaf 253
698384cd
AC
254 if (data->suppress_output)
255 return;
14dba4b4
JK
256
257 stream = VEC_last (ui_filep, data->streams);
258 print_spaces_filtered (numspaces, stream);
8b93c638
JM
259}
260
02a45ac0 261static void
e2e11a41 262cli_text (struct ui_out *uiout, const char *string)
8b93c638 263{
1248ede2 264 cli_out_data *data = ui_out_data (uiout);
14dba4b4 265 struct ui_file *stream;
c5504eaf 266
698384cd
AC
267 if (data->suppress_output)
268 return;
14dba4b4
JK
269
270 stream = VEC_last (ui_filep, data->streams);
271 fputs_filtered (string, stream);
8b93c638
JM
272}
273
a0b31db1 274static void ATTRIBUTE_PRINTF (3, 0)
e2e11a41
AC
275cli_message (struct ui_out *uiout, int verbosity,
276 const char *format, va_list args)
8b93c638 277{
1248ede2 278 cli_out_data *data = ui_out_data (uiout);
c5504eaf 279
698384cd
AC
280 if (data->suppress_output)
281 return;
14dba4b4 282
8b93c638 283 if (ui_out_get_verblvl (uiout) >= verbosity)
14dba4b4
JK
284 {
285 struct ui_file *stream = VEC_last (ui_filep, data->streams);
286
287 vfprintf_unfiltered (stream, format, args);
288 }
8b93c638
JM
289}
290
02a45ac0 291static void
fba45db2 292cli_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638 293{
1248ede2 294 cli_out_data *data = ui_out_data (uiout);
c5504eaf 295
698384cd
AC
296 if (data->suppress_output)
297 return;
8b93c638
JM
298 wrap_here (identstring);
299}
300
02a45ac0 301static void
fba45db2 302cli_flush (struct ui_out *uiout)
8b93c638 303{
1248ede2 304 cli_out_data *data = ui_out_data (uiout);
14dba4b4 305 struct ui_file *stream = VEC_last (ui_filep, data->streams);
c5504eaf 306
14dba4b4 307 gdb_flush (stream);
8b93c638
JM
308}
309
14dba4b4
JK
310/* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
311 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
312 output stream; it is an internal error if it does not exist. */
313
02a45ac0 314static int
0fac0b41
DJ
315cli_redirect (struct ui_out *uiout, struct ui_file *outstream)
316{
0a8fce9a 317 cli_out_data *data = ui_out_data (uiout);
c5504eaf 318
0fac0b41 319 if (outstream != NULL)
14dba4b4
JK
320 VEC_safe_push (ui_filep, data->streams, outstream);
321 else
322 VEC_pop (ui_filep, data->streams);
0fac0b41
DJ
323
324 return 0;
325}
326
8b93c638
JM
327/* local functions */
328
329/* Like cli_field_fmt, but takes a variable number of args
30fdc99f 330 and makes a va_list and does not insert a separator. */
8b93c638
JM
331
332/* VARARGS */
333static void
e2e11a41
AC
334out_field_fmt (struct ui_out *uiout, int fldno,
335 const char *fldname,
336 const char *format,...)
8b93c638 337{
1248ede2 338 cli_out_data *data = ui_out_data (uiout);
14dba4b4 339 struct ui_file *stream = VEC_last (ui_filep, data->streams);
8b93c638
JM
340 va_list args;
341
342 va_start (args, format);
14dba4b4 343 vfprintf_filtered (stream, format, args);
8b93c638
JM
344
345 va_end (args);
346}
347
30fdc99f 348/* Access to ui_out format private members. */
8b93c638
JM
349
350static void
fba45db2 351field_separator (void)
8b93c638 352{
79a45e25 353 cli_out_data *data = ui_out_data (current_uiout);
14dba4b4 354 struct ui_file *stream = VEC_last (ui_filep, data->streams);
c5504eaf 355
14dba4b4 356 fputc_filtered (' ', stream);
8b93c638
JM
357}
358
02a45ac0
PA
359/* This is the CLI ui-out implementation functions vector */
360
89de4da4 361const struct ui_out_impl cli_ui_out_impl =
02a45ac0
PA
362{
363 cli_table_begin,
364 cli_table_body,
365 cli_table_end,
366 cli_table_header,
367 cli_begin,
368 cli_end,
369 cli_field_int,
370 cli_field_skip,
371 cli_field_string,
372 cli_field_fmt,
373 cli_spaces,
374 cli_text,
375 cli_message,
376 cli_wrap_hint,
377 cli_flush,
378 cli_redirect,
17b2616c 379 cli_uiout_dtor,
02a45ac0
PA
380 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
381};
382
0a8fce9a
PA
383/* Constructor for a `cli_out_data' object. */
384
385void
386cli_out_data_ctor (cli_out_data *self, struct ui_file *stream)
387{
14dba4b4
JK
388 gdb_assert (stream != NULL);
389
390 self->streams = NULL;
391 VEC_safe_push (ui_filep, self->streams, stream);
392
0a8fce9a
PA
393 self->suppress_output = 0;
394}
395
396/* Initialize private members at startup. */
8b93c638
JM
397
398struct ui_out *
399cli_out_new (struct ui_file *stream)
400{
401 int flags = ui_source_list;
70ba0933 402 cli_out_data *data = XNEW (cli_out_data);
c5504eaf 403
0a8fce9a 404 cli_out_data_ctor (data, stream);
8b93c638
JM
405 return ui_out_new (&cli_ui_out_impl, data, flags);
406}
407
4389a95a
AC
408struct ui_file *
409cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
410{
1248ede2 411 cli_out_data *data = ui_out_data (uiout);
14dba4b4
JK
412 struct ui_file *old;
413
414 old = VEC_pop (ui_filep, data->streams);
415 VEC_quick_push (ui_filep, data->streams, stream);
c5504eaf 416
4389a95a
AC
417 return old;
418}
This page took 1.504258 seconds and 4 git commands to generate.