OLD | NEW |
1 /* MI Command Set - output generating routines. | 1 /* MI Command Set - output generating routines. |
2 | 2 |
3 Copyright (C) 2000, 2002-2005, 2007-2012 Free Software Foundation, | 3 Copyright (C) 2000, 2002-2005, 2007-2012 Free Software Foundation, |
4 Inc. | 4 Inc. |
5 | 5 |
6 Contributed by Cygnus Solutions (a Red Hat company). | 6 Contributed by Cygnus Solutions (a Red Hat company). |
7 | 7 |
8 This file is part of GDB. | 8 This file is part of GDB. |
9 | 9 |
10 This program is free software; you can redistribute it and/or modify | 10 This program is free software; you can redistribute it and/or modify |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 }; | 93 }; |
94 | 94 |
95 /* Prototypes for local functions */ | 95 /* Prototypes for local functions */ |
96 | 96 |
97 extern void _initialize_mi_out (void); | 97 extern void _initialize_mi_out (void); |
98 static void field_separator (struct ui_out *uiout); | 98 static void field_separator (struct ui_out *uiout); |
99 static void mi_open (struct ui_out *uiout, const char *name, | 99 static void mi_open (struct ui_out *uiout, const char *name, |
100 enum ui_out_type type); | 100 enum ui_out_type type); |
101 static void mi_close (struct ui_out *uiout, enum ui_out_type type); | 101 static void mi_close (struct ui_out *uiout, enum ui_out_type type); |
102 | 102 |
103 /* Mark beginning of a table */ | 103 /* Mark beginning of a table. */ |
104 | 104 |
105 void | 105 void |
106 mi_table_begin (struct ui_out *uiout, | 106 mi_table_begin (struct ui_out *uiout, |
107 int nr_cols, | 107 int nr_cols, |
108 int nr_rows, | 108 int nr_rows, |
109 const char *tblid) | 109 const char *tblid) |
110 { | 110 { |
111 mi_open (uiout, tblid, ui_out_type_tuple); | 111 mi_open (uiout, tblid, ui_out_type_tuple); |
112 mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/, | 112 mi_field_int (uiout, -1, -1, -1, "nr_rows", nr_rows); |
113 » » "nr_rows", nr_rows); | 113 mi_field_int (uiout, -1, -1, -1, "nr_cols", nr_cols); |
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); | 114 mi_open (uiout, "hdr", ui_out_type_list); |
117 } | 115 } |
118 | 116 |
119 /* Mark beginning of a table body */ | 117 /* Mark beginning of a table body. */ |
120 | 118 |
121 void | 119 void |
122 mi_table_body (struct ui_out *uiout) | 120 mi_table_body (struct ui_out *uiout) |
123 { | 121 { |
124 mi_out_data *data = ui_out_data (uiout); | 122 mi_out_data *data = ui_out_data (uiout); |
125 | 123 |
126 if (data->suppress_output) | 124 if (data->suppress_output) |
127 return; | 125 return; |
128 /* close the table header line if there were any headers */ | 126 /* close the table header line if there were any headers */ |
129 mi_close (uiout, ui_out_type_list); | 127 mi_close (uiout, ui_out_type_list); |
130 mi_open (uiout, "body", ui_out_type_list); | 128 mi_open (uiout, "body", ui_out_type_list); |
131 } | 129 } |
132 | 130 |
133 /* Mark end of a table */ | 131 /* Mark end of a table. */ |
134 | 132 |
135 void | 133 void |
136 mi_table_end (struct ui_out *uiout) | 134 mi_table_end (struct ui_out *uiout) |
137 { | 135 { |
138 mi_out_data *data = ui_out_data (uiout); | 136 mi_out_data *data = ui_out_data (uiout); |
139 | 137 |
140 data->suppress_output = 0; | 138 data->suppress_output = 0; |
141 mi_close (uiout, ui_out_type_list); /* body */ | 139 mi_close (uiout, ui_out_type_list); /* body */ |
142 mi_close (uiout, ui_out_type_tuple); | 140 mi_close (uiout, ui_out_type_tuple); |
143 } | 141 } |
144 | 142 |
145 /* Specify table header */ | 143 /* Specify table header. */ |
146 | 144 |
147 void | 145 void |
148 mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment, | 146 mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment, |
149 » » const char *col_name, | 147 » » const char *col_name, const char *colhdr) |
150 » » const char *colhdr) | |
151 { | 148 { |
152 mi_out_data *data = ui_out_data (uiout); | 149 mi_out_data *data = ui_out_data (uiout); |
153 | 150 |
154 if (data->suppress_output) | 151 if (data->suppress_output) |
155 return; | 152 return; |
| 153 |
156 mi_open (uiout, NULL, ui_out_type_tuple); | 154 mi_open (uiout, NULL, ui_out_type_tuple); |
157 mi_field_int (uiout, 0, 0, 0, "width", width); | 155 mi_field_int (uiout, 0, 0, 0, "width", width); |
158 mi_field_int (uiout, 0, 0, 0, "alignment", alignment); | 156 mi_field_int (uiout, 0, 0, 0, "alignment", alignment); |
159 mi_field_string (uiout, 0, 0, 0, "col_name", col_name); | 157 mi_field_string (uiout, 0, 0, 0, "col_name", col_name); |
160 mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr); | 158 mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr); |
161 mi_close (uiout, ui_out_type_tuple); | 159 mi_close (uiout, ui_out_type_tuple); |
162 } | 160 } |
163 | 161 |
164 /* Mark beginning of a list */ | 162 /* Mark beginning of a list. */ |
165 | 163 |
166 void | 164 void |
167 mi_begin (struct ui_out *uiout, | 165 mi_begin (struct ui_out *uiout, enum ui_out_type type, int level, |
168 » enum ui_out_type type, | |
169 » int level, | |
170 const char *id) | 166 const char *id) |
171 { | 167 { |
172 mi_out_data *data = ui_out_data (uiout); | 168 mi_out_data *data = ui_out_data (uiout); |
173 | 169 |
174 if (data->suppress_output) | 170 if (data->suppress_output) |
175 return; | 171 return; |
| 172 |
176 mi_open (uiout, id, type); | 173 mi_open (uiout, id, type); |
177 } | 174 } |
178 | 175 |
179 /* Mark end of a list */ | 176 /* Mark end of a list. */ |
180 | 177 |
181 void | 178 void |
182 mi_end (struct ui_out *uiout, | 179 mi_end (struct ui_out *uiout, enum ui_out_type type, int level) |
183 » enum ui_out_type type, | |
184 » int level) | |
185 { | 180 { |
186 mi_out_data *data = ui_out_data (uiout); | 181 mi_out_data *data = ui_out_data (uiout); |
187 | 182 |
188 if (data->suppress_output) | 183 if (data->suppress_output) |
189 return; | 184 return; |
| 185 |
190 mi_close (uiout, type); | 186 mi_close (uiout, type); |
191 } | 187 } |
192 | 188 |
193 /* output an int field */ | 189 /* Output an int field. */ |
194 | 190 |
195 void | 191 static void |
196 mi_field_int (struct ui_out *uiout, int fldno, int width, | 192 mi_field_int (struct ui_out *uiout, int fldno, int width, |
197 enum ui_align alignment, const char *fldname, int value) | 193 enum ui_align alignment, const char *fldname, int value) |
198 { | 194 { |
199 char buffer[20]; /* FIXME: how many chars long a %d can become? */ | 195 char buffer[20]; /* FIXME: how many chars long a %d can become? */ |
200 mi_out_data *data = ui_out_data (uiout); | 196 mi_out_data *data = ui_out_data (uiout); |
201 | 197 |
202 if (data->suppress_output) | 198 if (data->suppress_output) |
203 return; | 199 return; |
204 | 200 |
205 sprintf (buffer, "%d", value); | 201 sprintf (buffer, "%d", value); |
206 mi_field_string (uiout, fldno, width, alignment, fldname, buffer); | 202 mi_field_string (uiout, fldno, width, alignment, fldname, buffer); |
207 } | 203 } |
208 | 204 |
209 /* used to ommit a field */ | 205 /* Used to omit a field. */ |
210 | 206 |
211 void | 207 void |
212 mi_field_skip (struct ui_out *uiout, int fldno, int width, | 208 mi_field_skip (struct ui_out *uiout, int fldno, int width, |
213 enum ui_align alignment, const char *fldname) | 209 enum ui_align alignment, const char *fldname) |
214 { | 210 { |
215 } | 211 } |
216 | 212 |
217 /* other specific mi_field_* end up here so alignment and field | 213 /* Other specific mi_field_* end up here so alignment and field |
218 separators are both handled by mi_field_string */ | 214 separators are both handled by mi_field_string. */ |
219 | 215 |
220 void | 216 void |
221 mi_field_string (struct ui_out *uiout, | 217 mi_field_string (struct ui_out *uiout, int fldno, int width, |
222 » » int fldno, | 218 » » enum ui_align align, const char *fldname, const char *string) |
223 » » int width, | |
224 » » enum ui_align align, | |
225 » » const char *fldname, | |
226 » » const char *string) | |
227 { | 219 { |
228 mi_out_data *data = ui_out_data (uiout); | 220 mi_out_data *data = ui_out_data (uiout); |
229 | 221 |
230 if (data->suppress_output) | 222 if (data->suppress_output) |
231 return; | 223 return; |
| 224 |
232 field_separator (uiout); | 225 field_separator (uiout); |
233 if (fldname) | 226 if (fldname) |
234 fprintf_unfiltered (data->buffer, "%s=", fldname); | 227 fprintf_unfiltered (data->buffer, "%s=", fldname); |
235 fprintf_unfiltered (data->buffer, "\""); | 228 fprintf_unfiltered (data->buffer, "\""); |
236 if (string) | 229 if (string) |
237 fputstr_unfiltered (string, '"', data->buffer); | 230 fputstr_unfiltered (string, '"', data->buffer); |
238 fprintf_unfiltered (data->buffer, "\""); | 231 fprintf_unfiltered (data->buffer, "\""); |
239 } | 232 } |
240 | 233 |
241 /* This is the only field function that does not align */ | 234 /* This is the only field function that does not align. */ |
242 | 235 |
243 void | 236 void |
244 mi_field_fmt (struct ui_out *uiout, int fldno, | 237 mi_field_fmt (struct ui_out *uiout, int fldno, int width, |
245 » int width, enum ui_align align, | 238 » enum ui_align align, const char *fldname, |
246 » const char *fldname, | 239 » const char *format, va_list args) |
247 » const char *format, | |
248 » va_list args) | |
249 { | 240 { |
250 mi_out_data *data = ui_out_data (uiout); | 241 mi_out_data *data = ui_out_data (uiout); |
251 | 242 |
252 if (data->suppress_output) | 243 if (data->suppress_output) |
253 return; | 244 return; |
| 245 |
254 field_separator (uiout); | 246 field_separator (uiout); |
255 if (fldname) | 247 if (fldname) |
256 fprintf_unfiltered (data->buffer, "%s=\"", fldname); | 248 fprintf_unfiltered (data->buffer, "%s=\"", fldname); |
257 else | 249 else |
258 fputs_unfiltered ("\"", data->buffer); | 250 fputs_unfiltered ("\"", data->buffer); |
259 vfprintf_unfiltered (data->buffer, format, args); | 251 vfprintf_unfiltered (data->buffer, format, args); |
260 fputs_unfiltered ("\"", data->buffer); | 252 fputs_unfiltered ("\"", data->buffer); |
261 } | 253 } |
262 | 254 |
263 void | 255 void |
264 mi_spaces (struct ui_out *uiout, int numspaces) | 256 mi_spaces (struct ui_out *uiout, int numspaces) |
265 { | 257 { |
266 } | 258 } |
267 | 259 |
268 void | 260 void |
269 mi_text (struct ui_out *uiout, const char *string) | 261 mi_text (struct ui_out *uiout, const char *string) |
270 { | 262 { |
271 } | 263 } |
272 | 264 |
273 void | 265 void |
274 mi_message (struct ui_out *uiout, int verbosity, | 266 mi_message (struct ui_out *uiout, int verbosity, |
275 » const char *format, | 267 » const char *format, va_list args) |
276 » va_list args) | |
277 { | 268 { |
278 } | 269 } |
279 | 270 |
280 void | 271 void |
281 mi_wrap_hint (struct ui_out *uiout, char *identstring) | 272 mi_wrap_hint (struct ui_out *uiout, char *identstring) |
282 { | 273 { |
283 wrap_here (identstring); | 274 wrap_here (identstring); |
284 } | 275 } |
285 | 276 |
286 void | 277 void |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 { | 310 { |
320 mi_out_data *data = ui_out_data (uiout); | 311 mi_out_data *data = ui_out_data (uiout); |
321 | 312 |
322 if (data->suppress_field_separator) | 313 if (data->suppress_field_separator) |
323 data->suppress_field_separator = 0; | 314 data->suppress_field_separator = 0; |
324 else | 315 else |
325 fputc_unfiltered (',', data->buffer); | 316 fputc_unfiltered (',', data->buffer); |
326 } | 317 } |
327 | 318 |
328 static void | 319 static void |
329 mi_open (struct ui_out *uiout, | 320 mi_open (struct ui_out *uiout, const char *name, enum ui_out_type type) |
330 » const char *name, | |
331 » enum ui_out_type type) | |
332 { | 321 { |
333 mi_out_data *data = ui_out_data (uiout); | 322 mi_out_data *data = ui_out_data (uiout); |
334 | 323 |
335 field_separator (uiout); | 324 field_separator (uiout); |
336 data->suppress_field_separator = 1; | 325 data->suppress_field_separator = 1; |
337 if (name) | 326 if (name) |
338 fprintf_unfiltered (data->buffer, "%s=", name); | 327 fprintf_unfiltered (data->buffer, "%s=", name); |
339 switch (type) | 328 switch (type) |
340 { | 329 { |
341 case ui_out_type_tuple: | 330 case ui_out_type_tuple: |
342 fputc_unfiltered ('{', data->buffer); | 331 fputc_unfiltered ('{', data->buffer); |
343 break; | 332 break; |
344 case ui_out_type_list: | 333 case ui_out_type_list: |
345 fputc_unfiltered ('[', data->buffer); | 334 fputc_unfiltered ('[', data->buffer); |
346 break; | 335 break; |
347 default: | 336 default: |
348 internal_error (__FILE__, __LINE__, _("bad switch")); | 337 internal_error (__FILE__, __LINE__, _("bad switch")); |
349 } | 338 } |
350 } | 339 } |
351 | 340 |
352 static void | 341 static void |
353 mi_close (struct ui_out *uiout, | 342 mi_close (struct ui_out *uiout, enum ui_out_type type) |
354 » enum ui_out_type type) | |
355 { | 343 { |
356 mi_out_data *data = ui_out_data (uiout); | 344 mi_out_data *data = ui_out_data (uiout); |
357 | 345 |
358 switch (type) | 346 switch (type) |
359 { | 347 { |
360 case ui_out_type_tuple: | 348 case ui_out_type_tuple: |
361 fputc_unfiltered ('}', data->buffer); | 349 fputc_unfiltered ('}', data->buffer); |
362 break; | 350 break; |
363 case ui_out_type_list: | 351 case ui_out_type_list: |
364 fputc_unfiltered (']', data->buffer); | 352 fputc_unfiltered (']', data->buffer); |
365 break; | 353 break; |
366 default: | 354 default: |
367 internal_error (__FILE__, __LINE__, _("bad switch")); | 355 internal_error (__FILE__, __LINE__, _("bad switch")); |
368 } | 356 } |
369 data->suppress_field_separator = 0; | 357 data->suppress_field_separator = 0; |
370 } | 358 } |
371 | 359 |
372 /* add a string to the buffer */ | 360 /* Add a string to the buffer. */ |
373 | 361 |
374 void | 362 void |
375 mi_out_buffered (struct ui_out *uiout, char *string) | 363 mi_out_buffered (struct ui_out *uiout, char *string) |
376 { | 364 { |
377 mi_out_data *data = ui_out_data (uiout); | 365 mi_out_data *data = ui_out_data (uiout); |
378 | 366 |
379 fprintf_unfiltered (data->buffer, "%s", string); | 367 fprintf_unfiltered (data->buffer, "%s", string); |
380 } | 368 } |
381 | 369 |
382 /* clear the buffer */ | 370 /* Clear the buffer. */ |
383 | 371 |
384 void | 372 void |
385 mi_out_rewind (struct ui_out *uiout) | 373 mi_out_rewind (struct ui_out *uiout) |
386 { | 374 { |
387 mi_out_data *data = ui_out_data (uiout); | 375 mi_out_data *data = ui_out_data (uiout); |
388 | 376 |
389 ui_file_rewind (data->buffer); | 377 ui_file_rewind (data->buffer); |
390 } | 378 } |
391 | 379 |
392 /* dump the buffer onto the specified stream */ | 380 /* Dump the buffer onto the specified stream. */ |
393 | 381 |
394 static void | 382 static void |
395 do_write (void *data, const char *buffer, long length_buffer) | 383 do_write (void *data, const char *buffer, long length_buffer) |
396 { | 384 { |
397 ui_file_write (data, buffer, length_buffer); | 385 ui_file_write (data, buffer, length_buffer); |
398 } | 386 } |
399 | 387 |
400 void | 388 void |
401 mi_out_put (struct ui_out *uiout, | 389 mi_out_put (struct ui_out *uiout, struct ui_file *stream) |
402 » struct ui_file *stream) | |
403 { | 390 { |
404 mi_out_data *data = ui_out_data (uiout); | 391 mi_out_data *data = ui_out_data (uiout); |
405 | 392 |
406 ui_file_put (data->buffer, do_write, stream); | 393 ui_file_put (data->buffer, do_write, stream); |
407 ui_file_rewind (data->buffer); | 394 ui_file_rewind (data->buffer); |
408 } | 395 } |
409 | 396 |
410 /* Current MI version. */ | 397 /* Return the current MI version. */ |
411 | 398 |
412 int | 399 int |
413 mi_version (struct ui_out *uiout) | 400 mi_version (struct ui_out *uiout) |
414 { | 401 { |
415 mi_out_data *data = ui_out_data (uiout); | 402 mi_out_data *data = ui_out_data (uiout); |
416 | 403 |
417 return data->mi_version; | 404 return data->mi_version; |
418 } | 405 } |
419 | 406 |
420 /* initalize private members at startup */ | 407 /* Initialize private members at startup. */ |
421 | 408 |
422 struct ui_out * | 409 struct ui_out * |
423 mi_out_new (int mi_version) | 410 mi_out_new (int mi_version) |
424 { | 411 { |
425 int flags = 0; | 412 int flags = 0; |
426 | 413 |
427 mi_out_data *data = XMALLOC (mi_out_data); | 414 mi_out_data *data = XMALLOC (mi_out_data); |
428 data->suppress_field_separator = 0; | 415 data->suppress_field_separator = 0; |
429 data->suppress_output = 0; | 416 data->suppress_output = 0; |
430 data->mi_version = mi_version; | 417 data->mi_version = mi_version; |
431 /* FIXME: This code should be using a ``string_file'' and not the | 418 /* FIXME: This code should be using a ``string_file'' and not the |
432 TUI buffer hack. */ | 419 TUI buffer hack. */ |
433 data->buffer = mem_fileopen (); | 420 data->buffer = mem_fileopen (); |
434 return ui_out_new (&mi_ui_out_impl, data, flags); | 421 return ui_out_new (&mi_ui_out_impl, data, flags); |
435 } | 422 } |
436 | |
437 /* standard gdb initialization hook */ | |
438 void | |
439 _initialize_mi_out (void) | |
440 { | |
441 /* nothing happens here */ | |
442 } | |
OLD | NEW |