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