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 | ||
48 | enum { MAX_UI_OUT_LEVELS = 5 }; | |
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 | ||
276 | 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 | ||
321 | 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 | ||
354 | void | |
631ec795 AC |
355 | ui_out_begin (struct ui_out *uiout, |
356 | enum ui_out_type type, | |
357 | const char *id) | |
8b93c638 | 358 | { |
80f49b30 | 359 | int new_level; |
bafdd3b3 | 360 | if (uiout->table.flag && !uiout->table.body_flag) |
8e65ff28 AC |
361 | internal_error (__FILE__, __LINE__, |
362 | "table header or table_body expected; lists must be \ | |
8b93c638 | 363 | specified after table_body."); |
a6c47c14 AC |
364 | |
365 | /* Be careful to verify the ``field'' before the new tuple/list is | |
366 | pushed onto the stack. That way the containing list/table/row is | |
367 | verified and not the newly created tuple/list. This verification | |
368 | is needed (at least) for the case where a table row entry | |
369 | contains either a tuple/list. For that case bookkeeping such as | |
370 | updating the column count or advancing to the next heading still | |
371 | needs to be performed. */ | |
372 | { | |
373 | int fldno; | |
374 | int width; | |
375 | int align; | |
376 | verify_field (uiout, &fldno, &width, &align); | |
377 | } | |
378 | ||
631ec795 | 379 | new_level = push_level (uiout, type, id); |
a6c47c14 AC |
380 | |
381 | /* If the push puts us at the same level as a table row entry, we've | |
382 | got a new table row. Put the header pointer back to the start. */ | |
383 | if (uiout->table.body_flag | |
384 | && uiout->table.entry_level == new_level) | |
bafdd3b3 | 385 | uiout->table.header_next = uiout->table.header_first; |
a6c47c14 | 386 | |
631ec795 AC |
387 | uo_begin (uiout, type, new_level, id); |
388 | } | |
389 | ||
390 | void | |
6b28c186 AC |
391 | ui_out_list_begin (struct ui_out *uiout, |
392 | const char *id) | |
631ec795 | 393 | { |
6b28c186 | 394 | ui_out_begin (uiout, ui_out_type_list, id); |
666547aa AC |
395 | } |
396 | ||
397 | void | |
398 | ui_out_tuple_begin (struct ui_out *uiout, const char *id) | |
399 | { | |
400 | ui_out_begin (uiout, ui_out_type_tuple, id); | |
631ec795 AC |
401 | } |
402 | ||
403 | void | |
404 | ui_out_end (struct ui_out *uiout, | |
405 | enum ui_out_type type) | |
406 | { | |
407 | int old_level = pop_level (uiout, type); | |
408 | uo_end (uiout, type, old_level); | |
8b93c638 JM |
409 | } |
410 | ||
411 | void | |
fba45db2 | 412 | ui_out_list_end (struct ui_out *uiout) |
8b93c638 | 413 | { |
631ec795 | 414 | ui_out_end (uiout, ui_out_type_list); |
8b93c638 JM |
415 | } |
416 | ||
666547aa AC |
417 | void |
418 | ui_out_tuple_end (struct ui_out *uiout) | |
419 | { | |
420 | ui_out_end (uiout, ui_out_type_tuple); | |
421 | } | |
422 | ||
127431f9 AC |
423 | struct ui_out_end_cleanup_data |
424 | { | |
425 | struct ui_out *uiout; | |
426 | enum ui_out_type type; | |
427 | }; | |
428 | ||
e6e0bfab | 429 | static void |
127431f9 AC |
430 | do_cleanup_end (void *data) |
431 | { | |
432 | struct ui_out_end_cleanup_data *end_cleanup_data = data; | |
433 | ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type); | |
434 | xfree (end_cleanup_data); | |
435 | } | |
436 | ||
437 | static struct cleanup * | |
438 | make_cleanup_ui_out_end (struct ui_out *uiout, | |
439 | enum ui_out_type type) | |
440 | { | |
441 | struct ui_out_end_cleanup_data *end_cleanup_data; | |
442 | end_cleanup_data = XMALLOC (struct ui_out_end_cleanup_data); | |
443 | end_cleanup_data->uiout = uiout; | |
444 | end_cleanup_data->type = type; | |
445 | return make_cleanup (do_cleanup_end, end_cleanup_data); | |
446 | } | |
447 | ||
448 | struct cleanup * | |
449 | make_cleanup_ui_out_begin_end (struct ui_out *uiout, | |
450 | enum ui_out_type type, | |
451 | const char *id) | |
e6e0bfab | 452 | { |
127431f9 AC |
453 | ui_out_begin (uiout, type, id); |
454 | return make_cleanup_ui_out_end (uiout, type); | |
e6e0bfab MK |
455 | } |
456 | ||
457 | struct cleanup * | |
666547aa AC |
458 | make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout, |
459 | const char *id) | |
460 | { | |
461 | ui_out_tuple_begin (uiout, id); | |
462 | return make_cleanup_ui_out_end (uiout, ui_out_type_tuple); | |
463 | } | |
464 | ||
465 | struct cleanup * | |
6b28c186 AC |
466 | make_cleanup_ui_out_list_begin_end (struct ui_out *uiout, |
467 | const char *id) | |
e6e0bfab | 468 | { |
6b28c186 | 469 | ui_out_list_begin (uiout, id); |
127431f9 | 470 | return make_cleanup_ui_out_end (uiout, ui_out_type_list); |
e6e0bfab MK |
471 | } |
472 | ||
8b93c638 | 473 | void |
88379baf AC |
474 | ui_out_field_int (struct ui_out *uiout, |
475 | const char *fldname, | |
476 | int value) | |
8b93c638 JM |
477 | { |
478 | int fldno; | |
479 | int width; | |
480 | int align; | |
80f49b30 | 481 | struct ui_out_level *current = current_level (uiout); |
8b93c638 | 482 | |
a6c47c14 | 483 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
484 | |
485 | uo_field_int (uiout, fldno, width, align, fldname, value); | |
486 | } | |
487 | ||
488 | void | |
88379baf AC |
489 | ui_out_field_core_addr (struct ui_out *uiout, |
490 | const char *fldname, | |
491 | CORE_ADDR address) | |
8b93c638 JM |
492 | { |
493 | char addstr[20]; | |
494 | ||
495 | /* FIXME-32x64: need a print_address_numeric with field width */ | |
496 | /* print_address_numeric (address, 1, local_stream); */ | |
497 | strcpy (addstr, local_hex_string_custom ((unsigned long) address, "08l")); | |
498 | ||
499 | ui_out_field_string (uiout, fldname, addstr); | |
500 | } | |
501 | ||
502 | void | |
88379baf AC |
503 | ui_out_field_stream (struct ui_out *uiout, |
504 | const char *fldname, | |
505 | struct ui_stream *buf) | |
8b93c638 JM |
506 | { |
507 | long length; | |
508 | char *buffer = ui_file_xstrdup (buf->stream, &length); | |
b8c9b27d | 509 | struct cleanup *old_cleanup = make_cleanup (xfree, buffer); |
8b93c638 JM |
510 | if (length > 0) |
511 | ui_out_field_string (uiout, fldname, buffer); | |
512 | else | |
513 | ui_out_field_skip (uiout, fldname); | |
514 | ui_file_rewind (buf->stream); | |
515 | do_cleanups (old_cleanup); | |
516 | } | |
517 | ||
518 | /* used to ommit a field */ | |
519 | ||
520 | void | |
88379baf AC |
521 | ui_out_field_skip (struct ui_out *uiout, |
522 | const char *fldname) | |
8b93c638 JM |
523 | { |
524 | int fldno; | |
525 | int width; | |
526 | int align; | |
8b93c638 | 527 | |
a6c47c14 | 528 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
529 | |
530 | uo_field_skip (uiout, fldno, width, align, fldname); | |
531 | } | |
532 | ||
533 | void | |
534 | ui_out_field_string (struct ui_out *uiout, | |
88379baf | 535 | const char *fldname, |
8b93c638 JM |
536 | const char *string) |
537 | { | |
538 | int fldno; | |
539 | int width; | |
540 | int align; | |
8b93c638 | 541 | |
a6c47c14 | 542 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
543 | |
544 | uo_field_string (uiout, fldno, width, align, fldname, string); | |
545 | } | |
546 | ||
547 | /* VARARGS */ | |
548 | void | |
88379baf AC |
549 | ui_out_field_fmt (struct ui_out *uiout, |
550 | const char *fldname, | |
551 | const char *format, ...) | |
8b93c638 JM |
552 | { |
553 | va_list args; | |
554 | int fldno; | |
555 | int width; | |
556 | int align; | |
8b93c638 JM |
557 | |
558 | /* will not align, but has to call anyway */ | |
a6c47c14 | 559 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
560 | |
561 | va_start (args, format); | |
562 | ||
563 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); | |
564 | ||
565 | va_end (args); | |
566 | } | |
567 | ||
568 | void | |
fba45db2 | 569 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
570 | { |
571 | uo_spaces (uiout, numspaces); | |
572 | } | |
573 | ||
574 | void | |
88379baf AC |
575 | ui_out_text (struct ui_out *uiout, |
576 | const char *string) | |
8b93c638 JM |
577 | { |
578 | uo_text (uiout, string); | |
579 | } | |
580 | ||
581 | void | |
88379baf AC |
582 | ui_out_message (struct ui_out *uiout, int verbosity, |
583 | const char *format,...) | |
8b93c638 JM |
584 | { |
585 | va_list args; | |
586 | ||
587 | va_start (args, format); | |
588 | ||
589 | uo_message (uiout, verbosity, format, args); | |
590 | ||
591 | va_end (args); | |
592 | } | |
593 | ||
594 | struct ui_stream * | |
fba45db2 | 595 | ui_out_stream_new (struct ui_out *uiout) |
8b93c638 JM |
596 | { |
597 | struct ui_stream *tempbuf; | |
598 | ||
599 | tempbuf = XMALLOC (struct ui_stream); | |
600 | tempbuf->uiout = uiout; | |
601 | tempbuf->stream = mem_fileopen (); | |
602 | return tempbuf; | |
603 | } | |
604 | ||
605 | void | |
fba45db2 | 606 | ui_out_stream_delete (struct ui_stream *buf) |
8b93c638 JM |
607 | { |
608 | ui_file_delete (buf->stream); | |
b8c9b27d | 609 | xfree (buf); |
8b93c638 JM |
610 | } |
611 | ||
612 | static void | |
613 | do_stream_delete (void *buf) | |
614 | { | |
615 | ui_out_stream_delete (buf); | |
616 | } | |
617 | ||
618 | struct cleanup * | |
619 | make_cleanup_ui_out_stream_delete (struct ui_stream *buf) | |
620 | { | |
621 | return make_cleanup (do_stream_delete, buf); | |
622 | } | |
623 | ||
624 | ||
625 | void | |
fba45db2 | 626 | ui_out_wrap_hint (struct ui_out *uiout, char *identstring) |
8b93c638 JM |
627 | { |
628 | uo_wrap_hint (uiout, identstring); | |
629 | } | |
630 | ||
631 | void | |
fba45db2 | 632 | ui_out_flush (struct ui_out *uiout) |
8b93c638 JM |
633 | { |
634 | uo_flush (uiout); | |
635 | } | |
636 | ||
637 | /* set the flags specified by the mask given */ | |
638 | int | |
fba45db2 | 639 | ui_out_set_flags (struct ui_out *uiout, int mask) |
8b93c638 | 640 | { |
5bfb05ca | 641 | int oldflags = uiout->flags; |
8b93c638 | 642 | |
b8d86de3 | 643 | uiout->flags |= mask; |
8b93c638 JM |
644 | |
645 | return oldflags; | |
646 | } | |
647 | ||
648 | /* clear the flags specified by the mask given */ | |
649 | int | |
fba45db2 | 650 | ui_out_clear_flags (struct ui_out *uiout, int mask) |
8b93c638 | 651 | { |
5bfb05ca | 652 | int oldflags = uiout->flags; |
8b93c638 JM |
653 | |
654 | uiout->flags &= ~mask; | |
655 | ||
656 | return oldflags; | |
657 | } | |
658 | ||
659 | /* test the flags against the mask given */ | |
660 | int | |
fba45db2 | 661 | ui_out_test_flags (struct ui_out *uiout, int mask) |
8b93c638 JM |
662 | { |
663 | return (uiout->flags & mask); | |
664 | } | |
665 | ||
666 | /* obtain the current verbosity level (as stablished by the | |
667 | 'set verbositylevel' command */ | |
668 | ||
669 | int | |
fba45db2 | 670 | ui_out_get_verblvl (struct ui_out *uiout) |
8b93c638 JM |
671 | { |
672 | /* FIXME: not implemented yet */ | |
673 | return 0; | |
674 | } | |
675 | ||
676 | #if 0 | |
677 | void | |
fba45db2 | 678 | ui_out_result_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
679 | { |
680 | } | |
681 | ||
682 | void | |
fba45db2 | 683 | ui_out_result_end (struct ui_out *uiout) |
8b93c638 JM |
684 | { |
685 | } | |
686 | ||
687 | void | |
fba45db2 | 688 | ui_out_info_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
689 | { |
690 | } | |
691 | ||
692 | void | |
fba45db2 | 693 | ui_out_info_end (struct ui_out *uiout) |
8b93c638 JM |
694 | { |
695 | } | |
696 | ||
697 | void | |
fba45db2 | 698 | ui_out_notify_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
699 | { |
700 | } | |
701 | ||
702 | void | |
fba45db2 | 703 | ui_out_notify_end (struct ui_out *uiout) |
8b93c638 JM |
704 | { |
705 | } | |
706 | ||
707 | void | |
fba45db2 | 708 | ui_out_error_begin (struct ui_out *uiout, char *class) |
8b93c638 JM |
709 | { |
710 | } | |
711 | ||
712 | void | |
fba45db2 | 713 | ui_out_error_end (struct ui_out *uiout) |
8b93c638 JM |
714 | { |
715 | } | |
716 | #endif | |
717 | ||
718 | #if 0 | |
719 | void | |
720 | gdb_error (ui_out * uiout, int severity, char *format,...) | |
721 | { | |
722 | va_list args; | |
723 | } | |
724 | ||
725 | void | |
10689f25 | 726 | gdb_query (struct ui_out *uiout, int qflags, char *qprompt) |
8b93c638 JM |
727 | { |
728 | } | |
729 | #endif | |
730 | ||
9dc5e2a9 AC |
731 | int |
732 | ui_out_is_mi_like_p (struct ui_out *uiout) | |
733 | { | |
734 | return uiout->impl->is_mi_like_p; | |
735 | } | |
736 | ||
8b93c638 JM |
737 | /* default gdb-out hook functions */ |
738 | ||
739 | static void | |
d63f1d40 AC |
740 | default_table_begin (struct ui_out *uiout, int nbrofcols, |
741 | int nr_rows, | |
742 | const char *tblid) | |
8b93c638 JM |
743 | { |
744 | } | |
745 | ||
746 | static void | |
fba45db2 | 747 | default_table_body (struct ui_out *uiout) |
8b93c638 JM |
748 | { |
749 | } | |
750 | ||
751 | static void | |
fba45db2 | 752 | default_table_end (struct ui_out *uiout) |
8b93c638 JM |
753 | { |
754 | } | |
755 | ||
756 | static void | |
fba45db2 | 757 | default_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
b25959ec | 758 | const char *col_name, |
e2e11a41 | 759 | const char *colhdr) |
8b93c638 JM |
760 | { |
761 | } | |
762 | ||
763 | static void | |
631ec795 AC |
764 | default_begin (struct ui_out *uiout, |
765 | enum ui_out_type type, | |
766 | int level, | |
767 | const char *id) | |
8b93c638 JM |
768 | { |
769 | } | |
770 | ||
771 | static void | |
631ec795 AC |
772 | default_end (struct ui_out *uiout, |
773 | enum ui_out_type type, | |
774 | int level) | |
8b93c638 JM |
775 | { |
776 | } | |
777 | ||
778 | static void | |
fba45db2 | 779 | default_field_int (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
780 | enum ui_align align, |
781 | const char *fldname, int value) | |
8b93c638 JM |
782 | { |
783 | } | |
784 | ||
785 | static void | |
fba45db2 | 786 | default_field_skip (struct ui_out *uiout, int fldno, int width, |
e2e11a41 | 787 | enum ui_align align, const char *fldname) |
8b93c638 JM |
788 | { |
789 | } | |
790 | ||
791 | static void | |
792 | default_field_string (struct ui_out *uiout, | |
793 | int fldno, | |
794 | int width, | |
795 | enum ui_align align, | |
e2e11a41 | 796 | const char *fldname, |
8b93c638 JM |
797 | const char *string) |
798 | { | |
799 | } | |
800 | ||
801 | static void | |
fba45db2 | 802 | default_field_fmt (struct ui_out *uiout, int fldno, int width, |
e2e11a41 AC |
803 | enum ui_align align, |
804 | const char *fldname, | |
805 | const char *format, | |
fba45db2 | 806 | va_list args) |
8b93c638 JM |
807 | { |
808 | } | |
809 | ||
810 | static void | |
fba45db2 | 811 | default_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
812 | { |
813 | } | |
814 | ||
815 | static void | |
e2e11a41 | 816 | default_text (struct ui_out *uiout, const char *string) |
8b93c638 JM |
817 | { |
818 | } | |
819 | ||
820 | static void | |
e2e11a41 AC |
821 | default_message (struct ui_out *uiout, int verbosity, |
822 | const char *format, | |
fba45db2 | 823 | va_list args) |
8b93c638 JM |
824 | { |
825 | } | |
826 | ||
827 | static void | |
fba45db2 | 828 | default_wrap_hint (struct ui_out *uiout, char *identstring) |
8b93c638 JM |
829 | { |
830 | } | |
831 | ||
832 | static void | |
fba45db2 | 833 | default_flush (struct ui_out *uiout) |
8b93c638 JM |
834 | { |
835 | } | |
836 | ||
837 | /* Interface to the implementation functions */ | |
838 | ||
839 | void | |
88379baf | 840 | uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 841 | int nr_rows, |
88379baf | 842 | const char *tblid) |
8b93c638 JM |
843 | { |
844 | if (!uiout->impl->table_begin) | |
845 | return; | |
d63f1d40 | 846 | uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); |
8b93c638 JM |
847 | } |
848 | ||
849 | void | |
850 | uo_table_body (struct ui_out *uiout) | |
851 | { | |
852 | if (!uiout->impl->table_body) | |
853 | return; | |
854 | uiout->impl->table_body (uiout); | |
855 | } | |
856 | ||
857 | void | |
858 | uo_table_end (struct ui_out *uiout) | |
859 | { | |
860 | if (!uiout->impl->table_end) | |
861 | return; | |
862 | uiout->impl->table_end (uiout); | |
863 | } | |
864 | ||
865 | void | |
88379baf | 866 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, |
b25959ec | 867 | const char *col_name, |
88379baf | 868 | const char *colhdr) |
8b93c638 JM |
869 | { |
870 | if (!uiout->impl->table_header) | |
871 | return; | |
b25959ec | 872 | uiout->impl->table_header (uiout, width, align, col_name, colhdr); |
8b93c638 JM |
873 | } |
874 | ||
875 | void | |
631ec795 AC |
876 | uo_begin (struct ui_out *uiout, |
877 | enum ui_out_type type, | |
878 | int level, | |
879 | const char *id) | |
8b93c638 | 880 | { |
631ec795 | 881 | if (uiout->impl->begin == NULL) |
8b93c638 | 882 | return; |
631ec795 | 883 | uiout->impl->begin (uiout, type, level, id); |
8b93c638 JM |
884 | } |
885 | ||
886 | void | |
631ec795 AC |
887 | uo_end (struct ui_out *uiout, |
888 | enum ui_out_type type, | |
889 | int level) | |
8b93c638 | 890 | { |
631ec795 | 891 | if (uiout->impl->end == NULL) |
8b93c638 | 892 | return; |
631ec795 | 893 | uiout->impl->end (uiout, type, level); |
8b93c638 JM |
894 | } |
895 | ||
896 | void | |
88379baf AC |
897 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
898 | const char *fldname, | |
899 | int value) | |
8b93c638 JM |
900 | { |
901 | if (!uiout->impl->field_int) | |
902 | return; | |
903 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); | |
904 | } | |
905 | ||
906 | void | |
88379baf AC |
907 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
908 | const char *fldname) | |
8b93c638 JM |
909 | { |
910 | if (!uiout->impl->field_skip) | |
911 | return; | |
912 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); | |
913 | } | |
914 | ||
915 | void | |
916 | uo_field_string (struct ui_out *uiout, int fldno, int width, | |
88379baf AC |
917 | enum ui_align align, |
918 | const char *fldname, | |
919 | const char *string) | |
8b93c638 JM |
920 | { |
921 | if (!uiout->impl->field_string) | |
922 | return; | |
923 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); | |
924 | } | |
925 | ||
926 | void | |
88379baf AC |
927 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
928 | const char *fldname, | |
929 | const char *format, | |
930 | va_list args) | |
8b93c638 JM |
931 | { |
932 | if (!uiout->impl->field_fmt) | |
933 | return; | |
934 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); | |
935 | } | |
936 | ||
937 | void | |
938 | uo_spaces (struct ui_out *uiout, int numspaces) | |
939 | { | |
940 | if (!uiout->impl->spaces) | |
941 | return; | |
942 | uiout->impl->spaces (uiout, numspaces); | |
943 | } | |
944 | ||
945 | void | |
88379baf AC |
946 | uo_text (struct ui_out *uiout, |
947 | const char *string) | |
8b93c638 JM |
948 | { |
949 | if (!uiout->impl->text) | |
950 | return; | |
951 | uiout->impl->text (uiout, string); | |
952 | } | |
953 | ||
954 | void | |
88379baf AC |
955 | uo_message (struct ui_out *uiout, int verbosity, |
956 | const char *format, | |
957 | va_list args) | |
8b93c638 JM |
958 | { |
959 | if (!uiout->impl->message) | |
960 | return; | |
961 | uiout->impl->message (uiout, verbosity, format, args); | |
962 | } | |
963 | ||
964 | void | |
965 | uo_wrap_hint (struct ui_out *uiout, char *identstring) | |
966 | { | |
967 | if (!uiout->impl->wrap_hint) | |
968 | return; | |
969 | uiout->impl->wrap_hint (uiout, identstring); | |
970 | } | |
971 | ||
972 | void | |
973 | uo_flush (struct ui_out *uiout) | |
974 | { | |
975 | if (!uiout->impl->flush) | |
976 | return; | |
977 | uiout->impl->flush (uiout); | |
978 | } | |
979 | ||
980 | /* local functions */ | |
981 | ||
982 | /* list of column headers manipulation routines */ | |
983 | ||
984 | static void | |
fba45db2 | 985 | clear_header_list (struct ui_out *uiout) |
8b93c638 | 986 | { |
bafdd3b3 | 987 | while (uiout->table.header_first != NULL) |
8b93c638 | 988 | { |
bafdd3b3 AC |
989 | uiout->table.header_next = uiout->table.header_first; |
990 | uiout->table.header_first = uiout->table.header_first->next; | |
991 | if (uiout->table.header_next->colhdr != NULL) | |
992 | xfree (uiout->table.header_next->colhdr); | |
993 | xfree (uiout->table.header_next); | |
8b93c638 | 994 | } |
bafdd3b3 AC |
995 | gdb_assert (uiout->table.header_first == NULL); |
996 | uiout->table.header_last = NULL; | |
997 | uiout->table.header_next = NULL; | |
8b93c638 JM |
998 | } |
999 | ||
1000 | static void | |
1001 | append_header_to_list (struct ui_out *uiout, | |
1002 | int width, | |
1003 | int alignment, | |
b25959ec | 1004 | const char *col_name, |
88379baf | 1005 | const char *colhdr) |
8b93c638 JM |
1006 | { |
1007 | struct ui_out_hdr *temphdr; | |
1008 | ||
1009 | temphdr = XMALLOC (struct ui_out_hdr); | |
1010 | temphdr->width = width; | |
1011 | temphdr->alignment = alignment; | |
1012 | /* we have to copy the column title as the original may be an automatic */ | |
1013 | if (colhdr != NULL) | |
b25959ec AC |
1014 | temphdr->colhdr = xstrdup (colhdr); |
1015 | else | |
1016 | temphdr->colhdr = NULL; | |
1017 | if (col_name != NULL) | |
1018 | temphdr->col_name = xstrdup (colhdr); | |
1019 | else | |
1020 | temphdr->col_name = xstrdup (colhdr); | |
8b93c638 | 1021 | temphdr->next = NULL; |
bafdd3b3 | 1022 | if (uiout->table.header_first == NULL) |
8b93c638 JM |
1023 | { |
1024 | temphdr->colno = 1; | |
bafdd3b3 AC |
1025 | uiout->table.header_first = temphdr; |
1026 | uiout->table.header_last = temphdr; | |
8b93c638 JM |
1027 | } |
1028 | else | |
1029 | { | |
bafdd3b3 AC |
1030 | temphdr->colno = uiout->table.header_last->colno + 1; |
1031 | uiout->table.header_last->next = temphdr; | |
1032 | uiout->table.header_last = temphdr; | |
8b93c638 | 1033 | } |
bafdd3b3 | 1034 | uiout->table.header_next = uiout->table.header_last; |
8b93c638 JM |
1035 | } |
1036 | ||
bafdd3b3 AC |
1037 | /* Extract the format information for the NEXT header and and advance |
1038 | the header pointer. Return 0 if there was no next header. */ | |
8b93c638 JM |
1039 | |
1040 | static int | |
bafdd3b3 | 1041 | get_next_header (struct ui_out *uiout, |
8b93c638 JM |
1042 | int *colno, |
1043 | int *width, | |
1044 | int *alignment, | |
1045 | char **colhdr) | |
1046 | { | |
bafdd3b3 AC |
1047 | /* There may be no headers at all or we may have used all columns. */ |
1048 | if (uiout->table.header_next == NULL) | |
8b93c638 | 1049 | return 0; |
bafdd3b3 AC |
1050 | *colno = uiout->table.header_next->colno; |
1051 | *width = uiout->table.header_next->width; | |
1052 | *alignment = uiout->table.header_next->alignment; | |
1053 | *colhdr = uiout->table.header_next->colhdr; | |
1054 | /* Advance the header pointer to the next entry. */ | |
1055 | uiout->table.header_next = uiout->table.header_next->next; | |
8b93c638 JM |
1056 | return 1; |
1057 | } | |
1058 | ||
a6c47c14 AC |
1059 | |
1060 | /* Verify that the field/tuple/list is correctly positioned. Return | |
1061 | the field number and corresponding alignment (if | |
1062 | available/applicable). */ | |
8b93c638 JM |
1063 | |
1064 | static void | |
a6c47c14 | 1065 | verify_field (struct ui_out *uiout, int *fldno, int *width, int *align) |
8b93c638 | 1066 | { |
a6c47c14 AC |
1067 | struct ui_out_level *current = current_level (uiout); |
1068 | char *text; | |
1069 | ||
bafdd3b3 | 1070 | if (uiout->table.flag) |
8b93c638 | 1071 | { |
bafdd3b3 | 1072 | if (!uiout->table.body_flag) |
8e65ff28 AC |
1073 | internal_error (__FILE__, __LINE__, |
1074 | "table_body missing; table fields must be \ | |
8b93c638 | 1075 | specified after table_body and inside a list."); |
a6c47c14 AC |
1076 | /* NOTE: cagney/2001-12-08: There was a check here to ensure |
1077 | that this code was only executed when uiout->level was | |
1078 | greater than zero. That no longer applies - this code is run | |
1079 | before each table row tuple is started and at that point the | |
1080 | level is zero. */ | |
8b93c638 | 1081 | } |
8b93c638 | 1082 | |
a6c47c14 | 1083 | current->field_count += 1; |
8b93c638 | 1084 | |
a6c47c14 AC |
1085 | if (uiout->table.body_flag |
1086 | && uiout->table.entry_level == uiout->level | |
1087 | && get_next_header (uiout, fldno, width, align, &text)) | |
8b93c638 | 1088 | { |
a6c47c14 | 1089 | if (*fldno != current->field_count) |
8e65ff28 AC |
1090 | internal_error (__FILE__, __LINE__, |
1091 | "ui-out internal error in handling headers."); | |
8b93c638 JM |
1092 | } |
1093 | else | |
1094 | { | |
1095 | *width = 0; | |
1096 | *align = ui_noalign; | |
a6c47c14 | 1097 | *fldno = current->field_count; |
8b93c638 JM |
1098 | } |
1099 | } | |
1100 | ||
a6c47c14 | 1101 | |
8b93c638 JM |
1102 | /* access to ui_out format private members */ |
1103 | ||
1104 | void | |
fba45db2 | 1105 | ui_out_get_field_separator (struct ui_out *uiout) |
8b93c638 JM |
1106 | { |
1107 | } | |
1108 | ||
1109 | /* Access to ui-out members data */ | |
1110 | ||
1111 | struct ui_out_data * | |
1112 | ui_out_data (struct ui_out *uiout) | |
1113 | { | |
1114 | return uiout->data; | |
1115 | } | |
1116 | ||
1117 | /* initalize private members at startup */ | |
1118 | ||
1119 | struct ui_out * | |
1120 | ui_out_new (struct ui_out_impl *impl, | |
1121 | struct ui_out_data *data, | |
1122 | int flags) | |
1123 | { | |
1124 | struct ui_out *uiout = XMALLOC (struct ui_out); | |
1125 | uiout->data = data; | |
1126 | uiout->impl = impl; | |
1127 | uiout->flags = flags; | |
bafdd3b3 AC |
1128 | uiout->table.flag = 0; |
1129 | uiout->table.body_flag = 0; | |
80f49b30 AC |
1130 | uiout->level = 0; |
1131 | memset (uiout->levels, 0, sizeof (uiout->levels)); | |
bafdd3b3 AC |
1132 | uiout->table.header_first = NULL; |
1133 | uiout->table.header_last = NULL; | |
1134 | uiout->table.header_next = NULL; | |
8b93c638 JM |
1135 | return uiout; |
1136 | } | |
1137 | ||
1138 | /* standard gdb initialization hook */ | |
1139 | ||
1140 | void | |
fba45db2 | 1141 | _initialize_ui_out (void) |
8b93c638 JM |
1142 | { |
1143 | /* nothing needs to be done */ | |
1144 | } |