Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Latest commit

 

History

History
10978 lines (9350 loc) · 332 KB

ada-lang.c

File metadata and controls

10978 lines (9350 loc) · 332 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Ada language support routines for GDB, the GNU debugger. Copyright (C)
1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include <stdio.h>
#include "gdb_string.h"
#include <ctype.h>
#include <stdarg.h>
#include "demangle.h"
#include "gdb_regex.h"
#include "frame.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "gdbcmd.h"
#include "expression.h"
#include "parser-defs.h"
#include "language.h"
#include "c-lang.h"
#include "inferior.h"
#include "symfile.h"
#include "objfiles.h"
#include "breakpoint.h"
#include "gdbcore.h"
#include "hashtab.h"
#include "gdb_obstack.h"
#include "ada-lang.h"
#include "completer.h"
#include "gdb_stat.h"
#ifdef UI_OUT
#include "ui-out.h"
#endif
#include "block.h"
#include "infcall.h"
#include "dictionary.h"
#include "exceptions.h"
#include "annotate.h"
#include "valprint.h"
#include "source.h"
#include "observer.h"
#include "vec.h"
#ifndef ADA_RETAIN_DOTS
#define ADA_RETAIN_DOTS 0
#endif
/* Define whether or not the C operator '/' truncates towards zero for
differently signed operands (truncation direction is undefined in C).
Copied from valarith.c. */
#ifndef TRUNCATION_TOWARDS_ZERO
#define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
#endif
static void extract_string (CORE_ADDR addr, char *buf);
static void modify_general_field (char *, LONGEST, int, int);
static struct type *desc_base_type (struct type *);
static struct type *desc_bounds_type (struct type *);
static struct value *desc_bounds (struct value *);
static int fat_pntr_bounds_bitpos (struct type *);
static int fat_pntr_bounds_bitsize (struct type *);
static struct type *desc_data_type (struct type *);
static struct value *desc_data (struct value *);
static int fat_pntr_data_bitpos (struct type *);
static int fat_pntr_data_bitsize (struct type *);
static struct value *desc_one_bound (struct value *, int, int);
static int desc_bound_bitpos (struct type *, int, int);
static int desc_bound_bitsize (struct type *, int, int);
static struct type *desc_index_type (struct type *, int);
static int desc_arity (struct type *);
static int ada_type_match (struct type *, struct type *, int);
static int ada_args_match (struct symbol *, struct value **, int);
static struct value *ensure_lval (struct value *, CORE_ADDR *);
static struct value *convert_actual (struct value *, struct type *,
CORE_ADDR *);
static struct value *make_array_descriptor (struct type *, struct value *,
CORE_ADDR *);
static void ada_add_block_symbols (struct obstack *,
struct block *, const char *,
domain_enum, struct objfile *, int);
static int is_nonfunction (struct ada_symbol_info *, int);
static void add_defn_to_vec (struct obstack *, struct symbol *,
struct block *);
static int num_defns_collected (struct obstack *);
static struct ada_symbol_info *defns_collected (struct obstack *, int);
static struct partial_symbol *ada_lookup_partial_symbol (struct partial_symtab
*, const char *, int,
domain_enum, int);
static struct symtab *symtab_for_sym (struct symbol *);
static struct value *resolve_subexp (struct expression **, int *, int,
struct type *);
static void replace_operator_with_call (struct expression **, int, int, int,
struct symbol *, struct block *);
static int possible_user_operator_p (enum exp_opcode, struct value **);
static char *ada_op_name (enum exp_opcode);
static const char *ada_decoded_op_name (enum exp_opcode);
static int numeric_type_p (struct type *);
static int integer_type_p (struct type *);
static int scalar_type_p (struct type *);
static int discrete_type_p (struct type *);
static enum ada_renaming_category parse_old_style_renaming (struct type *,
const char **,
int *,
const char **);
static struct symbol *find_old_style_renaming_symbol (const char *,
struct block *);
static struct type *ada_lookup_struct_elt_type (struct type *, char *,
int, int, int *);
static struct value *evaluate_subexp (struct type *, struct expression *,
int *, enum noside);
static struct value *evaluate_subexp_type (struct expression *, int *);
static int is_dynamic_field (struct type *, int);
static struct type *to_fixed_variant_branch_type (struct type *,
const gdb_byte *,
CORE_ADDR, struct value *);
static struct type *to_fixed_array_type (struct type *, struct value *, int);
static struct type *to_fixed_range_type (char *, struct value *,
struct objfile *);
static struct type *to_static_fixed_type (struct type *);
static struct type *static_unwrap_type (struct type *type);
static struct value *unwrap_value (struct value *);
static struct type *packed_array_type (struct type *, long *);
static struct type *decode_packed_array_type (struct type *);
static struct value *decode_packed_array (struct value *);
static struct value *value_subscript_packed (struct value *, int,
struct value **);
static void move_bits (gdb_byte *, int, const gdb_byte *, int, int);
static struct value *coerce_unspec_val_to_type (struct value *,
struct type *);
static struct value *get_var_value (char *, char *);
static int lesseq_defined_than (struct symbol *, struct symbol *);
static int equiv_types (struct type *, struct type *);
static int is_name_suffix (const char *);
static int wild_match (const char *, int, const char *);
static struct value *ada_coerce_ref (struct value *);
static LONGEST pos_atr (struct value *);
static struct value *value_pos_atr (struct value *);
static struct value *value_val_atr (struct type *, struct value *);
static struct symbol *standard_lookup (const char *, const struct block *,
domain_enum);
static struct value *ada_search_struct_field (char *, struct value *, int,
struct type *);
static struct value *ada_value_primitive_field (struct value *, int, int,
struct type *);
static int find_struct_field (char *, struct type *, int,
struct type **, int *, int *, int *, int *);
static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR,
struct value *);
static struct value *ada_to_fixed_value (struct value *);
static int ada_resolve_function (struct ada_symbol_info *, int,
struct value **, int, const char *,
struct type *);
static struct value *ada_coerce_to_simple_array (struct value *);
static int ada_is_direct_array_type (struct type *);
static void ada_language_arch_info (struct gdbarch *,
struct language_arch_info *);
static void check_size (const struct type *);
static struct value *ada_index_struct_field (int, struct value *, int,
struct type *);
static struct value *assign_aggregate (struct value *, struct value *,
struct expression *, int *, enum noside);
static void aggregate_assign_from_choices (struct value *, struct value *,
struct expression *,
int *, LONGEST *, int *,
int, LONGEST, LONGEST);
static void aggregate_assign_positional (struct value *, struct value *,
struct expression *,
int *, LONGEST *, int *, int,
LONGEST, LONGEST);
static void aggregate_assign_others (struct value *, struct value *,
struct expression *,
int *, LONGEST *, int, LONGEST, LONGEST);
static void add_component_interval (LONGEST, LONGEST, LONGEST *, int *, int);
static struct value *ada_evaluate_subexp (struct type *, struct expression *,
int *, enum noside);
static void ada_forward_operator_length (struct expression *, int, int *,
int *);
/* Maximum-sized dynamic type. */
static unsigned int varsize_limit;
/* FIXME: brobecker/2003-09-17: No longer a const because it is
returned by a function that does not return a const char *. */
static char *ada_completer_word_break_characters =
#ifdef VMS
" \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
#else
" \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
#endif
/* The name of the symbol to use to get the name of the main subprogram. */
static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[]
= "__gnat_ada_main_program_name";
/* Limit on the number of warnings to raise per expression evaluation. */
static int warning_limit = 2;
/* Number of warning messages issued; reset to 0 by cleanups after
expression evaluation. */
static int warnings_issued = 0;
static const char *known_runtime_file_name_patterns[] = {
ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
};
static const char *known_auxiliary_function_name_patterns[] = {
ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
};
/* Space for allocating results of ada_lookup_symbol_list. */
static struct obstack symbol_list_obstack;
/* Utilities */
/* Given DECODED_NAME a string holding a symbol name in its
decoded form (ie using the Ada dotted notation), returns
its unqualified name. */
static const char *
ada_unqualified_name (const char *decoded_name)
{
const char *result = strrchr (decoded_name, '.');
if (result != NULL)
result++; /* Skip the dot... */
else
result = decoded_name;
return result;
}
/* Return a string starting with '<', followed by STR, and '>'.
The result is good until the next call. */
static char *
add_angle_brackets (const char *str)
{
static char *result = NULL;
xfree (result);
result = (char *) xmalloc ((strlen (str) + 3) * sizeof (char));
sprintf (result, "<%s>", str);
return result;
}
static char *
ada_get_gdb_completer_word_break_characters (void)
{
return ada_completer_word_break_characters;
}
/* Print an array element index using the Ada syntax. */
static void
ada_print_array_index (struct value *index_value, struct ui_file *stream,
int format, enum val_prettyprint pretty)
{
LA_VALUE_PRINT (index_value, stream, format, pretty);
fprintf_filtered (stream, " => ");
}
/* Read the string located at ADDR from the inferior and store the
result into BUF. */
static void
extract_string (CORE_ADDR addr, char *buf)
{
int char_index = 0;
/* Loop, reading one byte at a time, until we reach the '\000'
end-of-string marker. */
do
{
target_read_memory (addr + char_index * sizeof (char),
buf + char_index * sizeof (char), sizeof (char));
char_index++;
}
while (buf[char_index - 1] != '\000');
}
/* Assuming VECT points to an array of *SIZE objects of size
ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
updating *SIZE as necessary and returning the (new) array. */
void *
grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
{
if (*size < min_size)
{
*size *= 2;
if (*size < min_size)
*size = min_size;
vect = xrealloc (vect, *size * element_size);
}
return vect;
}
/* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
suffix of FIELD_NAME beginning "___". */
static int
field_name_match (const char *field_name, const char *target)
{
int len = strlen (target);
return
(strncmp (field_name, target, len) == 0
&& (field_name[len] == '\0'
|| (strncmp (field_name + len, "___", 3) == 0
&& strcmp (field_name + strlen (field_name) - 6,
"___XVN") != 0)));
}
/* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches
FIELD_NAME, and return its index. This function also handles fields
whose name have ___ suffixes because the compiler sometimes alters
their name by adding such a suffix to represent fields with certain
constraints. If the field could not be found, return a negative
number if MAYBE_MISSING is set. Otherwise raise an error. */
int
ada_get_field_index (const struct type *type, const char *field_name,
int maybe_missing)
{
int fieldno;
for (fieldno = 0; fieldno < TYPE_NFIELDS (type); fieldno++)
if (field_name_match (TYPE_FIELD_NAME (type, fieldno), field_name))
return fieldno;
if (!maybe_missing)
error (_("Unable to find field %s in struct %s. Aborting"),
field_name, TYPE_NAME (type));
return -1;
}
/* The length of the prefix of NAME prior to any "___" suffix. */
int
ada_name_prefix_len (const char *name)
{
if (name == NULL)
return 0;
else
{
const char *p = strstr (name, "___");
if (p == NULL)
return strlen (name);
else
return p - name;
}
}
/* Return non-zero if SUFFIX is a suffix of STR.
Return zero if STR is null. */
static int
is_suffix (const char *str, const char *suffix)
{
int len1, len2;
if (str == NULL)
return 0;
len1 = strlen (str);
len2 = strlen (suffix);
return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
}
/* Create a value of type TYPE whose contents come from VALADDR, if it
is non-null, and whose memory address (in the inferior) is
ADDRESS. */
struct value *
value_from_contents_and_address (struct type *type,
const gdb_byte *valaddr,
CORE_ADDR address)
{
struct value *v = allocate_value (type);
if (valaddr == NULL)
set_value_lazy (v, 1);
else
memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type));
VALUE_ADDRESS (v) = address;
if (address != 0)
VALUE_LVAL (v) = lval_memory;
return v;
}
/* The contents of value VAL, treated as a value of type TYPE. The
result is an lval in memory if VAL is. */
static struct value *
coerce_unspec_val_to_type (struct value *val, struct type *type)
{
type = ada_check_typedef (type);
if (value_type (val) == type)
return val;
else
{
struct value *result;
/* Make sure that the object size is not unreasonable before
trying to allocate some memory for it. */
check_size (type);
result = allocate_value (type);
VALUE_LVAL (result) = VALUE_LVAL (val);
set_value_bitsize (result, value_bitsize (val));
set_value_bitpos (result, value_bitpos (val));
VALUE_ADDRESS (result) = VALUE_ADDRESS (val) + value_offset (val);
if (value_lazy (val)
|| TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val)))
set_value_lazy (result, 1);
else
memcpy (value_contents_raw (result), value_contents (val),
TYPE_LENGTH (type));
return result;
}
}
static const gdb_byte *
cond_offset_host (const gdb_byte *valaddr, long offset)
{
if (valaddr == NULL)
return NULL;
else
return valaddr + offset;
}
static CORE_ADDR
cond_offset_target (CORE_ADDR address, long offset)
{
if (address == 0)
return 0;
else
return address + offset;
}
/* Issue a warning (as for the definition of warning in utils.c, but
with exactly one argument rather than ...), unless the limit on the
number of warnings has passed during the evaluation of the current
expression. */
/* FIXME: cagney/2004-10-10: This function is mimicking the behavior
provided by "complaint". */
static void lim_warning (const char *format, ...) ATTR_FORMAT (printf, 1, 2);
static void
lim_warning (const char *format, ...)
{
va_list args;
va_start (args, format);
warnings_issued += 1;
if (warnings_issued <= warning_limit)
vwarning (format, args);
va_end (args);
}
/* Issue an error if the size of an object of type T is unreasonable,
i.e. if it would be a bad idea to allocate a value of this type in
GDB. */
static void
check_size (const struct type *type)
{
if (TYPE_LENGTH (type) > varsize_limit)
error (_("object size is larger than varsize-limit"));
}
/* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from
gdbtypes.h, but some of the necessary definitions in that file
seem to have gone missing. */
/* Maximum value of a SIZE-byte signed integer type. */
static LONGEST
max_of_size (int size)
{
LONGEST top_bit = (LONGEST) 1 << (size * 8 - 2);
return top_bit | (top_bit - 1);
}
/* Minimum value of a SIZE-byte signed integer type. */
static LONGEST
min_of_size (int size)
{
return -max_of_size (size) - 1;
}
/* Maximum value of a SIZE-byte unsigned integer type. */
static ULONGEST
umax_of_size (int size)
{
ULONGEST top_bit = (ULONGEST) 1 << (size * 8 - 1);
return top_bit | (top_bit - 1);
}
/* Maximum value of integral type T, as a signed quantity. */
static LONGEST
max_of_type (struct type *t)
{
if (TYPE_UNSIGNED (t))
return (LONGEST) umax_of_size (TYPE_LENGTH (t));
else
return max_of_size (TYPE_LENGTH (t));
}
/* Minimum value of integral type T, as a signed quantity. */
static LONGEST
min_of_type (struct type *t)
{
if (TYPE_UNSIGNED (t))
return 0;
else
return min_of_size (TYPE_LENGTH (t));
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
static struct value *
discrete_type_high_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
return value_from_longest (TYPE_TARGET_TYPE (type),
TYPE_HIGH_BOUND (type));
case TYPE_CODE_ENUM:
return
value_from_longest (type,
TYPE_FIELD_BITPOS (type,
TYPE_NFIELDS (type) - 1));
case TYPE_CODE_INT:
return value_from_longest (type, max_of_type (type));
default:
error (_("Unexpected type in discrete_type_high_bound."));
}
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
static struct value *
discrete_type_low_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
return value_from_longest (TYPE_TARGET_TYPE (type),
TYPE_LOW_BOUND (type));
case TYPE_CODE_ENUM:
return value_from_longest (type, TYPE_FIELD_BITPOS (type, 0));
case TYPE_CODE_INT:
return value_from_longest (type, min_of_type (type));
default:
error (_("Unexpected type in discrete_type_low_bound."));
}
}
/* The identity on non-range types. For range types, the underlying
non-range scalar type. */
static struct type *
base_type (struct type *type)
{
while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
{
if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL)
return type;
type = TYPE_TARGET_TYPE (type);
}
return type;
}
/* Language Selection */
/* If the main program is in Ada, return language_ada, otherwise return LANG
(the main program is in Ada iif the adainit symbol is found).
MAIN_PST is not used. */
enum language
ada_update_initial_language (enum language lang,
struct partial_symtab *main_pst)
{
if (lookup_minimal_symbol ("adainit", (const char *) NULL,
(struct objfile *) NULL) != NULL)
return language_ada;
return lang;
}
/* If the main procedure is written in Ada, then return its name.
The result is good until the next call. Return NULL if the main
procedure doesn't appear to be in Ada. */
char *
ada_main_name (void)
{
struct minimal_symbol *msym;
CORE_ADDR main_program_name_addr;
static char main_program_name[1024];
/* For Ada, the name of the main procedure is stored in a specific
string constant, generated by the binder. Look for that symbol,
extract its address, and then read that string. If we didn't find
that string, then most probably the main procedure is not written
in Ada. */
msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL);
if (msym != NULL)
{
main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym);
if (main_program_name_addr == 0)
error (_("Invalid address for Ada main program name."));
extract_string (main_program_name_addr, main_program_name);
return main_program_name;
}
/* The main procedure doesn't seem to be in Ada. */
return NULL;
}
/* Symbols */
/* Table of Ada operators and their GNAT-encoded names. Last entry is pair
of NULLs. */
const struct ada_opname_map ada_opname_table[] = {
{"Oadd", "\"+\"", BINOP_ADD},
{"Osubtract", "\"-\"", BINOP_SUB},
{"Omultiply", "\"*\"", BINOP_MUL},
{"Odivide", "\"/\"", BINOP_DIV},
{"Omod", "\"mod\"", BINOP_MOD},
{"Orem", "\"rem\"", BINOP_REM},
{"Oexpon", "\"**\"", BINOP_EXP},
{"Olt", "\"<\"", BINOP_LESS},
{"Ole", "\"<=\"", BINOP_LEQ},
{"Ogt", "\">\"", BINOP_GTR},
{"Oge", "\">=\"", BINOP_GEQ},
{"Oeq", "\"=\"", BINOP_EQUAL},
{"One", "\"/=\"", BINOP_NOTEQUAL},
{"Oand", "\"and\"", BINOP_BITWISE_AND},
{"Oor", "\"or\"", BINOP_BITWISE_IOR},
{"Oxor", "\"xor\"", BINOP_BITWISE_XOR},
{"Oconcat", "\"&\"", BINOP_CONCAT},
{"Oabs", "\"abs\"", UNOP_ABS},
{"Onot", "\"not\"", UNOP_LOGICAL_NOT},
{"Oadd", "\"+\"", UNOP_PLUS},
{"Osubtract", "\"-\"", UNOP_NEG},
{NULL, NULL}
};
/* Return non-zero if STR should be suppressed in info listings. */
static int
is_suppressed_name (const char *str)
{
if (strncmp (str, "_ada_", 5) == 0)
str += 5;
if (str[0] == '_' || str[0] == '\000')
return 1;
else
{
const char *p;
const char *suffix = strstr (str, "___");
if (suffix != NULL && suffix[3] != 'X')
return 1;
if (suffix == NULL)
suffix = str + strlen (str);
for (p = suffix - 1; p != str; p -= 1)
if (isupper (*p))
{
int i;
if (p[0] == 'X' && p[-1] != '_')
goto OK;
if (*p != 'O')
return 1;
for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
if (strncmp (ada_opname_table[i].encoded, p,
strlen (ada_opname_table[i].encoded)) == 0)
goto OK;
return 1;
OK:;
}
return 0;
}
}
/* The "encoded" form of DECODED, according to GNAT conventions.
The result is valid until the next call to ada_encode. */
char *
ada_encode (const char *decoded)
{
static char *encoding_buffer = NULL;
static size_t encoding_buffer_size = 0;
const char *p;
int k;
if (decoded == NULL)
return NULL;
GROW_VECT (encoding_buffer, encoding_buffer_size,
2 * strlen (decoded) + 10);
k = 0;
for (p = decoded; *p != '\0'; p += 1)
{
if (!ADA_RETAIN_DOTS && *p == '.')
{
encoding_buffer[k] = encoding_buffer[k + 1] = '_';
k += 2;
}
else if (*p == '"')
{
const struct ada_opname_map *mapping;
for (mapping = ada_opname_table;
mapping->encoded != NULL
&& strncmp (mapping->decoded, p,
strlen (mapping->decoded)) != 0; mapping += 1)
;
if (mapping->encoded == NULL)
error (_("invalid Ada operator name: %s"), p);
strcpy (encoding_buffer + k, mapping->encoded);
k += strlen (mapping->encoded);
break;
}
else
{
encoding_buffer[k] = *p;
k += 1;
}
}
encoding_buffer[k] = '\0';
return encoding_buffer;
}
/* Return NAME folded to lower case, or, if surrounded by single
quotes, unfolded, but with the quotes stripped away. Result good
to next call. */
char *
ada_fold_name (const char *name)
{
static char *fold_buffer = NULL;
static size_t fold_buffer_size = 0;
int len = strlen (name);
GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
if (name[0] == '\'')
{
strncpy (fold_buffer, name + 1, len - 2);
fold_buffer[len - 2] = '\000';
}
else
{
int i;
for (i = 0; i <= len; i += 1)
fold_buffer[i] = tolower (name[i]);
}
return fold_buffer;
}
/* Return nonzero if C is either a digit or a lowercase alphabet character. */
static int
is_lower_alphanum (const char c)
{
return (isdigit (c) || (isalpha (c) && islower (c)));
}
/* Remove either of these suffixes:
. .{DIGIT}+
. ${DIGIT}+
. ___{DIGIT}+
. __{DIGIT}+.
These are suffixes introduced by the compiler for entities such as
nested subprogram for instance, in order to avoid name clashes.
They do not serve any purpose for the debugger. */
static void
ada_remove_trailing_digits (const char *encoded, int *len)
{
if (*len > 1 && isdigit (encoded[*len - 1]))
{
int i = *len - 2;
while (i > 0 && isdigit (encoded[i]))
i--;
if (i >= 0 && encoded[i] == '.')
*len = i;
else if (i >= 0 && encoded[i] == '$')
*len = i;
else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
*len = i - 2;
else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
*len = i - 1;
}
}
/* Remove the suffix introduced by the compiler for protected object
subprograms. */
static void
ada_remove_po_subprogram_suffix (const char *encoded, int *len)
{
/* Remove trailing N. */
/* Protected entry subprograms are broken into two
separate subprograms: The first one is unprotected, and has
a 'N' suffix; the second is the protected version, and has
the 'P' suffix. The second calls the first one after handling
the protection. Since the P subprograms are internally generated,
we leave these names undecoded, giving the user a clue that this
entity is internal. */
if (*len > 1
&& encoded[*len - 1] == 'N'
&& (isdigit (encoded[*len - 2]) || islower (encoded[*len - 2])))
*len = *len - 1;
}
/* If ENCODED follows the GNAT entity encoding conventions, then return
the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
replaced by ENCODED.
The resulting string is valid until the next call of ada_decode.
If the string is unchanged by decoding, the original string pointer
is returned. */
const char *
ada_decode (const char *encoded)
{
int i, j;
int len0;
const char *p;
char *decoded;
int at_start_name;
static char *decoding_buffer = NULL;
static size_t decoding_buffer_size = 0;
/* The name of the Ada main procedure starts with "_ada_".
This prefix is not part of the decoded name, so skip this part
if we see this prefix. */
if (strncmp (encoded, "_ada_", 5) == 0)
encoded += 5;
/* If the name starts with '_', then it is not a properly encoded
name, so do not attempt to decode it. Similarly, if the name
starts with '<', the name should not be decoded. */
if (encoded[0] == '_' || encoded[0] == '<')
goto Suppress;
len0 = strlen (encoded);
ada_remove_trailing_digits (encoded, &len0);
ada_remove_po_subprogram_suffix (encoded, &len0);
/* Remove the ___X.* suffix if present. Do not forget to verify that
the suffix is located before the current "end" of ENCODED. We want
to avoid re-matching parts of ENCODED that have previously been
marked as discarded (by decrementing LEN0). */
p = strstr (encoded, "___");
if (p != NULL && p - encoded < len0 - 3)
{
if (p[3] == 'X')
len0 = p - encoded;
else
goto Suppress;
}
/* Remove any trailing TKB suffix. It tells us that this symbol
is for the body of a task, but that information does not actually
appear in the decoded name. */
if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
len0 -= 3;
/* Remove trailing "B" suffixes. */
/* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
len0 -= 1;
/* Make decoded big enough for possible expansion by operator name. */
GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
decoded = decoding_buffer;
/* Remove trailing __{digit}+ or trailing ${digit}+. */
if (len0 > 1 && isdigit (encoded[len0 - 1]))