forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ada-lang.c
14039 lines (11718 loc) · 414 KB
/
ada-lang.c
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-2023 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 <ctype.h>
#include "gdbsupport/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 "varobj.h"
#include "inferior.h"
#include "symfile.h"
#include "objfiles.h"
#include "breakpoint.h"
#include "gdbcore.h"
#include "hashtab.h"
#include "gdbsupport/gdb_obstack.h"
#include "ada-lang.h"
#include "completer.h"
#include "ui-out.h"
#include "block.h"
#include "infcall.h"
#include "annotate.h"
#include "valprint.h"
#include "source.h"
#include "observable.h"
#include "stack.h"
#include "typeprint.h"
#include "namespace.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
#include "value.h"
#include "mi/mi-common.h"
#include "arch-utils.h"
#include "cli/cli-utils.h"
#include "gdbsupport/function-view.h"
#include "gdbsupport/byte-vector.h"
#include <algorithm>
#include "ada-exp.h"
#include "charset.h"
#include "ax-gdb.h"
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_target_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_args_match (struct symbol *, struct value **, int);
static struct value *make_array_descriptor (struct type *, struct value *);
static void ada_add_block_symbols (std::vector<struct block_symbol> &,
const struct block *,
const lookup_name_info &lookup_name,
domain_enum, struct objfile *);
static void ada_add_all_symbols (std::vector<struct block_symbol> &,
const struct block *,
const lookup_name_info &lookup_name,
domain_enum, int, int *);
static int is_nonfunction (const std::vector<struct block_symbol> &);
static void add_defn_to_vec (std::vector<struct block_symbol> &,
struct symbol *,
const struct block *);
static int possible_user_operator_p (enum exp_opcode, struct value **);
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 struct type *ada_lookup_struct_elt_type (struct type *, const char *,
int, int);
static struct type *ada_find_parallel_type_with_name (struct type *,
const char *);
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 (struct type *, struct value *);
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 *constrained_packed_array_type (struct type *, long *);
static struct type *decode_constrained_packed_array_type (struct type *);
static long decode_packed_array_bitsize (struct type *);
static struct value *decode_constrained_packed_array (struct value *);
static int ada_is_unconstrained_packed_array_type (struct type *);
static struct value *value_subscript_packed (struct value *, int,
struct value **);
static struct value *coerce_unspec_val_to_type (struct value *,
struct type *);
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 advance_wild_match (const char **, const char *, char);
static bool wild_match (const char *name, const char *patn);
static struct value *ada_coerce_ref (struct value *);
static LONGEST pos_atr (struct value *);
static struct value *val_atr (struct type *, LONGEST);
static struct symbol *standard_lookup (const char *, const struct block *,
domain_enum);
static struct value *ada_search_struct_field (const char *, struct value *, int,
struct type *);
static int find_struct_field (const char *, struct type *, int,
struct type **, int *, int *, int *, int *);
static int ada_resolve_function (std::vector<struct block_symbol> &,
struct value **, int, const char *,
struct type *, bool);
static int ada_is_direct_array_type (struct type *);
static struct value *ada_index_struct_field (int, struct value *, int,
struct type *);
static void add_component_interval (LONGEST, LONGEST, std::vector<LONGEST> &);
static struct type *ada_find_any_type (const char *name);
static symbol_name_matcher_ftype *ada_get_symbol_name_matcher
(const lookup_name_info &lookup_name);
/* The character set used for source files. */
static const char *ada_source_charset;
/* The string "UTF-8". This is here so we can check for the UTF-8
charset using == rather than strcmp. */
static const char ada_utf8[] = "UTF-8";
/* Each entry in the UTF-32 case-folding table is of this form. */
struct utf8_entry
{
/* The start and end, inclusive, of this range of codepoints. */
uint32_t start, end;
/* The delta to apply to get the upper-case form. 0 if this is
already upper-case. */
int upper_delta;
/* The delta to apply to get the lower-case form. 0 if this is
already lower-case. */
int lower_delta;
bool operator< (uint32_t val) const
{
return end < val;
}
};
static const utf8_entry ada_case_fold[] =
{
#include "ada-casefold.h"
};
static const 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 * const known_runtime_file_name_patterns[] = {
ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
};
static const char * const known_auxiliary_function_name_patterns[] = {
ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
};
/* Maintenance-related settings for this module. */
static struct cmd_list_element *maint_set_ada_cmdlist;
static struct cmd_list_element *maint_show_ada_cmdlist;
/* The "maintenance ada set/show ignore-descriptive-type" value. */
static bool ada_ignore_descriptive_types_p = false;
/* Inferior-specific data. */
/* Per-inferior data for this module. */
struct ada_inferior_data
{
/* The ada__tags__type_specific_data type, which is used when decoding
tagged types. With older versions of GNAT, this type was directly
accessible through a component ("tsd") in the object tag. But this
is no longer the case, so we cache it for each inferior. */
struct type *tsd_type = nullptr;
/* The exception_support_info data. This data is used to determine
how to implement support for Ada exception catchpoints in a given
inferior. */
const struct exception_support_info *exception_info = nullptr;
};
/* Our key to this module's inferior data. */
static const registry<inferior>::key<ada_inferior_data> ada_inferior_data;
/* Return our inferior data for the given inferior (INF).
This function always returns a valid pointer to an allocated
ada_inferior_data structure. If INF's inferior data has not
been previously set, this functions creates a new one with all
fields set to zero, sets INF's inferior to it, and then returns
a pointer to that newly allocated ada_inferior_data. */
static struct ada_inferior_data *
get_ada_inferior_data (struct inferior *inf)
{
struct ada_inferior_data *data;
data = ada_inferior_data.get (inf);
if (data == NULL)
data = ada_inferior_data.emplace (inf);
return data;
}
/* Perform all necessary cleanups regarding our module's inferior data
that is required after the inferior INF just exited. */
static void
ada_inferior_exit (struct inferior *inf)
{
ada_inferior_data.clear (inf);
}
/* program-space-specific data. */
/* The result of a symbol lookup to be stored in our symbol cache. */
struct cache_entry
{
/* The name used to perform the lookup. */
std::string name;
/* The namespace used during the lookup. */
domain_enum domain = UNDEF_DOMAIN;
/* The symbol returned by the lookup, or NULL if no matching symbol
was found. */
struct symbol *sym = nullptr;
/* The block where the symbol was found, or NULL if no matching
symbol was found. */
const struct block *block = nullptr;
};
/* The symbol cache uses this type when searching. */
struct cache_entry_search
{
const char *name;
domain_enum domain;
hashval_t hash () const
{
/* This must agree with hash_cache_entry, below. */
return htab_hash_string (name);
}
};
/* Hash function for cache_entry. */
static hashval_t
hash_cache_entry (const void *v)
{
const cache_entry *entry = (const cache_entry *) v;
return htab_hash_string (entry->name.c_str ());
}
/* Equality function for cache_entry. */
static int
eq_cache_entry (const void *a, const void *b)
{
const cache_entry *entrya = (const cache_entry *) a;
const cache_entry_search *entryb = (const cache_entry_search *) b;
return entrya->domain == entryb->domain && entrya->name == entryb->name;
}
/* Key to our per-program-space data. */
static const registry<program_space>::key<htab, htab_deleter>
ada_pspace_data_handle;
/* Return this module's data for the given program space (PSPACE).
If not is found, add a zero'ed one now.
This function always returns a valid object. */
static htab_t
get_ada_pspace_data (struct program_space *pspace)
{
htab_t data = ada_pspace_data_handle.get (pspace);
if (data == nullptr)
{
data = htab_create_alloc (10, hash_cache_entry, eq_cache_entry,
htab_delete_entry<cache_entry>,
xcalloc, xfree);
ada_pspace_data_handle.set (pspace, data);
}
return data;
}
/* Utilities */
/* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
all typedef layers have been peeled. Otherwise, return TYPE.
Normally, we really expect a typedef type to only have 1 typedef layer.
In other words, we really expect the target type of a typedef type to be
a non-typedef type. This is particularly true for Ada units, because
the language does not have a typedef vs not-typedef distinction.
In that respect, the Ada compiler has been trying to eliminate as many
typedef definitions in the debugging information, since they generally
do not bring any extra information (we still use typedef under certain
circumstances related mostly to the GNAT encoding).
Unfortunately, we have seen situations where the debugging information
generated by the compiler leads to such multiple typedef layers. For
instance, consider the following example with stabs:
.stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
.stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
This is an error in the debugging information which causes type
pck__float_array___XUP to be defined twice, and the second time,
it is defined as a typedef of a typedef.
This is on the fringe of legality as far as debugging information is
concerned, and certainly unexpected. But it is easy to handle these
situations correctly, so we can afford to be lenient in this case. */
static struct type *
ada_typedef_target_type (struct type *type)
{
while (type->code () == TYPE_CODE_TYPEDEF)
type = type->target_type ();
return type;
}
/* 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;
/* If the decoded name starts with '<', it means that the encoded
name does not follow standard naming conventions, and thus that
it is not your typical Ada symbol name. Trying to unqualify it
is therefore pointless and possibly erroneous. */
if (decoded_name[0] == '<')
return decoded_name;
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 '>'. */
static std::string
add_angle_brackets (const char *str)
{
return string_printf ("<%s>", str);
}
/* 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'
|| (startswith (field_name + len, "___")
&& strcmp (field_name + strlen (field_name) - 6,
"___XVN") != 0)));
}
/* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
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;
struct type *struct_type = check_typedef ((struct type *) type);
for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
if (field_name_match (struct_type->field (fieldno).name (), field_name))
return fieldno;
if (!maybe_missing)
error (_("Unable to find field %s in struct %s. Aborting"),
field_name, struct_type->name ());
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);
}
/* 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 (val->type () == type)
return val;
else
{
struct value *result;
if (val->optimized_out ())
result = value::allocate_optimized_out (type);
else if (val->lazy ()
/* Be careful not to make a lazy not_lval value. */
|| (val->lval () != not_lval
&& type->length () > val->type ()->length ()))
result = value::allocate_lazy (type);
else
{
result = value::allocate (type);
val->contents_copy (result, 0, 0, type->length ());
}
result->set_component_location (val);
result->set_bitsize (val->bitsize ());
result->set_bitpos (val->bitpos ());
if (result->lval () == lval_memory)
result->set_address (val->address ());
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, ...) ATTRIBUTE_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);
}
/* 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 (t->is_unsigned ())
return (LONGEST) umax_of_size (t->length ());
else
return max_of_size (t->length ());
}
/* Minimum value of integral type T, as a signed quantity. */
static LONGEST
min_of_type (struct type *t)
{
if (t->is_unsigned ())
return 0;
else
return min_of_size (t->length ());
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
LONGEST
ada_discrete_type_high_bound (struct type *type)
{
type = resolve_dynamic_type (type, {}, 0);
switch (type->code ())
{
case TYPE_CODE_RANGE:
{
const dynamic_prop &high = type->bounds ()->high;
if (high.is_constant ())
return high.const_val ();
else
{
gdb_assert (high.kind () == PROP_UNDEFINED);
/* This happens when trying to evaluate a type's dynamic bound
without a live target. There is nothing relevant for us to
return here, so return 0. */
return 0;
}
}
case TYPE_CODE_ENUM:
return type->field (type->num_fields () - 1).loc_enumval ();
case TYPE_CODE_BOOL:
return 1;
case TYPE_CODE_CHAR:
case TYPE_CODE_INT:
return max_of_type (type);
default:
error (_("Unexpected type in ada_discrete_type_high_bound."));
}
}
/* The smallest value in the domain of TYPE, a discrete type, as an integer. */
LONGEST
ada_discrete_type_low_bound (struct type *type)
{
type = resolve_dynamic_type (type, {}, 0);
switch (type->code ())
{
case TYPE_CODE_RANGE:
{
const dynamic_prop &low = type->bounds ()->low;
if (low.is_constant ())
return low.const_val ();
else
{
gdb_assert (low.kind () == PROP_UNDEFINED);
/* This happens when trying to evaluate a type's dynamic bound
without a live target. There is nothing relevant for us to
return here, so return 0. */
return 0;
}
}
case TYPE_CODE_ENUM:
return type->field (0).loc_enumval ();
case TYPE_CODE_BOOL:
return 0;
case TYPE_CODE_CHAR:
case TYPE_CODE_INT:
return min_of_type (type);
default:
error (_("Unexpected type in ada_discrete_type_low_bound."));
}
}
/* The identity on non-range types. For range types, the underlying
non-range scalar type. */
static struct type *
get_base_type (struct type *type)
{
while (type != NULL && type->code () == TYPE_CODE_RANGE)
{
if (type == type->target_type () || type->target_type () == NULL)
return type;
type = type->target_type ();
}
return type;
}
/* Return a decoded version of the given VALUE. This means returning
a value whose type is obtained by applying all the GNAT-specific
encodings, making the resulting type a static but standard description
of the initial type. */
struct value *
ada_get_decoded_value (struct value *value)
{
struct type *type = ada_check_typedef (value->type ());
if (ada_is_array_descriptor_type (type)
|| (ada_is_constrained_packed_array_type (type)
&& type->code () != TYPE_CODE_PTR))
{
if (type->code () == TYPE_CODE_TYPEDEF) /* array access type. */
value = ada_coerce_to_simple_array_ptr (value);
else
value = ada_coerce_to_simple_array (value);
}
else
value = ada_to_fixed_value (value);
return value;
}
/* Same as ada_get_decoded_value, but with the given TYPE.
Because there is no associated actual value for this type,
the resulting type might be a best-effort approximation in
the case of dynamic types. */
struct type *
ada_get_decoded_type (struct type *type)
{
type = to_static_fixed_type (type);
if (ada_is_constrained_packed_array_type (type))
type = ada_coerce_to_simple_array_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). */
static enum language
ada_update_initial_language (enum language lang)
{
if (lookup_minimal_symbol ("adainit", NULL, NULL).minsym != 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. */
const char *
ada_main_name ()
{
struct bound_minimal_symbol msym;
static gdb::unique_xmalloc_ptr<char> main_program_name;
/* 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.minsym != NULL)
{
CORE_ADDR main_program_name_addr = msym.value_address ();
if (main_program_name_addr == 0)
error (_("Invalid address for Ada main program name."));
main_program_name = target_read_string (main_program_name_addr, 1024);
return main_program_name.get ();
}
/* 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}
};
/* If STR is a decoded version of a compiler-provided suffix (like the
"[cold]" in "symbol[cold]"), return true. Otherwise, return
false. */
static bool
is_compiler_suffix (const char *str)
{
gdb_assert (*str == '[');
++str;
while (*str != '\0' && isalpha (*str))
++str;
/* We accept a missing "]" in order to support completion. */
return *str == '\0' || (str[0] == ']' && str[1] == '\0');
}
/* Append a non-ASCII character to RESULT. */
static void
append_hex_encoded (std::string &result, uint32_t one_char)
{
if (one_char <= 0xff)
{
result.append ("U");
result.append (phex (one_char, 1));
}
else if (one_char <= 0xffff)
{
result.append ("W");
result.append (phex (one_char, 2));
}
else
{
result.append ("WW");
result.append (phex (one_char, 4));
}
}
/* Return a string that is a copy of the data in STORAGE, with
non-ASCII characters replaced by the appropriate hex encoding. A
template is used because, for UTF-8, we actually want to work with
UTF-32 codepoints. */
template<typename T>
std::string
copy_and_hex_encode (struct obstack *storage)
{
const T *chars = (T *) obstack_base (storage);
int num_chars = obstack_object_size (storage) / sizeof (T);
std::string result;
for (int i = 0; i < num_chars; ++i)
{
if (chars[i] <= 0x7f)
{
/* The host character set has to be a superset of ASCII, as
are all the other character sets we can use. */
result.push_back (chars[i]);
}
else
append_hex_encoded (result, chars[i]);
}
return result;
}
/* The "encoded" form of DECODED, according to GNAT conventions. If
THROW_ERRORS, throw an error if invalid operator name is found.
Otherwise, return the empty string in that case. */
static std::string
ada_encode_1 (const char *decoded, bool throw_errors)
{
if (decoded == NULL)
return {};
std::string encoding_buffer;
bool saw_non_ascii = false;
for (const char *p = decoded; *p != '\0'; p += 1)
{
if ((*p & 0x80) != 0)
saw_non_ascii = true;
if (*p == '.')
encoding_buffer.append ("__");
else if (*p == '[' && is_compiler_suffix (p))
{
encoding_buffer = encoding_buffer + "." + (p + 1);
if (encoding_buffer.back () == ']')
encoding_buffer.pop_back ();
break;
}
else if (*p == '"')
{
const struct ada_opname_map *mapping;
for (mapping = ada_opname_table;
mapping->encoded != NULL
&& !startswith (p, mapping->decoded); mapping += 1)
;
if (mapping->encoded == NULL)
{
if (throw_errors)
error (_("invalid Ada operator name: %s"), p);
else
return {};
}
encoding_buffer.append (mapping->encoded);
break;
}
else
encoding_buffer.push_back (*p);
}
/* If a non-ASCII character is seen, we must convert it to the
appropriate hex form. As this is more expensive, we keep track
of whether it is even necessary. */
if (saw_non_ascii)
{
auto_obstack storage;
bool is_utf8 = ada_source_charset == ada_utf8;
try
{
convert_between_encodings
(host_charset (),
is_utf8 ? HOST_UTF32 : ada_source_charset,
(const gdb_byte *) encoding_buffer.c_str (),
encoding_buffer.length (), 1,
&storage, translit_none);
}
catch (const gdb_exception &)
{
static bool warned = false;
/* Converting to UTF-32 shouldn't fail, so if it doesn't, we
might like to know why. */
if (!warned)
{
warned = true;
warning (_("charset conversion failure for '%s'.\n"