Commit | Line | Data |
---|---|---|
8b93c638 | 1 | /* Output generating routines for GDB. |
349c5d5f | 2 | |
618f726f | 3 | Copyright (C) 1999-2016 Free Software Foundation, Inc. |
349c5d5f | 4 | |
8b93c638 JM |
5 | Contributed by Cygnus Solutions. |
6 | Written by Fernando Nasser for Cygnus. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
8b93c638 JM |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8b93c638 JM |
22 | |
23 | #include "defs.h" | |
8b93c638 JM |
24 | #include "expression.h" /* For language.h */ |
25 | #include "language.h" | |
26 | #include "ui-out.h" | |
27 | ||
56df3084 SM |
28 | #include <vector> |
29 | #include <memory> | |
95a23284 | 30 | #include <string> |
56df3084 | 31 | |
37e20dd6 | 32 | /* A header of a ui_out_table. */ |
8b93c638 | 33 | |
37e20dd6 SM |
34 | class ui_out_hdr |
35 | { | |
36 | public: | |
37 | ||
38 | explicit ui_out_hdr (int number, int min_width, ui_align alignment, | |
39 | const std::string &name, const std::string &header) | |
40 | : m_number (number), | |
41 | m_min_width (min_width), | |
42 | m_alignment (alignment), | |
43 | m_name (name), | |
44 | m_header (header) | |
8b93c638 | 45 | { |
37e20dd6 SM |
46 | } |
47 | ||
48 | int number () const | |
49 | { | |
50 | return m_number; | |
51 | } | |
52 | ||
53 | int min_width () const | |
54 | { | |
55 | return m_min_width; | |
56 | } | |
57 | ||
58 | ui_align alignment () const | |
59 | { | |
60 | return m_alignment; | |
61 | } | |
62 | ||
63 | const std::string &header () const | |
64 | { | |
65 | return m_header; | |
66 | } | |
67 | ||
68 | const std::string &name () const | |
69 | { | |
70 | return m_name; | |
71 | } | |
72 | ||
73 | private: | |
74 | ||
75 | /* The number of the table column this header represents, 1-based. */ | |
76 | int m_number; | |
77 | ||
78 | /* Minimal column width in characters. May or may not be applicable, | |
79 | depending on the actual implementation of ui_out. */ | |
80 | int m_min_width; | |
81 | ||
82 | /* Alignment of the content in the column. May or may not be applicable, | |
83 | depending on the actual implementation of ui_out. */ | |
84 | ui_align m_alignment; | |
85 | ||
86 | /* Internal column name, used to internally refer to the column. */ | |
87 | std::string m_name; | |
88 | ||
89 | /* Printed header text of the column. */ | |
90 | std::string m_header; | |
91 | }; | |
8b93c638 | 92 | |
909c0aa5 SM |
93 | /* A level of nesting (either a list or a tuple) in a ui_out output. */ |
94 | ||
95 | class ui_out_level | |
96 | { | |
97 | public: | |
98 | ||
99 | explicit ui_out_level (ui_out_type type) | |
100 | : m_type (type), | |
101 | m_field_count (0) | |
80f49b30 | 102 | { |
909c0aa5 SM |
103 | } |
104 | ||
105 | ui_out_type type () const | |
106 | { | |
107 | return m_type; | |
108 | } | |
109 | ||
110 | int field_count () const | |
111 | { | |
112 | return m_field_count; | |
113 | } | |
114 | ||
115 | void inc_field_count () | |
116 | { | |
117 | m_field_count++; | |
118 | } | |
119 | ||
120 | private: | |
121 | ||
122 | /* The type of this level. */ | |
123 | ui_out_type m_type; | |
124 | ||
125 | /* Count each field; the first element is for non-list fields. */ | |
126 | int m_field_count; | |
127 | }; | |
80f49b30 | 128 | |
bafdd3b3 AC |
129 | /* Tables are special. Maintain a separate structure that tracks |
130 | their state. At present an output can only contain a single table | |
131 | but that restriction might eventually be lifted. */ | |
132 | ||
36d18bc5 | 133 | class ui_out_table |
bafdd3b3 | 134 | { |
36d18bc5 SM |
135 | public: |
136 | ||
137 | /* States (steps) of a table generation. */ | |
138 | ||
139 | enum class state | |
140 | { | |
141 | /* We are generating the table headers. */ | |
142 | HEADERS, | |
143 | ||
144 | /* We are generating the table body. */ | |
145 | BODY, | |
146 | }; | |
147 | ||
148 | explicit ui_out_table (int entry_level, int nr_cols, const std::string &id) | |
149 | : m_state (state::HEADERS), | |
150 | m_entry_level (entry_level), | |
151 | m_nr_cols (nr_cols), | |
152 | m_id (id) | |
153 | { | |
154 | } | |
155 | ||
156 | /* Start building the body of the table. */ | |
157 | ||
158 | void start_body (); | |
159 | ||
160 | /* Add a new header to the table. */ | |
161 | ||
162 | void append_header (int width, ui_align alignment, | |
163 | const std::string &col_name, const std::string &col_hdr); | |
bafdd3b3 | 164 | |
36d18bc5 SM |
165 | void start_row (); |
166 | ||
167 | /* Extract the format information for the next header and advance | |
168 | the header iterator. Return false if there was no next header. */ | |
169 | ||
170 | bool get_next_header (int *colno, int *width, ui_align *alignment, | |
171 | const char **col_hdr); | |
172 | ||
173 | bool query_field (int colno, int *width, int *alignment, | |
174 | const char **col_name) const; | |
175 | ||
176 | state current_state () const; | |
177 | ||
178 | int entry_level () const; | |
179 | ||
180 | private: | |
181 | ||
182 | state m_state; | |
bafdd3b3 | 183 | |
a6c47c14 AC |
184 | /* The level at which each entry of the table is to be found. A row |
185 | (a tuple) is made up of entries. Consequently ENTRY_LEVEL is one | |
186 | above that of the table. */ | |
36d18bc5 | 187 | int m_entry_level; |
a6c47c14 | 188 | |
bafdd3b3 | 189 | /* Number of table columns (as specified in the table_begin call). */ |
36d18bc5 | 190 | int m_nr_cols; |
bafdd3b3 AC |
191 | |
192 | /* String identifying the table (as specified in the table_begin | |
193 | call). */ | |
36d18bc5 | 194 | std::string m_id; |
bafdd3b3 | 195 | |
78afa7f8 | 196 | /* Pointers to the column headers. */ |
36d18bc5 | 197 | std::vector<std::unique_ptr<ui_out_hdr>> m_headers; |
bafdd3b3 | 198 | |
78afa7f8 | 199 | /* Iterator over the headers vector, used when printing successive fields. */ |
36d18bc5 | 200 | std::vector<std::unique_ptr<ui_out_hdr>>::const_iterator m_headers_iterator; |
bafdd3b3 AC |
201 | }; |
202 | ||
36d18bc5 SM |
203 | /* See ui-out.h. */ |
204 | ||
205 | void ui_out_table::start_body () | |
206 | { | |
207 | if (m_state != state::HEADERS) | |
208 | internal_error (__FILE__, __LINE__, | |
209 | _("extra table_body call not allowed; there must be only " | |
210 | "one table_body after a table_begin and before a " | |
211 | "table_end.")); | |
212 | ||
213 | /* Check if the number of defined headers matches the number of expected | |
214 | columns. */ | |
215 | if (m_headers.size () != m_nr_cols) | |
216 | internal_error (__FILE__, __LINE__, | |
217 | _("number of headers differ from number of table " | |
218 | "columns.")); | |
219 | ||
220 | m_state = state::BODY; | |
221 | m_headers_iterator = m_headers.begin (); | |
222 | } | |
223 | ||
224 | /* See ui-out.h. */ | |
225 | ||
226 | void ui_out_table::append_header (int width, ui_align alignment, | |
227 | const std::string &col_name, | |
228 | const std::string &col_hdr) | |
229 | { | |
230 | if (m_state != state::HEADERS) | |
231 | internal_error (__FILE__, __LINE__, | |
232 | _("table header must be specified after table_begin and " | |
233 | "before table_body.")); | |
234 | ||
235 | std::unique_ptr<ui_out_hdr> header (new ui_out_hdr (m_headers.size () + 1, | |
236 | width, alignment, | |
237 | col_name, col_hdr)); | |
238 | ||
239 | m_headers.push_back (std::move (header)); | |
240 | } | |
241 | ||
242 | /* See ui-out.h. */ | |
243 | ||
244 | void ui_out_table::start_row () | |
245 | { | |
246 | m_headers_iterator = m_headers.begin (); | |
247 | } | |
248 | ||
249 | /* See ui-out.h. */ | |
250 | ||
251 | bool ui_out_table::get_next_header (int *colno, int *width, ui_align *alignment, | |
252 | const char **col_hdr) | |
253 | { | |
254 | /* There may be no headers at all or we may have used all columns. */ | |
255 | if (m_headers_iterator == m_headers.end ()) | |
256 | return false; | |
257 | ||
258 | ui_out_hdr *hdr = m_headers_iterator->get (); | |
259 | ||
260 | *colno = hdr->number (); | |
261 | *width = hdr->min_width (); | |
262 | *alignment = hdr->alignment (); | |
263 | *col_hdr = hdr->header ().c_str (); | |
264 | ||
265 | /* Advance the header pointer to the next entry. */ | |
266 | m_headers_iterator++; | |
267 | ||
268 | return true; | |
269 | } | |
270 | ||
271 | /* See ui-out.h. */ | |
272 | ||
273 | bool ui_out_table::query_field (int colno, int *width, int *alignment, | |
274 | const char **col_name) const | |
275 | { | |
276 | /* Column numbers are 1-based, so convert to 0-based index. */ | |
277 | int index = colno - 1; | |
278 | ||
279 | if (index >= 0 && index < m_headers.size ()) | |
280 | { | |
281 | ui_out_hdr *hdr = m_headers[index].get (); | |
282 | ||
283 | gdb_assert (colno == hdr->number ()); | |
284 | ||
285 | *width = hdr->min_width (); | |
286 | *alignment = hdr->alignment (); | |
287 | *col_name = hdr->name ().c_str (); | |
288 | ||
289 | return true; | |
290 | } | |
291 | else | |
292 | return false; | |
293 | } | |
294 | ||
295 | /* See ui-out.h. */ | |
296 | ||
297 | ui_out_table::state ui_out_table::current_state () const | |
298 | { | |
299 | return m_state; | |
300 | } | |
301 | ||
302 | /* See ui-out.h. */ | |
303 | ||
304 | int ui_out_table::entry_level () const | |
305 | { | |
306 | return m_entry_level; | |
307 | } | |
bafdd3b3 | 308 | |
8b93c638 | 309 | /* The ui_out structure */ |
8b93c638 JM |
310 | |
311 | struct ui_out | |
312 | { | |
313 | int flags; | |
581e13c1 | 314 | /* Specific implementation of ui-out. */ |
89de4da4 | 315 | const struct ui_out_impl *impl; |
0a8fce9a | 316 | void *data; |
8b93c638 | 317 | |
54eb231c | 318 | /* Vector to store and track the ui-out levels. */ |
56df3084 | 319 | std::vector<std::unique_ptr<ui_out_level>> levels; |
8b93c638 | 320 | |
33b2fac6 SM |
321 | int level () const |
322 | { | |
323 | return this->levels.size (); | |
324 | } | |
325 | ||
bafdd3b3 | 326 | /* A table, if any. At present only a single table is supported. */ |
36d18bc5 | 327 | std::unique_ptr<ui_out_table> table; |
8b93c638 JM |
328 | }; |
329 | ||
581e13c1 | 330 | /* The current (inner most) level. */ |
909c0aa5 | 331 | static ui_out_level * |
80f49b30 AC |
332 | current_level (struct ui_out *uiout) |
333 | { | |
33b2fac6 | 334 | return uiout->levels.back ().get (); |
80f49b30 AC |
335 | } |
336 | ||
33b2fac6 SM |
337 | /* Create a new level, of TYPE. */ |
338 | static void | |
80f49b30 | 339 | push_level (struct ui_out *uiout, |
49d06418 | 340 | enum ui_out_type type) |
80f49b30 | 341 | { |
909c0aa5 | 342 | std::unique_ptr<ui_out_level> level (new ui_out_level (type)); |
56df3084 | 343 | |
909c0aa5 | 344 | uiout->levels.push_back (std::move (level)); |
80f49b30 AC |
345 | } |
346 | ||
33b2fac6 SM |
347 | /* Discard the current level. TYPE is the type of the level being |
348 | discarded. */ | |
349 | static void | |
631ec795 AC |
350 | pop_level (struct ui_out *uiout, |
351 | enum ui_out_type type) | |
80f49b30 | 352 | { |
581e13c1 | 353 | /* We had better not underflow the buffer. */ |
33b2fac6 | 354 | gdb_assert (uiout->level () > 0); |
909c0aa5 | 355 | gdb_assert (current_level (uiout)->type () == type); |
56df3084 SM |
356 | |
357 | uiout->levels.pop_back (); | |
80f49b30 AC |
358 | } |
359 | ||
581e13c1 | 360 | /* These are the interfaces to implementation functions. */ |
8b93c638 | 361 | |
88379baf | 362 | static void uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 363 | int nr_rows, const char *tblid); |
8b93c638 JM |
364 | static void uo_table_body (struct ui_out *uiout); |
365 | static void uo_table_end (struct ui_out *uiout); | |
366 | static void uo_table_header (struct ui_out *uiout, int width, | |
c5209615 SM |
367 | enum ui_align align, |
368 | const std::string &col_name, | |
369 | const std::string &col_hdr); | |
631ec795 AC |
370 | static void uo_begin (struct ui_out *uiout, |
371 | enum ui_out_type type, | |
33b2fac6 | 372 | const char *id); |
631ec795 | 373 | static void uo_end (struct ui_out *uiout, |
33b2fac6 | 374 | enum ui_out_type type); |
8b93c638 | 375 | static void uo_field_int (struct ui_out *uiout, int fldno, int width, |
88379baf | 376 | enum ui_align align, const char *fldname, int value); |
8b93c638 | 377 | static void uo_field_skip (struct ui_out *uiout, int fldno, int width, |
88379baf | 378 | enum ui_align align, const char *fldname); |
8b93c638 | 379 | static void uo_field_fmt (struct ui_out *uiout, int fldno, int width, |
88379baf | 380 | enum ui_align align, const char *fldname, |
bee0189a | 381 | const char *format, va_list args) |
a0b31db1 | 382 | ATTRIBUTE_PRINTF (6, 0); |
8b93c638 | 383 | static void uo_spaces (struct ui_out *uiout, int numspaces); |
88379baf | 384 | static void uo_text (struct ui_out *uiout, const char *string); |
7fb048a2 | 385 | static void uo_message (struct ui_out *uiout, |
bee0189a | 386 | const char *format, va_list args) |
7fb048a2 | 387 | ATTRIBUTE_PRINTF (2, 0); |
d2c0eef4 | 388 | static void uo_wrap_hint (struct ui_out *uiout, const char *identstring); |
8b93c638 | 389 | static void uo_flush (struct ui_out *uiout); |
0fac0b41 | 390 | static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); |
8b93c638 JM |
391 | |
392 | /* Prototypes for local functions */ | |
393 | ||
a6c47c14 | 394 | static void verify_field (struct ui_out *uiout, int *fldno, int *width, |
f486487f | 395 | enum ui_align *align); |
8b93c638 | 396 | |
8b93c638 JM |
397 | /* exported functions (ui_out API) */ |
398 | ||
581e13c1 | 399 | /* Mark beginning of a table. */ |
8b93c638 | 400 | |
3b31d625 | 401 | static void |
36d18bc5 | 402 | ui_out_table_begin (struct ui_out *uiout, int nr_cols, |
95a23284 | 403 | int nr_rows, const std::string &tblid) |
8b93c638 | 404 | { |
36d18bc5 | 405 | if (uiout->table != nullptr) |
8e65ff28 | 406 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
407 | _("tables cannot be nested; table_begin found before \ |
408 | previous table_end.")); | |
8b93c638 | 409 | |
36d18bc5 SM |
410 | uiout->table.reset ( |
411 | new ui_out_table (uiout->level () + 1, nr_cols, tblid)); | |
95a23284 | 412 | |
36d18bc5 | 413 | uo_table_begin (uiout, nr_cols, nr_rows, tblid.c_str ()); |
8b93c638 JM |
414 | } |
415 | ||
416 | void | |
fba45db2 | 417 | ui_out_table_body (struct ui_out *uiout) |
8b93c638 | 418 | { |
36d18bc5 | 419 | if (uiout->table == nullptr) |
8e65ff28 | 420 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
421 | _("table_body outside a table is not valid; it must be \ |
422 | after a table_begin and before a table_end.")); | |
77a179e7 | 423 | |
36d18bc5 | 424 | uiout->table->start_body (); |
8b93c638 JM |
425 | |
426 | uo_table_body (uiout); | |
427 | } | |
428 | ||
3b31d625 | 429 | static void |
fba45db2 | 430 | ui_out_table_end (struct ui_out *uiout) |
8b93c638 | 431 | { |
36d18bc5 | 432 | if (uiout->table == nullptr) |
8e65ff28 | 433 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 434 | _("misplaced table_end or missing table_begin.")); |
8b93c638 | 435 | |
8b93c638 | 436 | uo_table_end (uiout); |
36d18bc5 SM |
437 | |
438 | uiout->table = nullptr; | |
8b93c638 JM |
439 | } |
440 | ||
441 | void | |
fba45db2 | 442 | ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
c5209615 | 443 | const std::string &col_name, const std::string &col_hdr) |
8b93c638 | 444 | { |
36d18bc5 | 445 | if (uiout->table == nullptr) |
8e65ff28 | 446 | internal_error (__FILE__, __LINE__, |
36d18bc5 SM |
447 | _("table_header outside a table is not valid; it must be " |
448 | "after a table_begin and before a table_body.")); | |
8b93c638 | 449 | |
36d18bc5 | 450 | uiout->table->append_header (width, alignment, col_name, col_hdr); |
8b93c638 | 451 | |
c5209615 | 452 | uo_table_header (uiout, width, alignment, col_name, col_hdr); |
8b93c638 JM |
453 | } |
454 | ||
3b31d625 EZ |
455 | static void |
456 | do_cleanup_table_end (void *data) | |
457 | { | |
19ba03f4 | 458 | struct ui_out *ui_out = (struct ui_out *) data; |
3b31d625 EZ |
459 | |
460 | ui_out_table_end (ui_out); | |
461 | } | |
462 | ||
463 | struct cleanup * | |
464 | make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out, int nr_cols, | |
465 | int nr_rows, const char *tblid) | |
466 | { | |
467 | ui_out_table_begin (ui_out, nr_cols, nr_rows, tblid); | |
468 | return make_cleanup (do_cleanup_table_end, ui_out); | |
469 | } | |
470 | ||
8b93c638 | 471 | void |
631ec795 AC |
472 | ui_out_begin (struct ui_out *uiout, |
473 | enum ui_out_type type, | |
474 | const char *id) | |
8b93c638 | 475 | { |
a6c47c14 AC |
476 | /* Be careful to verify the ``field'' before the new tuple/list is |
477 | pushed onto the stack. That way the containing list/table/row is | |
478 | verified and not the newly created tuple/list. This verification | |
479 | is needed (at least) for the case where a table row entry | |
480 | contains either a tuple/list. For that case bookkeeping such as | |
481 | updating the column count or advancing to the next heading still | |
482 | needs to be performed. */ | |
483 | { | |
484 | int fldno; | |
485 | int width; | |
f486487f | 486 | enum ui_align align; |
5d502164 | 487 | |
a6c47c14 AC |
488 | verify_field (uiout, &fldno, &width, &align); |
489 | } | |
490 | ||
33b2fac6 | 491 | push_level (uiout, type); |
a6c47c14 AC |
492 | |
493 | /* If the push puts us at the same level as a table row entry, we've | |
494 | got a new table row. Put the header pointer back to the start. */ | |
36d18bc5 SM |
495 | if (uiout->table != nullptr |
496 | && uiout->table->current_state () == ui_out_table::state::BODY | |
497 | && uiout->table->entry_level () == uiout->level ()) | |
498 | uiout->table->start_row (); | |
a6c47c14 | 499 | |
33b2fac6 | 500 | uo_begin (uiout, type, id); |
631ec795 AC |
501 | } |
502 | ||
631ec795 AC |
503 | void |
504 | ui_out_end (struct ui_out *uiout, | |
505 | enum ui_out_type type) | |
506 | { | |
33b2fac6 | 507 | pop_level (uiout, type); |
5d502164 | 508 | |
33b2fac6 | 509 | uo_end (uiout, type); |
8b93c638 JM |
510 | } |
511 | ||
127431f9 AC |
512 | struct ui_out_end_cleanup_data |
513 | { | |
514 | struct ui_out *uiout; | |
515 | enum ui_out_type type; | |
516 | }; | |
517 | ||
e6e0bfab | 518 | static void |
127431f9 AC |
519 | do_cleanup_end (void *data) |
520 | { | |
19ba03f4 SM |
521 | struct ui_out_end_cleanup_data *end_cleanup_data |
522 | = (struct ui_out_end_cleanup_data *) data; | |
5d502164 | 523 | |
127431f9 AC |
524 | ui_out_end (end_cleanup_data->uiout, end_cleanup_data->type); |
525 | xfree (end_cleanup_data); | |
526 | } | |
527 | ||
528 | static struct cleanup * | |
529 | make_cleanup_ui_out_end (struct ui_out *uiout, | |
530 | enum ui_out_type type) | |
531 | { | |
532 | struct ui_out_end_cleanup_data *end_cleanup_data; | |
5d502164 | 533 | |
70ba0933 | 534 | end_cleanup_data = XNEW (struct ui_out_end_cleanup_data); |
127431f9 AC |
535 | end_cleanup_data->uiout = uiout; |
536 | end_cleanup_data->type = type; | |
537 | return make_cleanup (do_cleanup_end, end_cleanup_data); | |
538 | } | |
539 | ||
e6e0bfab | 540 | struct cleanup * |
666547aa AC |
541 | make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout, |
542 | const char *id) | |
543 | { | |
3b31d625 | 544 | ui_out_begin (uiout, ui_out_type_tuple, id); |
666547aa AC |
545 | return make_cleanup_ui_out_end (uiout, ui_out_type_tuple); |
546 | } | |
547 | ||
548 | struct cleanup * | |
6b28c186 AC |
549 | make_cleanup_ui_out_list_begin_end (struct ui_out *uiout, |
550 | const char *id) | |
e6e0bfab | 551 | { |
3b31d625 | 552 | ui_out_begin (uiout, ui_out_type_list, id); |
127431f9 | 553 | return make_cleanup_ui_out_end (uiout, ui_out_type_list); |
e6e0bfab MK |
554 | } |
555 | ||
8b93c638 | 556 | void |
88379baf AC |
557 | ui_out_field_int (struct ui_out *uiout, |
558 | const char *fldname, | |
559 | int value) | |
8b93c638 JM |
560 | { |
561 | int fldno; | |
562 | int width; | |
f486487f | 563 | enum ui_align align; |
8b93c638 | 564 | |
a6c47c14 | 565 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
566 | |
567 | uo_field_int (uiout, fldno, width, align, fldname, value); | |
568 | } | |
569 | ||
52c6a6ac JJ |
570 | void |
571 | ui_out_field_fmt_int (struct ui_out *uiout, | |
572 | int input_width, | |
573 | enum ui_align input_align, | |
574 | const char *fldname, | |
575 | int value) | |
576 | { | |
577 | int fldno; | |
578 | int width; | |
f486487f | 579 | enum ui_align align; |
52c6a6ac JJ |
580 | |
581 | verify_field (uiout, &fldno, &width, &align); | |
582 | ||
583 | uo_field_int (uiout, fldno, input_width, input_align, fldname, value); | |
584 | } | |
585 | ||
15230f37 TJB |
586 | /* Documented in ui-out.h. */ |
587 | ||
8b93c638 | 588 | void |
88379baf AC |
589 | ui_out_field_core_addr (struct ui_out *uiout, |
590 | const char *fldname, | |
5af949e3 | 591 | struct gdbarch *gdbarch, |
88379baf | 592 | CORE_ADDR address) |
8b93c638 | 593 | { |
f1310107 TJB |
594 | ui_out_field_string (uiout, fldname, |
595 | print_core_address (gdbarch, address)); | |
8b93c638 JM |
596 | } |
597 | ||
598 | void | |
88379baf AC |
599 | ui_out_field_stream (struct ui_out *uiout, |
600 | const char *fldname, | |
f99d8bf4 | 601 | struct ui_file *stream) |
8b93c638 | 602 | { |
56dbf317 | 603 | std::string buffer = ui_file_as_string (stream); |
5d502164 | 604 | |
56dbf317 PA |
605 | if (!buffer.empty ()) |
606 | ui_out_field_string (uiout, fldname, buffer.c_str ()); | |
8b93c638 JM |
607 | else |
608 | ui_out_field_skip (uiout, fldname); | |
f99d8bf4 | 609 | ui_file_rewind (stream); |
8b93c638 JM |
610 | } |
611 | ||
581e13c1 | 612 | /* Used to omit a field. */ |
8b93c638 JM |
613 | |
614 | void | |
88379baf AC |
615 | ui_out_field_skip (struct ui_out *uiout, |
616 | const char *fldname) | |
8b93c638 JM |
617 | { |
618 | int fldno; | |
619 | int width; | |
f486487f | 620 | enum ui_align align; |
8b93c638 | 621 | |
a6c47c14 | 622 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
623 | |
624 | uo_field_skip (uiout, fldno, width, align, fldname); | |
625 | } | |
626 | ||
627 | void | |
628 | ui_out_field_string (struct ui_out *uiout, | |
88379baf | 629 | const char *fldname, |
8b93c638 JM |
630 | const char *string) |
631 | { | |
632 | int fldno; | |
633 | int width; | |
f486487f | 634 | enum ui_align align; |
8b93c638 | 635 | |
a6c47c14 | 636 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
637 | |
638 | uo_field_string (uiout, fldno, width, align, fldname, string); | |
639 | } | |
640 | ||
641 | /* VARARGS */ | |
642 | void | |
88379baf AC |
643 | ui_out_field_fmt (struct ui_out *uiout, |
644 | const char *fldname, | |
645 | const char *format, ...) | |
8b93c638 JM |
646 | { |
647 | va_list args; | |
648 | int fldno; | |
649 | int width; | |
f486487f | 650 | enum ui_align align; |
8b93c638 | 651 | |
581e13c1 | 652 | /* Will not align, but has to call anyway. */ |
a6c47c14 | 653 | verify_field (uiout, &fldno, &width, &align); |
8b93c638 JM |
654 | |
655 | va_start (args, format); | |
656 | ||
657 | uo_field_fmt (uiout, fldno, width, align, fldname, format, args); | |
658 | ||
659 | va_end (args); | |
660 | } | |
661 | ||
662 | void | |
fba45db2 | 663 | ui_out_spaces (struct ui_out *uiout, int numspaces) |
8b93c638 JM |
664 | { |
665 | uo_spaces (uiout, numspaces); | |
666 | } | |
667 | ||
668 | void | |
88379baf AC |
669 | ui_out_text (struct ui_out *uiout, |
670 | const char *string) | |
8b93c638 JM |
671 | { |
672 | uo_text (uiout, string); | |
673 | } | |
674 | ||
675 | void | |
7fb048a2 | 676 | ui_out_message (struct ui_out *uiout, const char *format, ...) |
8b93c638 JM |
677 | { |
678 | va_list args; | |
679 | ||
680 | va_start (args, format); | |
7fb048a2 | 681 | uo_message (uiout, format, args); |
8b93c638 JM |
682 | va_end (args); |
683 | } | |
684 | ||
8b93c638 | 685 | void |
d2c0eef4 | 686 | ui_out_wrap_hint (struct ui_out *uiout, const char *identstring) |
8b93c638 JM |
687 | { |
688 | uo_wrap_hint (uiout, identstring); | |
689 | } | |
690 | ||
691 | void | |
fba45db2 | 692 | ui_out_flush (struct ui_out *uiout) |
8b93c638 JM |
693 | { |
694 | uo_flush (uiout); | |
695 | } | |
696 | ||
0fac0b41 DJ |
697 | int |
698 | ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
699 | { | |
700 | return uo_redirect (uiout, outstream); | |
701 | } | |
702 | ||
581e13c1 | 703 | /* Test the flags against the mask given. */ |
8b93c638 | 704 | int |
bef721e2 | 705 | ui_out_test_flags (struct ui_out *uiout, ui_out_flags mask) |
8b93c638 JM |
706 | { |
707 | return (uiout->flags & mask); | |
708 | } | |
709 | ||
9dc5e2a9 AC |
710 | int |
711 | ui_out_is_mi_like_p (struct ui_out *uiout) | |
712 | { | |
713 | return uiout->impl->is_mi_like_p; | |
714 | } | |
715 | ||
581e13c1 | 716 | /* Interface to the implementation functions. */ |
8b93c638 JM |
717 | |
718 | void | |
88379baf | 719 | uo_table_begin (struct ui_out *uiout, int nbrofcols, |
d63f1d40 | 720 | int nr_rows, |
88379baf | 721 | const char *tblid) |
8b93c638 JM |
722 | { |
723 | if (!uiout->impl->table_begin) | |
724 | return; | |
d63f1d40 | 725 | uiout->impl->table_begin (uiout, nbrofcols, nr_rows, tblid); |
8b93c638 JM |
726 | } |
727 | ||
728 | void | |
729 | uo_table_body (struct ui_out *uiout) | |
730 | { | |
731 | if (!uiout->impl->table_body) | |
732 | return; | |
733 | uiout->impl->table_body (uiout); | |
734 | } | |
735 | ||
736 | void | |
737 | uo_table_end (struct ui_out *uiout) | |
738 | { | |
739 | if (!uiout->impl->table_end) | |
740 | return; | |
741 | uiout->impl->table_end (uiout); | |
742 | } | |
743 | ||
744 | void | |
88379baf | 745 | uo_table_header (struct ui_out *uiout, int width, enum ui_align align, |
c5209615 | 746 | const std::string &col_name, const std::string &col_hdr) |
8b93c638 JM |
747 | { |
748 | if (!uiout->impl->table_header) | |
749 | return; | |
c5209615 | 750 | uiout->impl->table_header (uiout, width, align, col_name, col_hdr); |
8b93c638 JM |
751 | } |
752 | ||
753 | void | |
631ec795 AC |
754 | uo_begin (struct ui_out *uiout, |
755 | enum ui_out_type type, | |
631ec795 | 756 | const char *id) |
8b93c638 | 757 | { |
631ec795 | 758 | if (uiout->impl->begin == NULL) |
8b93c638 | 759 | return; |
33b2fac6 | 760 | uiout->impl->begin (uiout, type, id); |
8b93c638 JM |
761 | } |
762 | ||
763 | void | |
631ec795 | 764 | uo_end (struct ui_out *uiout, |
33b2fac6 | 765 | enum ui_out_type type) |
8b93c638 | 766 | { |
631ec795 | 767 | if (uiout->impl->end == NULL) |
8b93c638 | 768 | return; |
33b2fac6 | 769 | uiout->impl->end (uiout, type); |
8b93c638 JM |
770 | } |
771 | ||
772 | void | |
88379baf AC |
773 | uo_field_int (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
774 | const char *fldname, | |
775 | int value) | |
8b93c638 JM |
776 | { |
777 | if (!uiout->impl->field_int) | |
778 | return; | |
779 | uiout->impl->field_int (uiout, fldno, width, align, fldname, value); | |
780 | } | |
781 | ||
782 | void | |
88379baf AC |
783 | uo_field_skip (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
784 | const char *fldname) | |
8b93c638 JM |
785 | { |
786 | if (!uiout->impl->field_skip) | |
787 | return; | |
788 | uiout->impl->field_skip (uiout, fldno, width, align, fldname); | |
789 | } | |
790 | ||
791 | void | |
792 | uo_field_string (struct ui_out *uiout, int fldno, int width, | |
88379baf AC |
793 | enum ui_align align, |
794 | const char *fldname, | |
795 | const char *string) | |
8b93c638 JM |
796 | { |
797 | if (!uiout->impl->field_string) | |
798 | return; | |
799 | uiout->impl->field_string (uiout, fldno, width, align, fldname, string); | |
800 | } | |
801 | ||
802 | void | |
88379baf AC |
803 | uo_field_fmt (struct ui_out *uiout, int fldno, int width, enum ui_align align, |
804 | const char *fldname, | |
805 | const char *format, | |
806 | va_list args) | |
8b93c638 JM |
807 | { |
808 | if (!uiout->impl->field_fmt) | |
809 | return; | |
810 | uiout->impl->field_fmt (uiout, fldno, width, align, fldname, format, args); | |
811 | } | |
812 | ||
813 | void | |
814 | uo_spaces (struct ui_out *uiout, int numspaces) | |
815 | { | |
816 | if (!uiout->impl->spaces) | |
817 | return; | |
818 | uiout->impl->spaces (uiout, numspaces); | |
819 | } | |
820 | ||
821 | void | |
88379baf AC |
822 | uo_text (struct ui_out *uiout, |
823 | const char *string) | |
8b93c638 JM |
824 | { |
825 | if (!uiout->impl->text) | |
826 | return; | |
827 | uiout->impl->text (uiout, string); | |
828 | } | |
829 | ||
830 | void | |
7fb048a2 | 831 | uo_message (struct ui_out *uiout, |
88379baf AC |
832 | const char *format, |
833 | va_list args) | |
8b93c638 JM |
834 | { |
835 | if (!uiout->impl->message) | |
836 | return; | |
7fb048a2 | 837 | uiout->impl->message (uiout, format, args); |
8b93c638 JM |
838 | } |
839 | ||
840 | void | |
d2c0eef4 | 841 | uo_wrap_hint (struct ui_out *uiout, const char *identstring) |
8b93c638 JM |
842 | { |
843 | if (!uiout->impl->wrap_hint) | |
844 | return; | |
845 | uiout->impl->wrap_hint (uiout, identstring); | |
846 | } | |
847 | ||
848 | void | |
849 | uo_flush (struct ui_out *uiout) | |
850 | { | |
851 | if (!uiout->impl->flush) | |
852 | return; | |
853 | uiout->impl->flush (uiout); | |
854 | } | |
855 | ||
0fac0b41 DJ |
856 | int |
857 | uo_redirect (struct ui_out *uiout, struct ui_file *outstream) | |
858 | { | |
859 | if (!uiout->impl->redirect) | |
860 | return -1; | |
82bbe65a | 861 | return uiout->impl->redirect (uiout, outstream); |
0fac0b41 DJ |
862 | } |
863 | ||
a6c47c14 AC |
864 | /* Verify that the field/tuple/list is correctly positioned. Return |
865 | the field number and corresponding alignment (if | |
866 | available/applicable). */ | |
8b93c638 JM |
867 | |
868 | static void | |
f486487f SM |
869 | verify_field (struct ui_out *uiout, int *fldno, int *width, |
870 | enum ui_align *align) | |
8b93c638 | 871 | { |
909c0aa5 | 872 | ui_out_level *current = current_level (uiout); |
c5209615 | 873 | const char *text; |
a6c47c14 | 874 | |
36d18bc5 SM |
875 | if (uiout->table != nullptr |
876 | && uiout->table->current_state () != ui_out_table::state::BODY) | |
8b93c638 | 877 | { |
77a179e7 SM |
878 | internal_error (__FILE__, __LINE__, |
879 | _("table_body missing; table fields must be \ | |
e2e0b3e5 | 880 | specified after table_body and inside a list.")); |
8b93c638 | 881 | } |
8b93c638 | 882 | |
909c0aa5 | 883 | current->inc_field_count (); |
8b93c638 | 884 | |
36d18bc5 SM |
885 | if (uiout->table != nullptr |
886 | && uiout->table->current_state () == ui_out_table::state::BODY | |
887 | && uiout->table->entry_level () == uiout->level () | |
888 | && uiout->table->get_next_header (fldno, width, align, &text)) | |
8b93c638 | 889 | { |
909c0aa5 | 890 | if (*fldno != current->field_count ()) |
8e65ff28 | 891 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 892 | _("ui-out internal error in handling headers.")); |
8b93c638 JM |
893 | } |
894 | else | |
895 | { | |
896 | *width = 0; | |
897 | *align = ui_noalign; | |
909c0aa5 | 898 | *fldno = current->field_count (); |
8b93c638 JM |
899 | } |
900 | } | |
901 | ||
a6c47c14 | 902 | |
581e13c1 | 903 | /* Access to ui-out members data. */ |
8b93c638 | 904 | |
0a8fce9a | 905 | void * |
8b93c638 JM |
906 | ui_out_data (struct ui_out *uiout) |
907 | { | |
908 | return uiout->data; | |
909 | } | |
910 | ||
170b53b2 UW |
911 | /* Access table field parameters. */ |
912 | int | |
913 | ui_out_query_field (struct ui_out *uiout, int colno, | |
c5209615 | 914 | int *width, int *alignment, const char **col_name) |
170b53b2 | 915 | { |
36d18bc5 | 916 | if (uiout->table == nullptr) |
170b53b2 UW |
917 | return 0; |
918 | ||
36d18bc5 | 919 | return uiout->table->query_field (colno, width, alignment, col_name); |
170b53b2 UW |
920 | } |
921 | ||
26c4b26f | 922 | /* Initialize private members at startup. */ |
8b93c638 JM |
923 | |
924 | struct ui_out * | |
89de4da4 | 925 | ui_out_new (const struct ui_out_impl *impl, void *data, |
bef721e2 | 926 | ui_out_flags flags) |
8b93c638 | 927 | { |
5486f164 | 928 | struct ui_out *uiout = new ui_out (); |
5d502164 | 929 | |
8b93c638 JM |
930 | uiout->data = data; |
931 | uiout->impl = impl; | |
932 | uiout->flags = flags; | |
54eb231c | 933 | |
33b2fac6 SM |
934 | /* Create the ui-out level #1, the default level. */ |
935 | push_level (uiout, ui_out_type_tuple); | |
54eb231c | 936 | |
8b93c638 JM |
937 | return uiout; |
938 | } |