1 /* MI Command Set - output generating routines.
3 Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions (a Red Hat company).
8 This file is part of GDB.
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 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 int suppress_field_separator
;
32 struct ui_file
*buffer
;
34 typedef struct ui_out_data mi_out_data
;
36 /* These are the MI output functions */
38 static void mi_table_begin (struct ui_out
*uiout
, int nbrofcols
,
39 int nr_rows
, const char *tblid
);
40 static void mi_table_body (struct ui_out
*uiout
);
41 static void mi_table_end (struct ui_out
*uiout
);
42 static void mi_table_header (struct ui_out
*uiout
, int width
,
43 enum ui_align alig
, const char *col_name
,
45 static void mi_begin (struct ui_out
*uiout
, enum ui_out_type type
,
46 int level
, const char *id
);
47 static void mi_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
48 static void mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
49 enum ui_align alig
, const char *fldname
, int value
);
50 static void mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
51 enum ui_align alig
, const char *fldname
);
52 static void mi_field_string (struct ui_out
*uiout
, int fldno
, int width
,
53 enum ui_align alig
, const char *fldname
,
55 static void mi_field_fmt (struct ui_out
*uiout
, int fldno
,
56 int width
, enum ui_align align
,
57 const char *fldname
, const char *format
,
58 va_list args
) ATTRIBUTE_PRINTF (6, 0);
59 static void mi_spaces (struct ui_out
*uiout
, int numspaces
);
60 static void mi_text (struct ui_out
*uiout
, const char *string
);
61 static void mi_message (struct ui_out
*uiout
, int verbosity
,
62 const char *format
, va_list args
)
63 ATTRIBUTE_PRINTF (3, 0);
64 static void mi_wrap_hint (struct ui_out
*uiout
, char *identstring
);
65 static void mi_flush (struct ui_out
*uiout
);
67 /* This is the MI ui-out implementation functions vector */
69 /* FIXME: This can be initialized dynamically after default is set to
70 handle initial output in main.c */
72 struct ui_out_impl mi_ui_out_impl
=
90 1, /* Needs MI hacks. */
93 /* Prototypes for local functions */
95 extern void _initialize_mi_out (void);
96 static void field_separator (struct ui_out
*uiout
);
97 static void mi_open (struct ui_out
*uiout
, const char *name
,
98 enum ui_out_type type
);
99 static void mi_close (struct ui_out
*uiout
, enum ui_out_type type
);
101 /* Mark beginning of a table */
104 mi_table_begin (struct ui_out
*uiout
,
109 mi_open (uiout
, tblid
, ui_out_type_tuple
);
110 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
112 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
114 mi_open (uiout
, "hdr", ui_out_type_list
);
117 /* Mark beginning of a table body */
120 mi_table_body (struct ui_out
*uiout
)
122 mi_out_data
*data
= ui_out_data (uiout
);
124 if (data
->suppress_output
)
126 /* close the table header line if there were any headers */
127 mi_close (uiout
, ui_out_type_list
);
128 mi_open (uiout
, "body", ui_out_type_list
);
131 /* Mark end of a table */
134 mi_table_end (struct ui_out
*uiout
)
136 mi_out_data
*data
= ui_out_data (uiout
);
138 data
->suppress_output
= 0;
139 mi_close (uiout
, ui_out_type_list
); /* body */
140 mi_close (uiout
, ui_out_type_tuple
);
143 /* Specify table header */
146 mi_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
147 const char *col_name
,
150 mi_out_data
*data
= ui_out_data (uiout
);
152 if (data
->suppress_output
)
154 mi_open (uiout
, NULL
, ui_out_type_tuple
);
155 mi_field_int (uiout
, 0, 0, 0, "width", width
);
156 mi_field_int (uiout
, 0, 0, 0, "alignment", alignment
);
157 mi_field_string (uiout
, 0, 0, 0, "col_name", col_name
);
158 mi_field_string (uiout
, 0, width
, alignment
, "colhdr", colhdr
);
159 mi_close (uiout
, ui_out_type_tuple
);
162 /* Mark beginning of a list */
165 mi_begin (struct ui_out
*uiout
,
166 enum ui_out_type type
,
170 mi_out_data
*data
= ui_out_data (uiout
);
172 if (data
->suppress_output
)
174 mi_open (uiout
, id
, type
);
177 /* Mark end of a list */
180 mi_end (struct ui_out
*uiout
,
181 enum ui_out_type type
,
184 mi_out_data
*data
= ui_out_data (uiout
);
186 if (data
->suppress_output
)
188 mi_close (uiout
, type
);
191 /* output an int field */
194 mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
195 enum ui_align alignment
, const char *fldname
, int value
)
197 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
198 mi_out_data
*data
= ui_out_data (uiout
);
200 if (data
->suppress_output
)
203 sprintf (buffer
, "%d", value
);
204 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
207 /* used to ommit a field */
210 mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
211 enum ui_align alignment
, const char *fldname
)
213 mi_out_data
*data
= ui_out_data (uiout
);
215 if (data
->suppress_output
)
217 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
220 /* other specific mi_field_* end up here so alignment and field
221 separators are both handled by mi_field_string */
224 mi_field_string (struct ui_out
*uiout
,
231 mi_out_data
*data
= ui_out_data (uiout
);
233 if (data
->suppress_output
)
235 field_separator (uiout
);
237 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
238 fprintf_unfiltered (data
->buffer
, "\"");
240 fputstr_unfiltered (string
, '"', data
->buffer
);
241 fprintf_unfiltered (data
->buffer
, "\"");
244 /* This is the only field function that does not align */
247 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
248 int width
, enum ui_align align
,
253 mi_out_data
*data
= ui_out_data (uiout
);
255 if (data
->suppress_output
)
257 field_separator (uiout
);
259 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
261 fputs_unfiltered ("\"", data
->buffer
);
262 vfprintf_unfiltered (data
->buffer
, format
, args
);
263 fputs_unfiltered ("\"", data
->buffer
);
267 mi_spaces (struct ui_out
*uiout
, int numspaces
)
272 mi_text (struct ui_out
*uiout
, const char *string
)
277 mi_message (struct ui_out
*uiout
, int verbosity
,
284 mi_wrap_hint (struct ui_out
*uiout
, char *identstring
)
286 wrap_here (identstring
);
290 mi_flush (struct ui_out
*uiout
)
292 mi_out_data
*data
= ui_out_data (uiout
);
294 gdb_flush (data
->buffer
);
297 /* local functions */
299 /* access to ui_out format private members */
302 field_separator (struct ui_out
*uiout
)
304 mi_out_data
*data
= ui_out_data (uiout
);
306 if (data
->suppress_field_separator
)
307 data
->suppress_field_separator
= 0;
309 fputc_unfiltered (',', data
->buffer
);
313 mi_open (struct ui_out
*uiout
,
315 enum ui_out_type type
)
317 mi_out_data
*data
= ui_out_data (uiout
);
319 field_separator (uiout
);
320 data
->suppress_field_separator
= 1;
322 fprintf_unfiltered (data
->buffer
, "%s=", name
);
325 case ui_out_type_tuple
:
326 fputc_unfiltered ('{', data
->buffer
);
328 case ui_out_type_list
:
329 fputc_unfiltered ('[', data
->buffer
);
332 internal_error (__FILE__
, __LINE__
, _("bad switch"));
337 mi_close (struct ui_out
*uiout
,
338 enum ui_out_type type
)
340 mi_out_data
*data
= ui_out_data (uiout
);
344 case ui_out_type_tuple
:
345 fputc_unfiltered ('}', data
->buffer
);
347 case ui_out_type_list
:
348 fputc_unfiltered (']', data
->buffer
);
351 internal_error (__FILE__
, __LINE__
, _("bad switch"));
353 data
->suppress_field_separator
= 0;
356 /* add a string to the buffer */
359 mi_out_buffered (struct ui_out
*uiout
, char *string
)
361 mi_out_data
*data
= ui_out_data (uiout
);
363 fprintf_unfiltered (data
->buffer
, "%s", string
);
366 /* clear the buffer */
369 mi_out_rewind (struct ui_out
*uiout
)
371 mi_out_data
*data
= ui_out_data (uiout
);
373 ui_file_rewind (data
->buffer
);
376 /* dump the buffer onto the specified stream */
379 do_write (void *data
, const char *buffer
, long length_buffer
)
381 ui_file_write (data
, buffer
, length_buffer
);
385 mi_out_put (struct ui_out
*uiout
,
386 struct ui_file
*stream
)
388 mi_out_data
*data
= ui_out_data (uiout
);
390 ui_file_put (data
->buffer
, do_write
, stream
);
391 ui_file_rewind (data
->buffer
);
394 /* Current MI version. */
397 mi_version (struct ui_out
*uiout
)
399 mi_out_data
*data
= ui_out_data (uiout
);
401 return data
->mi_version
;
404 /* initalize private members at startup */
407 mi_out_new (int mi_version
)
411 mi_out_data
*data
= XMALLOC (mi_out_data
);
412 data
->suppress_field_separator
= 0;
413 data
->suppress_output
= 0;
414 data
->mi_version
= mi_version
;
415 /* FIXME: This code should be using a ``string_file'' and not the
417 data
->buffer
= mem_fileopen ();
418 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
421 /* standard gdb initialization hook */
423 _initialize_mi_out (void)
425 /* nothing happens here */