Incorrect .debug_line prologue header length for 64-bit DWARF
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
ecd75fc8 3 Copyright (C) 1999-2014 Free Software Foundation, Inc.
349c5d5f 4
8b93c638
JM
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
22
23#include "defs.h"
24#include "ui-out.h"
25#include "cli-out.h"
0e9f083f 26#include <string.h>
698384cd 27#include "gdb_assert.h"
14dba4b4 28#include "vec.h"
8b93c638 29
0a8fce9a 30typedef struct cli_ui_out_data cli_out_data;
8b93c638 31
8b93c638
JM
32
33/* Prototypes for local functions */
34
02a45ac0 35static void cli_text (struct ui_out *uiout, const char *string);
8b93c638
JM
36
37static void field_separator (void);
38
e2e11a41
AC
39static void out_field_fmt (struct ui_out *uiout, int fldno,
40 const char *fldname,
a0b31db1 41 const char *format,...) ATTRIBUTE_PRINTF (4, 5);
8b93c638 42
02a45ac0
PA
43/* These are the CLI output functions */
44
8b93c638
JM
45/* Mark beginning of a table */
46
02a45ac0 47static void
e2e11a41 48cli_table_begin (struct ui_out *uiout, int nbrofcols,
d63f1d40 49 int nr_rows,
e2e11a41 50 const char *tblid)
8b93c638 51{
1248ede2 52 cli_out_data *data = ui_out_data (uiout);
c5504eaf 53
698384cd
AC
54 if (nr_rows == 0)
55 data->suppress_output = 1;
56 else
ce2826aa 57 /* Only the table suppresses the output and, fortunately, a table
30fdc99f 58 is not a recursive data structure. */
698384cd 59 gdb_assert (data->suppress_output == 0);
8b93c638
JM
60}
61
62/* Mark beginning of a table body */
63
02a45ac0 64static void
fba45db2 65cli_table_body (struct ui_out *uiout)
8b93c638 66{
1248ede2 67 cli_out_data *data = ui_out_data (uiout);
c5504eaf 68
698384cd
AC
69 if (data->suppress_output)
70 return;
8b93c638
JM
71 /* first, close the table header line */
72 cli_text (uiout, "\n");
73}
74
75/* Mark end of a table */
76
02a45ac0 77static void
fba45db2 78cli_table_end (struct ui_out *uiout)
8b93c638 79{
1248ede2 80 cli_out_data *data = ui_out_data (uiout);
c5504eaf 81
698384cd 82 data->suppress_output = 0;
8b93c638
JM
83}
84
85/* Specify table header */
86
02a45ac0 87static void
fba45db2 88cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
b25959ec 89 const char *col_name,
e2e11a41 90 const char *colhdr)
8b93c638 91{
1248ede2 92 cli_out_data *data = ui_out_data (uiout);
c5504eaf 93
698384cd
AC
94 if (data->suppress_output)
95 return;
0a8fce9a
PA
96
97 /* Always go through the function pointer (virtual function call).
98 We may have been extended. */
99 uo_field_string (uiout, 0, width, alignment, 0, colhdr);
8b93c638
JM
100}
101
102/* Mark beginning of a list */
103
02a45ac0 104static void
631ec795
AC
105cli_begin (struct ui_out *uiout,
106 enum ui_out_type type,
107 int level,
108 const char *id)
8b93c638 109{
1248ede2 110 cli_out_data *data = ui_out_data (uiout);
c5504eaf 111
698384cd
AC
112 if (data->suppress_output)
113 return;
8b93c638
JM
114}
115
116/* Mark end of a list */
117
02a45ac0 118static void
631ec795
AC
119cli_end (struct ui_out *uiout,
120 enum ui_out_type type,
121 int level)
8b93c638 122{
1248ede2 123 cli_out_data *data = ui_out_data (uiout);
c5504eaf 124
698384cd
AC
125 if (data->suppress_output)
126 return;
8b93c638
JM
127}
128
129/* output an int field */
130
02a45ac0 131static void
fba45db2 132cli_field_int (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
133 enum ui_align alignment,
134 const char *fldname, int value)
8b93c638 135{
c5504eaf 136 char buffer[20]; /* FIXME: how many chars long a %d can become? */
1248ede2 137 cli_out_data *data = ui_out_data (uiout);
c5504eaf 138
698384cd
AC
139 if (data->suppress_output)
140 return;
08850b56 141 xsnprintf (buffer, sizeof (buffer), "%d", value);
0a8fce9a
PA
142
143 /* Always go through the function pointer (virtual function call).
144 We may have been extended. */
145 uo_field_string (uiout, fldno, width, alignment, fldname, buffer);
8b93c638
JM
146}
147
148/* used to ommit a field */
149
02a45ac0 150static void
fba45db2 151cli_field_skip (struct ui_out *uiout, int fldno, int width,
e2e11a41
AC
152 enum ui_align alignment,
153 const char *fldname)
8b93c638 154{
1248ede2 155 cli_out_data *data = ui_out_data (uiout);
c5504eaf 156
698384cd
AC
157 if (data->suppress_output)
158 return;
0a8fce9a
PA
159
160 /* Always go through the function pointer (virtual function call).
161 We may have been extended. */
162 uo_field_string (uiout, fldno, width, alignment, fldname, "");
8b93c638
JM
163}
164
165/* other specific cli_field_* end up here so alignment and field
166 separators are both handled by cli_field_string */
167
02a45ac0 168static void
8b93c638
JM
169cli_field_string (struct ui_out *uiout,
170 int fldno,
171 int width,
55555bbc 172 enum ui_align align,
e2e11a41 173 const char *fldname,
8b93c638
JM
174 const char *string)
175{
176 int before = 0;
177 int after = 0;
1248ede2 178 cli_out_data *data = ui_out_data (uiout);
c5504eaf 179
698384cd
AC
180 if (data->suppress_output)
181 return;
182
8b93c638
JM
183 if ((align != ui_noalign) && string)
184 {
185 before = width - strlen (string);
186 if (before <= 0)
187 before = 0;
188 else
189 {
190 if (align == ui_right)
191 after = 0;
192 else if (align == ui_left)
193 {
194 after = before;
195 before = 0;
196 }
197 else
198 /* ui_center */
199 {
200 after = before / 2;
201 before -= after;
202 }
203 }
204 }
205
206 if (before)
207 ui_out_spaces (uiout, before);
208 if (string)
209 out_field_fmt (uiout, fldno, fldname, "%s", string);
210 if (after)
211 ui_out_spaces (uiout, after);
212
213 if (align != ui_noalign)
214 field_separator ();
215}
216
30fdc99f 217/* This is the only field function that does not align. */
8b93c638 218
a0b31db1 219static void ATTRIBUTE_PRINTF (6, 0)
8b93c638
JM
220cli_field_fmt (struct ui_out *uiout, int fldno,
221 int width, enum ui_align align,
e2e11a41
AC
222 const char *fldname,
223 const char *format,
224 va_list args)
8b93c638 225{
1248ede2 226 cli_out_data *data = ui_out_data (uiout);
14dba4b4 227 struct ui_file *stream;
c5504eaf 228
698384cd
AC
229 if (data->suppress_output)
230 return;
231
14dba4b4
JK
232 stream = VEC_last (ui_filep, data->streams);
233 vfprintf_filtered (stream, format, args);
8b93c638
JM
234
235 if (align != ui_noalign)
236 field_separator ();
237}
238
02a45ac0 239static void
fba45db2 240cli_spaces (struct ui_out *uiout, int numspaces)
8b93c638 241{
1248ede2 242 cli_out_data *data = ui_out_data (uiout);
14dba4b4 243 struct ui_file *stream;
c5504eaf 244
698384cd
AC
245 if (data->suppress_output)
246 return;
14dba4b4
JK
247
248 stream = VEC_last (ui_filep, data->streams);
249 print_spaces_filtered (numspaces, stream);
8b93c638
JM
250}
251
02a45ac0 252static void
e2e11a41 253cli_text (struct ui_out *uiout, const char *string)
8b93c638 254{
1248ede2 255 cli_out_data *data = ui_out_data (uiout);
14dba4b4 256 struct ui_file *stream;
c5504eaf 257
698384cd
AC
258 if (data->suppress_output)
259 return;
14dba4b4
JK
260
261 stream = VEC_last (ui_filep, data->streams);
262 fputs_filtered (string, stream);
8b93c638
JM
263}
264
a0b31db1 265static void ATTRIBUTE_PRINTF (3, 0)
e2e11a41
AC
266cli_message (struct ui_out *uiout, int verbosity,
267 const char *format, va_list args)
8b93c638 268{
1248ede2 269 cli_out_data *data = ui_out_data (uiout);
c5504eaf 270
698384cd
AC
271 if (data->suppress_output)
272 return;
14dba4b4 273
8b93c638 274 if (ui_out_get_verblvl (uiout) >= verbosity)
14dba4b4
JK
275 {
276 struct ui_file *stream = VEC_last (ui_filep, data->streams);
277
278 vfprintf_unfiltered (stream, format, args);
279 }
8b93c638
JM
280}
281
02a45ac0 282static void
fba45db2 283cli_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638 284{
1248ede2 285 cli_out_data *data = ui_out_data (uiout);
c5504eaf 286
698384cd
AC
287 if (data->suppress_output)
288 return;
8b93c638
JM
289 wrap_here (identstring);
290}
291
02a45ac0 292static void
fba45db2 293cli_flush (struct ui_out *uiout)
8b93c638 294{
1248ede2 295 cli_out_data *data = ui_out_data (uiout);
14dba4b4 296 struct ui_file *stream = VEC_last (ui_filep, data->streams);
c5504eaf 297
14dba4b4 298 gdb_flush (stream);
8b93c638
JM
299}
300
14dba4b4
JK
301/* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
302 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
303 output stream; it is an internal error if it does not exist. */
304
02a45ac0 305static int
0fac0b41
DJ
306cli_redirect (struct ui_out *uiout, struct ui_file *outstream)
307{
0a8fce9a 308 cli_out_data *data = ui_out_data (uiout);
c5504eaf 309
0fac0b41 310 if (outstream != NULL)
14dba4b4
JK
311 VEC_safe_push (ui_filep, data->streams, outstream);
312 else
313 VEC_pop (ui_filep, data->streams);
0fac0b41
DJ
314
315 return 0;
316}
317
8b93c638
JM
318/* local functions */
319
320/* Like cli_field_fmt, but takes a variable number of args
30fdc99f 321 and makes a va_list and does not insert a separator. */
8b93c638
JM
322
323/* VARARGS */
324static void
e2e11a41
AC
325out_field_fmt (struct ui_out *uiout, int fldno,
326 const char *fldname,
327 const char *format,...)
8b93c638 328{
1248ede2 329 cli_out_data *data = ui_out_data (uiout);
14dba4b4 330 struct ui_file *stream = VEC_last (ui_filep, data->streams);
8b93c638
JM
331 va_list args;
332
333 va_start (args, format);
14dba4b4 334 vfprintf_filtered (stream, format, args);
8b93c638
JM
335
336 va_end (args);
337}
338
30fdc99f 339/* Access to ui_out format private members. */
8b93c638
JM
340
341static void
fba45db2 342field_separator (void)
8b93c638 343{
79a45e25 344 cli_out_data *data = ui_out_data (current_uiout);
14dba4b4 345 struct ui_file *stream = VEC_last (ui_filep, data->streams);
c5504eaf 346
14dba4b4 347 fputc_filtered (' ', stream);
8b93c638
JM
348}
349
02a45ac0
PA
350/* This is the CLI ui-out implementation functions vector */
351
352/* FIXME: This can be initialized dynamically after default is set to
353 handle initial output in main.c */
354
355struct ui_out_impl cli_ui_out_impl =
356{
357 cli_table_begin,
358 cli_table_body,
359 cli_table_end,
360 cli_table_header,
361 cli_begin,
362 cli_end,
363 cli_field_int,
364 cli_field_skip,
365 cli_field_string,
366 cli_field_fmt,
367 cli_spaces,
368 cli_text,
369 cli_message,
370 cli_wrap_hint,
371 cli_flush,
372 cli_redirect,
b65a2bd9 373 0,
02a45ac0
PA
374 0, /* Does not need MI hacks (i.e. needs CLI hacks). */
375};
376
0a8fce9a
PA
377/* Constructor for a `cli_out_data' object. */
378
379void
380cli_out_data_ctor (cli_out_data *self, struct ui_file *stream)
381{
14dba4b4
JK
382 gdb_assert (stream != NULL);
383
384 self->streams = NULL;
385 VEC_safe_push (ui_filep, self->streams, stream);
386
0a8fce9a
PA
387 self->suppress_output = 0;
388}
389
390/* Initialize private members at startup. */
8b93c638
JM
391
392struct ui_out *
393cli_out_new (struct ui_file *stream)
394{
395 int flags = ui_source_list;
70ba0933 396 cli_out_data *data = XNEW (cli_out_data);
c5504eaf 397
0a8fce9a 398 cli_out_data_ctor (data, stream);
8b93c638
JM
399 return ui_out_new (&cli_ui_out_impl, data, flags);
400}
401
4389a95a
AC
402struct ui_file *
403cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
404{
1248ede2 405 cli_out_data *data = ui_out_data (uiout);
14dba4b4
JK
406 struct ui_file *old;
407
408 old = VEC_pop (ui_filep, data->streams);
409 VEC_quick_push (ui_filep, data->streams, stream);
c5504eaf 410
4389a95a
AC
411 return old;
412}
This page took 0.91369 seconds and 4 git commands to generate.