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