btrace: remove leftover comment
[deliverable/binutils-gdb.git] / gdb / ui-out.c
1 /* Output generating routines for GDB.
2
3 Copyright (C) 1999-2016 Free Software Foundation, Inc.
4
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
12 the Free Software Foundation; either version 3 of the License, or
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
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23 #include "defs.h"
24 #include "expression.h" /* For language.h */
25 #include "language.h"
26 #include "ui-out.h"
27
28 /* table header structures */
29
30 struct ui_out_hdr
31 {
32 int colno;
33 int width;
34 enum ui_align alignment;
35 char *col_name;
36 char *colhdr;
37 struct ui_out_hdr *next;
38 };
39
40 struct ui_out_level
41 {
42 /* Count each field; the first element is for non-list fields. */
43 int field_count;
44 /* The type of this level. */
45 enum ui_out_type type;
46 };
47
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);
51
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. */
55
56 struct ui_out_table
57 {
58 /* If on, a table is being generated. */
59 int flag;
60
61 /* If on, the body of a table is being generated. If off, the table
62 header is being generated. */
63 int body_flag;
64
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. */
68 int entry_level;
69
70 /* Number of table columns (as specified in the table_begin call). */
71 int columns;
72
73 /* String identifying the table (as specified in the table_begin
74 call). */
75 char *id;
76
77 /* Points to the first table header (if any). */
78 struct ui_out_hdr *header_first;
79
80 /* Points to the last table header (if any). */
81 struct ui_out_hdr *header_last;
82
83 /* Points to header of NEXT column to format. */
84 struct ui_out_hdr *header_next;
85
86 };
87
88
89 /* The ui_out structure */
90 /* Any change here requires a corresponding one in the initialization
91 of the default uiout, which is statically initialized. */
92
93 struct ui_out
94 {
95 int flags;
96 /* Specific implementation of ui-out. */
97 const struct ui_out_impl *impl;
98 void *data;
99
100 /* Current level. */
101 int level;
102
103 /* Vector to store and track the ui-out levels. */
104 VEC (ui_out_level_p) *levels;
105
106 /* A table, if any. At present only a single table is supported. */
107 struct ui_out_table table;
108 };
109
110 /* The current (inner most) level. */
111 static struct ui_out_level *
112 current_level (struct ui_out *uiout)
113 {
114 return VEC_index (ui_out_level_p, uiout->levels, uiout->level);
115 }
116
117 /* Create a new level, of TYPE. Return the new level's index. */
118 static int
119 push_level (struct ui_out *uiout,
120 enum ui_out_type type)
121 {
122 struct ui_out_level *current;
123
124 uiout->level++;
125 current = XNEW (struct ui_out_level);
126 current->field_count = 0;
127 current->type = type;
128 VEC_safe_push (ui_out_level_p, uiout->levels, current);
129 return uiout->level;
130 }
131
132 /* Discard the current level, return the discarded level's index.
133 TYPE is the type of the level being discarded. */
134 static int
135 pop_level (struct ui_out *uiout,
136 enum ui_out_type type)
137 {
138 struct ui_out_level *current;
139
140 /* We had better not underflow the buffer. */
141 gdb_assert (uiout->level > 0);
142 gdb_assert (current_level (uiout)->type == type);
143 current = VEC_pop (ui_out_level_p, uiout->levels);
144 xfree (current);
145 uiout->level--;
146 return uiout->level + 1;
147 }
148
149 /* These are the interfaces to implementation functions. */
150
151 static void uo_table_begin (struct ui_out *uiout, int nbrofcols,
152 int nr_rows, const char *tblid);
153 static void uo_table_body (struct ui_out *uiout);
154 static void uo_table_end (struct ui_out *uiout);
155 static void uo_table_header (struct ui_out *uiout, int width,
156 enum ui_align align, const char *col_name,
157 const char *colhdr);
158 static void uo_begin (struct ui_out *uiout,
159 enum ui_out_type type,
160 int level, const char *id);
161 static void uo_end (struct ui_out *uiout,
162 enum ui_out_type type,
163 int level);
164 static void uo_field_int (struct ui_out *uiout, int fldno, int width,
165 enum ui_align align, const char *fldname, int value);
166 static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
167 enum ui_align align, const char *fldname);
168 static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
169 enum ui_align align, const char *fldname,
170 const char *format, va_list args)
171 ATTRIBUTE_PRINTF (6, 0);
172 static void uo_spaces (struct ui_out *uiout, int numspaces);
173 static void uo_text (struct ui_out *uiout, const char *string);
174 static void uo_message (struct ui_out *uiout, int verbosity,
175 const char *format, va_list args)
176 ATTRIBUTE_PRINTF (3, 0);
177 static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
178 static void uo_flush (struct ui_out *uiout);
179 static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
180 static void uo_data_destroy (struct ui_out *uiout);
181
182 /* Prototypes for local functions */
183
184 extern void _initialize_ui_out (void);
185 static void append_header_to_list (struct ui_out *uiout, int width,
186 enum ui_align alignment, const char *col_name,
187 const char *colhdr);
188 static int get_next_header (struct ui_out *uiout, int *colno, int *width,
189 enum ui_align *alignment, char **colhdr);
190 static void clear_header_list (struct ui_out *uiout);
191 static void clear_table (struct ui_out *uiout);
192 static void verify_field (struct ui_out *uiout, int *fldno, int *width,
193 enum ui_align *align);
194
195 /* exported functions (ui_out API) */
196
197 /* Mark beginning of a table. */
198
199 static void
200 ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
201 int nr_rows,
202 const char *tblid)
203 {
204 if (uiout->table.flag)
205 internal_error (__FILE__, __LINE__,
206 _("tables cannot be nested; table_begin found before \
207 previous table_end."));
208
209 uiout->table.flag = 1;
210 uiout->table.body_flag = 0;
211 uiout->table.entry_level = uiout->level + 1;
212 uiout->table.columns = nbrofcols;
213 if (tblid != NULL)
214 uiout->table.id = xstrdup (tblid);
215 else
216 uiout->table.id = NULL;
217 clear_header_list (uiout);
218
219 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
220 }
221
222 void
223 ui_out_table_body (struct ui_out *uiout)
224 {
225 if (!uiout->table.flag)
226 internal_error (__FILE__, __LINE__,
227 _("table_body outside a table is not valid; it must be \
228 after a table_begin and before a table_end."));
229 if (uiout->table.body_flag)
230 internal_error (__FILE__, __LINE__,
231 _("extra table_body call not allowed; there must be \
232 only one table_body after a table_begin and before a table_end."));
233 if (uiout->table.header_next->colno != uiout->table.columns)
234 internal_error (__FILE__, __LINE__,
235 _("number of headers differ from number of table \
236 columns."));
237
238 uiout->table.body_flag = 1;
239 uiout->table.header_next = uiout->table.header_first;
240
241 uo_table_body (uiout);
242 }
243
244 static void
245 ui_out_table_end (struct ui_out *uiout)
246 {
247 if (!uiout->table.flag)
248 internal_error (__FILE__, __LINE__,
249 _("misplaced table_end or missing table_begin."));
250
251 uiout->table.entry_level = 0;
252 uiout->table.body_flag = 0;
253 uiout->table.flag = 0;
254
255 uo_table_end (uiout);
256 clear_table (uiout);
257 }
258
259 void
260 ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
261 const char *col_name,
262 const char *colhdr)
263 {
264 if (!uiout->table.flag || uiout->table.body_flag)
265 internal_error (__FILE__, __LINE__,
266 _("table header must be specified after table_begin \
267 and before table_body."));
268
269 append_header_to_list (uiout, width, alignment, col_name, colhdr);
270
271 uo_table_header (uiout, width, alignment, col_name, colhdr);
272 }
273
274 static void
275 do_cleanup_table_end (void *data)
276 {
277 struct ui_out *ui_out = (struct ui_out *) data;
278
279 ui_out_table_end (ui_out);
280 }
281
282 struct cleanup *
283 make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
284 int nr_rows, const char *tblid)
285 {
286 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
287 return make_cleanup (do_cleanup_table_end, ui_out);
288 }
289
290 void
291 ui_out_begin (struct ui_out *uiout,
292 enum ui_out_type type,
293 const char *id)
294 {
295 int new_level;
296
297 if (uiout->table.flag && !uiout->table.body_flag)
298 internal_error (__FILE__, __LINE__,
299 _("table header or table_body expected; lists must be \
300 specified after table_body."));
301
302 /* Be careful to verify the ``field'' before the new tuple/list is
303 pushed onto the stack. That way the containing list/table/row is
304 verified and not the newly created tuple/list. This verification
305 is needed (at least) for the case where a table row entry
306 contains either a tuple/list. For that case bookkeeping such as
307 updating the column count or advancing to the next heading still
308 needs to be performed. */
309 {
310 int fldno;
311 int width;
312 enum ui_align align;
313
314 verify_field (uiout, &fldno, &width, &align);
315 }
316
317 new_level = push_level (uiout, type);
318
319 /* If the push puts us at the same level as a table row entry, we've
320 got a new table row. Put the header pointer back to the start. */
321 if (uiout->table.body_flag
322 && uiout->table.entry_level == new_level)
323 uiout->table.header_next = uiout->table.header_first;
324
325 uo_begin (uiout, type, new_level, id);
326 }
327
328 void
329 ui_out_end (struct ui_out *uiout,
330 enum ui_out_type type)
331 {
332 int old_level = pop_level (uiout, type);
333
334 uo_end (uiout, type, old_level);
335 }
336
337 struct ui_out_end_cleanup_data
338 {
339 struct ui_out *uiout;
340 enum ui_out_type type;
341 };
342
343 static void
344 do_cleanup_end (void *data)
345 {
346 struct ui_out_end_cleanup_data *end_cleanup_data
347 = (struct ui_out_end_cleanup_data *) data;
348
349 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
350 xfree (end_cleanup_data);
351 }
352
353 static struct cleanup *
354 make_cleanup_ui_out_end (struct ui_out *uiout,
355 enum ui_out_type type)
356 {
357 struct ui_out_end_cleanup_data *end_cleanup_data;
358
359 end_cleanup_data = XNEW (struct ui_out_end_cleanup_data);
360 end_cleanup_data->uiout = uiout;
361 end_cleanup_data->type = type;
362 return make_cleanup (do_cleanup_end, end_cleanup_data);
363 }
364
365 struct cleanup *
366 make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
367 const char *id)
368 {
369 ui_out_begin (uiout, ui_out_type_tuple, id);
370 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
371 }
372
373 struct cleanup *
374 make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
375 const char *id)
376 {
377 ui_out_begin (uiout, ui_out_type_list, id);
378 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
379 }
380
381 void
382 ui_out_field_int (struct ui_out *uiout,
383 const char *fldname,
384 int value)
385 {
386 int fldno;
387 int width;
388 enum ui_align align;
389
390 verify_field (uiout, &fldno, &width, &align);
391
392 uo_field_int (uiout, fldno, width, align, fldname, value);
393 }
394
395 void
396 ui_out_field_fmt_int (struct ui_out *uiout,
397 int input_width,
398 enum ui_align input_align,
399 const char *fldname,
400 int value)
401 {
402 int fldno;
403 int width;
404 enum ui_align align;
405
406 verify_field (uiout, &fldno, &width, &align);
407
408 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
409 }
410
411 /* Documented in ui-out.h. */
412
413 void
414 ui_out_field_core_addr (struct ui_out *uiout,
415 const char *fldname,
416 struct gdbarch *gdbarch,
417 CORE_ADDR address)
418 {
419 ui_out_field_string (uiout, fldname,
420 print_core_address (gdbarch, address));
421 }
422
423 void
424 ui_out_field_stream (struct ui_out *uiout,
425 const char *fldname,
426 struct ui_file *stream)
427 {
428 long length;
429 char *buffer = ui_file_xstrdup (stream, &length);
430 struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
431
432 if (length > 0)
433 ui_out_field_string (uiout, fldname, buffer);
434 else
435 ui_out_field_skip (uiout, fldname);
436 ui_file_rewind (stream);
437 do_cleanups (old_cleanup);
438 }
439
440 /* Used to omit a field. */
441
442 void
443 ui_out_field_skip (struct ui_out *uiout,
444 const char *fldname)
445 {
446 int fldno;
447 int width;
448 enum ui_align align;
449
450 verify_field (uiout, &fldno, &width, &align);
451
452 uo_field_skip (uiout, fldno, width, align, fldname);
453 }
454
455 void
456 ui_out_field_string (struct ui_out *uiout,
457 const char *fldname,
458 const char *string)
459 {
460 int fldno;
461 int width;
462 enum ui_align align;
463
464 verify_field (uiout, &fldno, &width, &align);
465
466 uo_field_string (uiout, fldno, width, align, fldname, string);
467 }
468
469 /* VARARGS */
470 void
471 ui_out_field_fmt (struct ui_out *uiout,
472 const char *fldname,
473 const char *format, ...)
474 {
475 va_list args;
476 int fldno;
477 int width;
478 enum ui_align align;
479
480 /* Will not align, but has to call anyway. */
481 verify_field (uiout, &fldno, &width, &align);
482
483 va_start (args, format);
484
485 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
486
487 va_end (args);
488 }
489
490 void
491 ui_out_spaces (struct ui_out *uiout, int numspaces)
492 {
493 uo_spaces (uiout, numspaces);
494 }
495
496 void
497 ui_out_text (struct ui_out *uiout,
498 const char *string)
499 {
500 uo_text (uiout, string);
501 }
502
503 void
504 ui_out_message (struct ui_out *uiout, int verbosity,
505 const char *format,...)
506 {
507 va_list args;
508
509 va_start (args, format);
510 uo_message (uiout, verbosity, format, args);
511 va_end (args);
512 }
513
514 void
515 ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
516 {
517 uo_wrap_hint (uiout, identstring);
518 }
519
520 void
521 ui_out_flush (struct ui_out *uiout)
522 {
523 uo_flush (uiout);
524 }
525
526 int
527 ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
528 {
529 return uo_redirect (uiout, outstream);
530 }
531
532 /* Set the flags specified by the mask given. */
533 int
534 ui_out_set_flags (struct ui_out *uiout, int mask)
535 {
536 int oldflags = uiout->flags;
537
538 uiout->flags |= mask;
539 return oldflags;
540 }
541
542 /* Clear the flags specified by the mask given. */
543 int
544 ui_out_clear_flags (struct ui_out *uiout, int mask)
545 {
546 int oldflags = uiout->flags;
547
548 uiout->flags &= ~mask;
549 return oldflags;
550 }
551
552 /* Test the flags against the mask given. */
553 int
554 ui_out_test_flags (struct ui_out *uiout, int mask)
555 {
556 return (uiout->flags & mask);
557 }
558
559 /* Obtain the current verbosity level (as stablished by the
560 'set verbositylevel' command. */
561
562 int
563 ui_out_get_verblvl (struct ui_out *uiout)
564 {
565 /* FIXME: not implemented yet. */
566 return 0;
567 }
568
569 int
570 ui_out_is_mi_like_p (struct ui_out *uiout)
571 {
572 return uiout->impl->is_mi_like_p;
573 }
574
575 /* Interface to the implementation functions. */
576
577 void
578 uo_table_begin (struct ui_out *uiout, int nbrofcols,
579 int nr_rows,
580 const char *tblid)
581 {
582 if (!uiout->impl->table_begin)
583 return;
584 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
585 }
586
587 void
588 uo_table_body (struct ui_out *uiout)
589 {
590 if (!uiout->impl->table_body)
591 return;
592 uiout->impl->table_body (uiout);
593 }
594
595 void
596 uo_table_end (struct ui_out *uiout)
597 {
598 if (!uiout->impl->table_end)
599 return;
600 uiout->impl->table_end (uiout);
601 }
602
603 void
604 uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
605 const char *col_name,
606 const char *colhdr)
607 {
608 if (!uiout->impl->table_header)
609 return;
610 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
611 }
612
613 /* Clear the table associated with UIOUT. */
614
615 static void
616 clear_table (struct ui_out *uiout)
617 {
618 xfree (uiout->table.id);
619 uiout->table.id = NULL;
620 clear_header_list (uiout);
621 }
622
623 void
624 uo_begin (struct ui_out *uiout,
625 enum ui_out_type type,
626 int level,
627 const char *id)
628 {
629 if (uiout->impl->begin == NULL)
630 return;
631 uiout->impl->begin (uiout, type, level, id);
632 }
633
634 void
635 uo_end (struct ui_out *uiout,
636 enum ui_out_type type,
637 int level)
638 {
639 if (uiout->impl->end == NULL)
640 return;
641 uiout->impl->end (uiout, type, level);
642 }
643
644 void
645 uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
646 const char *fldname,
647 int value)
648 {
649 if (!uiout->impl->field_int)
650 return;
651 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
652 }
653
654 void
655 uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
656 const char *fldname)
657 {
658 if (!uiout->impl->field_skip)
659 return;
660 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
661 }
662
663 void
664 uo_field_string (struct ui_out *uiout, int fldno, int width,
665 enum ui_align align,
666 const char *fldname,
667 const char *string)
668 {
669 if (!uiout->impl->field_string)
670 return;
671 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
672 }
673
674 void
675 uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
676 const char *fldname,
677 const char *format,
678 va_list args)
679 {
680 if (!uiout->impl->field_fmt)
681 return;
682 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
683 }
684
685 void
686 uo_spaces (struct ui_out *uiout, int numspaces)
687 {
688 if (!uiout->impl->spaces)
689 return;
690 uiout->impl->spaces (uiout, numspaces);
691 }
692
693 void
694 uo_text (struct ui_out *uiout,
695 const char *string)
696 {
697 if (!uiout->impl->text)
698 return;
699 uiout->impl->text (uiout, string);
700 }
701
702 void
703 uo_message (struct ui_out *uiout, int verbosity,
704 const char *format,
705 va_list args)
706 {
707 if (!uiout->impl->message)
708 return;
709 uiout->impl->message (uiout, verbosity, format, args);
710 }
711
712 void
713 uo_wrap_hint (struct ui_out *uiout, char *identstring)
714 {
715 if (!uiout->impl->wrap_hint)
716 return;
717 uiout->impl->wrap_hint (uiout, identstring);
718 }
719
720 void
721 uo_flush (struct ui_out *uiout)
722 {
723 if (!uiout->impl->flush)
724 return;
725 uiout->impl->flush (uiout);
726 }
727
728 int
729 uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
730 {
731 if (!uiout->impl->redirect)
732 return -1;
733 uiout->impl->redirect (uiout, outstream);
734 return 0;
735 }
736
737 void
738 uo_data_destroy (struct ui_out *uiout)
739 {
740 if (!uiout->impl->data_destroy)
741 return;
742
743 uiout->impl->data_destroy (uiout);
744 }
745
746 /* local functions */
747
748 /* List of column headers manipulation routines. */
749
750 static void
751 clear_header_list (struct ui_out *uiout)
752 {
753 while (uiout->table.header_first != NULL)
754 {
755 uiout->table.header_next = uiout->table.header_first;
756 uiout->table.header_first = uiout->table.header_first->next;
757 xfree (uiout->table.header_next->colhdr);
758 xfree (uiout->table.header_next->col_name);
759 xfree (uiout->table.header_next);
760 }
761 gdb_assert (uiout->table.header_first == NULL);
762 uiout->table.header_last = NULL;
763 uiout->table.header_next = NULL;
764 }
765
766 static void
767 append_header_to_list (struct ui_out *uiout,
768 int width,
769 enum ui_align alignment,
770 const char *col_name,
771 const char *colhdr)
772 {
773 struct ui_out_hdr *temphdr;
774
775 temphdr = XNEW (struct ui_out_hdr);
776 temphdr->width = width;
777 temphdr->alignment = alignment;
778 /* We have to copy the column title as the original may be an
779 automatic. */
780 if (colhdr != NULL)
781 temphdr->colhdr = xstrdup (colhdr);
782 else
783 temphdr->colhdr = NULL;
784
785 if (col_name != NULL)
786 temphdr->col_name = xstrdup (col_name);
787 else if (colhdr != NULL)
788 temphdr->col_name = xstrdup (colhdr);
789 else
790 temphdr->col_name = NULL;
791
792 temphdr->next = NULL;
793 if (uiout->table.header_first == NULL)
794 {
795 temphdr->colno = 1;
796 uiout->table.header_first = temphdr;
797 uiout->table.header_last = temphdr;
798 }
799 else
800 {
801 temphdr->colno = uiout->table.header_last->colno + 1;
802 uiout->table.header_last->next = temphdr;
803 uiout->table.header_last = temphdr;
804 }
805 uiout->table.header_next = uiout->table.header_last;
806 }
807
808 /* Extract the format information for the NEXT header and advance
809 the header pointer. Return 0 if there was no next header. */
810
811 static int
812 get_next_header (struct ui_out *uiout,
813 int *colno,
814 int *width,
815 enum ui_align *alignment,
816 char **colhdr)
817 {
818 /* There may be no headers at all or we may have used all columns. */
819 if (uiout->table.header_next == NULL)
820 return 0;
821 *colno = uiout->table.header_next->colno;
822 *width = uiout->table.header_next->width;
823 *alignment = uiout->table.header_next->alignment;
824 *colhdr = uiout->table.header_next->colhdr;
825 /* Advance the header pointer to the next entry. */
826 uiout->table.header_next = uiout->table.header_next->next;
827 return 1;
828 }
829
830
831 /* Verify that the field/tuple/list is correctly positioned. Return
832 the field number and corresponding alignment (if
833 available/applicable). */
834
835 static void
836 verify_field (struct ui_out *uiout, int *fldno, int *width,
837 enum ui_align *align)
838 {
839 struct ui_out_level *current = current_level (uiout);
840 char *text;
841
842 if (uiout->table.flag)
843 {
844 if (!uiout->table.body_flag)
845 internal_error (__FILE__, __LINE__,
846 _("table_body missing; table fields must be \
847 specified after table_body and inside a list."));
848 /* NOTE: cagney/2001-12-08: There was a check here to ensure
849 that this code was only executed when uiout->level was
850 greater than zero. That no longer applies - this code is run
851 before each table row tuple is started and at that point the
852 level is zero. */
853 }
854
855 current->field_count += 1;
856
857 if (uiout->table.body_flag
858 && uiout->table.entry_level == uiout->level
859 && get_next_header (uiout, fldno, width, align, &text))
860 {
861 if (*fldno != current->field_count)
862 internal_error (__FILE__, __LINE__,
863 _("ui-out internal error in handling headers."));
864 }
865 else
866 {
867 *width = 0;
868 *align = ui_noalign;
869 *fldno = current->field_count;
870 }
871 }
872
873
874 /* Access to ui-out members data. */
875
876 void *
877 ui_out_data (struct ui_out *uiout)
878 {
879 return uiout->data;
880 }
881
882 /* Access table field parameters. */
883 int
884 ui_out_query_field (struct ui_out *uiout, int colno,
885 int *width, int *alignment, char **col_name)
886 {
887 struct ui_out_hdr *hdr;
888
889 if (!uiout->table.flag)
890 return 0;
891
892 for (hdr = uiout->table.header_first; hdr; hdr = hdr->next)
893 if (hdr->colno == colno)
894 {
895 *width = hdr->width;
896 *alignment = hdr->alignment;
897 *col_name = hdr->col_name;
898 return 1;
899 }
900
901 return 0;
902 }
903
904 /* Initalize private members at startup. */
905
906 struct ui_out *
907 ui_out_new (const struct ui_out_impl *impl, void *data,
908 int flags)
909 {
910 struct ui_out *uiout = XNEW (struct ui_out);
911 struct ui_out_level *current = XNEW (struct ui_out_level);
912
913 uiout->data = data;
914 uiout->impl = impl;
915 uiout->flags = flags;
916 uiout->table.flag = 0;
917 uiout->table.body_flag = 0;
918 uiout->level = 0;
919 uiout->levels = NULL;
920
921 /* Create uiout->level 0, the default level. */
922 current->type = ui_out_type_tuple;
923 current->field_count = 0;
924 VEC_safe_push (ui_out_level_p, uiout->levels, current);
925
926 uiout->table.id = NULL;
927 uiout->table.header_first = NULL;
928 uiout->table.header_last = NULL;
929 uiout->table.header_next = NULL;
930 return uiout;
931 }
932
933 /* Free UIOUT and the memory areas it references. */
934
935 void
936 ui_out_destroy (struct ui_out *uiout)
937 {
938 int i;
939 struct ui_out_level *current;
940
941 /* Make sure that all levels are freed in the case where levels have
942 been pushed, but not popped before the ui_out object is
943 destroyed. */
944 for (i = 0;
945 VEC_iterate (ui_out_level_p, uiout->levels, i, current);
946 ++i)
947 xfree (current);
948
949 VEC_free (ui_out_level_p, uiout->levels);
950 uo_data_destroy (uiout);
951 clear_table (uiout);
952 xfree (uiout);
953 }
954
955 /* Cleanup that restores a previous current uiout. */
956
957 static void
958 restore_current_uiout_cleanup (void *arg)
959 {
960 struct ui_out *saved_uiout = (struct ui_out *) arg;
961
962 current_uiout = saved_uiout;
963 }
964
965 /* See ui-out.h. */
966
967 struct cleanup *
968 make_cleanup_restore_current_uiout (void)
969 {
970 return make_cleanup (restore_current_uiout_cleanup, current_uiout);
971 }
972
973 /* Standard gdb initialization hook. */
974
975 void
976 _initialize_ui_out (void)
977 {
978 /* nothing needs to be done */
979 }
This page took 0.058475 seconds and 4 git commands to generate.