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 suppress_field_separator
;
37 struct ui_file
*buffer
;
40 /* These are the MI output functions */
42 static void mi_table_begin (struct ui_out
*uiout
, int nbrofcols
,
43 int nr_rows
, const char *tblid
);
44 static void mi_table_body (struct ui_out
*uiout
);
45 static void mi_table_end (struct ui_out
*uiout
);
46 static void mi_table_header (struct ui_out
*uiout
, int width
,
47 enum ui_align alig
, const char *col_name
,
49 static void mi_begin (struct ui_out
*uiout
, enum ui_out_type type
,
50 int level
, const char *id
);
51 static void mi_end (struct ui_out
*uiout
, enum ui_out_type type
, int level
);
52 static void mi_field_int (struct ui_out
*uiout
, int fldno
, int width
,
53 enum ui_align alig
, const char *fldname
, int value
);
54 static void mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
,
55 enum ui_align alig
, const char *fldname
);
56 static void mi_field_string (struct ui_out
*uiout
, int fldno
, int width
,
57 enum ui_align alig
, const char *fldname
,
59 static void mi_field_fmt (struct ui_out
*uiout
, int fldno
,
60 int width
, enum ui_align align
,
61 const char *fldname
, const char *format
,
63 static void mi_spaces (struct ui_out
*uiout
, int numspaces
);
64 static void mi_text (struct ui_out
*uiout
, const char *string
);
65 static void mi_message (struct ui_out
*uiout
, int verbosity
,
66 const char *format
, va_list args
);
67 static void mi_wrap_hint (struct ui_out
*uiout
, char *identstring
);
68 static void mi_flush (struct ui_out
*uiout
);
70 /* This is the MI ui-out implementation functions vector */
72 /* FIXME: This can be initialized dynamically after default is set to
73 handle initial output in main.c */
75 struct ui_out_impl mi_ui_out_impl
=
94 /* Prototypes for local functions */
96 extern void _initialize_mi_out (void);
97 static void field_separator (struct ui_out
*uiout
);
98 static void mi_open (struct ui_out
*uiout
, const char *name
,
99 enum ui_out_type type
);
100 static void mi_close (struct ui_out
*uiout
, enum ui_out_type type
);
102 static void out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
105 /* Mark beginning of a table */
108 mi_table_begin (struct ui_out
*uiout
,
113 struct ui_out_data
*data
= ui_out_data (uiout
);
114 mi_open (uiout
, tblid
, ui_out_type_tuple
);
115 if (data
->mi_version
== 0)
118 data
->suppress_output
= 1;
120 mi_open (uiout
, "hdr", ui_out_type_list
);
123 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
125 mi_field_int (uiout
, -1/*fldno*/, -1/*width*/, -1/*alin*/,
127 mi_open (uiout
, "hdr", ui_out_type_list
);
130 /* Mark beginning of a table body */
133 mi_table_body (struct ui_out
*uiout
)
135 struct ui_out_data
*data
= ui_out_data (uiout
);
136 if (data
->suppress_output
)
138 /* close the table header line if there were any headers */
139 mi_close (uiout
, ui_out_type_list
);
140 if (data
->mi_version
== 0)
142 mi_open (uiout
, "body", ui_out_type_list
);
145 /* Mark end of a table */
148 mi_table_end (struct ui_out
*uiout
)
150 struct ui_out_data
*data
= ui_out_data (uiout
);
151 data
->suppress_output
= 0;
152 if (data
->mi_version
== 0)
154 mi_close (uiout
, ui_out_type_tuple
);
157 mi_close (uiout
, ui_out_type_list
); /* body */
158 mi_close (uiout
, ui_out_type_tuple
);
161 /* Specify table header */
164 mi_table_header (struct ui_out
*uiout
, int width
, int alignment
,
165 const char *col_name
,
168 struct ui_out_data
*data
= ui_out_data (uiout
);
169 if (data
->suppress_output
)
171 if (data
->mi_version
== 0)
173 mi_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
176 mi_open (uiout
, NULL
, ui_out_type_tuple
);
177 mi_field_int (uiout
, 0, 0, 0, "width", width
);
178 mi_field_int (uiout
, 0, 0, 0, "alignment", alignment
);
179 mi_field_string (uiout
, 0, 0, 0, "col_name", col_name
);
180 mi_field_string (uiout
, 0, width
, alignment
, "colhdr", colhdr
);
181 mi_close (uiout
, ui_out_type_tuple
);
184 /* Mark beginning of a list */
187 mi_begin (struct ui_out
*uiout
,
188 enum ui_out_type type
,
192 struct ui_out_data
*data
= ui_out_data (uiout
);
193 if (data
->suppress_output
)
195 mi_open (uiout
, id
, type
);
198 /* Mark end of a list */
201 mi_end (struct ui_out
*uiout
,
202 enum ui_out_type type
,
205 struct ui_out_data
*data
= ui_out_data (uiout
);
206 if (data
->suppress_output
)
208 mi_close (uiout
, type
);
211 /* output an int field */
214 mi_field_int (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
215 const char *fldname
, int value
)
217 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
218 struct ui_out_data
*data
= ui_out_data (uiout
);
219 if (data
->suppress_output
)
222 sprintf (buffer
, "%d", value
);
223 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
226 /* used to ommit a field */
229 mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
232 struct ui_out_data
*data
= ui_out_data (uiout
);
233 if (data
->suppress_output
)
235 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
238 /* other specific mi_field_* end up here so alignment and field
239 separators are both handled by mi_field_string */
242 mi_field_string (struct ui_out
*uiout
,
249 struct ui_out_data
*data
= ui_out_data (uiout
);
250 if (data
->suppress_output
)
252 field_separator (uiout
);
254 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
255 fprintf_unfiltered (data
->buffer
, "\"");
257 fputstr_unfiltered (string
, '"', data
->buffer
);
258 fprintf_unfiltered (data
->buffer
, "\"");
261 /* This is the only field function that does not align */
264 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
265 int width
, enum ui_align align
,
270 struct ui_out_data
*data
= ui_out_data (uiout
);
271 if (data
->suppress_output
)
273 field_separator (uiout
);
275 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
277 fputs_unfiltered ("\"", data
->buffer
);
278 vfprintf_unfiltered (data
->buffer
, format
, args
);
279 fputs_unfiltered ("\"", data
->buffer
);
283 mi_spaces (struct ui_out
*uiout
, int numspaces
)
288 mi_text (struct ui_out
*uiout
, const char *string
)
293 mi_message (struct ui_out
*uiout
, int verbosity
,
300 mi_wrap_hint (struct ui_out
*uiout
, char *identstring
)
302 wrap_here (identstring
);
306 mi_flush (struct ui_out
*uiout
)
308 struct ui_out_data
*data
= ui_out_data (uiout
);
309 gdb_flush (data
->buffer
);
312 /* local functions */
314 /* Like mi_field_fmt, but takes a variable number of args
315 and makes a va_list and does not insert a separator */
319 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
322 struct ui_out_data
*data
= ui_out_data (uiout
);
325 field_separator (uiout
);
327 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
329 fputs_unfiltered ("\"", data
->buffer
);
331 va_start (args
, format
);
332 vfprintf_unfiltered (data
->buffer
, format
, args
);
334 fputs_unfiltered ("\"", data
->buffer
);
339 /* access to ui_out format private members */
342 field_separator (struct ui_out
*uiout
)
344 struct ui_out_data
*data
= ui_out_data (uiout
);
345 if (data
->suppress_field_separator
)
346 data
->suppress_field_separator
= 0;
348 fputc_unfiltered (',', data
->buffer
);
352 mi_open (struct ui_out
*uiout
,
354 enum ui_out_type type
)
356 struct ui_out_data
*data
= ui_out_data (uiout
);
357 field_separator (uiout
);
358 data
->suppress_field_separator
= 1;
360 fprintf_unfiltered (data
->buffer
, "%s=", name
);
363 case ui_out_type_tuple
:
364 fputc_unfiltered ('{', data
->buffer
);
366 case ui_out_type_list
:
367 if (data
->mi_version
== 0)
368 fputc_unfiltered ('{', data
->buffer
);
370 fputc_unfiltered ('[', data
->buffer
);
373 internal_error (__FILE__
, __LINE__
, "bad switch");
378 mi_close (struct ui_out
*uiout
,
379 enum ui_out_type type
)
381 struct ui_out_data
*data
= ui_out_data (uiout
);
384 case ui_out_type_tuple
:
385 fputc_unfiltered ('}', data
->buffer
);
387 case ui_out_type_list
:
388 if (data
->mi_version
== 0)
389 fputc_unfiltered ('}', data
->buffer
);
391 fputc_unfiltered (']', data
->buffer
);
394 internal_error (__FILE__
, __LINE__
, "bad switch");
396 data
->suppress_field_separator
= 0;
399 /* add a string to the buffer */
402 mi_out_buffered (struct ui_out
*uiout
, char *string
)
404 struct ui_out_data
*data
= ui_out_data (uiout
);
405 fprintf_unfiltered (data
->buffer
, "%s", string
);
408 /* clear the buffer */
411 mi_out_rewind (struct ui_out
*uiout
)
413 struct ui_out_data
*data
= ui_out_data (uiout
);
414 ui_file_rewind (data
->buffer
);
417 /* dump the buffer onto the specified stream */
420 do_write (void *data
, const char *buffer
, long length_buffer
)
422 ui_file_write (data
, buffer
, length_buffer
);
426 mi_out_put (struct ui_out
*uiout
,
427 struct ui_file
*stream
)
429 struct ui_out_data
*data
= ui_out_data (uiout
);
430 ui_file_put (data
->buffer
, do_write
, stream
);
431 ui_file_rewind (data
->buffer
);
434 /* initalize private members at startup */
437 mi_out_new (int mi_version
)
440 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
441 data
->suppress_field_separator
= 0;
442 data
->mi_version
= mi_version
;
443 /* FIXME: This code should be using a ``string_file'' and not the
445 data
->buffer
= mem_fileopen ();
446 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
449 /* standard gdb initialization hook */
451 _initialize_mi_out (void)
453 /* nothing happens here */