10f733518928255c341ecb1db4e9271c3cd4de1d
1 /* Output generating routines for GDB.
3 Copyright (C) 1999-2016 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h" /* For language.h */
28 /* table header structures */
34 enum ui_align alignment
;
37 struct ui_out_hdr
*next
;
42 /* Count each field; the first element is for non-list fields. */
44 /* The type of this level. */
45 enum ui_out_type type
;
48 /* Define uiout->level vector types and operations. */
49 typedef struct ui_out_level
*ui_out_level_p
;
50 DEF_VEC_P (ui_out_level_p
);
52 /* Tables are special. Maintain a separate structure that tracks
53 their state. At present an output can only contain a single table
54 but that restriction might eventually be lifted. */
58 /* If on, a table is being generated. */
61 /* If on, the body of a table is being generated. If off, the table
62 header is being generated. */
65 /* The level at which each entry of the table is to be found. A row
66 (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
67 above that of the table. */
70 /* Number of table columns (as specified in the table_begin call). */
73 /* String identifying the table (as specified in the table_begin
77 /* Points to the first table header (if any). */
78 struct ui_out_hdr
*header_first
;
80 /* Points to the last table header (if any). */
81 struct ui_out_hdr
*header_last
;
83 /* Points to header of NEXT column to format. */
84 struct ui_out_hdr
*header_next
;
89 /* The ui_out structure */
94 /* Specific implementation of ui-out. */
95 const struct ui_out_impl
*impl
;
101 /* Vector to store and track the ui-out levels. */
102 VEC (ui_out_level_p
) *levels
;
104 /* A table, if any. At present only a single table is supported. */
105 struct ui_out_table table
;
108 /* The current (inner most) level. */
109 static struct ui_out_level
*
110 current_level (struct ui_out
*uiout
)
112 return VEC_index (ui_out_level_p
, uiout
->levels
, uiout
->level
);
115 /* Create a new level, of TYPE. Return the new level's index. */
117 push_level (struct ui_out
*uiout
,
118 enum ui_out_type type
)
120 struct ui_out_level
*current
;
123 current
= XNEW (struct ui_out_level
);
124 current
->field_count
= 0;
125 current
->type
= type
;
126 VEC_safe_push (ui_out_level_p
, uiout
->levels
, current
);
130 /* Discard the current level, return the discarded level's index.
131 TYPE is the type of the level being discarded. */
133 pop_level (struct ui_out
*uiout
,
134 enum ui_out_type type
)
136 struct ui_out_level
*current
;
138 /* We had better not underflow the buffer. */
139 gdb_assert (uiout
->level
> 0);
140 gdb_assert (current_level (uiout
)->type
== type
);
141 current
= VEC_pop (ui_out_level_p
, uiout
->levels
);
144 return uiout
->level
+ 1;
147 /* These are the interfaces to implementation functions. */
149 static void uo_table_begin (struct ui_out
*uiout
, int nbrofcols
,
150 int nr_rows
, const char *tblid
);
151 static void uo_table_body (struct ui_out
*uiout
);
152 static void uo_table_end (struct ui_out
*uiout
);
153 static void uo_table_header (struct ui_out
*uiout
, int width
,
154 enum ui_align align
, const char *col_name
,
156 static void uo_begin (struct ui_out
*uiout
,
157 enum ui_out_type type
,
158 int level
, const char *id
);
159 static void uo_end (struct ui_out
*uiout
,
160 enum ui_out_type type
,
162 static void uo_field_int (struct ui_out
*uiout
, int fldno
, int width
,
163 enum ui_align align
, const char *fldname
, int value
);
164 static void uo_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
165 enum ui_align align
, const char *fldname
);
166 static void uo_field_fmt (struct ui_out
*uiout
, int fldno
, int width
,
167 enum ui_align align
, const char *fldname
,
168 const char *format
, va_list args
)
169 ATTRIBUTE_PRINTF (6, 0);
170 static void uo_spaces (struct ui_out
*uiout
, int numspaces
);
171 static void uo_text (struct ui_out
*uiout
, const char *string
);
172 static void uo_message (struct ui_out
*uiout
, int verbosity
,
173 const char *format
, va_list args
)
174 ATTRIBUTE_PRINTF (3, 0);
175 static void uo_wrap_hint (struct ui_out
*uiout
, char *identstring
);
176 static void uo_flush (struct ui_out
*uiout
);
177 static int uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
);
178 static void uo_data_destroy (struct ui_out
*uiout
);
180 /* Prototypes for local functions */
182 extern void _initialize_ui_out (void);
183 static void append_header_to_list (struct ui_out
*uiout
, int width
,
184 enum ui_align alignment
, const char *col_name
,
186 static int get_next_header (struct ui_out
*uiout
, int *colno
, int *width
,
187 enum ui_align
*alignment
, char **colhdr
);
188 static void clear_header_list (struct ui_out
*uiout
);
189 static void clear_table (struct ui_out
*uiout
);
190 static void verify_field (struct ui_out
*uiout
, int *fldno
, int *width
,
191 enum ui_align
*align
);
193 /* exported functions (ui_out API) */
195 /* Mark beginning of a table. */
198 ui_out_table_begin (struct ui_out
*uiout
, int nbrofcols
,
202 if (uiout
->table
.flag
)
203 internal_error (__FILE__
, __LINE__
,
204 _("tables cannot be nested; table_begin found before \
205 previous table_end."));
207 uiout
->table
.flag
= 1;
208 uiout
->table
.body_flag
= 0;
209 uiout
->table
.entry_level
= uiout
->level
+ 1;
210 uiout
->table
.columns
= nbrofcols
;
212 uiout
->table
.id
= xstrdup (tblid
);
214 uiout
->table
.id
= NULL
;
215 clear_header_list (uiout
);
217 uo_table_begin (uiout
, nbrofcols
, nr_rows
, uiout
->table
.id
);
221 ui_out_table_body (struct ui_out
*uiout
)
223 if (!uiout
->table
.flag
)
224 internal_error (__FILE__
, __LINE__
,
225 _("table_body outside a table is not valid; it must be \
226 after a table_begin and before a table_end."));
227 if (uiout
->table
.body_flag
)
228 internal_error (__FILE__
, __LINE__
,
229 _("extra table_body call not allowed; there must be \
230 only one table_body after a table_begin and before a table_end."));
231 if (uiout
->table
.header_next
->colno
!= uiout
->table
.columns
)
232 internal_error (__FILE__
, __LINE__
,
233 _("number of headers differ from number of table \
236 uiout
->table
.body_flag
= 1;
237 uiout
->table
.header_next
= uiout
->table
.header_first
;
239 uo_table_body (uiout
);
243 ui_out_table_end (struct ui_out
*uiout
)
245 if (!uiout
->table
.flag
)
246 internal_error (__FILE__
, __LINE__
,
247 _("misplaced table_end or missing table_begin."));
249 uiout
->table
.entry_level
= 0;
250 uiout
->table
.body_flag
= 0;
251 uiout
->table
.flag
= 0;
253 uo_table_end (uiout
);
258 ui_out_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
259 const char *col_name
,
262 if (!uiout
->table
.flag
|| uiout
->table
.body_flag
)
263 internal_error (__FILE__
, __LINE__
,
264 _("table header must be specified after table_begin \
265 and before table_body."));
267 append_header_to_list (uiout
, width
, alignment
, col_name
, colhdr
);
269 uo_table_header (uiout
, width
, alignment
, col_name
, colhdr
);
273 do_cleanup_table_end (void *data
)
275 struct ui_out
*ui_out
= (struct ui_out
*) data
;
277 ui_out_table_end (ui_out
);
281 make_cleanup_ui_out_table_begin_end (struct ui_out
*ui_out
, int nr_cols
,
282 int nr_rows
, const char *tblid
)
284 ui_out_table_begin (ui_out
, nr_cols
, nr_rows
, tblid
);
285 return make_cleanup (do_cleanup_table_end
, ui_out
);
289 ui_out_begin (struct ui_out
*uiout
,
290 enum ui_out_type type
,
295 if (uiout
->table
.flag
&& !uiout
->table
.body_flag
)
296 internal_error (__FILE__
, __LINE__
,
297 _("table header or table_body expected; lists must be \
298 specified after table_body."));
300 /* Be careful to verify the ``field'' before the new tuple/list is
301 pushed onto the stack. That way the containing list/table/row is
302 verified and not the newly created tuple/list. This verification
303 is needed (at least) for the case where a table row entry
304 contains either a tuple/list. For that case bookkeeping such as
305 updating the column count or advancing to the next heading still
306 needs to be performed. */
312 verify_field (uiout
, &fldno
, &width
, &align
);
315 new_level
= push_level (uiout
, type
);
317 /* If the push puts us at the same level as a table row entry, we've
318 got a new table row. Put the header pointer back to the start. */
319 if (uiout
->table
.body_flag
320 && uiout
->table
.entry_level
== new_level
)
321 uiout
->table
.header_next
= uiout
->table
.header_first
;
323 uo_begin (uiout
, type
, new_level
, id
);
327 ui_out_end (struct ui_out
*uiout
,
328 enum ui_out_type type
)
330 int old_level
= pop_level (uiout
, type
);
332 uo_end (uiout
, type
, old_level
);
335 struct ui_out_end_cleanup_data
337 struct ui_out
*uiout
;
338 enum ui_out_type type
;
342 do_cleanup_end (void *data
)
344 struct ui_out_end_cleanup_data
*end_cleanup_data
345 = (struct ui_out_end_cleanup_data
*) data
;
347 ui_out_end (end_cleanup_data
->uiout
, end_cleanup_data
->type
);
348 xfree (end_cleanup_data
);
351 static struct cleanup
*
352 make_cleanup_ui_out_end (struct ui_out
*uiout
,
353 enum ui_out_type type
)
355 struct ui_out_end_cleanup_data
*end_cleanup_data
;
357 end_cleanup_data
= XNEW (struct ui_out_end_cleanup_data
);
358 end_cleanup_data
->uiout
= uiout
;
359 end_cleanup_data
->type
= type
;
360 return make_cleanup (do_cleanup_end
, end_cleanup_data
);
364 make_cleanup_ui_out_tuple_begin_end (struct ui_out
*uiout
,
367 ui_out_begin (uiout
, ui_out_type_tuple
, id
);
368 return make_cleanup_ui_out_end (uiout
, ui_out_type_tuple
);
372 make_cleanup_ui_out_list_begin_end (struct ui_out
*uiout
,
375 ui_out_begin (uiout
, ui_out_type_list
, id
);
376 return make_cleanup_ui_out_end (uiout
, ui_out_type_list
);
380 ui_out_field_int (struct ui_out
*uiout
,
388 verify_field (uiout
, &fldno
, &width
, &align
);
390 uo_field_int (uiout
, fldno
, width
, align
, fldname
, value
);
394 ui_out_field_fmt_int (struct ui_out
*uiout
,
396 enum ui_align input_align
,
404 verify_field (uiout
, &fldno
, &width
, &align
);
406 uo_field_int (uiout
, fldno
, input_width
, input_align
, fldname
, value
);
409 /* Documented in ui-out.h. */
412 ui_out_field_core_addr (struct ui_out
*uiout
,
414 struct gdbarch
*gdbarch
,
417 ui_out_field_string (uiout
, fldname
,
418 print_core_address (gdbarch
, address
));
422 ui_out_field_stream (struct ui_out
*uiout
,
424 struct ui_file
*stream
)
426 std::string buffer
= ui_file_as_string (stream
);
428 if (!buffer
.empty ())
429 ui_out_field_string (uiout
, fldname
, buffer
.c_str ());
431 ui_out_field_skip (uiout
, fldname
);
432 ui_file_rewind (stream
);
435 /* Used to omit a field. */
438 ui_out_field_skip (struct ui_out
*uiout
,
445 verify_field (uiout
, &fldno
, &width
, &align
);
447 uo_field_skip (uiout
, fldno
, width
, align
, fldname
);
451 ui_out_field_string (struct ui_out
*uiout
,
459 verify_field (uiout
, &fldno
, &width
, &align
);
461 uo_field_string (uiout
, fldno
, width
, align
, fldname
, string
);
466 ui_out_field_fmt (struct ui_out
*uiout
,
468 const char *format
, ...)
475 /* Will not align, but has to call anyway. */
476 verify_field (uiout
, &fldno
, &width
, &align
);
478 va_start (args
, format
);
480 uo_field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
486 ui_out_spaces (struct ui_out
*uiout
, int numspaces
)
488 uo_spaces (uiout
, numspaces
);
492 ui_out_text (struct ui_out
*uiout
,
495 uo_text (uiout
, string
);
499 ui_out_message (struct ui_out
*uiout
, int verbosity
,
500 const char *format
,...)
504 va_start (args
, format
);
505 uo_message (uiout
, verbosity
, format
, args
);
510 ui_out_wrap_hint (struct ui_out
*uiout
, char *identstring
)
512 uo_wrap_hint (uiout
, identstring
);
516 ui_out_flush (struct ui_out
*uiout
)
522 ui_out_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
524 return uo_redirect (uiout
, outstream
);
527 /* Set the flags specified by the mask given. */
529 ui_out_set_flags (struct ui_out
*uiout
, int mask
)
531 int oldflags
= uiout
->flags
;
533 uiout
->flags
|= mask
;
537 /* Clear the flags specified by the mask given. */
539 ui_out_clear_flags (struct ui_out
*uiout
, int mask
)
541 int oldflags
= uiout
->flags
;
543 uiout
->flags
&= ~mask
;
547 /* Test the flags against the mask given. */
549 ui_out_test_flags (struct ui_out
*uiout
, int mask
)
551 return (uiout
->flags
& mask
);
554 /* Obtain the current verbosity level (as stablished by the
555 'set verbositylevel' command. */
558 ui_out_get_verblvl (struct ui_out
*uiout
)
560 /* FIXME: not implemented yet. */
565 ui_out_is_mi_like_p (struct ui_out
*uiout
)
567 return uiout
->impl
->is_mi_like_p
;
570 /* Interface to the implementation functions. */
573 uo_table_begin (struct ui_out
*uiout
, int nbrofcols
,
577 if (!uiout
->impl
->table_begin
)
579 uiout
->impl
->table_begin (uiout
, nbrofcols
, nr_rows
, tblid
);
583 uo_table_body (struct ui_out
*uiout
)
585 if (!uiout
->impl
->table_body
)
587 uiout
->impl
->table_body (uiout
);
591 uo_table_end (struct ui_out
*uiout
)
593 if (!uiout
->impl
->table_end
)
595 uiout
->impl
->table_end (uiout
);
599 uo_table_header (struct ui_out
*uiout
, int width
, enum ui_align align
,
600 const char *col_name
,
603 if (!uiout
->impl
->table_header
)
605 uiout
->impl
->table_header (uiout
, width
, align
, col_name
, colhdr
);
608 /* Clear the table associated with UIOUT. */
611 clear_table (struct ui_out
*uiout
)
613 xfree (uiout
->table
.id
);
614 uiout
->table
.id
= NULL
;
615 clear_header_list (uiout
);
619 uo_begin (struct ui_out
*uiout
,
620 enum ui_out_type type
,
624 if (uiout
->impl
->begin
== NULL
)
626 uiout
->impl
->begin (uiout
, type
, level
, id
);
630 uo_end (struct ui_out
*uiout
,
631 enum ui_out_type type
,
634 if (uiout
->impl
->end
== NULL
)
636 uiout
->impl
->end (uiout
, type
, level
);
640 uo_field_int (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
644 if (!uiout
->impl
->field_int
)
646 uiout
->impl
->field_int (uiout
, fldno
, width
, align
, fldname
, value
);
650 uo_field_skip (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
653 if (!uiout
->impl
->field_skip
)
655 uiout
->impl
->field_skip (uiout
, fldno
, width
, align
, fldname
);
659 uo_field_string (struct ui_out
*uiout
, int fldno
, int width
,
664 if (!uiout
->impl
->field_string
)
666 uiout
->impl
->field_string (uiout
, fldno
, width
, align
, fldname
, string
);
670 uo_field_fmt (struct ui_out
*uiout
, int fldno
, int width
, enum ui_align align
,
675 if (!uiout
->impl
->field_fmt
)
677 uiout
->impl
->field_fmt (uiout
, fldno
, width
, align
, fldname
, format
, args
);
681 uo_spaces (struct ui_out
*uiout
, int numspaces
)
683 if (!uiout
->impl
->spaces
)
685 uiout
->impl
->spaces (uiout
, numspaces
);
689 uo_text (struct ui_out
*uiout
,
692 if (!uiout
->impl
->text
)
694 uiout
->impl
->text (uiout
, string
);
698 uo_message (struct ui_out
*uiout
, int verbosity
,
702 if (!uiout
->impl
->message
)
704 uiout
->impl
->message (uiout
, verbosity
, format
, args
);
708 uo_wrap_hint (struct ui_out
*uiout
, char *identstring
)
710 if (!uiout
->impl
->wrap_hint
)
712 uiout
->impl
->wrap_hint (uiout
, identstring
);
716 uo_flush (struct ui_out
*uiout
)
718 if (!uiout
->impl
->flush
)
720 uiout
->impl
->flush (uiout
);
724 uo_redirect (struct ui_out
*uiout
, struct ui_file
*outstream
)
726 if (!uiout
->impl
->redirect
)
728 uiout
->impl
->redirect (uiout
, outstream
);
733 uo_data_destroy (struct ui_out
*uiout
)
735 if (!uiout
->impl
->data_destroy
)
738 uiout
->impl
->data_destroy (uiout
);
741 /* local functions */
743 /* List of column headers manipulation routines. */
746 clear_header_list (struct ui_out
*uiout
)
748 while (uiout
->table
.header_first
!= NULL
)
750 uiout
->table
.header_next
= uiout
->table
.header_first
;
751 uiout
->table
.header_first
= uiout
->table
.header_first
->next
;
752 xfree (uiout
->table
.header_next
->colhdr
);
753 xfree (uiout
->table
.header_next
->col_name
);
754 xfree (uiout
->table
.header_next
);
756 gdb_assert (uiout
->table
.header_first
== NULL
);
757 uiout
->table
.header_last
= NULL
;
758 uiout
->table
.header_next
= NULL
;
762 append_header_to_list (struct ui_out
*uiout
,
764 enum ui_align alignment
,
765 const char *col_name
,
768 struct ui_out_hdr
*temphdr
;
770 temphdr
= XNEW (struct ui_out_hdr
);
771 temphdr
->width
= width
;
772 temphdr
->alignment
= alignment
;
773 /* We have to copy the column title as the original may be an
776 temphdr
->colhdr
= xstrdup (colhdr
);
778 temphdr
->colhdr
= NULL
;
780 if (col_name
!= NULL
)
781 temphdr
->col_name
= xstrdup (col_name
);
782 else if (colhdr
!= NULL
)
783 temphdr
->col_name
= xstrdup (colhdr
);
785 temphdr
->col_name
= NULL
;
787 temphdr
->next
= NULL
;
788 if (uiout
->table
.header_first
== NULL
)
791 uiout
->table
.header_first
= temphdr
;
792 uiout
->table
.header_last
= temphdr
;
796 temphdr
->colno
= uiout
->table
.header_last
->colno
+ 1;
797 uiout
->table
.header_last
->next
= temphdr
;
798 uiout
->table
.header_last
= temphdr
;
800 uiout
->table
.header_next
= uiout
->table
.header_last
;
803 /* Extract the format information for the NEXT header and advance
804 the header pointer. Return 0 if there was no next header. */
807 get_next_header (struct ui_out
*uiout
,
810 enum ui_align
*alignment
,
813 /* There may be no headers at all or we may have used all columns. */
814 if (uiout
->table
.header_next
== NULL
)
816 *colno
= uiout
->table
.header_next
->colno
;
817 *width
= uiout
->table
.header_next
->width
;
818 *alignment
= uiout
->table
.header_next
->alignment
;
819 *colhdr
= uiout
->table
.header_next
->colhdr
;
820 /* Advance the header pointer to the next entry. */
821 uiout
->table
.header_next
= uiout
->table
.header_next
->next
;
826 /* Verify that the field/tuple/list is correctly positioned. Return
827 the field number and corresponding alignment (if
828 available/applicable). */
831 verify_field (struct ui_out
*uiout
, int *fldno
, int *width
,
832 enum ui_align
*align
)
834 struct ui_out_level
*current
= current_level (uiout
);
837 if (uiout
->table
.flag
)
839 if (!uiout
->table
.body_flag
)
840 internal_error (__FILE__
, __LINE__
,
841 _("table_body missing; table fields must be \
842 specified after table_body and inside a list."));
843 /* NOTE: cagney/2001-12-08: There was a check here to ensure
844 that this code was only executed when uiout->level was
845 greater than zero. That no longer applies - this code is run
846 before each table row tuple is started and at that point the
850 current
->field_count
+= 1;
852 if (uiout
->table
.body_flag
853 && uiout
->table
.entry_level
== uiout
->level
854 && get_next_header (uiout
, fldno
, width
, align
, &text
))
856 if (*fldno
!= current
->field_count
)
857 internal_error (__FILE__
, __LINE__
,
858 _("ui-out internal error in handling headers."));
864 *fldno
= current
->field_count
;
869 /* Access to ui-out members data. */
872 ui_out_data (struct ui_out
*uiout
)
877 /* Access table field parameters. */
879 ui_out_query_field (struct ui_out
*uiout
, int colno
,
880 int *width
, int *alignment
, char **col_name
)
882 struct ui_out_hdr
*hdr
;
884 if (!uiout
->table
.flag
)
887 for (hdr
= uiout
->table
.header_first
; hdr
; hdr
= hdr
->next
)
888 if (hdr
->colno
== colno
)
891 *alignment
= hdr
->alignment
;
892 *col_name
= hdr
->col_name
;
899 /* Initialize private members at startup. */
902 ui_out_new (const struct ui_out_impl
*impl
, void *data
,
905 struct ui_out
*uiout
= XNEW (struct ui_out
);
906 struct ui_out_level
*current
= XNEW (struct ui_out_level
);
910 uiout
->flags
= flags
;
911 uiout
->table
.flag
= 0;
912 uiout
->table
.body_flag
= 0;
914 uiout
->levels
= NULL
;
916 /* Create uiout->level 0, the default level. */
917 current
->type
= ui_out_type_tuple
;
918 current
->field_count
= 0;
919 VEC_safe_push (ui_out_level_p
, uiout
->levels
, current
);
921 uiout
->table
.id
= NULL
;
922 uiout
->table
.header_first
= NULL
;
923 uiout
->table
.header_last
= NULL
;
924 uiout
->table
.header_next
= NULL
;
928 /* Free UIOUT and the memory areas it references. */
931 ui_out_destroy (struct ui_out
*uiout
)
934 struct ui_out_level
*current
;
936 /* Make sure that all levels are freed in the case where levels have
937 been pushed, but not popped before the ui_out object is
940 VEC_iterate (ui_out_level_p
, uiout
->levels
, i
, current
);
944 VEC_free (ui_out_level_p
, uiout
->levels
);
945 uo_data_destroy (uiout
);
950 /* Standard gdb initialization hook. */
953 _initialize_ui_out (void)
955 /* nothing needs to be done */
This page took 0.059664 seconds and 4 git commands to generate.