1 /* MI Command Set - output generating routines.
2 Copyright 2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 /* Convenience macro for allocting typesafe memory. */
29 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
34 int supress_field_separator
;
36 struct ui_file
*buffer
;
39 /* These are the MI output functions */
41 static void mi_table_begin (struct ui_out
*uiout
, int nbrofcols
,
43 static void mi_table_body (struct ui_out
*uiout
);
44 static void mi_table_end (struct ui_out
*uiout
);
45 static void mi_table_header (struct ui_out
*uiout
, int width
,
48 static void mi_begin (struct ui_out
*uiout
, enum ui_out_type type
,
49 int level
, const char *id
);
50 static void mi_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
51 static void mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
52 enum ui_align alig
, const char *fldname
, int value
);
53 static void mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
54 enum ui_align alig
, const char *fldname
);
55 static void mi_field_string (struct ui_out
*uiout
, int fldno
, int width
,
56 enum ui_align alig
, const char *fldname
,
58 static void mi_field_fmt (struct ui_out
*uiout
, int fldno
,
59 int width
, enum ui_align align
,
60 const char *fldname
, const char *format
,
62 static void mi_spaces (struct ui_out
*uiout
, int numspaces
);
63 static void mi_text (struct ui_out
*uiout
, const char *string
);
64 static void mi_message (struct ui_out
*uiout
, int verbosity
,
65 const char *format
, va_list args
);
66 static void mi_wrap_hint (struct ui_out
*uiout
, char *identstring
);
67 static void mi_flush (struct ui_out
*uiout
);
69 /* This is the MI ui-out implementation functions vector */
71 /* FIXME: This can be initialized dynamically after default is set to
72 handle initial output in main.c */
74 struct ui_out_impl mi_ui_out_impl
=
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
, enum ui_out_type type
);
98 static void mi_close (struct ui_out
*uiout
, enum ui_out_type type
);
100 static void out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
103 /* Mark beginning of a table */
106 mi_table_begin (struct ui_out
*uiout
, int nbrofcols
,
109 struct ui_out_data
*data
= ui_out_data (uiout
);
110 field_separator (uiout
);
112 fprintf_unfiltered (data
->buffer
, "%s=", tblid
);
113 mi_open (uiout
, ui_out_type_tuple
);
114 data
->first_header
= 0;
115 data
->supress_field_separator
= 1;
118 /* Mark beginning of a table body */
121 mi_table_body (struct ui_out
*uiout
)
123 struct ui_out_data
*data
= ui_out_data (uiout
);
124 /* close the table header line if there were any headers */
125 if (data
->first_header
)
126 mi_close (uiout
, ui_out_type_tuple
);
129 /* Mark end of a table */
132 mi_table_end (struct ui_out
*uiout
)
134 struct ui_out_data
*data
= ui_out_data (uiout
);
135 mi_close (uiout
, ui_out_type_tuple
);
136 /* If table was empty this flag did not get reset yet */
137 data
->supress_field_separator
= 0;
140 /* Specify table header */
143 mi_table_header (struct ui_out
*uiout
, int width
, int alignment
,
146 struct ui_out_data
*data
= ui_out_data (uiout
);
147 if (!data
->first_header
++)
149 fputs_unfiltered ("hdr=", data
->buffer
);
150 mi_open (uiout
, ui_out_type_tuple
);
152 mi_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
155 /* Mark beginning of a list */
158 mi_begin (struct ui_out
*uiout
,
159 enum ui_out_type type
,
163 struct ui_out_data
*data
= ui_out_data (uiout
);
164 field_separator (uiout
);
165 data
->supress_field_separator
= 1;
167 fprintf_unfiltered (data
->buffer
, "%s=", id
);
168 mi_open (uiout
, type
);
171 /* Mark end of a list */
174 mi_end (struct ui_out
*uiout
,
175 enum ui_out_type type
,
178 struct ui_out_data
*data
= ui_out_data (uiout
);
179 mi_close (uiout
, type
);
180 /* If list was empty this flag did not get reset yet */
181 data
->supress_field_separator
= 0;
184 /* output an int field */
187 mi_field_int (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
188 const char *fldname
, int value
)
190 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
192 sprintf (buffer
, "%d", value
);
193 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
196 /* used to ommit a field */
199 mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
202 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
205 /* other specific mi_field_* end up here so alignment and field
206 separators are both handled by mi_field_string */
209 mi_field_string (struct ui_out
*uiout
,
216 struct ui_out_data
*data
= ui_out_data (uiout
);
217 field_separator (uiout
);
219 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
220 fprintf_unfiltered (data
->buffer
, "\"");
222 fputstr_unfiltered (string
, '"', data
->buffer
);
223 fprintf_unfiltered (data
->buffer
, "\"");
226 /* This is the only field function that does not align */
229 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
230 int width
, enum ui_align align
,
235 struct ui_out_data
*data
= ui_out_data (uiout
);
236 field_separator (uiout
);
238 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
240 fputs_unfiltered ("\"", data
->buffer
);
241 vfprintf_unfiltered (data
->buffer
, format
, args
);
242 fputs_unfiltered ("\"", data
->buffer
);
246 mi_spaces (struct ui_out
*uiout
, int numspaces
)
251 mi_text (struct ui_out
*uiout
, const char *string
)
256 mi_message (struct ui_out
*uiout
, int verbosity
,
263 mi_wrap_hint (struct ui_out
*uiout
, char *identstring
)
265 wrap_here (identstring
);
269 mi_flush (struct ui_out
*uiout
)
271 struct ui_out_data
*data
= ui_out_data (uiout
);
272 gdb_flush (data
->buffer
);
275 /* local functions */
277 /* Like mi_field_fmt, but takes a variable number of args
278 and makes a va_list and does not insert a separator */
282 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
285 struct ui_out_data
*data
= ui_out_data (uiout
);
288 field_separator (uiout
);
290 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
292 fputs_unfiltered ("\"", data
->buffer
);
294 va_start (args
, format
);
295 vfprintf_unfiltered (data
->buffer
, format
, args
);
297 fputs_unfiltered ("\"", data
->buffer
);
302 /* access to ui_out format private members */
305 field_separator (struct ui_out
*uiout
)
307 struct ui_out_data
*data
= ui_out_data (uiout
);
308 if (data
->supress_field_separator
)
309 data
->supress_field_separator
= 0;
311 fputc_unfiltered (',', data
->buffer
);
315 mi_open (struct ui_out
*uiout
,
316 enum ui_out_type type
)
318 struct ui_out_data
*data
= ui_out_data (uiout
);
321 case ui_out_type_tuple
:
322 fputc_unfiltered ('{', data
->buffer
);
324 case ui_out_type_list
:
325 fputc_unfiltered ('[', data
->buffer
);
328 internal_error (__FILE__
, __LINE__
, "bad switch");
333 mi_close (struct ui_out
*uiout
,
334 enum ui_out_type type
)
336 struct ui_out_data
*data
= ui_out_data (uiout
);
339 case ui_out_type_tuple
:
340 fputc_unfiltered ('}', data
->buffer
);
342 case ui_out_type_list
:
343 fputc_unfiltered (']', data
->buffer
);
346 internal_error (__FILE__
, __LINE__
, "bad switch");
350 /* add a string to the buffer */
353 mi_out_buffered (struct ui_out
*uiout
, char *string
)
355 struct ui_out_data
*data
= ui_out_data (uiout
);
356 fprintf_unfiltered (data
->buffer
, "%s", string
);
359 /* clear the buffer */
362 mi_out_rewind (struct ui_out
*uiout
)
364 struct ui_out_data
*data
= ui_out_data (uiout
);
365 ui_file_rewind (data
->buffer
);
368 /* dump the buffer onto the specified stream */
371 do_write (void *data
, const char *buffer
, long length_buffer
)
373 ui_file_write (data
, buffer
, length_buffer
);
377 mi_out_put (struct ui_out
*uiout
,
378 struct ui_file
*stream
)
380 struct ui_out_data
*data
= ui_out_data (uiout
);
381 ui_file_put (data
->buffer
, do_write
, stream
);
382 ui_file_rewind (data
->buffer
);
385 /* initalize private members at startup */
391 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
392 data
->supress_field_separator
= 0;
393 /* FIXME: This code should be using a ``string_file'' and not the
395 data
->buffer
= mem_fileopen ();
396 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
399 /* standard gdb initialization hook */
401 _initialize_mi_out (void)
403 /* nothing happens here */