Bug Summary

File:src/gnu/usr.bin/binutils/gdb/ada-typeprint.c
Warning:line 241, column 3
Null pointer passed as 1st argument to string copy function

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ada-typeprint.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -resource-dir /usr/local/lib/clang/13.0.0 -D PIE_DEFAULT=1 -I . -I /usr/src/gnu/usr.bin/binutils/gdb -I /usr/src/gnu/usr.bin/binutils/gdb/config -D LOCALEDIR="/usr/share/locale" -D HAVE_CONFIG_H -I /usr/src/gnu/usr.bin/binutils/gdb/../include/opcode -I ../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../include -I ../intl -I /usr/src/gnu/usr.bin/binutils/gdb/../intl -D MI_OUT=1 -D TUI=1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -fcommon -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/binutils/gdb/ada-typeprint.c
1/* Support for printing Ada types for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include "defs.h"
22#include "gdb_obstack.h"
23#include "bfd.h" /* Binary File Description */
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
28#include "gdbcore.h"
29#include "target.h"
30#include "command.h"
31#include "gdbcmd.h"
32#include "language.h"
33#include "demangle.h"
34#include "c-lang.h"
35#include "typeprint.h"
36#include "ada-lang.h"
37
38#include <ctype.h>
39#include "gdb_string.h"
40#include <errno(*__errno()).h>
41
42static int print_record_field_types (struct type *, struct type *,
43 struct ui_file *, int, int);
44
45static void print_array_type (struct type *, struct ui_file *, int, int);
46
47static void print_choices (struct type *, int, struct ui_file *,
48 struct type *);
49
50static void print_range (struct type *, struct ui_file *);
51
52static void print_range_bound (struct type *, char *, int *,
53 struct ui_file *);
54
55static void
56print_dynamic_range_bound (struct type *, const char *, int,
57 const char *, struct ui_file *);
58
59static void print_range_type_named (char *, struct ui_file *);
60
61
62
63static char *name_buffer;
64static int name_buffer_len;
65
66/* The (decoded) Ada name of TYPE. This value persists until the
67 next call. */
68
69static char *
70decoded_type_name (struct type *type)
71{
72 if (ada_type_name (type) == NULL((void*)0))
73 return NULL((void*)0);
74 else
75 {
76 char *raw_name = ada_type_name (type);
77 char *s, *q;
78
79 if (name_buffer == NULL((void*)0) || name_buffer_len <= strlen (raw_name))
80 {
81 name_buffer_len = 16 + 2 * strlen (raw_name);
82 name_buffer = xrealloc (name_buffer, name_buffer_len);
83 }
84 strcpy (name_buffer, raw_name);
85
86 s = (char *) strstr (name_buffer, "___");
87 if (s != NULL((void*)0))
88 *s = '\0';
89
90 s = name_buffer + strlen (name_buffer) - 1;
91 while (s > name_buffer && (s[0] != '_' || s[-1] != '_'))
92 s -= 1;
93
94 if (s == name_buffer)
95 return name_buffer;
96
97 if (!islower (s[1]))
98 return NULL((void*)0);
99
100 for (s = q = name_buffer; *s != '\0'; q += 1)
101 {
102 if (s[0] == '_' && s[1] == '_')
103 {
104 *q = '.';
105 s += 2;
106 }
107 else
108 {
109 *q = *s;
110 s += 1;
111 }
112 }
113 *q = '\0';
114 return name_buffer;
115 }
116}
117
118
119/* Print a description of a type in the format of a
120 typedef for the current language.
121 NEW is the new name for a type TYPE. */
122
123void
124ada_typedef_print (struct type *type, struct symbol *new,
125 struct ui_file *stream)
126{
127 fprintf_filtered (stream, "type %.*s is ",
128 ada_name_prefix_len (SYMBOL_PRINT_NAME (new)(demangle ? (symbol_natural_name (&(new)->ginfo)) : (new
)->ginfo.name)
),
129 SYMBOL_PRINT_NAME (new)(demangle ? (symbol_natural_name (&(new)->ginfo)) : (new
)->ginfo.name)
);
130 type_print (type, "", stream, 1);
131}
132
133/* Print range type TYPE on STREAM. */
134
135static void
136print_range (struct type *type, struct ui_file *stream)
137{
138 struct type *target_type;
139 target_type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type;
140 if (target_type == NULL((void*)0))
141 target_type = type;
142
143 switch (TYPE_CODE (target_type)(target_type)->main_type->code)
144 {
145 case TYPE_CODE_RANGE:
146 case TYPE_CODE_INT:
147 case TYPE_CODE_BOOL:
148 case TYPE_CODE_CHAR:
149 case TYPE_CODE_ENUM:
150 break;
151 default:
152 target_type = builtin_type_int;
153 break;
154 }
155
156 if (TYPE_NFIELDS (type)(type)->main_type->nfields < 2)
157 {
158 /* A range needs at least 2 bounds to be printed. If there are less
159 than 2, just print the type name instead of the range itself.
160 This check handles cases such as characters, for example.
161
162 Note that if the name is not defined, then we don't print anything.
163 */
164 fprintf_filtered (stream, "%.*s",
165 ada_name_prefix_len (TYPE_NAME (type)(type)->main_type->name),
166 TYPE_NAME (type)(type)->main_type->name);
167 }
168 else
169 {
170 /* We extract the range type bounds respectively from the first element
171 and the last element of the type->fields array */
172 const LONGESTlong lower_bound = (LONGESTlong) TYPE_LOW_BOUND (type)(((type)->main_type->fields[0]).loc.bitpos);
173 const LONGESTlong upper_bound =
174 (LONGESTlong) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1)(((type)->main_type->fields[(type)->main_type->nfields
- 1]).loc.bitpos)
;
175
176 ada_print_scalar (target_type, lower_bound, stream);
177 fprintf_filtered (stream, " .. ");
178 ada_print_scalar (target_type, upper_bound, stream);
179 }
180}
181
182/* Print the number or discriminant bound at BOUNDS+*N on STREAM, and
183 set *N past the bound and its delimiter, if any. */
184
185static void
186print_range_bound (struct type *type, char *bounds, int *n,
187 struct ui_file *stream)
188{
189 LONGESTlong B;
190 if (ada_scan_number (bounds, *n, &B, n))
191 {
192 /* STABS decodes all range types which bounds are 0 .. -1 as
193 unsigned integers (ie. the type code is TYPE_CODE_INT, not
194 TYPE_CODE_RANGE). Unfortunately, ada_print_scalar() relies
195 on the unsigned flag to determine whether the bound should
196 be printed as a signed or an unsigned value. This causes
197 the upper bound of the 0 .. -1 range types to be printed as
198 a very large unsigned number instead of -1.
199 To workaround this stabs deficiency, we replace the TYPE by
200 builtin_type_long when we detect that the bound is negative,
201 and the type is a TYPE_CODE_INT. The bound is negative when
202 'm' is the last character of the number scanned in BOUNDS. */
203 if (bounds[*n - 1] == 'm' && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_INT)
204 type = builtin_type_long;
205 ada_print_scalar (type, B, stream);
206 if (bounds[*n] == '_')
207 *n += 2;
208 }
209 else
210 {
211 int bound_len;
212 char *bound = bounds + *n;
213 char *pend;
214
215 pend = strstr (bound, "__");
216 if (pend == NULL((void*)0))
217 *n += bound_len = strlen (bound);
218 else
219 {
220 bound_len = pend - bound;
221 *n += bound_len + 2;
222 }
223 fprintf_filtered (stream, "%.*s", bound_len, bound);
224 }
225}
226
227/* Assuming NAME[0 .. NAME_LEN-1] is the name of a range type, print
228 the value (if found) of the bound indicated by SUFFIX ("___L" or
229 "___U") according to the ___XD conventions. */
230
231static void
232print_dynamic_range_bound (struct type *type, const char *name, int name_len,
233 const char *suffix, struct ui_file *stream)
234{
235 static char *name_buf = NULL((void*)0);
22
'name_buf' initialized to a null pointer value
236 static size_t name_buf_len = 0;
237 LONGESTlong B;
238 int OK;
239
240 GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1)if ((name_buf_len) < (name_len + strlen (suffix) + 1)) grow_vect
((void**) &(name_buf), &(name_buf_len), (name_len + strlen
(suffix) + 1), sizeof(*(name_buf)));
;
23
Assuming the condition is false
24
Taking false branch
241 strncpy (name_buf, name, name_len);
25
Null pointer passed as 1st argument to string copy function
242 strcpy (name_buf + name_len, suffix);
243
244 B = get_int_var_value (name_buf, &OK);
245 if (OK)
246 ada_print_scalar (type, B, stream);
247 else
248 fprintf_filtered (stream, "?");
249}
250
251/* Print the range type named NAME. */
252
253static void
254print_range_type_named (char *name, struct ui_file *stream)
255{
256 struct type *raw_type = ada_find_any_type (name);
257 struct type *base_type;
258 char *subtype_info;
259
260 if (raw_type == NULL((void*)0))
15
Assuming 'raw_type' is equal to NULL
16
Taking true branch
261 base_type = builtin_type_int;
262 else if (TYPE_CODE (raw_type)(raw_type)->main_type->code == TYPE_CODE_RANGE)
263 base_type = TYPE_TARGET_TYPE (raw_type)(raw_type)->main_type->target_type;
264 else
265 base_type = raw_type;
266
267 subtype_info = strstr (name, "___XD");
268 if (subtype_info == NULL((void*)0) && raw_type == NULL((void*)0))
17
Assuming 'subtype_info' is not equal to NULL
269 fprintf_filtered (stream, "? .. ?");
270 else if (subtype_info
17.1
'subtype_info' is not equal to NULL
== NULL((void*)0))
18
Taking false branch
271 print_range (raw_type, stream);
272 else
273 {
274 int prefix_len = subtype_info - name;
275 char *bounds_str;
276 int n;
277
278 subtype_info += 5;
279 bounds_str = strchr (subtype_info, '_');
280 n = 1;
281
282 if (*subtype_info == 'L')
19
Assuming the condition is false
20
Taking false branch
283 {
284 print_range_bound (base_type, bounds_str, &n, stream);
285 subtype_info += 1;
286 }
287 else
288 print_dynamic_range_bound (base_type, name, prefix_len, "___L",
21
Calling 'print_dynamic_range_bound'
289 stream);
290
291 fprintf_filtered (stream, " .. ");
292
293 if (*subtype_info == 'U')
294 print_range_bound (base_type, bounds_str, &n, stream);
295 else
296 print_dynamic_range_bound (base_type, name, prefix_len, "___U",
297 stream);
298 }
299}
300
301/* Print enumerated type TYPE on STREAM. */
302
303static void
304print_enum_type (struct type *type, struct ui_file *stream)
305{
306 int len = TYPE_NFIELDS (type)(type)->main_type->nfields;
307 int i, lastval;
308
309 fprintf_filtered (stream, "(");
310 wrap_here (" ");
311
312 lastval = 0;
313 for (i = 0; i < len; i++)
314 {
315 QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook
(); }
;
316 if (i)
317 fprintf_filtered (stream, ", ");
318 wrap_here (" ");
319 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name)), stream);
320 if (lastval != TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos))
321 {
322 fprintf_filtered (stream, " => %d", TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos));
323 lastval = TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos);
324 }
325 lastval += 1;
326 }
327 fprintf_filtered (stream, ")");
328}
329
330/* Print representation of Ada fixed-point type TYPE on STREAM. */
331
332static void
333print_fixed_point_type (struct type *type, struct ui_file *stream)
334{
335 DOUBLEST delta = ada_delta (type);
336 DOUBLEST small = ada_fixed_to_float (type, 1.0);
337
338 if (delta < 0.0)
339 fprintf_filtered (stream, "delta ??");
340 else
341 {
342 fprintf_filtered (stream, "delta %g", (double) delta);
343 if (delta != small)
344 fprintf_filtered (stream, " <'small = %g>", (double) small);
345 }
346}
347
348/* Print representation of special VAX floating-point type TYPE on STREAM. */
349
350static void
351print_vax_floating_point_type (struct type *type, struct ui_file *stream)
352{
353 fprintf_filtered (stream, "<float format %c>",
354 ada_vax_float_type_suffix (type));
355}
356
357/* Print simple (constrained) array type TYPE on STREAM. LEVEL is the
358 recursion (indentation) level, in case the element type itself has
359 nested structure, and SHOW is the number of levels of internal
360 structure to show (see ada_print_type). */
361
362static void
363print_array_type (struct type *type, struct ui_file *stream, int show,
364 int level)
365{
366 int bitsize;
367 int n_indices;
368
369 bitsize = 0;
370 fprintf_filtered (stream, "array (");
371
372 n_indices = -1;
373 if (show < 0)
1
Assuming 'show' is >= 0
2
Taking false branch
374 fprintf_filtered (stream, "...");
375 else
376 {
377 if (ada_is_packed_array_type (type))
3
Assuming the condition is false
4
Taking false branch
378 type = ada_coerce_to_simple_array_type (type);
379 if (type == NULL((void*)0))
5
Assuming 'type' is not equal to NULL
6
Taking false branch
380 {
381 fprintf_filtered (stream, "<undecipherable array type>");
382 return;
383 }
384 if (ada_is_simple_array_type (type))
7
Assuming the condition is true
8
Taking true branch
385 {
386 struct type *range_desc_type =
387 ada_find_parallel_type (type, "___XA");
388 struct type *arr_type;
389
390 bitsize = 0;
391 if (range_desc_type == NULL((void*)0))
9
Assuming 'range_desc_type' is not equal to NULL
10
Taking false branch
392 {
393 for (arr_type = type; TYPE_CODE (arr_type)(arr_type)->main_type->code == TYPE_CODE_ARRAY;
394 arr_type = TYPE_TARGET_TYPE (arr_type)(arr_type)->main_type->target_type)
395 {
396 if (arr_type != type)
397 fprintf_filtered (stream, ", ");
398 print_range (TYPE_INDEX_TYPE (arr_type)(((arr_type)->main_type->fields[0]).type), stream);
399 if (TYPE_FIELD_BITSIZE (arr_type, 0)(((arr_type)->main_type->fields[0]).bitsize) > 0)
400 bitsize = TYPE_FIELD_BITSIZE (arr_type, 0)(((arr_type)->main_type->fields[0]).bitsize);
401 }
402 }
403 else
404 {
405 int k;
406 n_indices = TYPE_NFIELDS (range_desc_type)(range_desc_type)->main_type->nfields;
407 for (k = 0, arr_type = type;
12
Loop condition is true. Entering loop body
408 k < n_indices;
11
Assuming 'k' is < 'n_indices'
409 k += 1, arr_type = TYPE_TARGET_TYPE (arr_type)(arr_type)->main_type->target_type)
410 {
411 if (k
12.1
'k' is <= 0
> 0)
13
Taking false branch
412 fprintf_filtered (stream, ", ");
413 print_range_type_named (TYPE_FIELD_NAME(((range_desc_type)->main_type->fields[k]).name)
14
Calling 'print_range_type_named'
414 (range_desc_type, k)(((range_desc_type)->main_type->fields[k]).name), stream);
415 if (TYPE_FIELD_BITSIZE (arr_type, 0)(((arr_type)->main_type->fields[0]).bitsize) > 0)
416 bitsize = TYPE_FIELD_BITSIZE (arr_type, 0)(((arr_type)->main_type->fields[0]).bitsize);
417 }
418 }
419 }
420 else
421 {
422 int i, i0;
423 for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
424 fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
425 }
426 }
427
428 fprintf_filtered (stream, ") of ");
429 wrap_here ("");
430 ada_print_type (ada_array_element_type (type, n_indices), "", stream,
431 show == 0 ? 0 : show - 1, level + 1);
432 if (bitsize > 0)
433 fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize);
434}
435
436/* Print the choices encoded by field FIELD_NUM of variant-part TYPE on
437 STREAM, assuming the VAL_TYPE is the type of the values. */
438
439static void
440print_choices (struct type *type, int field_num, struct ui_file *stream,
441 struct type *val_type)
442{
443 int have_output;
444 int p;
445 const char *name = TYPE_FIELD_NAME (type, field_num)(((type)->main_type->fields[field_num]).name);
446
447 have_output = 0;
448
449 /* Skip over leading 'V': NOTE soon to be obsolete. */
450 if (name[0] == 'V')
451 {
452 if (!ada_scan_number (name, 1, NULL((void*)0), &p))
453 goto Huh;
454 }
455 else
456 p = 0;
457
458 while (1)
459 {
460 switch (name[p])
461 {
462 default:
463 return;
464 case 'S':
465 case 'R':
466 case 'O':
467 if (have_output)
468 fprintf_filtered (stream, " | ");
469 have_output = 1;
470 break;
471 }
472
473 switch (name[p])
474 {
475 case 'S':
476 {
477 LONGESTlong W;
478 if (!ada_scan_number (name, p + 1, &W, &p))
479 goto Huh;
480 ada_print_scalar (val_type, W, stream);
481 break;
482 }
483 case 'R':
484 {
485 LONGESTlong L, U;
486 if (!ada_scan_number (name, p + 1, &L, &p)
487 || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
488 goto Huh;
489 ada_print_scalar (val_type, L, stream);
490 fprintf_filtered (stream, " .. ");
491 ada_print_scalar (val_type, U, stream);
492 break;
493 }
494 case 'O':
495 fprintf_filtered (stream, "others");
496 p += 1;
497 break;
498 }
499 }
500
501Huh:
502 fprintf_filtered (stream, "??");
503
504}
505
506/* Assuming that field FIELD_NUM of TYPE is a VARIANTS field whose
507 discriminant is contained in OUTER_TYPE, print its variants on STREAM.
508 LEVEL is the recursion
509 (indentation) level, in case any of the fields themselves have
510 nested structure, and SHOW is the number of levels of internal structure
511 to show (see ada_print_type). For this purpose, fields nested in a
512 variant part are taken to be at the same level as the fields
513 immediately outside the variant part. */
514
515static void
516print_variant_clauses (struct type *type, int field_num,
517 struct type *outer_type, struct ui_file *stream,
518 int show, int level)
519{
520 int i;
521 struct type *var_type, *par_type;
522 struct type *discr_type;
523
524 var_type = TYPE_FIELD_TYPE (type, field_num)(((type)->main_type->fields[field_num]).type);
525 discr_type = ada_variant_discrim_type (var_type, outer_type);
526
527 if (TYPE_CODE (var_type)(var_type)->main_type->code == TYPE_CODE_PTR)
528 {
529 var_type = TYPE_TARGET_TYPE (var_type)(var_type)->main_type->target_type;
530 if (var_type == NULL((void*)0) || TYPE_CODE (var_type)(var_type)->main_type->code != TYPE_CODE_UNION)
531 return;
532 }
533
534 par_type = ada_find_parallel_type (var_type, "___XVU");
535 if (par_type != NULL((void*)0))
536 var_type = par_type;
537
538 for (i = 0; i < TYPE_NFIELDS (var_type)(var_type)->main_type->nfields; i += 1)
539 {
540 fprintf_filtered (stream, "\n%*swhen ", level + 4, "");
541 print_choices (var_type, i, stream, discr_type);
542 fprintf_filtered (stream, " =>");
543 if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i)(((var_type)->main_type->fields[i]).type),
544 outer_type, stream, show, level + 4) <= 0)
545 fprintf_filtered (stream, " null;");
546 }
547}
548
549/* Assuming that field FIELD_NUM of TYPE is a variant part whose
550 discriminants are contained in OUTER_TYPE, print a description of it
551 on STREAM. LEVEL is the recursion (indentation) level, in case any of
552 the fields themselves have nested structure, and SHOW is the number of
553 levels of internal structure to show (see ada_print_type). For this
554 purpose, fields nested in a variant part are taken to be at the same
555 level as the fields immediately outside the variant part. */
556
557static void
558print_variant_part (struct type *type, int field_num, struct type *outer_type,
559 struct ui_file *stream, int show, int level)
560{
561 fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
562 ada_variant_discrim_name
563 (TYPE_FIELD_TYPE (type, field_num)(((type)->main_type->fields[field_num]).type)));
564 print_variant_clauses (type, field_num, outer_type, stream, show,
565 level + 4);
566 fprintf_filtered (stream, "\n%*send case;", level + 4, "");
567}
568
569/* Print a description on STREAM of the fields in record type TYPE, whose
570 discriminants are in OUTER_TYPE. LEVEL is the recursion (indentation)
571 level, in case any of the fields themselves have nested structure,
572 and SHOW is the number of levels of internal structure to show
573 (see ada_print_type). Does not print parent type information of TYPE.
574 Returns 0 if no fields printed, -1 for an incomplete type, else > 0.
575 Prints each field beginning on a new line, but does not put a new line at
576 end. */
577
578static int
579print_record_field_types (struct type *type, struct type *outer_type,
580 struct ui_file *stream, int show, int level)
581{
582 int len, i, flds;
583
584 flds = 0;
585 len = TYPE_NFIELDS (type)(type)->main_type->nfields;
586
587 if (len == 0 && (TYPE_FLAGS (type)(type)->main_type->flags & TYPE_FLAG_STUB(1 << 2)) != 0)
588 return -1;
589
590 for (i = 0; i < len; i += 1)
591 {
592 QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook
(); }
;
593
594 if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i))
595 ;
596 else if (ada_is_wrapper_field (type, i))
597 flds += print_record_field_types (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), type,
598 stream, show, level);
599 else if (ada_is_variant_part (type, i))
600 {
601 print_variant_part (type, i, outer_type, stream, show, level);
602 flds = 1;
603 }
604 else
605 {
606 flds += 1;
607 fprintf_filtered (stream, "\n%*s", level + 4, "");
608 ada_print_type (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type),
609 TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name),
610 stream, show - 1, level + 4);
611 fprintf_filtered (stream, ";");
612 }
613 }
614
615 return flds;
616}
617
618/* Print record type TYPE on STREAM. LEVEL is the recursion (indentation)
619 level, in case the element type itself has nested structure, and SHOW is
620 the number of levels of internal structure to show (see ada_print_type). */
621
622static void
623print_record_type (struct type *type0, struct ui_file *stream, int show,
624 int level)
625{
626 struct type *parent_type;
627 struct type *type;
628
629 type = ada_find_parallel_type (type0, "___XVE");
630 if (type == NULL((void*)0))
631 type = type0;
632
633 parent_type = ada_parent_type (type);
634 if (ada_type_name (parent_type) != NULL((void*)0))
635 fprintf_filtered (stream, "new %s with ",
636 decoded_type_name (parent_type));
637 else if (parent_type == NULL((void*)0) && ada_is_tagged_type (type, 0))
638 fprintf_filtered (stream, "tagged ");
639
640 fprintf_filtered (stream, "record");
641
642 if (show < 0)
643 fprintf_filtered (stream, " ... end record");
644 else
645 {
646 int flds;
647
648 flds = 0;
649 if (parent_type != NULL((void*)0) && ada_type_name (parent_type) == NULL((void*)0))
650 flds += print_record_field_types (parent_type, parent_type,
651 stream, show, level);
652 flds += print_record_field_types (type, type, stream, show, level);
653
654 if (flds > 0)
655 fprintf_filtered (stream, "\n%*send record", level, "");
656 else if (flds < 0)
657 fprintf_filtered (stream, " <incomplete type> end record");
658 else
659 fprintf_filtered (stream, " null; end record");
660 }
661}
662
663/* Print the unchecked union type TYPE in something resembling Ada
664 format on STREAM. LEVEL is the recursion (indentation) level
665 in case the element type itself has nested structure, and SHOW is the
666 number of levels of internal structure to show (see ada_print_type). */
667static void
668print_unchecked_union_type (struct type *type, struct ui_file *stream,
669 int show, int level)
670{
671 fprintf_filtered (stream, "record (?) is");
672
673 if (show < 0)
674 fprintf_filtered (stream, " ... end record");
675 else if (TYPE_NFIELDS (type)(type)->main_type->nfields == 0)
676 fprintf_filtered (stream, " null; end record");
677 else
678 {
679 int i;
680
681 fprintf_filtered (stream, "\n%*scase ? is", level + 4, "");
682
683 for (i = 0; i < TYPE_NFIELDS (type)(type)->main_type->nfields; i += 1)
684 {
685 fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
686 level + 12, "");
687 ada_print_type (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type),
688 TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name),
689 stream, show - 1, level + 12);
690 fprintf_filtered (stream, ";");
691 }
692
693 fprintf_filtered (stream, "\n%*send case;\n%*send record",
694 level + 4, "", level, "");
695 }
696}
697
698
699
700/* Print function or procedure type TYPE on STREAM. Make it a header
701 for function or procedure NAME if NAME is not null. */
702
703static void
704print_func_type (struct type *type, struct ui_file *stream, char *name)
705{
706 int i, len = TYPE_NFIELDS (type)(type)->main_type->nfields;
707
708 if (TYPE_CODE (TYPE_TARGET_TYPE (type))((type)->main_type->target_type)->main_type->code == TYPE_CODE_VOID)
709 fprintf_filtered (stream, "procedure");
710 else
711 fprintf_filtered (stream, "function");
712
713 if (name != NULL((void*)0) && name[0] != '\0')
714 fprintf_filtered (stream, " %s", name);
715
716 if (len > 0)
717 {
718 fprintf_filtered (stream, " (");
719 for (i = 0; i < len; i += 1)
720 {
721 if (i > 0)
722 {
723 fputs_filtered ("; ", stream);
724 wrap_here (" ");
725 }
726 fprintf_filtered (stream, "a%d: ", i + 1);
727 ada_print_type (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), "", stream, -1, 0);
728 }
729 fprintf_filtered (stream, ")");
730 }
731
732 if (TYPE_CODE (TYPE_TARGET_TYPE (type))((type)->main_type->target_type)->main_type->code != TYPE_CODE_VOID)
733 {
734 fprintf_filtered (stream, " return ");
735 ada_print_type (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, "", stream, 0, 0);
736 }
737}
738
739
740/* Print a description of a type TYPE0.
741 Output goes to STREAM (via stdio).
742 If VARSTRING is a non-empty string, print as an Ada variable/field
743 declaration.
744 SHOW+1 is the maximum number of levels of internal type structure
745 to show (this applies to record types, enumerated types, and
746 array types).
747 SHOW is the number of levels of internal type structure to show
748 when there is a type name for the SHOWth deepest level (0th is
749 outer level).
750 When SHOW<0, no inner structure is shown.
751 LEVEL indicates level of recursion (for nested definitions). */
752
753void
754ada_print_type (struct type *type0, char *varstring, struct ui_file *stream,
755 int show, int level)
756{
757 struct type *type = ada_check_typedef (ada_get_base_type (type0));
758 char *type_name = decoded_type_name (type);
759 int is_var_decl = (varstring != NULL((void*)0) && varstring[0] != '\0');
760
761 if (type == NULL((void*)0))
762 {
763 if (is_var_decl)
764 fprintf_filtered (stream, "%.*s: ",
765 ada_name_prefix_len (varstring), varstring);
766 fprintf_filtered (stream, "<null type?>");
767 return;
768 }
769
770 if (show > 0)
771 type = ada_check_typedef (type);
772
773 if (is_var_decl && TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_FUNC)
774 fprintf_filtered (stream, "%.*s: ",
775 ada_name_prefix_len (varstring), varstring);
776
777 if (type_name != NULL((void*)0) && show <= 0)
778 {
779 fprintf_filtered (stream, "%.*s",
780 ada_name_prefix_len (type_name), type_name);
781 return;
782 }
783
784 if (ada_is_aligner_type (type))
785 ada_print_type (ada_aligned_type (type), "", stream, show, level);
786 else if (ada_is_packed_array_type (type))
787 print_array_type (type, stream, show, level);
788 else
789 switch (TYPE_CODE (type)(type)->main_type->code)
790 {
791 default:
792 fprintf_filtered (stream, "<");
793 c_print_type (type, "", stream, show, level);
794 fprintf_filtered (stream, ">");
795 break;
796 case TYPE_CODE_PTR:
797 fprintf_filtered (stream, "access ");
798 ada_print_type (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, "", stream, show, level);
799 break;
800 case TYPE_CODE_REF:
801 fprintf_filtered (stream, "<ref> ");
802 ada_print_type (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, "", stream, show, level);
803 break;
804 case TYPE_CODE_ARRAY:
805 print_array_type (type, stream, show, level);
806 break;
807 case TYPE_CODE_INT:
808 if (ada_is_fixed_point_type (type))
809 print_fixed_point_type (type, stream);
810 else if (ada_is_vax_floating_type (type))
811 print_vax_floating_point_type (type, stream);
812 else
813 {
814 char *name = ada_type_name (type);
815 if (!ada_is_range_type_name (name))
816 fprintf_filtered (stream, "<%d-byte integer>",
817 TYPE_LENGTH (type)(type)->length);
818 else
819 {
820 fprintf_filtered (stream, "range ");
821 print_range_type_named (name, stream);
822 }
823 }
824 break;
825 case TYPE_CODE_RANGE:
826 if (ada_is_fixed_point_type (type))
827 print_fixed_point_type (type, stream);
828 else if (ada_is_vax_floating_type (type))
829 print_vax_floating_point_type (type, stream);
830 else if (ada_is_modular_type (type))
831 fprintf_filtered (stream, "mod %ld", (long) ada_modulus (type));
832 else
833 {
834 fprintf_filtered (stream, "range ");
835 print_range (type, stream);
836 }
837 break;
838 case TYPE_CODE_FLT:
839 fprintf_filtered (stream, "<%d-byte float>", TYPE_LENGTH (type)(type)->length);
840 break;
841 case TYPE_CODE_ENUM:
842 if (show < 0)
843 fprintf_filtered (stream, "(...)");
844 else
845 print_enum_type (type, stream);
846 break;
847 case TYPE_CODE_STRUCT:
848 if (ada_is_array_descriptor_type (type))
849 print_array_type (type, stream, show, level);
850 else if (ada_is_bogus_array_descriptor (type))
851 fprintf_filtered (stream,
852 "array (?) of ? (<mal-formed descriptor>)");
853 else
854 print_record_type (type, stream, show, level);
855 break;
856 case TYPE_CODE_UNION:
857 print_unchecked_union_type (type, stream, show, level);
858 break;
859 case TYPE_CODE_FUNC:
860 print_func_type (type, stream, varstring);
861 break;
862 }
863}