1 /* Output generating routines for GDB.
3 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
9 This file is part of GDB.
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
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
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.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_string.h"
26 #include "expression.h" /* For language.h */
29 #include "gdb_assert.h"
31 /* table header structures */
40 struct ui_out_hdr
*next
;
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
47 enum { MAX_UI_OUT_LEVELS
= 8 };
51 /* Count each field; the first element is for non-list fields. */
53 /* The type of this level. */
54 enum ui_out_type type
;
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. */
63 /* If on, a table is being generated. */
66 /* If on, the body of a table is being generated. If off, the table
67 header is being generated. */
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. */
75 /* Number of table columns (as specified in the table_begin call). */
78 /* String identifying the table (as specified in the table_begin
82 /* Points to the first table header (if any). */
83 struct ui_out_hdr
*header_first
;
85 /* Points to the last table header (if any). */
86 struct ui_out_hdr
*header_last
;
88 /* Points to header of NEXT column to format. */
89 struct ui_out_hdr
*header_next
;
94 /* The ui_out structure */
95 /* Any change here requires a corresponding one in the initialization
96 of the default uiout, which is statically initialized. */
101 /* Specific implementation of ui-out. */
102 struct ui_out_impl
*impl
;
105 /* Sub structure tracking the ui-out depth. */
107 struct ui_out_level levels
[MAX_UI_OUT_LEVELS
];
109 /* A table, if any. At present only a single table is supported. */
110 struct ui_out_table table
;
113 /* The current (inner most) level. */
114 static struct ui_out_level
*
115 current_level (struct ui_out
*uiout
)
117 return &uiout
->levels
[uiout
->level
];
120 /* Create a new level, of TYPE. Return the new level's index. */
122 push_level (struct ui_out
*uiout
,
123 enum ui_out_type type
,
126 struct ui_out_level
*current
;
128 /* We had better not overflow the buffer. */
130 gdb_assert (uiout
->level
>= 0 && uiout
->level
< MAX_UI_OUT_LEVELS
);
131 current
= current_level (uiout
);
132 current
->field_count
= 0;
133 current
->type
= type
;
137 /* Discard the current level, return the discarded level's index.
138 TYPE is the type of the level being discarded. */
140 pop_level (struct ui_out
*uiout
,
141 enum ui_out_type type
)
143 /* We had better not underflow the buffer. */
144 gdb_assert (uiout
->level
> 0 && uiout
->level
< MAX_UI_OUT_LEVELS
);
145 gdb_assert (current_level (uiout
)->type
== type
);
147 return uiout
->level
+ 1;
151 /* These are the default implementation functions. */
153 static void default_table_begin (struct ui_out
*uiout
, int nbrofcols
,
154 int nr_rows
, const char *tblid
);
155 static void default_table_body (struct ui_out
*uiout
);
156 static void default_table_end (struct ui_out
*uiout
);
157 static void default_table_header (struct ui_out
*uiout
, int width
,
158 enum ui_align alig
, const char *col_name
,
160 static void default_begin (struct ui_out
*uiout
,
161 enum ui_out_type type
,
162 int level
, const char *id
);
163 static void default_end (struct ui_out
*uiout
,
164 enum ui_out_type type
,
166 static void default_field_int (struct ui_out
*uiout
, int fldno
, int width
,
170 static void default_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
172 const char *fldname
);
173 static void default_field_string (struct ui_out
*uiout
, int fldno
, int width
,
177 static void default_field_fmt (struct ui_out
*uiout
, int fldno
,
178 int width
, enum ui_align align
,
181 va_list args
) ATTRIBUTE_PRINTF (6, 0);
182 static void default_spaces (struct ui_out
*uiout
, int numspaces
);
183 static void default_text (struct ui_out
*uiout
, const char *string
);
184 static void default_message (struct ui_out
*uiout
, int verbosity
,
186 va_list args
) ATTRIBUTE_PRINTF (3, 0);
187 static void default_wrap_hint (struct ui_out
*uiout
, char *identstring
);
188 static void default_flush (struct ui_out
*uiout
);
190 /* This is the default ui-out implementation functions vector. */
192 struct ui_out_impl default_ui_out_impl
=
197 default_table_header
,
202 default_field_string
,
210 0, /* Does not need MI hacks. */
213 /* The default ui_out */
215 struct ui_out def_uiout
=
218 &default_ui_out_impl
, /* impl */
221 /* Pointer to current ui_out */
222 /* FIXME: This should not be a global, but something passed down from main.c
225 struct ui_out
*uiout
= &def_uiout
;
227 /* These are the interfaces to implementation functions. */
229 static void uo_table_begin (struct ui_out
*uiout
, int nbrofcols
,
230 int nr_rows
, const char *tblid
);
231 static void uo_table_body (struct ui_out
*uiout
);
232 static void uo_table_end (struct ui_out
*uiout
);
233 static void uo_table_header (struct ui_out
*uiout
, int width
,
234 enum ui_align align
, const char *col_name
,
236 static void uo_begin (struct ui_out
*uiout
,
237 enum ui_out_type type
,
238 int level
, const char *id
);
239 static void uo_end (struct ui_out
*uiout
,
240 enum ui_out_type type
,
242 static void uo_field_int (struct ui_out
*uiout
, int fldno
, int width
,
243 enum ui_align align
, const char *fldname
, int value
);
244 static void uo_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
245 enum ui_align align
, const char *fldname
);
246 static void uo_field_fmt (struct ui_out
*uiout
, int fldno
, int width
,
247 enum ui_align align
, const char *fldname
,
248 const char *format
, va_list args
)
249 ATTRIBUTE_PRINTF (6, 0);
250 static void uo_spaces (struct ui_out
*uiout
, int numspaces
);
251 static void uo_text (struct ui_out
*uiout
, const char *string
);
252 static void uo_message (struct ui_out
*uiout
, int verbosity
,
253 const char *format
, va_list args
)
254 ATTRIBUTE_PRINTF (3, 0);
255 static void uo_wrap_hint (struct ui_out
*uiout
, char *identstring
);
256 static void uo_flush (struct ui_out
*uiout
);
257 static int uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
);
259 /* Prototypes for local functions */
261 extern void _initialize_ui_out (void);
262 static void append_header_to_list (struct ui_out
*uiout
, int width
,
263 int alignment
, const char *col_name
,
265 static int get_next_header (struct ui_out
*uiout
, int *colno
, int *width
,
266 int *alignment
, char **colhdr
);
267 static void clear_header_list (struct ui_out
*uiout
);
268 static void verify_field (struct ui_out
*uiout
, int *fldno
, int *width
,
271 /* exported functions (ui_out API) */
273 /* Mark beginning of a table. */
276 ui_out_table_begin (struct ui_out
*uiout
, int nbrofcols
,
280 if (uiout
->table
.flag
)
281 internal_error (__FILE__
, __LINE__
,
282 _("tables cannot be nested; table_begin found before \
283 previous table_end."));
285 uiout
->table
.flag
= 1;
286 uiout
->table
.body_flag
= 0;
287 uiout
->table
.entry_level
= uiout
->level
+ 1;
288 uiout
->table
.columns
= nbrofcols
;
290 uiout
->table
.id
= xstrdup (tblid
);
292 uiout
->table
.id
= NULL
;
293 clear_header_list (uiout
);
295 uo_table_begin (uiout
, nbrofcols
, nr_rows
, uiout
->table
.id
);
299 ui_out_table_body (struct ui_out
*uiout
)
301 if (!uiout
->table
.flag
)
302 internal_error (__FILE__
, __LINE__
,
303 _("table_body outside a table is not valid; it must be \
304 after a table_begin and before a table_end."));
305 if (uiout
->table
.body_flag
)
306 internal_error (__FILE__
, __LINE__
,
307 _("extra table_body call not allowed; there must be \
308 only one table_body after a table_begin and before a table_end."));
309 if (uiout
->table
.header_next
->colno
!= uiout
->table
.columns
)
310 internal_error (__FILE__
, __LINE__
,
311 _("number of headers differ from number of table \
314 uiout
->table
.body_flag
= 1;
315 uiout
->table
.header_next
= uiout
->table
.header_first
;
317 uo_table_body (uiout
);
321 ui_out_table_end (struct ui_out
*uiout
)
323 if (!uiout
->table
.flag
)
324 internal_error (__FILE__
, __LINE__
,
325 _("misplaced table_end or missing table_begin."));
327 uiout
->table
.entry_level
= 0;
328 uiout
->table
.body_flag
= 0;
329 uiout
->table
.flag
= 0;
331 uo_table_end (uiout
);
334 xfree (uiout
->table
.id
);
335 clear_header_list (uiout
);
339 ui_out_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
340 const char *col_name
,
343 if (!uiout
->table
.flag
|| uiout
->table
.body_flag
)
344 internal_error (__FILE__
, __LINE__
,
345 _("table header must be specified after table_begin \
346 and before table_body."));
348 append_header_to_list (uiout
, width
, alignment
, col_name
, colhdr
);
350 uo_table_header (uiout
, width
, alignment
, col_name
, colhdr
);
354 do_cleanup_table_end (void *data
)
356 struct ui_out
*ui_out
= data
;
358 ui_out_table_end (ui_out
);
362 make_cleanup_ui_out_table_begin_end (struct ui_out
*ui_out
, int nr_cols
,
363 int nr_rows
, const char *tblid
)
365 ui_out_table_begin (ui_out
, nr_cols
, nr_rows
, tblid
);
366 return make_cleanup (do_cleanup_table_end
, ui_out
);
370 ui_out_begin (struct ui_out
*uiout
,
371 enum ui_out_type type
,
376 if (uiout
->table
.flag
&& !uiout
->table
.body_flag
)
377 internal_error (__FILE__
, __LINE__
,
378 _("table header or table_body expected; lists must be \
379 specified after table_body."));
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. */
393 verify_field (uiout
, &fldno
, &width
, &align
);
396 new_level
= push_level (uiout
, type
, id
);
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
)
402 uiout
->table
.header_next
= uiout
->table
.header_first
;
404 uo_begin (uiout
, type
, new_level
, id
);
408 ui_out_end (struct ui_out
*uiout
,
409 enum ui_out_type type
)
411 int old_level
= pop_level (uiout
, type
);
413 uo_end (uiout
, type
, old_level
);
416 struct ui_out_end_cleanup_data
418 struct ui_out
*uiout
;
419 enum ui_out_type type
;
423 do_cleanup_end (void *data
)
425 struct ui_out_end_cleanup_data
*end_cleanup_data
= data
;
427 ui_out_end (end_cleanup_data
->uiout
, end_cleanup_data
->type
);
428 xfree (end_cleanup_data
);
431 static struct cleanup
*
432 make_cleanup_ui_out_end (struct ui_out
*uiout
,
433 enum ui_out_type type
)
435 struct ui_out_end_cleanup_data
*end_cleanup_data
;
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
);
444 make_cleanup_ui_out_tuple_begin_end (struct ui_out
*uiout
,
447 ui_out_begin (uiout
, ui_out_type_tuple
, id
);
448 return make_cleanup_ui_out_end (uiout
, ui_out_type_tuple
);
452 make_cleanup_ui_out_list_begin_end (struct ui_out
*uiout
,
455 ui_out_begin (uiout
, ui_out_type_list
, id
);
456 return make_cleanup_ui_out_end (uiout
, ui_out_type_list
);
460 ui_out_field_int (struct ui_out
*uiout
,
468 verify_field (uiout
, &fldno
, &width
, &align
);
470 uo_field_int (uiout
, fldno
, width
, align
, fldname
, value
);
474 ui_out_field_fmt_int (struct ui_out
*uiout
,
476 enum ui_align input_align
,
484 verify_field (uiout
, &fldno
, &width
, &align
);
486 uo_field_int (uiout
, fldno
, input_width
, input_align
, fldname
, value
);
490 ui_out_field_core_addr (struct ui_out
*uiout
,
492 struct gdbarch
*gdbarch
,
495 ui_out_field_string (uiout
, fldname
,
496 print_core_address (gdbarch
, address
));
500 ui_out_field_stream (struct ui_out
*uiout
,
502 struct ui_stream
*buf
)
505 char *buffer
= ui_file_xstrdup (buf
->stream
, &length
);
506 struct cleanup
*old_cleanup
= make_cleanup (xfree
, buffer
);
509 ui_out_field_string (uiout
, fldname
, buffer
);
511 ui_out_field_skip (uiout
, fldname
);
512 ui_file_rewind (buf
->stream
);
513 do_cleanups (old_cleanup
);
516 /* Used to omit a field. */
519 ui_out_field_skip (struct ui_out
*uiout
,
526 verify_field (uiout
, &fldno
, &width
, &align
);
528 uo_field_skip (uiout
, fldno
, width
, align
, fldname
);
532 ui_out_field_string (struct ui_out
*uiout
,
540 verify_field (uiout
, &fldno
, &width
, &align
);
542 uo_field_string (uiout
, fldno
, width
, align
, fldname
, string
);
547 ui_out_field_fmt (struct ui_out
*uiout
,
549 const char *format
, ...)
556 /* Will not align, but has to call anyway. */
557 verify_field (uiout
, &fldno
, &width
, &align
);
559 va_start (args
, format
);
561 uo_field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
567 ui_out_spaces (struct ui_out
*uiout
, int numspaces
)
569 uo_spaces (uiout
, numspaces
);
573 ui_out_text (struct ui_out
*uiout
,
576 uo_text (uiout
, string
);
580 ui_out_message (struct ui_out
*uiout
, int verbosity
,
581 const char *format
,...)
585 va_start (args
, format
);
586 uo_message (uiout
, verbosity
, format
, args
);
591 ui_out_stream_new (struct ui_out
*uiout
)
593 struct ui_stream
*tempbuf
;
595 tempbuf
= XMALLOC (struct ui_stream
);
596 tempbuf
->uiout
= uiout
;
597 tempbuf
->stream
= mem_fileopen ();
602 ui_out_stream_delete (struct ui_stream
*buf
)
604 ui_file_delete (buf
->stream
);
609 do_stream_delete (void *buf
)
611 ui_out_stream_delete (buf
);
615 make_cleanup_ui_out_stream_delete (struct ui_stream
*buf
)
617 return make_cleanup (do_stream_delete
, buf
);
622 ui_out_wrap_hint (struct ui_out
*uiout
, char *identstring
)
624 uo_wrap_hint (uiout
, identstring
);
628 ui_out_flush (struct ui_out
*uiout
)
634 ui_out_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
636 return uo_redirect (uiout
, outstream
);
639 /* Set the flags specified by the mask given. */
641 ui_out_set_flags (struct ui_out
*uiout
, int mask
)
643 int oldflags
= uiout
->flags
;
645 uiout
->flags
|= mask
;
649 /* Clear the flags specified by the mask given. */
651 ui_out_clear_flags (struct ui_out
*uiout
, int mask
)
653 int oldflags
= uiout
->flags
;
655 uiout
->flags
&= ~mask
;
659 /* Test the flags against the mask given. */
661 ui_out_test_flags (struct ui_out
*uiout
, int mask
)
663 return (uiout
->flags
& mask
);
666 /* Obtain the current verbosity level (as stablished by the
667 'set verbositylevel' command. */
670 ui_out_get_verblvl (struct ui_out
*uiout
)
672 /* FIXME: not implemented yet. */
678 ui_out_result_begin (struct ui_out
*uiout
, char *class)
683 ui_out_result_end (struct ui_out
*uiout
)
688 ui_out_info_begin (struct ui_out
*uiout
, char *class)
693 ui_out_info_end (struct ui_out
*uiout
)
698 ui_out_notify_begin (struct ui_out
*uiout
, char *class)
703 ui_out_notify_end (struct ui_out
*uiout
)
708 ui_out_error_begin (struct ui_out
*uiout
, char *class)
713 ui_out_error_end (struct ui_out
*uiout
)
720 gdb_error (ui_out
* uiout
, int severity
, char *format
,...)
726 gdb_query (struct ui_out
*uiout
, int qflags
, char *qprompt
)
732 ui_out_is_mi_like_p (struct ui_out
*uiout
)
734 return uiout
->impl
->is_mi_like_p
;
737 /* Default gdb-out hook functions. */
740 default_table_begin (struct ui_out
*uiout
, int nbrofcols
,
747 default_table_body (struct ui_out
*uiout
)
752 default_table_end (struct ui_out
*uiout
)
757 default_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
758 const char *col_name
,
764 default_begin (struct ui_out
*uiout
,
765 enum ui_out_type type
,
772 default_end (struct ui_out
*uiout
,
773 enum ui_out_type type
,
779 default_field_int (struct ui_out
*uiout
, int fldno
, int width
,
781 const char *fldname
, int value
)
786 default_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
787 enum ui_align align
, const char *fldname
)
792 default_field_string (struct ui_out
*uiout
,
802 default_field_fmt (struct ui_out
*uiout
, int fldno
, int width
,
811 default_spaces (struct ui_out
*uiout
, int numspaces
)
816 default_text (struct ui_out
*uiout
, const char *string
)
821 default_message (struct ui_out
*uiout
, int verbosity
,
828 default_wrap_hint (struct ui_out
*uiout
, char *identstring
)
833 default_flush (struct ui_out
*uiout
)
837 /* Interface to the implementation functions. */
840 uo_table_begin (struct ui_out
*uiout
, int nbrofcols
,
844 if (!uiout
->impl
->table_begin
)
846 uiout
->impl
->table_begin (uiout
, nbrofcols
, nr_rows
, tblid
);
850 uo_table_body (struct ui_out
*uiout
)
852 if (!uiout
->impl
->table_body
)
854 uiout
->impl
->table_body (uiout
);
858 uo_table_end (struct ui_out
*uiout
)
860 if (!uiout
->impl
->table_end
)
862 uiout
->impl
->table_end (uiout
);
866 uo_table_header (struct ui_out
*uiout
, int width
, enum ui_align align
,
867 const char *col_name
,
870 if (!uiout
->impl
->table_header
)
872 uiout
->impl
->table_header (uiout
, width
, align
, col_name
, colhdr
);
876 uo_begin (struct ui_out
*uiout
,
877 enum ui_out_type type
,
881 if (uiout
->impl
->begin
== NULL
)
883 uiout
->impl
->begin (uiout
, type
, level
, id
);
887 uo_end (struct ui_out
*uiout
,
888 enum ui_out_type type
,
891 if (uiout
->impl
->end
== NULL
)
893 uiout
->impl
->end (uiout
, type
, level
);
897 uo_field_int (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
901 if (!uiout
->impl
->field_int
)
903 uiout
->impl
->field_int (uiout
, fldno
, width
, align
, fldname
, value
);
907 uo_field_skip (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
910 if (!uiout
->impl
->field_skip
)
912 uiout
->impl
->field_skip (uiout
, fldno
, width
, align
, fldname
);
916 uo_field_string (struct ui_out
*uiout
, int fldno
, int width
,
921 if (!uiout
->impl
->field_string
)
923 uiout
->impl
->field_string (uiout
, fldno
, width
, align
, fldname
, string
);
927 uo_field_fmt (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
932 if (!uiout
->impl
->field_fmt
)
934 uiout
->impl
->field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
938 uo_spaces (struct ui_out
*uiout
, int numspaces
)
940 if (!uiout
->impl
->spaces
)
942 uiout
->impl
->spaces (uiout
, numspaces
);
946 uo_text (struct ui_out
*uiout
,
949 if (!uiout
->impl
->text
)
951 uiout
->impl
->text (uiout
, string
);
955 uo_message (struct ui_out
*uiout
, int verbosity
,
959 if (!uiout
->impl
->message
)
961 uiout
->impl
->message (uiout
, verbosity
, format
, args
);
965 uo_wrap_hint (struct ui_out
*uiout
, char *identstring
)
967 if (!uiout
->impl
->wrap_hint
)
969 uiout
->impl
->wrap_hint (uiout
, identstring
);
973 uo_flush (struct ui_out
*uiout
)
975 if (!uiout
->impl
->flush
)
977 uiout
->impl
->flush (uiout
);
981 uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
983 if (!uiout
->impl
->redirect
)
985 uiout
->impl
->redirect (uiout
, outstream
);
989 /* local functions */
991 /* List of column headers manipulation routines. */
994 clear_header_list (struct ui_out
*uiout
)
996 while (uiout
->table
.header_first
!= NULL
)
998 uiout
->table
.header_next
= uiout
->table
.header_first
;
999 uiout
->table
.header_first
= uiout
->table
.header_first
->next
;
1000 if (uiout
->table
.header_next
->colhdr
!= NULL
)
1001 xfree (uiout
->table
.header_next
->colhdr
);
1002 xfree (uiout
->table
.header_next
);
1004 gdb_assert (uiout
->table
.header_first
== NULL
);
1005 uiout
->table
.header_last
= NULL
;
1006 uiout
->table
.header_next
= NULL
;
1010 append_header_to_list (struct ui_out
*uiout
,
1013 const char *col_name
,
1016 struct ui_out_hdr
*temphdr
;
1018 temphdr
= XMALLOC (struct ui_out_hdr
);
1019 temphdr
->width
= width
;
1020 temphdr
->alignment
= alignment
;
1021 /* We have to copy the column title as the original may be an
1024 temphdr
->colhdr
= xstrdup (colhdr
);
1026 temphdr
->colhdr
= NULL
;
1028 if (col_name
!= NULL
)
1029 temphdr
->col_name
= xstrdup (col_name
);
1030 else if (colhdr
!= NULL
)
1031 temphdr
->col_name
= xstrdup (colhdr
);
1033 temphdr
->col_name
= NULL
;
1035 temphdr
->next
= NULL
;
1036 if (uiout
->table
.header_first
== NULL
)
1039 uiout
->table
.header_first
= temphdr
;
1040 uiout
->table
.header_last
= temphdr
;
1044 temphdr
->colno
= uiout
->table
.header_last
->colno
+ 1;
1045 uiout
->table
.header_last
->next
= temphdr
;
1046 uiout
->table
.header_last
= temphdr
;
1048 uiout
->table
.header_next
= uiout
->table
.header_last
;
1051 /* Extract the format information for the NEXT header and and advance
1052 the header pointer. Return 0 if there was no next header. */
1055 get_next_header (struct ui_out
*uiout
,
1061 /* There may be no headers at all or we may have used all columns. */
1062 if (uiout
->table
.header_next
== NULL
)
1064 *colno
= uiout
->table
.header_next
->colno
;
1065 *width
= uiout
->table
.header_next
->width
;
1066 *alignment
= uiout
->table
.header_next
->alignment
;
1067 *colhdr
= uiout
->table
.header_next
->colhdr
;
1068 /* Advance the header pointer to the next entry. */
1069 uiout
->table
.header_next
= uiout
->table
.header_next
->next
;
1074 /* Verify that the field/tuple/list is correctly positioned. Return
1075 the field number and corresponding alignment (if
1076 available/applicable). */
1079 verify_field (struct ui_out
*uiout
, int *fldno
, int *width
, int *align
)
1081 struct ui_out_level
*current
= current_level (uiout
);
1084 if (uiout
->table
.flag
)
1086 if (!uiout
->table
.body_flag
)
1087 internal_error (__FILE__
, __LINE__
,
1088 _("table_body missing; table fields must be \
1089 specified after table_body and inside a list."));
1090 /* NOTE: cagney/2001-12-08: There was a check here to ensure
1091 that this code was only executed when uiout->level was
1092 greater than zero. That no longer applies - this code is run
1093 before each table row tuple is started and at that point the
1097 current
->field_count
+= 1;
1099 if (uiout
->table
.body_flag
1100 && uiout
->table
.entry_level
== uiout
->level
1101 && get_next_header (uiout
, fldno
, width
, align
, &text
))
1103 if (*fldno
!= current
->field_count
)
1104 internal_error (__FILE__
, __LINE__
,
1105 _("ui-out internal error in handling headers."));
1110 *align
= ui_noalign
;
1111 *fldno
= current
->field_count
;
1116 /* Access to ui_out format private members. */
1119 ui_out_get_field_separator (struct ui_out
*uiout
)
1123 /* Access to ui-out members data. */
1126 ui_out_data (struct ui_out
*uiout
)
1131 /* Access table field parameters. */
1133 ui_out_query_field (struct ui_out
*uiout
, int colno
,
1134 int *width
, int *alignment
, char **col_name
)
1136 struct ui_out_hdr
*hdr
;
1138 if (!uiout
->table
.flag
)
1141 for (hdr
= uiout
->table
.header_first
; hdr
; hdr
= hdr
->next
)
1142 if (hdr
->colno
== colno
)
1144 *width
= hdr
->width
;
1145 *alignment
= hdr
->alignment
;
1146 *col_name
= hdr
->col_name
;
1153 /* Initalize private members at startup. */
1156 ui_out_new (struct ui_out_impl
*impl
, void *data
,
1159 struct ui_out
*uiout
= XMALLOC (struct ui_out
);
1163 uiout
->flags
= flags
;
1164 uiout
->table
.flag
= 0;
1165 uiout
->table
.body_flag
= 0;
1167 memset (uiout
->levels
, 0, sizeof (uiout
->levels
));
1168 uiout
->table
.header_first
= NULL
;
1169 uiout
->table
.header_last
= NULL
;
1170 uiout
->table
.header_next
= NULL
;
1174 /* Standard gdb initialization hook. */
1177 _initialize_ui_out (void)
1179 /* nothing needs to be done */