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
;
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
, 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
, int nbrofcols
,
110 struct ui_out_data
*data
= ui_out_data (uiout
);
111 mi_open (uiout
, tblid
, ui_out_type_tuple
);
112 data
->first_header
= 0;
115 /* Mark beginning of a table body */
118 mi_table_body (struct ui_out
*uiout
)
120 struct ui_out_data
*data
= ui_out_data (uiout
);
121 /* close the table header line if there were any headers */
122 if (data
->first_header
)
123 mi_close (uiout
, ui_out_type_tuple
);
126 /* Mark end of a table */
129 mi_table_end (struct ui_out
*uiout
)
131 struct ui_out_data
*data
= ui_out_data (uiout
);
132 mi_close (uiout
, ui_out_type_tuple
);
135 /* Specify table header */
138 mi_table_header (struct ui_out
*uiout
, int width
, int alignment
,
141 struct ui_out_data
*data
= ui_out_data (uiout
);
142 if (!data
->first_header
++)
144 mi_open (uiout
, "hdr", ui_out_type_tuple
);
146 mi_field_string (uiout
, 0, width
, alignment
, 0, colhdr
);
149 /* Mark beginning of a list */
152 mi_begin (struct ui_out
*uiout
,
153 enum ui_out_type type
,
157 struct ui_out_data
*data
= ui_out_data (uiout
);
158 mi_open (uiout
, id
, type
);
161 /* Mark end of a list */
164 mi_end (struct ui_out
*uiout
,
165 enum ui_out_type type
,
168 struct ui_out_data
*data
= ui_out_data (uiout
);
169 mi_close (uiout
, type
);
172 /* output an int field */
175 mi_field_int (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
176 const char *fldname
, int value
)
178 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
180 sprintf (buffer
, "%d", value
);
181 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, buffer
);
184 /* used to ommit a field */
187 mi_field_skip (struct ui_out
*uiout
, int fldno
, int width
, int alignment
,
190 mi_field_string (uiout
, fldno
, width
, alignment
, fldname
, "");
193 /* other specific mi_field_* end up here so alignment and field
194 separators are both handled by mi_field_string */
197 mi_field_string (struct ui_out
*uiout
,
204 struct ui_out_data
*data
= ui_out_data (uiout
);
205 field_separator (uiout
);
207 fprintf_unfiltered (data
->buffer
, "%s=", fldname
);
208 fprintf_unfiltered (data
->buffer
, "\"");
210 fputstr_unfiltered (string
, '"', data
->buffer
);
211 fprintf_unfiltered (data
->buffer
, "\"");
214 /* This is the only field function that does not align */
217 mi_field_fmt (struct ui_out
*uiout
, int fldno
,
218 int width
, enum ui_align align
,
223 struct ui_out_data
*data
= ui_out_data (uiout
);
224 field_separator (uiout
);
226 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
228 fputs_unfiltered ("\"", data
->buffer
);
229 vfprintf_unfiltered (data
->buffer
, format
, args
);
230 fputs_unfiltered ("\"", data
->buffer
);
234 mi_spaces (struct ui_out
*uiout
, int numspaces
)
239 mi_text (struct ui_out
*uiout
, const char *string
)
244 mi_message (struct ui_out
*uiout
, int verbosity
,
251 mi_wrap_hint (struct ui_out
*uiout
, char *identstring
)
253 wrap_here (identstring
);
257 mi_flush (struct ui_out
*uiout
)
259 struct ui_out_data
*data
= ui_out_data (uiout
);
260 gdb_flush (data
->buffer
);
263 /* local functions */
265 /* Like mi_field_fmt, but takes a variable number of args
266 and makes a va_list and does not insert a separator */
270 out_field_fmt (struct ui_out
*uiout
, int fldno
, char *fldname
,
273 struct ui_out_data
*data
= ui_out_data (uiout
);
276 field_separator (uiout
);
278 fprintf_unfiltered (data
->buffer
, "%s=\"", fldname
);
280 fputs_unfiltered ("\"", data
->buffer
);
282 va_start (args
, format
);
283 vfprintf_unfiltered (data
->buffer
, format
, args
);
285 fputs_unfiltered ("\"", data
->buffer
);
290 /* access to ui_out format private members */
293 field_separator (struct ui_out
*uiout
)
295 struct ui_out_data
*data
= ui_out_data (uiout
);
296 if (data
->suppress_field_separator
)
297 data
->suppress_field_separator
= 0;
299 fputc_unfiltered (',', data
->buffer
);
303 mi_open (struct ui_out
*uiout
,
305 enum ui_out_type type
)
307 struct ui_out_data
*data
= ui_out_data (uiout
);
308 field_separator (uiout
);
309 data
->suppress_field_separator
= 1;
311 fprintf_unfiltered (data
->buffer
, "%s=", name
);
314 case ui_out_type_tuple
:
315 fputc_unfiltered ('{', data
->buffer
);
317 case ui_out_type_list
:
318 fputc_unfiltered ('[', data
->buffer
);
321 internal_error (__FILE__
, __LINE__
, "bad switch");
326 mi_close (struct ui_out
*uiout
,
327 enum ui_out_type type
)
329 struct ui_out_data
*data
= ui_out_data (uiout
);
332 case ui_out_type_tuple
:
333 fputc_unfiltered ('}', data
->buffer
);
335 case ui_out_type_list
:
336 fputc_unfiltered (']', data
->buffer
);
339 internal_error (__FILE__
, __LINE__
, "bad switch");
341 data
->suppress_field_separator
= 0;
344 /* add a string to the buffer */
347 mi_out_buffered (struct ui_out
*uiout
, char *string
)
349 struct ui_out_data
*data
= ui_out_data (uiout
);
350 fprintf_unfiltered (data
->buffer
, "%s", string
);
353 /* clear the buffer */
356 mi_out_rewind (struct ui_out
*uiout
)
358 struct ui_out_data
*data
= ui_out_data (uiout
);
359 ui_file_rewind (data
->buffer
);
362 /* dump the buffer onto the specified stream */
365 do_write (void *data
, const char *buffer
, long length_buffer
)
367 ui_file_write (data
, buffer
, length_buffer
);
371 mi_out_put (struct ui_out
*uiout
,
372 struct ui_file
*stream
)
374 struct ui_out_data
*data
= ui_out_data (uiout
);
375 ui_file_put (data
->buffer
, do_write
, stream
);
376 ui_file_rewind (data
->buffer
);
379 /* initalize private members at startup */
385 struct ui_out_data
*data
= XMALLOC (struct ui_out_data
);
386 data
->suppress_field_separator
= 0;
387 /* FIXME: This code should be using a ``string_file'' and not the
389 data
->buffer
= mem_fileopen ();
390 return ui_out_new (&mi_ui_out_impl
, data
, flags
);
393 /* standard gdb initialization hook */
395 _initialize_mi_out (void)
397 /* nothing happens here */