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, | |
49d06418 | 120 | enum ui_out_type type) |
80f49b30 AC |
121 | { |
122 | struct ui_out_level *current; | |
5d502164 | 123 | |
80f49b30 | 124 | uiout->level++; |
70ba0933 | 125 | current = XNEW (struct ui_out_level); |
80f49b30 | 126 | current->field_count = 0; |
631ec795 | 127 | current->type = type; |
54eb231c | 128 | VEC_safe_push (ui_out_level_p, uiout->levels, current); |
80f49b30 AC |
129 | return uiout->level; |
130 | } | |
131 | ||
132 | /* Discard the current level, return the discarded level's index. | |
581e13c1 | 133 | TYPE is the type of the level being discarded. */ |
80f49b30 | 134 | static int |
631ec795 AC |
135 | pop_level (struct ui_out *uiout, |
136 | enum ui_out_type type) | |
80f49b30 | 137 | { |
54eb231c PM |
138 | struct ui_out_level *current; |
139 | ||
581e13c1 | 140 | /* We had better not underflow the buffer. */ |
54eb231c | 141 | gdb_assert (uiout->level > 0); |
631ec795 | 142 | gdb_assert (current_level (uiout)->type == type); |
54eb231c PM |
143 | current = VEC_pop (ui_out_level_p, uiout->levels); |
144 | xfree (current); | |
80f49b30 AC |
145 | uiout->level--; |
146 | return uiout->level + 1; | |
147 | } | |
148 | ||
581e13c1 | 149 | /* These are the interfaces to implementation functions. */ |
8b93c638 | 150 | |
88379baf | 151 | static void uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 152 | int nr_rows, const char *tblid); |
8b93c638 JM |
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, | |
b25959ec AC |
156 | enum ui_align align, const char *col_name, |
157 | const char *colhdr); | |
631ec795 AC |
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); | |
8b93c638 | 164 | static void uo_field_int (struct ui_out *uiout, int fldno, int width, |
88379baf | 165 | enum ui_align align, const char *fldname, int value); |
8b93c638 | 166 | static void uo_field_skip (struct ui_out *uiout, int fldno, int width, |
88379baf | 167 | enum ui_align align, const char *fldname); |
8b93c638 | 168 | static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, |
88379baf | 169 | enum ui_align align, const char *fldname, |
bee0189a | 170 | const char *format, va_list args) |
a0b31db1 | 171 | ATTRIBUTE_PRINTF (6, 0); |
8b93c638 | 172 | static void uo_spaces (struct ui_out *uiout, int numspaces); |
88379baf | 173 | static void uo_text (struct ui_out *uiout, const char *string); |
8b93c638 | 174 | static void uo_message (struct ui_out *uiout, int verbosity, |
bee0189a | 175 | const char *format, va_list args) |
a0b31db1 | 176 | ATTRIBUTE_PRINTF (3, 0); |
8b93c638 JM |
177 | static void uo_wrap_hint (struct ui_out *uiout, char *identstring); |
178 | static void uo_flush (struct ui_out *uiout); | |
0fac0b41 | 179 | static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); |
b65a2bd9 | 180 | static void uo_data_destroy (struct ui_out *uiout); |
8b93c638 JM |
181 | |
182 | /* Prototypes for local functions */ | |
183 | ||
184 | extern void _initialize_ui_out (void); | |
88379baf | 185 | static void append_header_to_list (struct ui_out *uiout, int width, |
f486487f | 186 | enum ui_align alignment, const char *col_name, |
b25959ec | 187 | const char *colhdr); |
bafdd3b3 | 188 | static int get_next_header (struct ui_out *uiout, int *colno, int *width, |
f486487f | 189 | enum ui_align *alignment, char **colhdr); |
8b93c638 | 190 | static void clear_header_list (struct ui_out *uiout); |
b65a2bd9 | 191 | static void clear_table (struct ui_out *uiout); |
a6c47c14 | 192 | static void verify_field (struct ui_out *uiout, int *fldno, int *width, |
f486487f | 193 | enum ui_align *align); |
8b93c638 | 194 | |
8b93c638 JM |
195 | /* exported functions (ui_out API) */ |
196 | ||
581e13c1 | 197 | /* Mark beginning of a table. */ |
8b93c638 | 198 | |
3b31d625 | 199 | static void |
88379baf | 200 | ui_out_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 201 | int nr_rows, |
88379baf | 202 | const char *tblid) |
8b93c638 | 203 | { |
bafdd3b3 | 204 | if (uiout->table.flag) |
8e65ff28 | 205 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
206 | _("tables cannot be nested; table_begin found before \ |
207 | previous table_end.")); | |
8b93c638 | 208 | |
bafdd3b3 AC |
209 | uiout->table.flag = 1; |
210 | uiout->table.body_flag = 0; | |
a6c47c14 | 211 | uiout->table.entry_level = uiout->level + 1; |
bafdd3b3 | 212 | uiout->table.columns = nbrofcols; |
8b93c638 | 213 | if (tblid != NULL) |
bafdd3b3 | 214 | uiout->table.id = xstrdup (tblid); |
8b93c638 | 215 | else |
bafdd3b3 | 216 | uiout->table.id = NULL; |
8b93c638 JM |
217 | clear_header_list (uiout); |
218 | ||
bafdd3b3 | 219 | uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id); |
8b93c638 JM |
220 | } |
221 | ||
222 | void | |
fba45db2 | 223 | ui_out_table_body (struct ui_out *uiout) |
8b93c638 | 224 | { |
bafdd3b3 | 225 | if (!uiout->table.flag) |
8e65ff28 | 226 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
227 | _("table_body outside a table is not valid; it must be \ |
228 | after a table_begin and before a table_end.")); | |
bafdd3b3 | 229 | if (uiout->table.body_flag) |
8e65ff28 | 230 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
231 | _("extra table_body call not allowed; there must be \ |
232 | only one table_body after a table_begin and before a table_end.")); | |
bafdd3b3 | 233 | if (uiout->table.header_next->colno != uiout->table.columns) |
8e65ff28 | 234 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
235 | _("number of headers differ from number of table \ |
236 | columns.")); | |
8b93c638 | 237 | |
bafdd3b3 AC |
238 | uiout->table.body_flag = 1; |
239 | uiout->table.header_next = uiout->table.header_first; | |
8b93c638 JM |
240 | |
241 | uo_table_body (uiout); | |
242 | } | |
243 | ||
3b31d625 | 244 | static void |
fba45db2 | 245 | ui_out_table_end (struct ui_out *uiout) |
8b93c638 | 246 | { |
bafdd3b3 | 247 | if (!uiout->table.flag) |
8e65ff28 | 248 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 249 | _("misplaced table_end or missing table_begin.")); |
8b93c638 | 250 | |
a6c47c14 | 251 | uiout->table.entry_level = 0; |
bafdd3b3 AC |
252 | uiout->table.body_flag = 0; |
253 | uiout->table.flag = 0; | |
8b93c638 JM |
254 | |
255 | uo_table_end (uiout); | |
b65a2bd9 | 256 | clear_table (uiout); |
8b93c638 JM |
257 | } |
258 | ||
259 | void | |
fba45db2 | 260 | ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
b25959ec | 261 | const char *col_name, |
88379baf | 262 | const char *colhdr) |
8b93c638 | 263 | { |
bafdd3b3 | 264 | if (!uiout->table.flag || uiout->table.body_flag) |
8e65ff28 | 265 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
266 | _("table header must be specified after table_begin \ |
267 | and before table_body.")); | |
8b93c638 | 268 | |
b25959ec | 269 | append_header_to_list (uiout, width, alignment, col_name, colhdr); |
8b93c638 | 270 | |
b25959ec | 271 | uo_table_header (uiout, width, alignment, col_name, colhdr); |
8b93c638 JM |
272 | } |
273 | ||
3b31d625 EZ |
274 | static void |
275 | do_cleanup_table_end (void *data) | |
276 | { | |
19ba03f4 | 277 | struct ui_out *ui_out = (struct ui_out *) data; |
3b31d625 EZ |
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 | ||
8b93c638 | 290 | void |
631ec795 AC |
291 | ui_out_begin (struct ui_out *uiout, |
292 | enum ui_out_type type, | |
293 | const char *id) | |
8b93c638 | 294 | { |
80f49b30 | 295 | int new_level; |
5d502164 | 296 | |
bafdd3b3 | 297 | if (uiout->table.flag && !uiout->table.body_flag) |
8e65ff28 | 298 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
299 | _("table header or table_body expected; lists must be \ |
300 | specified after table_body.")); | |
a6c47c14 AC |
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; | |
f486487f | 312 | enum ui_align align; |
5d502164 | 313 | |
a6c47c14 AC |
314 | verify_field (uiout, &fldno, &width, &align); |
315 | } | |
316 | ||
49d06418 | 317 | new_level = push_level (uiout, type); |
a6c47c14 AC |
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) | |
bafdd3b3 | 323 | uiout->table.header_next = uiout->table.header_first; |
a6c47c14 | 324 | |
631ec795 AC |
325 | uo_begin (uiout, type, new_level, id); |
326 | } | |
327 | ||
631ec795 AC |
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); | |
5d502164 | 333 | |
631ec795 | 334 | uo_end (uiout, type, old_level); |
8b93c638 JM |
335 | } |
336 | ||
127431f9 AC |
337 | struct ui_out_end_cleanup_data |
338 | { | |
339 | struct ui_out *uiout; | |
340 | enum ui_out_type type; | |
341 | }; | |
342 | ||
e6e0bfab | 343 | static void |
127431f9 AC |
344 | do_cleanup_end (void *data) |
345 | { | |
19ba03f4 SM |
346 | struct ui_out_end_cleanup_data *end_cleanup_data |
347 | = (struct ui_out_end_cleanup_data *) data; | |
5d502164 | 348 | |
127431f9 AC |
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; | |
5d502164 | 358 | |
70ba0933 | 359 | end_cleanup_data = XNEW (struct ui_out_end_cleanup_data); |
127431f9 AC |
360 | end_cleanup_data->uiout = uiout; |
361 | end_cleanup_data->type = type; | |
362 | return make_cleanup (do_cleanup_end, end_cleanup_data); | |
363 | } | |
364 | ||
e6e0bfab | 365 | struct cleanup * |
666547aa AC |
366 | make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout, |
367 | const char *id) | |
368 | { | |
3b31d625 | 369 | ui_out_begin (uiout, ui_out_type_tuple, id); |
666547aa AC |
370 | return make_cleanup_ui_out_end (uiout, ui_out_type_tuple); |
371 | } | |
372 | ||
373 | struct cleanup * | |
6b28c186 AC |
374 | make_cleanup_ui_out_list_begin_end (struct ui_out *uiout, |
375 | const char *id) | |
e6e0bfab | 376 | { |
3b31d625 | 377 | ui_out_begin (uiout, ui_out_type_list, id); |
127431f9 | 378 | return make_cleanup_ui_out_end (uiout, ui_out_type_list); |
e6e0bfab MK |
379 | } |
380 | ||
8b93c638 | 381 | void |
88379baf AC |
382 | ui_out_field_int (struct ui_out *uiout, |
383 | const char *fldname, | |
384 | int value) | |
8b93c638 JM |
385 | { |
386 | int fldno; | |
387 | int width; | |
f486487f | 388 | enum ui_align align; |
8b93c638 | 389 | |
a6c47c14 | 390 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
391 | |
392 | uo_field_int (uiout, fldno, width, align, fldname, value); | |
393 | } | |
394 | ||
52c6a6ac JJ |
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; | |
f486487f | 404 | enum ui_align align; |
52c6a6ac JJ |
405 | |
406 | verify_field (uiout, &fldno, &width, &align); | |
407 | ||
408 | uo_field_int (uiout, fldno, input_width, input_align, fldname, value); | |
409 | } | |
410 | ||
15230f37 TJB |
411 | /* Documented in ui-out.h. */ |
412 | ||
8b93c638 | 413 | void |
88379baf AC |
414 | ui_out_field_core_addr (struct ui_out *uiout, |
415 | const char *fldname, | |
5af949e3 | 416 | struct gdbarch *gdbarch, |
88379baf | 417 | CORE_ADDR address) |
8b93c638 | 418 | { |
f1310107 TJB |
419 | ui_out_field_string (uiout, fldname, |
420 | print_core_address (gdbarch, address)); | |
8b93c638 JM |
421 | } |
422 | ||
423 | void | |
88379baf AC |
424 | ui_out_field_stream (struct ui_out *uiout, |
425 | const char *fldname, | |
f99d8bf4 | 426 | struct ui_file *stream) |
8b93c638 | 427 | { |
56dbf317 | 428 | std::string buffer = ui_file_as_string (stream); |
5d502164 | 429 | |
56dbf317 PA |
430 | if (!buffer.empty ()) |
431 | ui_out_field_string (uiout, fldname, buffer.c_str ()); | |
8b93c638 JM |
432 | else |
433 | ui_out_field_skip (uiout, fldname); | |
f99d8bf4 | 434 | ui_file_rewind (stream); |
8b93c638 JM |
435 | } |
436 | ||
581e13c1 | 437 | /* Used to omit a field. */ |
8b93c638 JM |
438 | |
439 | void | |
88379baf AC |
440 | ui_out_field_skip (struct ui_out *uiout, |
441 | const char *fldname) | |
8b93c638 JM |
442 | { |
443 | int fldno; | |
444 | int width; | |
f486487f | 445 | enum ui_align align; |
8b93c638 | 446 | |
a6c47c14 | 447 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
448 | |
449 | uo_field_skip (uiout, fldno, width, align, fldname); | |
450 | } | |
451 | ||
452 | void | |
453 | ui_out_field_string (struct ui_out *uiout, | |
88379baf | 454 | const char *fldname, |
8b93c638 JM |
455 | const char *string) |
456 | { | |
457 | int fldno; | |
458 | int width; | |
f486487f | 459 | enum ui_align align; |
8b93c638 | 460 | |
a6c47c14 | 461 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
462 | |
463 | uo_field_string (uiout, fldno, width, align, fldname, string); | |
464 | } | |
465 | ||
466 | /* VARARGS */ | |
467 | void | |
88379baf AC |
468 | ui_out_field_fmt (struct ui_out *uiout, |
469 | const char *fldname, | |
470 | const char *format, ...) | |
8b93c638 JM |
471 | { |
472 | va_list args; | |
473 | int fldno; | |
474 | int width; | |
f486487f | 475 | enum ui_align align; |
8b93c638 | 476 | |
581e13c1 | 477 | /* Will not align, but has to call anyway. */ |
a6c47c14 | 478 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
479 | |
480 | va_start (args, format); | |
481 | ||
482 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); | |
483 | ||
484 | va_end (args); | |
485 | } | |
486 | ||
487 | void | |
fba45db2 | 488 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
489 | { |
490 | uo_spaces (uiout, numspaces); | |
491 | } | |
492 | ||
493 | void | |
88379baf AC |
494 | ui_out_text (struct ui_out *uiout, |
495 | const char *string) | |
8b93c638 JM |
496 | { |
497 | uo_text (uiout, string); | |
498 | } | |
499 | ||
500 | void | |
88379baf AC |
501 | ui_out_message (struct ui_out *uiout, int verbosity, |
502 | const char *format,...) | |
8b93c638 JM |
503 | { |
504 | va_list args; | |
505 | ||
506 | va_start (args, format); | |
8b93c638 | 507 | uo_message (uiout, verbosity, format, args); |
8b93c638 JM |
508 | va_end (args); |
509 | } | |
510 | ||
8b93c638 | 511 | void |
fba45db2 | 512 | ui_out_wrap_hint (struct ui_out *uiout, char *identstring) |
8b93c638 JM |
513 | { |
514 | uo_wrap_hint (uiout, identstring); | |
515 | } | |
516 | ||
517 | void | |
fba45db2 | 518 | ui_out_flush (struct ui_out *uiout) |
8b93c638 JM |
519 | { |
520 | uo_flush (uiout); | |
521 | } | |
522 | ||
0fac0b41 DJ |
523 | int |
524 | ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
525 | { | |
526 | return uo_redirect (uiout, outstream); | |
527 | } | |
528 | ||
581e13c1 | 529 | /* Set the flags specified by the mask given. */ |
8b93c638 | 530 | int |
fba45db2 | 531 | ui_out_set_flags (struct ui_out *uiout, int mask) |
8b93c638 | 532 | { |
5bfb05ca | 533 | int oldflags = uiout->flags; |
8b93c638 | 534 | |
b8d86de3 | 535 | uiout->flags |= mask; |
8b93c638 JM |
536 | return oldflags; |
537 | } | |
538 | ||
581e13c1 | 539 | /* Clear the flags specified by the mask given. */ |
8b93c638 | 540 | int |
fba45db2 | 541 | ui_out_clear_flags (struct ui_out *uiout, int mask) |
8b93c638 | 542 | { |
5bfb05ca | 543 | int oldflags = uiout->flags; |
8b93c638 JM |
544 | |
545 | uiout->flags &= ~mask; | |
8b93c638 JM |
546 | return oldflags; |
547 | } | |
548 | ||
581e13c1 | 549 | /* Test the flags against the mask given. */ |
8b93c638 | 550 | int |
fba45db2 | 551 | ui_out_test_flags (struct ui_out *uiout, int mask) |
8b93c638 JM |
552 | { |
553 | return (uiout->flags & mask); | |
554 | } | |
555 | ||
581e13c1 MS |
556 | /* Obtain the current verbosity level (as stablished by the |
557 | 'set verbositylevel' command. */ | |
8b93c638 JM |
558 | |
559 | int | |
fba45db2 | 560 | ui_out_get_verblvl (struct ui_out *uiout) |
8b93c638 | 561 | { |
581e13c1 | 562 | /* FIXME: not implemented yet. */ |
8b93c638 JM |
563 | return 0; |
564 | } | |
565 | ||
9dc5e2a9 AC |
566 | int |
567 | ui_out_is_mi_like_p (struct ui_out *uiout) | |
568 | { | |
569 | return uiout->impl->is_mi_like_p; | |
570 | } | |
571 | ||
581e13c1 | 572 | /* Interface to the implementation functions. */ |
8b93c638 JM |
573 | |
574 | void | |
88379baf | 575 | uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 576 | int nr_rows, |
88379baf | 577 | const char *tblid) |
8b93c638 JM |
578 | { |
579 | if (!uiout->impl->table_begin) | |
580 | return; | |
d63f1d40 | 581 | uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); |
8b93c638 JM |
582 | } |
583 | ||
584 | void | |
585 | uo_table_body (struct ui_out *uiout) | |
586 | { | |
587 | if (!uiout->impl->table_body) | |
588 | return; | |
589 | uiout->impl->table_body (uiout); | |
590 | } | |
591 | ||
592 | void | |
593 | uo_table_end (struct ui_out *uiout) | |
594 | { | |
595 | if (!uiout->impl->table_end) | |
596 | return; | |
597 | uiout->impl->table_end (uiout); | |
598 | } | |
599 | ||
600 | void | |
88379baf | 601 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, |
b25959ec | 602 | const char *col_name, |
88379baf | 603 | const char *colhdr) |
8b93c638 JM |
604 | { |
605 | if (!uiout->impl->table_header) | |
606 | return; | |
b25959ec | 607 | uiout->impl->table_header (uiout, width, align, col_name, colhdr); |
8b93c638 JM |
608 | } |
609 | ||
b65a2bd9 SCR |
610 | /* Clear the table associated with UIOUT. */ |
611 | ||
612 | static void | |
613 | clear_table (struct ui_out *uiout) | |
614 | { | |
9c1fcd01 TT |
615 | xfree (uiout->table.id); |
616 | uiout->table.id = NULL; | |
b65a2bd9 SCR |
617 | clear_header_list (uiout); |
618 | } | |
619 | ||
8b93c638 | 620 | void |
631ec795 AC |
621 | uo_begin (struct ui_out *uiout, |
622 | enum ui_out_type type, | |
623 | int level, | |
624 | const char *id) | |
8b93c638 | 625 | { |
631ec795 | 626 | if (uiout->impl->begin == NULL) |
8b93c638 | 627 | return; |
631ec795 | 628 | uiout->impl->begin (uiout, type, level, id); |
8b93c638 JM |
629 | } |
630 | ||
631 | void | |
631ec795 AC |
632 | uo_end (struct ui_out *uiout, |
633 | enum ui_out_type type, | |
634 | int level) | |
8b93c638 | 635 | { |
631ec795 | 636 | if (uiout->impl->end == NULL) |
8b93c638 | 637 | return; |
631ec795 | 638 | uiout->impl->end (uiout, type, level); |
8b93c638 JM |
639 | } |
640 | ||
641 | void | |
88379baf AC |
642 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
643 | const char *fldname, | |
644 | int value) | |
8b93c638 JM |
645 | { |
646 | if (!uiout->impl->field_int) | |
647 | return; | |
648 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); | |
649 | } | |
650 | ||
651 | void | |
88379baf AC |
652 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
653 | const char *fldname) | |
8b93c638 JM |
654 | { |
655 | if (!uiout->impl->field_skip) | |
656 | return; | |
657 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); | |
658 | } | |
659 | ||
660 | void | |
661 | uo_field_string (struct ui_out *uiout, int fldno, int width, | |
88379baf AC |
662 | enum ui_align align, |
663 | const char *fldname, | |
664 | const char *string) | |
8b93c638 JM |
665 | { |
666 | if (!uiout->impl->field_string) | |
667 | return; | |
668 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); | |
669 | } | |
670 | ||
671 | void | |
88379baf AC |
672 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
673 | const char *fldname, | |
674 | const char *format, | |
675 | va_list args) | |
8b93c638 JM |
676 | { |
677 | if (!uiout->impl->field_fmt) | |
678 | return; | |
679 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); | |
680 | } | |
681 | ||
682 | void | |
683 | uo_spaces (struct ui_out *uiout, int numspaces) | |
684 | { | |
685 | if (!uiout->impl->spaces) | |
686 | return; | |
687 | uiout->impl->spaces (uiout, numspaces); | |
688 | } | |
689 | ||
690 | void | |
88379baf AC |
691 | uo_text (struct ui_out *uiout, |
692 | const char *string) | |
8b93c638 JM |
693 | { |
694 | if (!uiout->impl->text) | |
695 | return; | |
696 | uiout->impl->text (uiout, string); | |
697 | } | |
698 | ||
699 | void | |
88379baf AC |
700 | uo_message (struct ui_out *uiout, int verbosity, |
701 | const char *format, | |
702 | va_list args) | |
8b93c638 JM |
703 | { |
704 | if (!uiout->impl->message) | |
705 | return; | |
706 | uiout->impl->message (uiout, verbosity, format, args); | |
707 | } | |
708 | ||
709 | void | |
710 | uo_wrap_hint (struct ui_out *uiout, char *identstring) | |
711 | { | |
712 | if (!uiout->impl->wrap_hint) | |
713 | return; | |
714 | uiout->impl->wrap_hint (uiout, identstring); | |
715 | } | |
716 | ||
717 | void | |
718 | uo_flush (struct ui_out *uiout) | |
719 | { | |
720 | if (!uiout->impl->flush) | |
721 | return; | |
722 | uiout->impl->flush (uiout); | |
723 | } | |
724 | ||
0fac0b41 DJ |
725 | int |
726 | uo_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
727 | { | |
728 | if (!uiout->impl->redirect) | |
729 | return -1; | |
730 | uiout->impl->redirect (uiout, outstream); | |
731 | return 0; | |
732 | } | |
733 | ||
b65a2bd9 SCR |
734 | void |
735 | uo_data_destroy (struct ui_out *uiout) | |
736 | { | |
737 | if (!uiout->impl->data_destroy) | |
738 | return; | |
739 | ||
740 | uiout->impl->data_destroy (uiout); | |
741 | } | |
742 | ||
8b93c638 JM |
743 | /* local functions */ |
744 | ||
581e13c1 | 745 | /* List of column headers manipulation routines. */ |
8b93c638 JM |
746 | |
747 | static void | |
fba45db2 | 748 | clear_header_list (struct ui_out *uiout) |
8b93c638 | 749 | { |
bafdd3b3 | 750 | while (uiout->table.header_first != NULL) |
8b93c638 | 751 | { |
bafdd3b3 AC |
752 | uiout->table.header_next = uiout->table.header_first; |
753 | uiout->table.header_first = uiout->table.header_first->next; | |
71bdabee KS |
754 | xfree (uiout->table.header_next->colhdr); |
755 | xfree (uiout->table.header_next->col_name); | |
bafdd3b3 | 756 | xfree (uiout->table.header_next); |
8b93c638 | 757 | } |
bafdd3b3 AC |
758 | gdb_assert (uiout->table.header_first == NULL); |
759 | uiout->table.header_last = NULL; | |
760 | uiout->table.header_next = NULL; | |
8b93c638 JM |
761 | } |
762 | ||
763 | static void | |
764 | append_header_to_list (struct ui_out *uiout, | |
765 | int width, | |
f486487f | 766 | enum ui_align alignment, |
b25959ec | 767 | const char *col_name, |
88379baf | 768 | const char *colhdr) |
8b93c638 JM |
769 | { |
770 | struct ui_out_hdr *temphdr; | |
771 | ||
70ba0933 | 772 | temphdr = XNEW (struct ui_out_hdr); |
8b93c638 JM |
773 | temphdr->width = width; |
774 | temphdr->alignment = alignment; | |
44db85f8 MS |
775 | /* We have to copy the column title as the original may be an |
776 | automatic. */ | |
8b93c638 | 777 | if (colhdr != NULL) |
b25959ec AC |
778 | temphdr->colhdr = xstrdup (colhdr); |
779 | else | |
780 | temphdr->colhdr = NULL; | |
44db85f8 | 781 | |
b25959ec | 782 | if (col_name != NULL) |
44db85f8 MS |
783 | temphdr->col_name = xstrdup (col_name); |
784 | else if (colhdr != NULL) | |
b25959ec AC |
785 | temphdr->col_name = xstrdup (colhdr); |
786 | else | |
44db85f8 MS |
787 | temphdr->col_name = NULL; |
788 | ||
8b93c638 | 789 | temphdr->next = NULL; |
bafdd3b3 | 790 | if (uiout->table.header_first == NULL) |
8b93c638 JM |
791 | { |
792 | temphdr->colno = 1; | |
bafdd3b3 AC |
793 | uiout->table.header_first = temphdr; |
794 | uiout->table.header_last = temphdr; | |
8b93c638 JM |
795 | } |
796 | else | |
797 | { | |
bafdd3b3 AC |
798 | temphdr->colno = uiout->table.header_last->colno + 1; |
799 | uiout->table.header_last->next = temphdr; | |
800 | uiout->table.header_last = temphdr; | |
8b93c638 | 801 | } |
bafdd3b3 | 802 | uiout->table.header_next = uiout->table.header_last; |
8b93c638 JM |
803 | } |
804 | ||
7a9dd1b2 | 805 | /* Extract the format information for the NEXT header and advance |
bafdd3b3 | 806 | the header pointer. Return 0 if there was no next header. */ |
8b93c638 JM |
807 | |
808 | static int | |
bafdd3b3 | 809 | get_next_header (struct ui_out *uiout, |
8b93c638 JM |
810 | int *colno, |
811 | int *width, | |
f486487f | 812 | enum ui_align *alignment, |
8b93c638 JM |
813 | char **colhdr) |
814 | { | |
bafdd3b3 AC |
815 | /* There may be no headers at all or we may have used all columns. */ |
816 | if (uiout->table.header_next == NULL) | |
8b93c638 | 817 | return 0; |
bafdd3b3 AC |
818 | *colno = uiout->table.header_next->colno; |
819 | *width = uiout->table.header_next->width; | |
820 | *alignment = uiout->table.header_next->alignment; | |
821 | *colhdr = uiout->table.header_next->colhdr; | |
822 | /* Advance the header pointer to the next entry. */ | |
823 | uiout->table.header_next = uiout->table.header_next->next; | |
8b93c638 JM |
824 | return 1; |
825 | } | |
826 | ||
a6c47c14 AC |
827 | |
828 | /* Verify that the field/tuple/list is correctly positioned. Return | |
829 | the field number and corresponding alignment (if | |
830 | available/applicable). */ | |
8b93c638 JM |
831 | |
832 | static void | |
f486487f SM |
833 | verify_field (struct ui_out *uiout, int *fldno, int *width, |
834 | enum ui_align *align) | |
8b93c638 | 835 | { |
a6c47c14 AC |
836 | struct ui_out_level *current = current_level (uiout); |
837 | char *text; | |
838 | ||
bafdd3b3 | 839 | if (uiout->table.flag) |
8b93c638 | 840 | { |
bafdd3b3 | 841 | if (!uiout->table.body_flag) |
8e65ff28 | 842 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
843 | _("table_body missing; table fields must be \ |
844 | specified after table_body and inside a list.")); | |
a6c47c14 AC |
845 | /* NOTE: cagney/2001-12-08: There was a check here to ensure |
846 | that this code was only executed when uiout->level was | |
847 | greater than zero. That no longer applies - this code is run | |
848 | before each table row tuple is started and at that point the | |
849 | level is zero. */ | |
8b93c638 | 850 | } |
8b93c638 | 851 | |
a6c47c14 | 852 | current->field_count += 1; |
8b93c638 | 853 | |
a6c47c14 AC |
854 | if (uiout->table.body_flag |
855 | && uiout->table.entry_level == uiout->level | |
856 | && get_next_header (uiout, fldno, width, align, &text)) | |
8b93c638 | 857 | { |
a6c47c14 | 858 | if (*fldno != current->field_count) |
8e65ff28 | 859 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 860 | _("ui-out internal error in handling headers.")); |
8b93c638 JM |
861 | } |
862 | else | |
863 | { | |
864 | *width = 0; | |
865 | *align = ui_noalign; | |
a6c47c14 | 866 | *fldno = current->field_count; |
8b93c638 JM |
867 | } |
868 | } | |
869 | ||
a6c47c14 | 870 | |
581e13c1 | 871 | /* Access to ui-out members data. */ |
8b93c638 | 872 | |
0a8fce9a | 873 | void * |
8b93c638 JM |
874 | ui_out_data (struct ui_out *uiout) |
875 | { | |
876 | return uiout->data; | |
877 | } | |
878 | ||
170b53b2 UW |
879 | /* Access table field parameters. */ |
880 | int | |
881 | ui_out_query_field (struct ui_out *uiout, int colno, | |
882 | int *width, int *alignment, char **col_name) | |
883 | { | |
884 | struct ui_out_hdr *hdr; | |
885 | ||
886 | if (!uiout->table.flag) | |
887 | return 0; | |
888 | ||
889 | for (hdr = uiout->table.header_first; hdr; hdr = hdr->next) | |
890 | if (hdr->colno == colno) | |
891 | { | |
892 | *width = hdr->width; | |
893 | *alignment = hdr->alignment; | |
894 | *col_name = hdr->col_name; | |
895 | return 1; | |
896 | } | |
897 | ||
898 | return 0; | |
899 | } | |
900 | ||
26c4b26f | 901 | /* Initialize private members at startup. */ |
8b93c638 JM |
902 | |
903 | struct ui_out * | |
89de4da4 | 904 | ui_out_new (const struct ui_out_impl *impl, void *data, |
8b93c638 JM |
905 | int flags) |
906 | { | |
70ba0933 TT |
907 | struct ui_out *uiout = XNEW (struct ui_out); |
908 | struct ui_out_level *current = XNEW (struct ui_out_level); | |
5d502164 | 909 | |
8b93c638 JM |
910 | uiout->data = data; |
911 | uiout->impl = impl; | |
912 | uiout->flags = flags; | |
bafdd3b3 AC |
913 | uiout->table.flag = 0; |
914 | uiout->table.body_flag = 0; | |
80f49b30 | 915 | uiout->level = 0; |
54eb231c PM |
916 | uiout->levels = NULL; |
917 | ||
918 | /* Create uiout->level 0, the default level. */ | |
919 | current->type = ui_out_type_tuple; | |
920 | current->field_count = 0; | |
921 | VEC_safe_push (ui_out_level_p, uiout->levels, current); | |
922 | ||
9c1fcd01 | 923 | uiout->table.id = NULL; |
bafdd3b3 AC |
924 | uiout->table.header_first = NULL; |
925 | uiout->table.header_last = NULL; | |
926 | uiout->table.header_next = NULL; | |
8b93c638 JM |
927 | return uiout; |
928 | } | |
929 | ||
b65a2bd9 SCR |
930 | /* Free UIOUT and the memory areas it references. */ |
931 | ||
932 | void | |
933 | ui_out_destroy (struct ui_out *uiout) | |
934 | { | |
54eb231c PM |
935 | int i; |
936 | struct ui_out_level *current; | |
937 | ||
938 | /* Make sure that all levels are freed in the case where levels have | |
939 | been pushed, but not popped before the ui_out object is | |
940 | destroyed. */ | |
941 | for (i = 0; | |
942 | VEC_iterate (ui_out_level_p, uiout->levels, i, current); | |
943 | ++i) | |
944 | xfree (current); | |
945 | ||
946 | VEC_free (ui_out_level_p, uiout->levels); | |
b65a2bd9 SCR |
947 | uo_data_destroy (uiout); |
948 | clear_table (uiout); | |
949 | xfree (uiout); | |
950 | } | |
951 | ||
581e13c1 | 952 | /* Standard gdb initialization hook. */ |
8b93c638 JM |
953 | |
954 | void | |
fba45db2 | 955 | _initialize_ui_out (void) |
8b93c638 JM |
956 | { |
957 | /* nothing needs to be done */ | |
958 | } |