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