2011-08-04 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / ui-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB.
349c5d5f 2
7b6bb8da
JB
3 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
349c5d5f 5
8b93c638
JM
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
a9762ec7 13 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
a9762ec7 22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "expression.h" /* For language.h */
27#include "language.h"
28#include "ui-out.h"
80f49b30 29#include "gdb_assert.h"
8b93c638 30
8b93c638
JM
31/* table header structures */
32
33struct ui_out_hdr
34 {
35 int colno;
36 int width;
37 int alignment;
b25959ec 38 char *col_name;
8b93c638
JM
39 char *colhdr;
40 struct ui_out_hdr *next;
41 };
42
80f49b30
AC
43/* Maintain a stack so that the info applicable to the inner most list
44 is always available. Stack/nested level 0 is reserved for the
581e13c1 45 top-level result. */
80f49b30 46
dc146f7c 47enum { MAX_UI_OUT_LEVELS = 8 };
80f49b30
AC
48
49struct ui_out_level
50 {
581e13c1 51 /* Count each field; the first element is for non-list fields. */
80f49b30 52 int field_count;
581e13c1 53 /* The type of this level. */
631ec795 54 enum ui_out_type type;
80f49b30
AC
55 };
56
bafdd3b3
AC
57/* Tables are special. Maintain a separate structure that tracks
58 their state. At present an output can only contain a single table
59 but that restriction might eventually be lifted. */
60
61struct ui_out_table
62{
63 /* If on, a table is being generated. */
64 int flag;
65
66 /* If on, the body of a table is being generated. If off, the table
67 header is being generated. */
68 int body_flag;
69
a6c47c14
AC
70 /* The level at which each entry of the table is to be found. A row
71 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
72 above that of the table. */
73 int entry_level;
74
bafdd3b3
AC
75 /* Number of table columns (as specified in the table_begin call). */
76 int columns;
77
78 /* String identifying the table (as specified in the table_begin
79 call). */
80 char *id;
81
82 /* Points to the first table header (if any). */
83 struct ui_out_hdr *header_first;
84
85 /* Points to the last table header (if any). */
86 struct ui_out_hdr *header_last;
87
88 /* Points to header of NEXT column to format. */
89 struct ui_out_hdr *header_next;
90
91};
92
93
8b93c638
JM
94/* The ui_out structure */
95/* Any change here requires a corresponding one in the initialization
581e13c1 96 of the default uiout, which is statically initialized. */
8b93c638
JM
97
98struct ui_out
99 {
100 int flags;
581e13c1 101 /* Specific implementation of ui-out. */
8b93c638 102 struct ui_out_impl *impl;
0a8fce9a 103 void *data;
8b93c638 104
bafdd3b3 105 /* Sub structure tracking the ui-out depth. */
80f49b30
AC
106 int level;
107 struct ui_out_level levels[MAX_UI_OUT_LEVELS];
8b93c638 108
bafdd3b3
AC
109 /* A table, if any. At present only a single table is supported. */
110 struct ui_out_table table;
8b93c638
JM
111 };
112
581e13c1 113/* The current (inner most) level. */
80f49b30
AC
114static struct ui_out_level *
115current_level (struct ui_out *uiout)
116{
117 return &uiout->levels[uiout->level];
118}
119
581e13c1 120/* Create a new level, of TYPE. Return the new level's index. */
80f49b30
AC
121static int
122push_level (struct ui_out *uiout,
631ec795 123 enum ui_out_type type,
80f49b30
AC
124 const char *id)
125{
126 struct ui_out_level *current;
5d502164 127
581e13c1 128 /* We had better not overflow the buffer. */
80f49b30 129 uiout->level++;
631ec795 130 gdb_assert (uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS);
80f49b30
AC
131 current = current_level (uiout);
132 current->field_count = 0;
631ec795 133 current->type = type;
80f49b30
AC
134 return uiout->level;
135}
136
137/* Discard the current level, return the discarded level's index.
581e13c1 138 TYPE is the type of the level being discarded. */
80f49b30 139static int
631ec795
AC
140pop_level (struct ui_out *uiout,
141 enum ui_out_type type)
80f49b30 142{
581e13c1 143 /* We had better not underflow the buffer. */
80f49b30 144 gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
631ec795 145 gdb_assert (current_level (uiout)->type == type);
80f49b30
AC
146 uiout->level--;
147 return uiout->level + 1;
148}
149
150
581e13c1 151/* These are the default implementation functions. */
8b93c638
JM
152
153static void default_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 154 int nr_rows, const char *tblid);
8b93c638
JM
155static void default_table_body (struct ui_out *uiout);
156static void default_table_end (struct ui_out *uiout);
157static void default_table_header (struct ui_out *uiout, int width,
b25959ec 158 enum ui_align alig, const char *col_name,
e2e11a41 159 const char *colhdr);
631ec795
AC
160static void default_begin (struct ui_out *uiout,
161 enum ui_out_type type,
162 int level, const char *id);
163static void default_end (struct ui_out *uiout,
164 enum ui_out_type type,
165 int level);
8b93c638 166static void default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
167 enum ui_align alig,
168 const char *fldname,
169 int value);
8b93c638 170static void default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
171 enum ui_align alig,
172 const char *fldname);
8b93c638 173static void default_field_string (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
174 enum ui_align align,
175 const char *fldname,
8b93c638
JM
176 const char *string);
177static void default_field_fmt (struct ui_out *uiout, int fldno,
178 int width, enum ui_align align,
e2e11a41
AC
179 const char *fldname,
180 const char *format,
a0b31db1 181 va_list args) ATTRIBUTE_PRINTF (6, 0);
8b93c638 182static void default_spaces (struct ui_out *uiout, int numspaces);
e2e11a41
AC
183static void default_text (struct ui_out *uiout, const char *string);
184static void default_message (struct ui_out *uiout, int verbosity,
185 const char *format,
a0b31db1 186 va_list args) ATTRIBUTE_PRINTF (3, 0);
8b93c638
JM
187static void default_wrap_hint (struct ui_out *uiout, char *identstring);
188static void default_flush (struct ui_out *uiout);
189
581e13c1 190/* This is the default ui-out implementation functions vector. */
8b93c638
JM
191
192struct ui_out_impl default_ui_out_impl =
193{
194 default_table_begin,
195 default_table_body,
196 default_table_end,
197 default_table_header,
631ec795
AC
198 default_begin,
199 default_end,
8b93c638
JM
200 default_field_int,
201 default_field_skip,
202 default_field_string,
203 default_field_fmt,
204 default_spaces,
205 default_text,
206 default_message,
207 default_wrap_hint,
9dc5e2a9 208 default_flush,
0fac0b41 209 NULL,
9dc5e2a9 210 0, /* Does not need MI hacks. */
8b93c638
JM
211};
212
213/* The default ui_out */
214
215struct ui_out def_uiout =
216{
217 0, /* flags */
218 &default_ui_out_impl, /* impl */
219};
220
221/* Pointer to current ui_out */
222/* FIXME: This should not be a global, but something passed down from main.c
581e13c1 223 or top.c. */
8b93c638 224
79a45e25 225struct ui_out *current_uiout = &def_uiout;
8b93c638 226
581e13c1 227/* These are the interfaces to implementation functions. */
8b93c638 228
88379baf 229static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 230 int nr_rows, const char *tblid);
8b93c638
JM
231static void uo_table_body (struct ui_out *uiout);
232static void uo_table_end (struct ui_out *uiout);
233static void uo_table_header (struct ui_out *uiout, int width,
b25959ec
AC
234 enum ui_align align, const char *col_name,
235 const char *colhdr);
631ec795
AC
236static void uo_begin (struct ui_out *uiout,
237 enum ui_out_type type,
238 int level, const char *id);
239static void uo_end (struct ui_out *uiout,
240 enum ui_out_type type,
241 int level);
8b93c638 242static void uo_field_int (struct ui_out *uiout, int fldno, int width,
88379baf 243 enum ui_align align, const char *fldname, int value);
8b93c638 244static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
88379baf 245 enum ui_align align, const char *fldname);
8b93c638 246static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
88379baf 247 enum ui_align align, const char *fldname,
bee0189a 248 const char *format, va_list args)
a0b31db1 249 ATTRIBUTE_PRINTF (6, 0);
8b93c638 250static void uo_spaces (struct ui_out *uiout, int numspaces);
88379baf 251static void uo_text (struct ui_out *uiout, const char *string);
8b93c638 252static void uo_message (struct ui_out *uiout, int verbosity,
bee0189a 253 const char *format, va_list args)
a0b31db1 254 ATTRIBUTE_PRINTF (3, 0);
8b93c638
JM
255static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
256static void uo_flush (struct ui_out *uiout);
0fac0b41 257static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
8b93c638
JM
258
259/* Prototypes for local functions */
260
261extern void _initialize_ui_out (void);
88379baf 262static void append_header_to_list (struct ui_out *uiout, int width,
b25959ec
AC
263 int alignment, const char *col_name,
264 const char *colhdr);
bafdd3b3 265static int get_next_header (struct ui_out *uiout, int *colno, int *width,
8b93c638
JM
266 int *alignment, char **colhdr);
267static void clear_header_list (struct ui_out *uiout);
a6c47c14
AC
268static void verify_field (struct ui_out *uiout, int *fldno, int *width,
269 int *align);
8b93c638 270
8b93c638
JM
271/* exported functions (ui_out API) */
272
581e13c1 273/* Mark beginning of a table. */
8b93c638 274
3b31d625 275static void
88379baf 276ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 277 int nr_rows,
88379baf 278 const char *tblid)
8b93c638 279{
bafdd3b3 280 if (uiout->table.flag)
8e65ff28 281 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
282 _("tables cannot be nested; table_begin found before \
283previous table_end."));
8b93c638 284
bafdd3b3
AC
285 uiout->table.flag = 1;
286 uiout->table.body_flag = 0;
a6c47c14 287 uiout->table.entry_level = uiout->level + 1;
bafdd3b3 288 uiout->table.columns = nbrofcols;
8b93c638 289 if (tblid != NULL)
bafdd3b3 290 uiout->table.id = xstrdup (tblid);
8b93c638 291 else
bafdd3b3 292 uiout->table.id = NULL;
8b93c638
JM
293 clear_header_list (uiout);
294
bafdd3b3 295 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
8b93c638
JM
296}
297
298void
fba45db2 299ui_out_table_body (struct ui_out *uiout)
8b93c638 300{
bafdd3b3 301 if (!uiout->table.flag)
8e65ff28 302 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
303 _("table_body outside a table is not valid; it must be \
304after a table_begin and before a table_end."));
bafdd3b3 305 if (uiout->table.body_flag)
8e65ff28 306 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
307 _("extra table_body call not allowed; there must be \
308only one table_body after a table_begin and before a table_end."));
bafdd3b3 309 if (uiout->table.header_next->colno != uiout->table.columns)
8e65ff28 310 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
311 _("number of headers differ from number of table \
312columns."));
8b93c638 313
bafdd3b3
AC
314 uiout->table.body_flag = 1;
315 uiout->table.header_next = uiout->table.header_first;
8b93c638
JM
316
317 uo_table_body (uiout);
318}
319
3b31d625 320static void
fba45db2 321ui_out_table_end (struct ui_out *uiout)
8b93c638 322{
bafdd3b3 323 if (!uiout->table.flag)
8e65ff28 324 internal_error (__FILE__, __LINE__,
e2e0b3e5 325 _("misplaced table_end or missing table_begin."));
8b93c638 326
a6c47c14 327 uiout->table.entry_level = 0;
bafdd3b3
AC
328 uiout->table.body_flag = 0;
329 uiout->table.flag = 0;
8b93c638
JM
330
331 uo_table_end (uiout);
332
bafdd3b3
AC
333 if (uiout->table.id)
334 xfree (uiout->table.id);
8b93c638
JM
335 clear_header_list (uiout);
336}
337
338void
fba45db2 339ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 340 const char *col_name,
88379baf 341 const char *colhdr)
8b93c638 342{
bafdd3b3 343 if (!uiout->table.flag || uiout->table.body_flag)
8e65ff28 344 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
345 _("table header must be specified after table_begin \
346and before table_body."));
8b93c638 347
b25959ec 348 append_header_to_list (uiout, width, alignment, col_name, colhdr);
8b93c638 349
b25959ec 350 uo_table_header (uiout, width, alignment, col_name, colhdr);
8b93c638
JM
351}
352
3b31d625
EZ
353static void
354do_cleanup_table_end (void *data)
355{
356 struct ui_out *ui_out = data;
357
358 ui_out_table_end (ui_out);
359}
360
361struct cleanup *
362make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
363 int nr_rows, const char *tblid)
364{
365 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
366 return make_cleanup (do_cleanup_table_end, ui_out);
367}
368
8b93c638 369void
631ec795
AC
370ui_out_begin (struct ui_out *uiout,
371 enum ui_out_type type,
372 const char *id)
8b93c638 373{
80f49b30 374 int new_level;
5d502164 375
bafdd3b3 376 if (uiout->table.flag && !uiout->table.body_flag)
8e65ff28 377 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
378 _("table header or table_body expected; lists must be \
379specified after table_body."));
a6c47c14
AC
380
381 /* Be careful to verify the ``field'' before the new tuple/list is
382 pushed onto the stack. That way the containing list/table/row is
383 verified and not the newly created tuple/list. This verification
384 is needed (at least) for the case where a table row entry
385 contains either a tuple/list. For that case bookkeeping such as
386 updating the column count or advancing to the next heading still
387 needs to be performed. */
388 {
389 int fldno;
390 int width;
391 int align;
5d502164 392
a6c47c14
AC
393 verify_field (uiout, &fldno, &width, &align);
394 }
395
631ec795 396 new_level = push_level (uiout, type, id);
a6c47c14
AC
397
398 /* If the push puts us at the same level as a table row entry, we've
399 got a new table row. Put the header pointer back to the start. */
400 if (uiout->table.body_flag
401 && uiout->table.entry_level == new_level)
bafdd3b3 402 uiout->table.header_next = uiout->table.header_first;
a6c47c14 403
631ec795
AC
404 uo_begin (uiout, type, new_level, id);
405}
406
631ec795
AC
407void
408ui_out_end (struct ui_out *uiout,
409 enum ui_out_type type)
410{
411 int old_level = pop_level (uiout, type);
5d502164 412
631ec795 413 uo_end (uiout, type, old_level);
8b93c638
JM
414}
415
127431f9
AC
416struct ui_out_end_cleanup_data
417{
418 struct ui_out *uiout;
419 enum ui_out_type type;
420};
421
e6e0bfab 422static void
127431f9
AC
423do_cleanup_end (void *data)
424{
425 struct ui_out_end_cleanup_data *end_cleanup_data = data;
5d502164 426
127431f9
AC
427 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
428 xfree (end_cleanup_data);
429}
430
431static struct cleanup *
432make_cleanup_ui_out_end (struct ui_out *uiout,
433 enum ui_out_type type)
434{
435 struct ui_out_end_cleanup_data *end_cleanup_data;
5d502164 436
127431f9
AC
437 end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data);
438 end_cleanup_data->uiout = uiout;
439 end_cleanup_data->type = type;
440 return make_cleanup (do_cleanup_end, end_cleanup_data);
441}
442
e6e0bfab 443struct cleanup *
666547aa
AC
444make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
445 const char *id)
446{
3b31d625 447 ui_out_begin (uiout, ui_out_type_tuple, id);
666547aa
AC
448 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
449}
450
451struct cleanup *
6b28c186
AC
452make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
453 const char *id)
e6e0bfab 454{
3b31d625 455 ui_out_begin (uiout, ui_out_type_list, id);
127431f9 456 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
e6e0bfab
MK
457}
458
8b93c638 459void
88379baf
AC
460ui_out_field_int (struct ui_out *uiout,
461 const char *fldname,
462 int value)
8b93c638
JM
463{
464 int fldno;
465 int width;
466 int align;
467
a6c47c14 468 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
469
470 uo_field_int (uiout, fldno, width, align, fldname, value);
471}
472
52c6a6ac
JJ
473void
474ui_out_field_fmt_int (struct ui_out *uiout,
475 int input_width,
476 enum ui_align input_align,
477 const char *fldname,
478 int value)
479{
480 int fldno;
481 int width;
482 int align;
52c6a6ac
JJ
483
484 verify_field (uiout, &fldno, &width, &align);
485
486 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
487}
488
15230f37
TJB
489/* Documented in ui-out.h. */
490
8b93c638 491void
88379baf
AC
492ui_out_field_core_addr (struct ui_out *uiout,
493 const char *fldname,
5af949e3 494 struct gdbarch *gdbarch,
88379baf 495 CORE_ADDR address)
8b93c638 496{
f1310107
TJB
497 ui_out_field_string (uiout, fldname,
498 print_core_address (gdbarch, address));
8b93c638
JM
499}
500
501void
88379baf
AC
502ui_out_field_stream (struct ui_out *uiout,
503 const char *fldname,
504 struct ui_stream *buf)
8b93c638
JM
505{
506 long length;
507 char *buffer = ui_file_xstrdup (buf->stream, &length);
b8c9b27d 508 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
5d502164 509
8b93c638
JM
510 if (length > 0)
511 ui_out_field_string (uiout, fldname, buffer);
512 else
513 ui_out_field_skip (uiout, fldname);
514 ui_file_rewind (buf->stream);
515 do_cleanups (old_cleanup);
516}
517
581e13c1 518/* Used to omit a field. */
8b93c638
JM
519
520void
88379baf
AC
521ui_out_field_skip (struct ui_out *uiout,
522 const char *fldname)
8b93c638
JM
523{
524 int fldno;
525 int width;
526 int align;
8b93c638 527
a6c47c14 528 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
529
530 uo_field_skip (uiout, fldno, width, align, fldname);
531}
532
533void
534ui_out_field_string (struct ui_out *uiout,
88379baf 535 const char *fldname,
8b93c638
JM
536 const char *string)
537{
538 int fldno;
539 int width;
540 int align;
8b93c638 541
a6c47c14 542 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
543
544 uo_field_string (uiout, fldno, width, align, fldname, string);
545}
546
547/* VARARGS */
548void
88379baf
AC
549ui_out_field_fmt (struct ui_out *uiout,
550 const char *fldname,
551 const char *format, ...)
8b93c638
JM
552{
553 va_list args;
554 int fldno;
555 int width;
556 int align;
8b93c638 557
581e13c1 558 /* Will not align, but has to call anyway. */
a6c47c14 559 verify_field (uiout, &fldno, &width, &align);
8b93c638
JM
560
561 va_start (args, format);
562
563 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
564
565 va_end (args);
566}
567
568void
fba45db2 569ui_out_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
570{
571 uo_spaces (uiout, numspaces);
572}
573
574void
88379baf
AC
575ui_out_text (struct ui_out *uiout,
576 const char *string)
8b93c638
JM
577{
578 uo_text (uiout, string);
579}
580
581void
88379baf
AC
582ui_out_message (struct ui_out *uiout, int verbosity,
583 const char *format,...)
8b93c638
JM
584{
585 va_list args;
586
587 va_start (args, format);
8b93c638 588 uo_message (uiout, verbosity, format, args);
8b93c638
JM
589 va_end (args);
590}
591
592struct ui_stream *
fba45db2 593ui_out_stream_new (struct ui_out *uiout)
8b93c638
JM
594{
595 struct ui_stream *tempbuf;
596
597 tempbuf = XMALLOC (struct ui_stream);
598 tempbuf->uiout = uiout;
599 tempbuf->stream = mem_fileopen ();
600 return tempbuf;
601}
602
603void
fba45db2 604ui_out_stream_delete (struct ui_stream *buf)
8b93c638
JM
605{
606 ui_file_delete (buf->stream);
b8c9b27d 607 xfree (buf);
8b93c638
JM
608}
609
610static void
611do_stream_delete (void *buf)
612{
613 ui_out_stream_delete (buf);
614}
615
616struct cleanup *
617make_cleanup_ui_out_stream_delete (struct ui_stream *buf)
618{
619 return make_cleanup (do_stream_delete, buf);
620}
621
622
623void
fba45db2 624ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
625{
626 uo_wrap_hint (uiout, identstring);
627}
628
629void
fba45db2 630ui_out_flush (struct ui_out *uiout)
8b93c638
JM
631{
632 uo_flush (uiout);
633}
634
0fac0b41
DJ
635int
636ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
637{
638 return uo_redirect (uiout, outstream);
639}
640
581e13c1 641/* Set the flags specified by the mask given. */
8b93c638 642int
fba45db2 643ui_out_set_flags (struct ui_out *uiout, int mask)
8b93c638 644{
5bfb05ca 645 int oldflags = uiout->flags;
8b93c638 646
b8d86de3 647 uiout->flags |= mask;
8b93c638
JM
648 return oldflags;
649}
650
581e13c1 651/* Clear the flags specified by the mask given. */
8b93c638 652int
fba45db2 653ui_out_clear_flags (struct ui_out *uiout, int mask)
8b93c638 654{
5bfb05ca 655 int oldflags = uiout->flags;
8b93c638
JM
656
657 uiout->flags &= ~mask;
8b93c638
JM
658 return oldflags;
659}
660
581e13c1 661/* Test the flags against the mask given. */
8b93c638 662int
fba45db2 663ui_out_test_flags (struct ui_out *uiout, int mask)
8b93c638
JM
664{
665 return (uiout->flags & mask);
666}
667
581e13c1
MS
668/* Obtain the current verbosity level (as stablished by the
669 'set verbositylevel' command. */
8b93c638
JM
670
671int
fba45db2 672ui_out_get_verblvl (struct ui_out *uiout)
8b93c638 673{
581e13c1 674 /* FIXME: not implemented yet. */
8b93c638
JM
675 return 0;
676}
677
678#if 0
679void
fba45db2 680ui_out_result_begin (struct ui_out *uiout, char *class)
8b93c638
JM
681{
682}
683
684void
fba45db2 685ui_out_result_end (struct ui_out *uiout)
8b93c638
JM
686{
687}
688
689void
fba45db2 690ui_out_info_begin (struct ui_out *uiout, char *class)
8b93c638
JM
691{
692}
693
694void
fba45db2 695ui_out_info_end (struct ui_out *uiout)
8b93c638
JM
696{
697}
698
699void
fba45db2 700ui_out_notify_begin (struct ui_out *uiout, char *class)
8b93c638
JM
701{
702}
703
704void
fba45db2 705ui_out_notify_end (struct ui_out *uiout)
8b93c638
JM
706{
707}
708
709void
fba45db2 710ui_out_error_begin (struct ui_out *uiout, char *class)
8b93c638
JM
711{
712}
713
714void
fba45db2 715ui_out_error_end (struct ui_out *uiout)
8b93c638
JM
716{
717}
718#endif
719
720#if 0
721void
722gdb_error (ui_out * uiout, int severity, char *format,...)
723{
724 va_list args;
725}
726
727void
10689f25 728gdb_query (struct ui_out *uiout, int qflags, char *qprompt)
8b93c638
JM
729{
730}
731#endif
732
9dc5e2a9
AC
733int
734ui_out_is_mi_like_p (struct ui_out *uiout)
735{
736 return uiout->impl->is_mi_like_p;
737}
738
581e13c1 739/* Default gdb-out hook functions. */
8b93c638
JM
740
741static void
d63f1d40
AC
742default_table_begin (struct ui_out *uiout, int nbrofcols,
743 int nr_rows,
744 const char *tblid)
8b93c638
JM
745{
746}
747
748static void
fba45db2 749default_table_body (struct ui_out *uiout)
8b93c638
JM
750{
751}
752
753static void
fba45db2 754default_table_end (struct ui_out *uiout)
8b93c638
JM
755{
756}
757
758static void
fba45db2 759default_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 760 const char *col_name,
e2e11a41 761 const char *colhdr)
8b93c638
JM
762{
763}
764
765static void
631ec795
AC
766default_begin (struct ui_out *uiout,
767 enum ui_out_type type,
768 int level,
769 const char *id)
8b93c638
JM
770{
771}
772
773static void
631ec795
AC
774default_end (struct ui_out *uiout,
775 enum ui_out_type type,
776 int level)
8b93c638
JM
777{
778}
779
780static void
fba45db2 781default_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
782 enum ui_align align,
783 const char *fldname, int value)
8b93c638
JM
784{
785}
786
787static void
fba45db2 788default_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 789 enum ui_align align, const char *fldname)
8b93c638
JM
790{
791}
792
793static void
794default_field_string (struct ui_out *uiout,
795 int fldno,
796 int width,
797 enum ui_align align,
e2e11a41 798 const char *fldname,
8b93c638
JM
799 const char *string)
800{
801}
802
803static void
fba45db2 804default_field_fmt (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
805 enum ui_align align,
806 const char *fldname,
807 const char *format,
fba45db2 808 va_list args)
8b93c638
JM
809{
810}
811
812static void
fba45db2 813default_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
814{
815}
816
817static void
e2e11a41 818default_text (struct ui_out *uiout, const char *string)
8b93c638
JM
819{
820}
821
822static void
e2e11a41
AC
823default_message (struct ui_out *uiout, int verbosity,
824 const char *format,
fba45db2 825 va_list args)
8b93c638
JM
826{
827}
828
829static void
fba45db2 830default_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
831{
832}
833
834static void
fba45db2 835default_flush (struct ui_out *uiout)
8b93c638
JM
836{
837}
838
581e13c1 839/* Interface to the implementation functions. */
8b93c638
JM
840
841void
88379baf 842uo_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 843 int nr_rows,
88379baf 844 const char *tblid)
8b93c638
JM
845{
846 if (!uiout->impl->table_begin)
847 return;
d63f1d40 848 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
8b93c638
JM
849}
850
851void
852uo_table_body (struct ui_out *uiout)
853{
854 if (!uiout->impl->table_body)
855 return;
856 uiout->impl->table_body (uiout);
857}
858
859void
860uo_table_end (struct ui_out *uiout)
861{
862 if (!uiout->impl->table_end)
863 return;
864 uiout->impl->table_end (uiout);
865}
866
867void
88379baf 868uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
b25959ec 869 const char *col_name,
88379baf 870 const char *colhdr)
8b93c638
JM
871{
872 if (!uiout->impl->table_header)
873 return;
b25959ec 874 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
8b93c638
JM
875}
876
877void
631ec795
AC
878uo_begin (struct ui_out *uiout,
879 enum ui_out_type type,
880 int level,
881 const char *id)
8b93c638 882{
631ec795 883 if (uiout->impl->begin == NULL)
8b93c638 884 return;
631ec795 885 uiout->impl->begin (uiout, type, level, id);
8b93c638
JM
886}
887
888void
631ec795
AC
889uo_end (struct ui_out *uiout,
890 enum ui_out_type type,
891 int level)
8b93c638 892{
631ec795 893 if (uiout->impl->end == NULL)
8b93c638 894 return;
631ec795 895 uiout->impl->end (uiout, type, level);
8b93c638
JM
896}
897
898void
88379baf
AC
899uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
900 const char *fldname,
901 int value)
8b93c638
JM
902{
903 if (!uiout->impl->field_int)
904 return;
905 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
906}
907
908void
88379baf
AC
909uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
910 const char *fldname)
8b93c638
JM
911{
912 if (!uiout->impl->field_skip)
913 return;
914 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
915}
916
917void
918uo_field_string (struct ui_out *uiout, int fldno, int width,
88379baf
AC
919 enum ui_align align,
920 const char *fldname,
921 const char *string)
8b93c638
JM
922{
923 if (!uiout->impl->field_string)
924 return;
925 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
926}
927
928void
88379baf
AC
929uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
930 const char *fldname,
931 const char *format,
932 va_list args)
8b93c638
JM
933{
934 if (!uiout->impl->field_fmt)
935 return;
936 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
937}
938
939void
940uo_spaces (struct ui_out *uiout, int numspaces)
941{
942 if (!uiout->impl->spaces)
943 return;
944 uiout->impl->spaces (uiout, numspaces);
945}
946
947void
88379baf
AC
948uo_text (struct ui_out *uiout,
949 const char *string)
8b93c638
JM
950{
951 if (!uiout->impl->text)
952 return;
953 uiout->impl->text (uiout, string);
954}
955
956void
88379baf
AC
957uo_message (struct ui_out *uiout, int verbosity,
958 const char *format,
959 va_list args)
8b93c638
JM
960{
961 if (!uiout->impl->message)
962 return;
963 uiout->impl->message (uiout, verbosity, format, args);
964}
965
966void
967uo_wrap_hint (struct ui_out *uiout, char *identstring)
968{
969 if (!uiout->impl->wrap_hint)
970 return;
971 uiout->impl->wrap_hint (uiout, identstring);
972}
973
974void
975uo_flush (struct ui_out *uiout)
976{
977 if (!uiout->impl->flush)
978 return;
979 uiout->impl->flush (uiout);
980}
981
0fac0b41
DJ
982int
983uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
984{
985 if (!uiout->impl->redirect)
986 return -1;
987 uiout->impl->redirect (uiout, outstream);
988 return 0;
989}
990
8b93c638
JM
991/* local functions */
992
581e13c1 993/* List of column headers manipulation routines. */
8b93c638
JM
994
995static void
fba45db2 996clear_header_list (struct ui_out *uiout)
8b93c638 997{
bafdd3b3 998 while (uiout->table.header_first != NULL)
8b93c638 999 {
bafdd3b3
AC
1000 uiout->table.header_next = uiout->table.header_first;
1001 uiout->table.header_first = uiout->table.header_first->next;
1002 if (uiout->table.header_next->colhdr != NULL)
1003 xfree (uiout->table.header_next->colhdr);
1004 xfree (uiout->table.header_next);
8b93c638 1005 }
bafdd3b3
AC
1006 gdb_assert (uiout->table.header_first == NULL);
1007 uiout->table.header_last = NULL;
1008 uiout->table.header_next = NULL;
8b93c638
JM
1009}
1010
1011static void
1012append_header_to_list (struct ui_out *uiout,
1013 int width,
1014 int alignment,
b25959ec 1015 const char *col_name,
88379baf 1016 const char *colhdr)
8b93c638
JM
1017{
1018 struct ui_out_hdr *temphdr;
1019
1020 temphdr = XMALLOC (struct ui_out_hdr);
1021 temphdr->width = width;
1022 temphdr->alignment = alignment;
44db85f8
MS
1023 /* We have to copy the column title as the original may be an
1024 automatic. */
8b93c638 1025 if (colhdr != NULL)
b25959ec
AC
1026 temphdr->colhdr = xstrdup (colhdr);
1027 else
1028 temphdr->colhdr = NULL;
44db85f8 1029
b25959ec 1030 if (col_name != NULL)
44db85f8
MS
1031 temphdr->col_name = xstrdup (col_name);
1032 else if (colhdr != NULL)
b25959ec
AC
1033 temphdr->col_name = xstrdup (colhdr);
1034 else
44db85f8
MS
1035 temphdr->col_name = NULL;
1036
8b93c638 1037 temphdr->next = NULL;
bafdd3b3 1038 if (uiout->table.header_first == NULL)
8b93c638
JM
1039 {
1040 temphdr->colno = 1;
bafdd3b3
AC
1041 uiout->table.header_first = temphdr;
1042 uiout->table.header_last = temphdr;
8b93c638
JM
1043 }
1044 else
1045 {
bafdd3b3
AC
1046 temphdr->colno = uiout->table.header_last->colno + 1;
1047 uiout->table.header_last->next = temphdr;
1048 uiout->table.header_last = temphdr;
8b93c638 1049 }
bafdd3b3 1050 uiout->table.header_next = uiout->table.header_last;
8b93c638
JM
1051}
1052
7a9dd1b2 1053/* Extract the format information for the NEXT header and advance
bafdd3b3 1054 the header pointer. Return 0 if there was no next header. */
8b93c638
JM
1055
1056static int
bafdd3b3 1057get_next_header (struct ui_out *uiout,
8b93c638
JM
1058 int *colno,
1059 int *width,
1060 int *alignment,
1061 char **colhdr)
1062{
bafdd3b3
AC
1063 /* There may be no headers at all or we may have used all columns. */
1064 if (uiout->table.header_next == NULL)
8b93c638 1065 return 0;
bafdd3b3
AC
1066 *colno = uiout->table.header_next->colno;
1067 *width = uiout->table.header_next->width;
1068 *alignment = uiout->table.header_next->alignment;
1069 *colhdr = uiout->table.header_next->colhdr;
1070 /* Advance the header pointer to the next entry. */
1071 uiout->table.header_next = uiout->table.header_next->next;
8b93c638
JM
1072 return 1;
1073}
1074
a6c47c14
AC
1075
1076/* Verify that the field/tuple/list is correctly positioned. Return
1077 the field number and corresponding alignment (if
1078 available/applicable). */
8b93c638
JM
1079
1080static void
a6c47c14 1081verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
8b93c638 1082{
a6c47c14
AC
1083 struct ui_out_level *current = current_level (uiout);
1084 char *text;
1085
bafdd3b3 1086 if (uiout->table.flag)
8b93c638 1087 {
bafdd3b3 1088 if (!uiout->table.body_flag)
8e65ff28 1089 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
1090 _("table_body missing; table fields must be \
1091specified after table_body and inside a list."));
a6c47c14
AC
1092 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1093 that this code was only executed when uiout->level was
1094 greater than zero. That no longer applies - this code is run
1095 before each table row tuple is started and at that point the
1096 level is zero. */
8b93c638 1097 }
8b93c638 1098
a6c47c14 1099 current->field_count += 1;
8b93c638 1100
a6c47c14
AC
1101 if (uiout->table.body_flag
1102 && uiout->table.entry_level == uiout->level
1103 && get_next_header (uiout, fldno, width, align, &text))
8b93c638 1104 {
a6c47c14 1105 if (*fldno != current->field_count)
8e65ff28 1106 internal_error (__FILE__, __LINE__,
e2e0b3e5 1107 _("ui-out internal error in handling headers."));
8b93c638
JM
1108 }
1109 else
1110 {
1111 *width = 0;
1112 *align = ui_noalign;
a6c47c14 1113 *fldno = current->field_count;
8b93c638
JM
1114 }
1115}
1116
a6c47c14 1117
581e13c1 1118/* Access to ui-out members data. */
8b93c638 1119
0a8fce9a 1120void *
8b93c638
JM
1121ui_out_data (struct ui_out *uiout)
1122{
1123 return uiout->data;
1124}
1125
170b53b2
UW
1126/* Access table field parameters. */
1127int
1128ui_out_query_field (struct ui_out *uiout, int colno,
1129 int *width, int *alignment, char **col_name)
1130{
1131 struct ui_out_hdr *hdr;
1132
1133 if (!uiout->table.flag)
1134 return 0;
1135
1136 for (hdr = uiout->table.header_first; hdr; hdr = hdr->next)
1137 if (hdr->colno == colno)
1138 {
1139 *width = hdr->width;
1140 *alignment = hdr->alignment;
1141 *col_name = hdr->col_name;
1142 return 1;
1143 }
1144
1145 return 0;
1146}
1147
581e13c1 1148/* Initalize private members at startup. */
8b93c638
JM
1149
1150struct ui_out *
0a8fce9a 1151ui_out_new (struct ui_out_impl *impl, void *data,
8b93c638
JM
1152 int flags)
1153{
1154 struct ui_out *uiout = XMALLOC (struct ui_out);
5d502164 1155
8b93c638
JM
1156 uiout->data = data;
1157 uiout->impl = impl;
1158 uiout->flags = flags;
bafdd3b3
AC
1159 uiout->table.flag = 0;
1160 uiout->table.body_flag = 0;
80f49b30
AC
1161 uiout->level = 0;
1162 memset (uiout->levels, 0, sizeof (uiout->levels));
bafdd3b3
AC
1163 uiout->table.header_first = NULL;
1164 uiout->table.header_last = NULL;
1165 uiout->table.header_next = NULL;
8b93c638
JM
1166 return uiout;
1167}
1168
581e13c1 1169/* Standard gdb initialization hook. */
8b93c638
JM
1170
1171void
fba45db2 1172_initialize_ui_out (void)
8b93c638
JM
1173{
1174 /* nothing needs to be done */
1175}
This page took 1.361822 seconds and 4 git commands to generate.