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