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