10f733518928255c341ecb1db4e9271c3cd4de1d
[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
91 struct ui_out
92 {
93 int flags;
94 /* Specific implementation of ui-out. */
95 const struct ui_out_impl *impl;
96 void *data;
97
98 /* Current level. */
99 int level;
100
101 /* Vector to store and track the ui-out levels. */
102 VEC (ui_out_level_p) *levels;
103
104 /* A table, if any. At present only a single table is supported. */
105 struct ui_out_table table;
106 };
107
108 /* The current (inner most) level. */
109 static struct ui_out_level *
110 current_level (struct ui_out *uiout)
111 {
112 return VEC_index (ui_out_level_p, uiout->levels, uiout->level);
113 }
114
115 /* Create a new level, of TYPE. Return the new level's index. */
116 static int
117 push_level (struct ui_out *uiout,
118 enum ui_out_type type)
119 {
120 struct ui_out_level *current;
121
122 uiout->level++;
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);
127 return uiout->level;
128 }
129
130 /* Discard the current level, return the discarded level's index.
131 TYPE is the type of the level being discarded. */
132 static int
133 pop_level (struct ui_out *uiout,
134 enum ui_out_type type)
135 {
136 struct ui_out_level *current;
137
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);
142 xfree (current);
143 uiout->level--;
144 return uiout->level + 1;
145 }
146
147 /* These are the interfaces to implementation functions. */
148
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,
155 const char *colhdr);
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,
161 int level);
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);
179
180 /* Prototypes for local functions */
181
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,
185 const char *colhdr);
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);
192
193 /* exported functions (ui_out API) */
194
195 /* Mark beginning of a table. */
196
197 static void
198 ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
199 int nr_rows,
200 const char *tblid)
201 {
202 if (uiout->table.flag)
203 internal_error (__FILE__, __LINE__,
204 _("tables cannot be nested; table_begin found before \
205 previous table_end."));
206
207 uiout->table.flag = 1;
208 uiout->table.body_flag = 0;
209 uiout->table.entry_level = uiout->level + 1;
210 uiout->table.columns = nbrofcols;
211 if (tblid != NULL)
212 uiout->table.id = xstrdup (tblid);
213 else
214 uiout->table.id = NULL;
215 clear_header_list (uiout);
216
217 uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
218 }
219
220 void
221 ui_out_table_body (struct ui_out *uiout)
222 {
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 \
234 columns."));
235
236 uiout->table.body_flag = 1;
237 uiout->table.header_next = uiout->table.header_first;
238
239 uo_table_body (uiout);
240 }
241
242 static void
243 ui_out_table_end (struct ui_out *uiout)
244 {
245 if (!uiout->table.flag)
246 internal_error (__FILE__, __LINE__,
247 _("misplaced table_end or missing table_begin."));
248
249 uiout->table.entry_level = 0;
250 uiout->table.body_flag = 0;
251 uiout->table.flag = 0;
252
253 uo_table_end (uiout);
254 clear_table (uiout);
255 }
256
257 void
258 ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
259 const char *col_name,
260 const char *colhdr)
261 {
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."));
266
267 append_header_to_list (uiout, width, alignment, col_name, colhdr);
268
269 uo_table_header (uiout, width, alignment, col_name, colhdr);
270 }
271
272 static void
273 do_cleanup_table_end (void *data)
274 {
275 struct ui_out *ui_out = (struct ui_out *) data;
276
277 ui_out_table_end (ui_out);
278 }
279
280 struct cleanup *
281 make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols,
282 int nr_rows, const char *tblid)
283 {
284 ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid);
285 return make_cleanup (do_cleanup_table_end, ui_out);
286 }
287
288 void
289 ui_out_begin (struct ui_out *uiout,
290 enum ui_out_type type,
291 const char *id)
292 {
293 int new_level;
294
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."));
299
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. */
307 {
308 int fldno;
309 int width;
310 enum ui_align align;
311
312 verify_field (uiout, &fldno, &width, &align);
313 }
314
315 new_level = push_level (uiout, type);
316
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;
322
323 uo_begin (uiout, type, new_level, id);
324 }
325
326 void
327 ui_out_end (struct ui_out *uiout,
328 enum ui_out_type type)
329 {
330 int old_level = pop_level (uiout, type);
331
332 uo_end (uiout, type, old_level);
333 }
334
335 struct ui_out_end_cleanup_data
336 {
337 struct ui_out *uiout;
338 enum ui_out_type type;
339 };
340
341 static void
342 do_cleanup_end (void *data)
343 {
344 struct ui_out_end_cleanup_data *end_cleanup_data
345 = (struct ui_out_end_cleanup_data *) data;
346
347 ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type);
348 xfree (end_cleanup_data);
349 }
350
351 static struct cleanup *
352 make_cleanup_ui_out_end (struct ui_out *uiout,
353 enum ui_out_type type)
354 {
355 struct ui_out_end_cleanup_data *end_cleanup_data;
356
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);
361 }
362
363 struct cleanup *
364 make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
365 const char *id)
366 {
367 ui_out_begin (uiout, ui_out_type_tuple, id);
368 return make_cleanup_ui_out_end (uiout, ui_out_type_tuple);
369 }
370
371 struct cleanup *
372 make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
373 const char *id)
374 {
375 ui_out_begin (uiout, ui_out_type_list, id);
376 return make_cleanup_ui_out_end (uiout, ui_out_type_list);
377 }
378
379 void
380 ui_out_field_int (struct ui_out *uiout,
381 const char *fldname,
382 int value)
383 {
384 int fldno;
385 int width;
386 enum ui_align align;
387
388 verify_field (uiout, &fldno, &width, &align);
389
390 uo_field_int (uiout, fldno, width, align, fldname, value);
391 }
392
393 void
394 ui_out_field_fmt_int (struct ui_out *uiout,
395 int input_width,
396 enum ui_align input_align,
397 const char *fldname,
398 int value)
399 {
400 int fldno;
401 int width;
402 enum ui_align align;
403
404 verify_field (uiout, &fldno, &width, &align);
405
406 uo_field_int (uiout, fldno, input_width, input_align, fldname, value);
407 }
408
409 /* Documented in ui-out.h. */
410
411 void
412 ui_out_field_core_addr (struct ui_out *uiout,
413 const char *fldname,
414 struct gdbarch *gdbarch,
415 CORE_ADDR address)
416 {
417 ui_out_field_string (uiout, fldname,
418 print_core_address (gdbarch, address));
419 }
420
421 void
422 ui_out_field_stream (struct ui_out *uiout,
423 const char *fldname,
424 struct ui_file *stream)
425 {
426 std::string buffer = ui_file_as_string (stream);
427
428 if (!buffer.empty ())
429 ui_out_field_string (uiout, fldname, buffer.c_str ());
430 else
431 ui_out_field_skip (uiout, fldname);
432 ui_file_rewind (stream);
433 }
434
435 /* Used to omit a field. */
436
437 void
438 ui_out_field_skip (struct ui_out *uiout,
439 const char *fldname)
440 {
441 int fldno;
442 int width;
443 enum ui_align align;
444
445 verify_field (uiout, &fldno, &width, &align);
446
447 uo_field_skip (uiout, fldno, width, align, fldname);
448 }
449
450 void
451 ui_out_field_string (struct ui_out *uiout,
452 const char *fldname,
453 const char *string)
454 {
455 int fldno;
456 int width;
457 enum ui_align align;
458
459 verify_field (uiout, &fldno, &width, &align);
460
461 uo_field_string (uiout, fldno, width, align, fldname, string);
462 }
463
464 /* VARARGS */
465 void
466 ui_out_field_fmt (struct ui_out *uiout,
467 const char *fldname,
468 const char *format, ...)
469 {
470 va_list args;
471 int fldno;
472 int width;
473 enum ui_align align;
474
475 /* Will not align, but has to call anyway. */
476 verify_field (uiout, &fldno, &width, &align);
477
478 va_start (args, format);
479
480 uo_field_fmt (uiout, fldno, width, align, fldname, format, args);
481
482 va_end (args);
483 }
484
485 void
486 ui_out_spaces (struct ui_out *uiout, int numspaces)
487 {
488 uo_spaces (uiout, numspaces);
489 }
490
491 void
492 ui_out_text (struct ui_out *uiout,
493 const char *string)
494 {
495 uo_text (uiout, string);
496 }
497
498 void
499 ui_out_message (struct ui_out *uiout, int verbosity,
500 const char *format,...)
501 {
502 va_list args;
503
504 va_start (args, format);
505 uo_message (uiout, verbosity, format, args);
506 va_end (args);
507 }
508
509 void
510 ui_out_wrap_hint (struct ui_out *uiout, char *identstring)
511 {
512 uo_wrap_hint (uiout, identstring);
513 }
514
515 void
516 ui_out_flush (struct ui_out *uiout)
517 {
518 uo_flush (uiout);
519 }
520
521 int
522 ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream)
523 {
524 return uo_redirect (uiout, outstream);
525 }
526
527 /* Set the flags specified by the mask given. */
528 int
529 ui_out_set_flags (struct ui_out *uiout, int mask)
530 {
531 int oldflags = uiout->flags;
532
533 uiout->flags |= mask;
534 return oldflags;
535 }
536
537 /* Clear the flags specified by the mask given. */
538 int
539 ui_out_clear_flags (struct ui_out *uiout, int mask)
540 {
541 int oldflags = uiout->flags;
542
543 uiout->flags &= ~mask;
544 return oldflags;
545 }
546
547 /* Test the flags against the mask given. */
548 int
549 ui_out_test_flags (struct ui_out *uiout, int mask)
550 {
551 return (uiout->flags & mask);
552 }
553
554 /* Obtain the current verbosity level (as stablished by the
555 'set verbositylevel' command. */
556
557 int
558 ui_out_get_verblvl (struct ui_out *uiout)
559 {
560 /* FIXME: not implemented yet. */
561 return 0;
562 }
563
564 int
565 ui_out_is_mi_like_p (struct ui_out *uiout)
566 {
567 return uiout->impl->is_mi_like_p;
568 }
569
570 /* Interface to the implementation functions. */
571
572 void
573 uo_table_begin (struct ui_out *uiout, int nbrofcols,
574 int nr_rows,
575 const char *tblid)
576 {
577 if (!uiout->impl->table_begin)
578 return;
579 uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid);
580 }
581
582 void
583 uo_table_body (struct ui_out *uiout)
584 {
585 if (!uiout->impl->table_body)
586 return;
587 uiout->impl->table_body (uiout);
588 }
589
590 void
591 uo_table_end (struct ui_out *uiout)
592 {
593 if (!uiout->impl->table_end)
594 return;
595 uiout->impl->table_end (uiout);
596 }
597
598 void
599 uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
600 const char *col_name,
601 const char *colhdr)
602 {
603 if (!uiout->impl->table_header)
604 return;
605 uiout->impl->table_header (uiout, width, align, col_name, colhdr);
606 }
607
608 /* Clear the table associated with UIOUT. */
609
610 static void
611 clear_table (struct ui_out *uiout)
612 {
613 xfree (uiout->table.id);
614 uiout->table.id = NULL;
615 clear_header_list (uiout);
616 }
617
618 void
619 uo_begin (struct ui_out *uiout,
620 enum ui_out_type type,
621 int level,
622 const char *id)
623 {
624 if (uiout->impl->begin == NULL)
625 return;
626 uiout->impl->begin (uiout, type, level, id);
627 }
628
629 void
630 uo_end (struct ui_out *uiout,
631 enum ui_out_type type,
632 int level)
633 {
634 if (uiout->impl->end == NULL)
635 return;
636 uiout->impl->end (uiout, type, level);
637 }
638
639 void
640 uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align,
641 const char *fldname,
642 int value)
643 {
644 if (!uiout->impl->field_int)
645 return;
646 uiout->impl->field_int (uiout, fldno, width, align, fldname, value);
647 }
648
649 void
650 uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align,
651 const char *fldname)
652 {
653 if (!uiout->impl->field_skip)
654 return;
655 uiout->impl->field_skip (uiout, fldno, width, align, fldname);
656 }
657
658 void
659 uo_field_string (struct ui_out *uiout, int fldno, int width,
660 enum ui_align align,
661 const char *fldname,
662 const char *string)
663 {
664 if (!uiout->impl->field_string)
665 return;
666 uiout->impl->field_string (uiout, fldno, width, align, fldname, string);
667 }
668
669 void
670 uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align,
671 const char *fldname,
672 const char *format,
673 va_list args)
674 {
675 if (!uiout->impl->field_fmt)
676 return;
677 uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args);
678 }
679
680 void
681 uo_spaces (struct ui_out *uiout, int numspaces)
682 {
683 if (!uiout->impl->spaces)
684 return;
685 uiout->impl->spaces (uiout, numspaces);
686 }
687
688 void
689 uo_text (struct ui_out *uiout,
690 const char *string)
691 {
692 if (!uiout->impl->text)
693 return;
694 uiout->impl->text (uiout, string);
695 }
696
697 void
698 uo_message (struct ui_out *uiout, int verbosity,
699 const char *format,
700 va_list args)
701 {
702 if (!uiout->impl->message)
703 return;
704 uiout->impl->message (uiout, verbosity, format, args);
705 }
706
707 void
708 uo_wrap_hint (struct ui_out *uiout, char *identstring)
709 {
710 if (!uiout->impl->wrap_hint)
711 return;
712 uiout->impl->wrap_hint (uiout, identstring);
713 }
714
715 void
716 uo_flush (struct ui_out *uiout)
717 {
718 if (!uiout->impl->flush)
719 return;
720 uiout->impl->flush (uiout);
721 }
722
723 int
724 uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
725 {
726 if (!uiout->impl->redirect)
727 return -1;
728 uiout->impl->redirect (uiout, outstream);
729 return 0;
730 }
731
732 void
733 uo_data_destroy (struct ui_out *uiout)
734 {
735 if (!uiout->impl->data_destroy)
736 return;
737
738 uiout->impl->data_destroy (uiout);
739 }
740
741 /* local functions */
742
743 /* List of column headers manipulation routines. */
744
745 static void
746 clear_header_list (struct ui_out *uiout)
747 {
748 while (uiout->table.header_first != NULL)
749 {
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);
755 }
756 gdb_assert (uiout->table.header_first == NULL);
757 uiout->table.header_last = NULL;
758 uiout->table.header_next = NULL;
759 }
760
761 static void
762 append_header_to_list (struct ui_out *uiout,
763 int width,
764 enum ui_align alignment,
765 const char *col_name,
766 const char *colhdr)
767 {
768 struct ui_out_hdr *temphdr;
769
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
774 automatic. */
775 if (colhdr != NULL)
776 temphdr->colhdr = xstrdup (colhdr);
777 else
778 temphdr->colhdr = NULL;
779
780 if (col_name != NULL)
781 temphdr->col_name = xstrdup (col_name);
782 else if (colhdr != NULL)
783 temphdr->col_name = xstrdup (colhdr);
784 else
785 temphdr->col_name = NULL;
786
787 temphdr->next = NULL;
788 if (uiout->table.header_first == NULL)
789 {
790 temphdr->colno = 1;
791 uiout->table.header_first = temphdr;
792 uiout->table.header_last = temphdr;
793 }
794 else
795 {
796 temphdr->colno = uiout->table.header_last->colno + 1;
797 uiout->table.header_last->next = temphdr;
798 uiout->table.header_last = temphdr;
799 }
800 uiout->table.header_next = uiout->table.header_last;
801 }
802
803 /* Extract the format information for the NEXT header and advance
804 the header pointer. Return 0 if there was no next header. */
805
806 static int
807 get_next_header (struct ui_out *uiout,
808 int *colno,
809 int *width,
810 enum ui_align *alignment,
811 char **colhdr)
812 {
813 /* There may be no headers at all or we may have used all columns. */
814 if (uiout->table.header_next == NULL)
815 return 0;
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;
822 return 1;
823 }
824
825
826 /* Verify that the field/tuple/list is correctly positioned. Return
827 the field number and corresponding alignment (if
828 available/applicable). */
829
830 static void
831 verify_field (struct ui_out *uiout, int *fldno, int *width,
832 enum ui_align *align)
833 {
834 struct ui_out_level *current = current_level (uiout);
835 char *text;
836
837 if (uiout->table.flag)
838 {
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
847 level is zero. */
848 }
849
850 current->field_count += 1;
851
852 if (uiout->table.body_flag
853 && uiout->table.entry_level == uiout->level
854 && get_next_header (uiout, fldno, width, align, &text))
855 {
856 if (*fldno != current->field_count)
857 internal_error (__FILE__, __LINE__,
858 _("ui-out internal error in handling headers."));
859 }
860 else
861 {
862 *width = 0;
863 *align = ui_noalign;
864 *fldno = current->field_count;
865 }
866 }
867
868
869 /* Access to ui-out members data. */
870
871 void *
872 ui_out_data (struct ui_out *uiout)
873 {
874 return uiout->data;
875 }
876
877 /* Access table field parameters. */
878 int
879 ui_out_query_field (struct ui_out *uiout, int colno,
880 int *width, int *alignment, char **col_name)
881 {
882 struct ui_out_hdr *hdr;
883
884 if (!uiout->table.flag)
885 return 0;
886
887 for (hdr = uiout->table.header_first; hdr; hdr = hdr->next)
888 if (hdr->colno == colno)
889 {
890 *width = hdr->width;
891 *alignment = hdr->alignment;
892 *col_name = hdr->col_name;
893 return 1;
894 }
895
896 return 0;
897 }
898
899 /* Initialize private members at startup. */
900
901 struct ui_out *
902 ui_out_new (const struct ui_out_impl *impl, void *data,
903 int flags)
904 {
905 struct ui_out *uiout = XNEW (struct ui_out);
906 struct ui_out_level *current = XNEW (struct ui_out_level);
907
908 uiout->data = data;
909 uiout->impl = impl;
910 uiout->flags = flags;
911 uiout->table.flag = 0;
912 uiout->table.body_flag = 0;
913 uiout->level = 0;
914 uiout->levels = NULL;
915
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);
920
921 uiout->table.id = NULL;
922 uiout->table.header_first = NULL;
923 uiout->table.header_last = NULL;
924 uiout->table.header_next = NULL;
925 return uiout;
926 }
927
928 /* Free UIOUT and the memory areas it references. */
929
930 void
931 ui_out_destroy (struct ui_out *uiout)
932 {
933 int i;
934 struct ui_out_level *current;
935
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
938 destroyed. */
939 for (i = 0;
940 VEC_iterate (ui_out_level_p, uiout->levels, i, current);
941 ++i)
942 xfree (current);
943
944 VEC_free (ui_out_level_p, uiout->levels);
945 uo_data_destroy (uiout);
946 clear_table (uiout);
947 xfree (uiout);
948 }
949
950 /* Standard gdb initialization hook. */
951
952 void
953 _initialize_ui_out (void)
954 {
955 /* nothing needs to be done */
956 }
This page took 0.051427 seconds and 4 git commands to generate.