1 /* MI Command Set - output generating routines.
3 Copyright 2000, 2002, 2003 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions (a Red Hat company).
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
30 int suppress_field_separator
;
33 struct ui_file
*buffer
;
35 typedef struct ui_out_data mi_out_data
;
37 /* These are the MI output functions */
39 static void mi_table_begin (struct ui_out
*uiout
, int nbrofcols
,
40 int nr_rows
, const char *tblid
);
41 static void mi_table_body (struct ui_out
*uiout
);
42 static void mi_table_end (struct ui_out
*uiout
);
43 static void mi_table_header (struct ui_out
*uiout
, int width
,
44 enum ui_align alig
, const char *col_name
,
46 static void mi_begin (struct ui_out
*uiout
, enum ui_out_type type
,
47 int level
, const char *id
);
48 static void mi_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
49 static void mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
50 enum ui_align alig
, const char *fldname
, int value
);
51 static void mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, const char *fldname
);
53 static void mi_field_string (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
,
56 static void mi_field_fmt (struct ui_out
*uiout
, int fldno
,
57 int width
, enum ui_align align
,
58 const char *fldname
, const char *format
,
60 static void mi_spaces (struct ui_out
*uiout
, int numspaces
);
61 static void mi_text (struct ui_out
*uiout
, const char *string
);
62 static void mi_message (struct ui_out
*uiout
, int verbosity
,
63 const char *format
, va_list args
);
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 static void out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
104 /* Mark beginning of a table */
107 mi_table_begin (struct ui_out
*uiout
,
112 mi_out_data
*data
= ui_out_data (uiout
);
113 mi_open (uiout
, tblid
, ui_out_type_tuple
);
114 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
116 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
118 mi_open (uiout
, "hdr", ui_out_type_list
);
121 /* Mark beginning of a table body */
124 mi_table_body (struct ui_out
*uiout
)
126 mi_out_data
*data
= ui_out_data (uiout
);
127 if (data
->suppress_output
)
129 /* close the table header line if there were any headers */
130 mi_close (uiout
, ui_out_type_list
);
131 mi_open (uiout
, "body", ui_out_type_list
);
134 /* Mark end of a table */
137 mi_table_end (struct ui_out
*uiout
)
139 mi_out_data
*data
= ui_out_data (uiout
);
140 data
->suppress_output
= 0;
141 mi_close (uiout
, ui_out_type_list
); /* body */
142 mi_close (uiout
, ui_out_type_tuple
);
145 /* Specify table header */
148 mi_table_header (struct ui_out
*uiout
, int width
, enum ui_align alignment
,
149 const char *col_name
,
152 mi_out_data
*data
= ui_out_data (uiout
);
153 if (data
->suppress_output
)
155 mi_open (uiout
, NULL
, ui_out_type_tuple
);
156 mi_field_int (uiout
, 0, 0, 0, "width", width
);
157 mi_field_int (uiout
, 0, 0, 0, "alignment", alignment
);
158 mi_field_string (uiout
, 0, 0, 0, "col_name", col_name
);
159 mi_field_string (uiout
, 0, width
, alignment
, "colhdr", colhdr
);
160 mi_close (uiout
, ui_out_type_tuple
);
163 /* Mark beginning of a list */
166 mi_begin (struct ui_out
*uiout
,
167 enum ui_out_type type
,
171 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
);
185 if (data
->suppress_output
)
187 mi_close (uiout
, type
);
190 /* output an int field */
193 mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
194 enum ui_align alignment
, const char *fldname
, int value
)
196 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
197 mi_out_data
*data
= ui_out_data (uiout
);
198 if (data
->suppress_output
)
201 sprintf (buffer
, "%d", value
);
202 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
205 /* used to ommit a field */
208 mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
209 enum ui_align alignment
, const char *fldname
)
211 mi_out_data
*data
= ui_out_data (uiout
);
212 if (data
->suppress_output
)
214 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
217 /* other specific mi_field_* end up here so alignment and field
218 separators are both handled by mi_field_string */
221 mi_field_string (struct ui_out
*uiout
,
228 mi_out_data
*data
= ui_out_data (uiout
);
229 if (data
->suppress_output
)
231 field_separator (uiout
);
233 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
234 fprintf_unfiltered (data
->buffer
, "\"");
236 fputstr_unfiltered (string
, '"', data
->buffer
);
237 fprintf_unfiltered (data
->buffer
, "\"");
240 /* This is the only field function that does not align */
243 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
244 int width
, enum ui_align align
,
249 mi_out_data
*data
= ui_out_data (uiout
);
250 if (data
->suppress_output
)
252 field_separator (uiout
);
254 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
256 fputs_unfiltered ("\"", data
->buffer
);
257 vfprintf_unfiltered (data
->buffer
, format
, args
);
258 fputs_unfiltered ("\"", data
->buffer
);
262 mi_spaces (struct ui_out
*uiout
, int numspaces
)
267 mi_text (struct ui_out
*uiout
, const char *string
)
272 mi_message (struct ui_out
*uiout
, int verbosity
,
279 mi_wrap_hint (struct ui_out
*uiout
, char *identstring
)
281 wrap_here (identstring
);
285 mi_flush (struct ui_out
*uiout
)
287 mi_out_data
*data
= ui_out_data (uiout
);
288 gdb_flush (data
->buffer
);
291 /* local functions */
293 /* Like mi_field_fmt, but takes a variable number of args
294 and makes a va_list and does not insert a separator */
298 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
301 mi_out_data
*data
= ui_out_data (uiout
);
304 field_separator (uiout
);
306 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
308 fputs_unfiltered ("\"", data
->buffer
);
310 va_start (args
, format
);
311 vfprintf_unfiltered (data
->buffer
, format
, args
);
313 fputs_unfiltered ("\"", data
->buffer
);
318 /* access to ui_out format private members */
321 field_separator (struct ui_out
*uiout
)
323 mi_out_data
*data
= ui_out_data (uiout
);
324 if (data
->suppress_field_separator
)
325 data
->suppress_field_separator
= 0;
327 fputc_unfiltered (',', data
->buffer
);
331 mi_open (struct ui_out
*uiout
,
333 enum ui_out_type type
)
335 mi_out_data
*data
= ui_out_data (uiout
);
336 field_separator (uiout
);
337 data
->suppress_field_separator
= 1;
339 fprintf_unfiltered (data
->buffer
, "%s=", name
);
342 case ui_out_type_tuple
:
343 fputc_unfiltered ('{', data
->buffer
);
345 case ui_out_type_list
:
346 fputc_unfiltered ('[', data
->buffer
);
349 internal_error (__FILE__
, __LINE__
, "bad switch");
354 mi_close (struct ui_out
*uiout
,
355 enum ui_out_type type
)
357 mi_out_data
*data
= ui_out_data (uiout
);
360 case ui_out_type_tuple
:
361 fputc_unfiltered ('}', data
->buffer
);
363 case ui_out_type_list
:
364 fputc_unfiltered (']', data
->buffer
);
367 internal_error (__FILE__
, __LINE__
, "bad switch");
369 data
->suppress_field_separator
= 0;
372 /* add a string to the buffer */
375 mi_out_buffered (struct ui_out
*uiout
, char *string
)
377 mi_out_data
*data
= ui_out_data (uiout
);
378 fprintf_unfiltered (data
->buffer
, "%s", string
);
381 /* clear the buffer */
384 mi_out_rewind (struct ui_out
*uiout
)
386 mi_out_data
*data
= ui_out_data (uiout
);
387 ui_file_rewind (data
->buffer
);
390 /* dump the buffer onto the specified stream */
393 do_write (void *data
, const char *buffer
, long length_buffer
)
395 ui_file_write (data
, buffer
, length_buffer
);
399 mi_out_put (struct ui_out
*uiout
,
400 struct ui_file
*stream
)
402 mi_out_data
*data
= ui_out_data (uiout
);
403 ui_file_put (data
->buffer
, do_write
, stream
);
404 ui_file_rewind (data
->buffer
);
407 /* Current MI version. */
410 mi_version (struct ui_out
*uiout
)
412 mi_out_data
*data
= ui_out_data (uiout
);
413 return data
->mi_version
;
416 /* initalize private members at startup */
419 mi_out_new (int mi_version
)
422 mi_out_data
*data
= XMALLOC (mi_out_data
);
423 data
->suppress_field_separator
= 0;
424 data
->suppress_output
= 0;
425 data
->mi_version
= mi_version
;
426 /* FIXME: This code should be using a ``string_file'' and not the
428 data
->buffer
= mem_fileopen ();
429 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
432 /* standard gdb initialization hook */
434 _initialize_mi_out (void)
436 /* nothing happens here */