* configure.tgt (i[3456]86-*-openbsd*): Set gdb_target to obds.
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
CommitLineData
fb40c209 1/* MI Command Set - output generating routines.
349c5d5f
AC
2
3 Copyright 2000, 2002 Free Software Foundation, Inc.
4
ab91fdd5 5 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
6
7 This file is part of GDB.
8
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.
13
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.
18
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. */
23
24#include "defs.h"
25#include "ui-out.h"
26#include "mi-out.h"
27
fb40c209
AC
28struct ui_out_data
29 {
59807497 30 int suppress_field_separator;
76fe6b98 31 int suppress_output;
b30bf9ee 32 int mi_version;
fb40c209
AC
33 struct ui_file *buffer;
34 };
35
36/* These are the MI output functions */
37
e2e11a41 38static void mi_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 39 int nr_rows, const char *tblid);
fb40c209
AC
40static void mi_table_body (struct ui_out *uiout);
41static void mi_table_end (struct ui_out *uiout);
42static void mi_table_header (struct ui_out *uiout, int width,
b25959ec 43 enum ui_align alig, const char *col_name,
e2e11a41 44 const char *colhdr);
631ec795
AC
45static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
46 int level, const char *id);
47static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
fb40c209 48static void mi_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41 49 enum ui_align alig, const char *fldname, int value);
fb40c209 50static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41 51 enum ui_align alig, const char *fldname);
fb40c209 52static void mi_field_string (struct ui_out *uiout, int fldno, int width,
e2e11a41 53 enum ui_align alig, const char *fldname,
fb40c209
AC
54 const char *string);
55static void mi_field_fmt (struct ui_out *uiout, int fldno,
56 int width, enum ui_align align,
e2e11a41
AC
57 const char *fldname, const char *format,
58 va_list args);
fb40c209 59static void mi_spaces (struct ui_out *uiout, int numspaces);
e2e11a41
AC
60static void mi_text (struct ui_out *uiout, const char *string);
61static void mi_message (struct ui_out *uiout, int verbosity,
62 const char *format, va_list args);
fb40c209
AC
63static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
64static void mi_flush (struct ui_out *uiout);
65
66/* This is the MI ui-out implementation functions vector */
67
68/* FIXME: This can be initialized dynamically after default is set to
69 handle initial output in main.c */
70
71struct ui_out_impl mi_ui_out_impl =
72{
73 mi_table_begin,
74 mi_table_body,
75 mi_table_end,
76 mi_table_header,
631ec795
AC
77 mi_begin,
78 mi_end,
fb40c209
AC
79 mi_field_int,
80 mi_field_skip,
81 mi_field_string,
82 mi_field_fmt,
83 mi_spaces,
84 mi_text,
85 mi_message,
86 mi_wrap_hint,
9dc5e2a9
AC
87 mi_flush,
88 1, /* Needs MI hacks. */
fb40c209
AC
89};
90
91/* Prototypes for local functions */
92
a14ed312 93extern void _initialize_mi_out (void);
fb40c209 94static void field_separator (struct ui_out *uiout);
d5e8ba62
AC
95static void mi_open (struct ui_out *uiout, const char *name,
96 enum ui_out_type type);
9a0f0643 97static void mi_close (struct ui_out *uiout, enum ui_out_type type);
fb40c209
AC
98
99static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
100 char *format,...);
101
102/* Mark beginning of a table */
103
104void
cff22675
AC
105mi_table_begin (struct ui_out *uiout,
106 int nr_cols,
d63f1d40 107 int nr_rows,
e2e11a41 108 const char *tblid)
fb40c209
AC
109{
110 struct ui_out_data *data = ui_out_data (uiout);
d5e8ba62 111 mi_open (uiout, tblid, ui_out_type_tuple);
cff22675
AC
112 mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/,
113 "nr_rows", nr_rows);
114 mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/,
115 "nr_cols", nr_cols);
116 mi_open (uiout, "hdr", ui_out_type_list);
fb40c209
AC
117}
118
119/* Mark beginning of a table body */
120
121void
fba45db2 122mi_table_body (struct ui_out *uiout)
fb40c209
AC
123{
124 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
125 if (data->suppress_output)
126 return;
cff22675
AC
127 /* close the table header line if there were any headers */
128 mi_close (uiout, ui_out_type_list);
cff22675 129 mi_open (uiout, "body", ui_out_type_list);
fb40c209
AC
130}
131
132/* Mark end of a table */
133
134void
fba45db2 135mi_table_end (struct ui_out *uiout)
fb40c209
AC
136{
137 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98 138 data->suppress_output = 0;
cff22675 139 mi_close (uiout, ui_out_type_list); /* body */
666547aa 140 mi_close (uiout, ui_out_type_tuple);
fb40c209
AC
141}
142
143/* Specify table header */
144
145void
46712191 146mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 147 const char *col_name,
e2e11a41 148 const char *colhdr)
fb40c209
AC
149{
150 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
151 if (data->suppress_output)
152 return;
cff22675
AC
153 mi_open (uiout, NULL, ui_out_type_tuple);
154 mi_field_int (uiout, 0, 0, 0, "width", width);
155 mi_field_int (uiout, 0, 0, 0, "alignment", alignment);
156 mi_field_string (uiout, 0, 0, 0, "col_name", col_name);
157 mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
158 mi_close (uiout, ui_out_type_tuple);
fb40c209
AC
159}
160
161/* Mark beginning of a list */
162
163void
631ec795
AC
164mi_begin (struct ui_out *uiout,
165 enum ui_out_type type,
166 int level,
9a0f0643 167 const char *id)
fb40c209
AC
168{
169 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
170 if (data->suppress_output)
171 return;
d5e8ba62 172 mi_open (uiout, id, type);
fb40c209
AC
173}
174
175/* Mark end of a list */
176
177void
631ec795
AC
178mi_end (struct ui_out *uiout,
179 enum ui_out_type type,
180 int level)
fb40c209
AC
181{
182 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
183 if (data->suppress_output)
184 return;
9a0f0643 185 mi_close (uiout, type);
fb40c209
AC
186}
187
188/* output an int field */
189
190void
46712191
KB
191mi_field_int (struct ui_out *uiout, int fldno, int width,
192 enum ui_align alignment, const char *fldname, int value)
fb40c209
AC
193{
194 char buffer[20]; /* FIXME: how many chars long a %d can become? */
76fe6b98
AC
195 struct ui_out_data *data = ui_out_data (uiout);
196 if (data->suppress_output)
197 return;
fb40c209
AC
198
199 sprintf (buffer, "%d", value);
200 mi_field_string (uiout, fldno, width, alignment, fldname, buffer);
201}
202
203/* used to ommit a field */
204
205void
46712191
KB
206mi_field_skip (struct ui_out *uiout, int fldno, int width,
207 enum ui_align alignment, const char *fldname)
fb40c209 208{
76fe6b98
AC
209 struct ui_out_data *data = ui_out_data (uiout);
210 if (data->suppress_output)
211 return;
fb40c209
AC
212 mi_field_string (uiout, fldno, width, alignment, fldname, "");
213}
214
215/* other specific mi_field_* end up here so alignment and field
216 separators are both handled by mi_field_string */
217
218void
219mi_field_string (struct ui_out *uiout,
220 int fldno,
221 int width,
46712191 222 enum ui_align align,
e2e11a41 223 const char *fldname,
fb40c209
AC
224 const char *string)
225{
226 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
227 if (data->suppress_output)
228 return;
fb40c209
AC
229 field_separator (uiout);
230 if (fldname)
231 fprintf_unfiltered (data->buffer, "%s=", fldname);
232 fprintf_unfiltered (data->buffer, "\"");
233 if (string)
234 fputstr_unfiltered (string, '"', data->buffer);
235 fprintf_unfiltered (data->buffer, "\"");
236}
237
238/* This is the only field function that does not align */
239
240void
241mi_field_fmt (struct ui_out *uiout, int fldno,
242 int width, enum ui_align align,
e2e11a41
AC
243 const char *fldname,
244 const char *format,
245 va_list args)
fb40c209
AC
246{
247 struct ui_out_data *data = ui_out_data (uiout);
76fe6b98
AC
248 if (data->suppress_output)
249 return;
fb40c209
AC
250 field_separator (uiout);
251 if (fldname)
252 fprintf_unfiltered (data->buffer, "%s=\"", fldname);
253 else
254 fputs_unfiltered ("\"", data->buffer);
255 vfprintf_unfiltered (data->buffer, format, args);
256 fputs_unfiltered ("\"", data->buffer);
257}
258
259void
fba45db2 260mi_spaces (struct ui_out *uiout, int numspaces)
fb40c209
AC
261{
262}
263
264void
e2e11a41 265mi_text (struct ui_out *uiout, const char *string)
fb40c209
AC
266{
267}
268
269void
e2e11a41
AC
270mi_message (struct ui_out *uiout, int verbosity,
271 const char *format,
272 va_list args)
fb40c209
AC
273{
274}
275
276void
fba45db2 277mi_wrap_hint (struct ui_out *uiout, char *identstring)
fb40c209
AC
278{
279 wrap_here (identstring);
280}
281
282void
fba45db2 283mi_flush (struct ui_out *uiout)
fb40c209
AC
284{
285 struct ui_out_data *data = ui_out_data (uiout);
286 gdb_flush (data->buffer);
287}
288
289/* local functions */
290
291/* Like mi_field_fmt, but takes a variable number of args
292 and makes a va_list and does not insert a separator */
293
294/* VARARGS */
295static void
296out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
297 char *format,...)
298{
299 struct ui_out_data *data = ui_out_data (uiout);
300 va_list args;
301
302 field_separator (uiout);
303 if (fldname)
304 fprintf_unfiltered (data->buffer, "%s=\"", fldname);
305 else
306 fputs_unfiltered ("\"", data->buffer);
307
308 va_start (args, format);
309 vfprintf_unfiltered (data->buffer, format, args);
310
311 fputs_unfiltered ("\"", data->buffer);
312
313 va_end (args);
314}
315
316/* access to ui_out format private members */
317
318static void
319field_separator (struct ui_out *uiout)
320{
321 struct ui_out_data *data = ui_out_data (uiout);
59807497
AC
322 if (data->suppress_field_separator)
323 data->suppress_field_separator = 0;
fb40c209
AC
324 else
325 fputc_unfiltered (',', data->buffer);
326}
327
328static void
9a0f0643 329mi_open (struct ui_out *uiout,
d5e8ba62 330 const char *name,
9a0f0643 331 enum ui_out_type type)
fb40c209
AC
332{
333 struct ui_out_data *data = ui_out_data (uiout);
d5e8ba62 334 field_separator (uiout);
59807497 335 data->suppress_field_separator = 1;
d5e8ba62
AC
336 if (name)
337 fprintf_unfiltered (data->buffer, "%s=", name);
5a9aa5dc
AC
338 switch (type)
339 {
340 case ui_out_type_tuple:
341 fputc_unfiltered ('{', data->buffer);
342 break;
343 case ui_out_type_list:
da0f9dcd 344 fputc_unfiltered ('[', data->buffer);
5a9aa5dc
AC
345 break;
346 default:
347 internal_error (__FILE__, __LINE__, "bad switch");
348 }
fb40c209
AC
349}
350
351static void
9a0f0643
AC
352mi_close (struct ui_out *uiout,
353 enum ui_out_type type)
fb40c209
AC
354{
355 struct ui_out_data *data = ui_out_data (uiout);
5a9aa5dc
AC
356 switch (type)
357 {
358 case ui_out_type_tuple:
359 fputc_unfiltered ('}', data->buffer);
360 break;
361 case ui_out_type_list:
da0f9dcd 362 fputc_unfiltered (']', data->buffer);
5a9aa5dc
AC
363 break;
364 default:
365 internal_error (__FILE__, __LINE__, "bad switch");
366 }
59807497 367 data->suppress_field_separator = 0;
fb40c209
AC
368}
369
370/* add a string to the buffer */
371
372void
373mi_out_buffered (struct ui_out *uiout, char *string)
374{
375 struct ui_out_data *data = ui_out_data (uiout);
376 fprintf_unfiltered (data->buffer, "%s", string);
377}
378
379/* clear the buffer */
380
381void
382mi_out_rewind (struct ui_out *uiout)
383{
384 struct ui_out_data *data = ui_out_data (uiout);
385 ui_file_rewind (data->buffer);
386}
387
388/* dump the buffer onto the specified stream */
389
390static void
391do_write (void *data, const char *buffer, long length_buffer)
392{
393 ui_file_write (data, buffer, length_buffer);
394}
395
396void
397mi_out_put (struct ui_out *uiout,
398 struct ui_file *stream)
399{
400 struct ui_out_data *data = ui_out_data (uiout);
401 ui_file_put (data->buffer, do_write, stream);
402 ui_file_rewind (data->buffer);
403}
404
c7ec4050
AC
405/* Current MI version. */
406
407int
408mi_version (struct ui_out *uiout)
409{
410 struct ui_out_data *data = ui_out_data (uiout);
411 return data->mi_version;
412}
413
fb40c209
AC
414/* initalize private members at startup */
415
416struct ui_out *
b30bf9ee 417mi_out_new (int mi_version)
fb40c209
AC
418{
419 int flags = 0;
420 struct ui_out_data *data = XMALLOC (struct ui_out_data);
59807497 421 data->suppress_field_separator = 0;
bf702e7e 422 data->suppress_output = 0;
b30bf9ee 423 data->mi_version = mi_version;
fb40c209
AC
424 /* FIXME: This code should be using a ``string_file'' and not the
425 TUI buffer hack. */
426 data->buffer = mem_fileopen ();
427 return ui_out_new (&mi_ui_out_impl, data, flags);
428}
429
430/* standard gdb initialization hook */
431void
fba45db2 432_initialize_mi_out (void)
fb40c209
AC
433{
434 /* nothing happens here */
435}
This page took 0.234071 seconds and 4 git commands to generate.