aarch64: Add codegen support for AdvSIMD faminmax
[official-gcc.git] / gcc / ada / exp_dbug.ads
blob925021736394e7d087b6dc00c9535a71332dbabb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ D B U G --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1996-2024, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- Expand routines for the generation of special declarations used by the
27 -- debugger. In accordance with the DWARF specification, certain type names
28 -- may also be encoded to provide additional information to the debugger, but
29 -- this practice is being deprecated and some encodings described below are no
30 -- longer generated by default (they are marked OBSOLETE).
32 with Namet; use Namet;
33 with Types; use Types;
34 with Uintp; use Uintp;
36 package Exp_Dbug is
38 -----------------------------------------------------
39 -- Encoding and Qualification of Names of Entities --
40 -----------------------------------------------------
42 -- This section describes how the names of entities are encoded in the
43 -- generated debugging information.
45 -- An entity in Ada has a name of the form X.Y.Z ... E where X,Y,Z are the
46 -- enclosing scopes (not including Standard at the start).
48 -- The encoding of the name follows this basic qualified naming scheme,
49 -- where the encoding of individual entity names is as described in Namet
50 -- (i.e. in particular names present in the original source are folded to
51 -- all lower case, with upper half and wide characters encoded as described
52 -- in Namet). Upper case letters are used only for entities generated by
53 -- the compiler.
55 -- There are two cases, global entities, and local entities. In more formal
56 -- terms, local entities are those which have a dynamic enclosing scope,
57 -- and global entities are at the library level, except that we always
58 -- consider procedures to be global entities, even if they are nested
59 -- (that's because at the debugger level a procedure name refers to the
60 -- code, and the code is indeed a global entity, including the case of
61 -- nested procedures.) In addition, we also consider all types to be global
62 -- entities, even if they are defined within a procedure.
64 -- The reason for treating all type names as global entities is that a
65 -- number of our type encodings work by having related type names, and we
66 -- need the full qualification to keep this unique.
68 -- For global entities, the encoded name includes all components of the
69 -- fully expanded name (but omitting Standard at the start). For example,
70 -- if a library-level child package P.Q has an embedded package R, and
71 -- there is an entity in this embedded package whose name is S, the encoded
72 -- name will include the components p.q.r.s.
74 -- For local entities, the encoded name only includes the components up to
75 -- the enclosing dynamic scope (other than a block). At run time, such a
76 -- dynamic scope is a subprogram, and the debugging formats know about
77 -- local variables of procedures, so it is not necessary to have full
78 -- qualification for such entities. In particular this means that direct
79 -- local variables of a procedure are not qualified.
81 -- For Ghost entities, the encoding adds a prefix "___ghost_" to aid the
82 -- detection of leaks of Ignored Ghost entities in the "living" space.
83 -- Ignored Ghost entities and any code associated with them should be
84 -- removed by the compiler in a post-processing pass. As a result,
85 -- object files should not contain any occurrences of this prefix.
87 -- As an example of the local name convention, consider a procedure V.W
88 -- with a local variable X, and a nested block Y containing an entity Z.
89 -- The fully qualified names of the entities X and Z are:
91 -- V.W.X
92 -- V.W.Y.Z
94 -- but since V.W is a subprogram, the encoded names will end up
95 -- encoding only
97 -- x
98 -- y.z
100 -- The separating dots are translated into double underscores
102 -----------------------------
103 -- Handling of Overloading --
104 -----------------------------
106 -- The above scheme is incomplete for overloaded subprograms, since
107 -- overloading can legitimately result in case of two entities with
108 -- exactly the same fully qualified names. To distinguish between
109 -- entries in a set of overloaded subprograms, the encoded names are
110 -- serialized by adding the suffix:
112 -- __nn (two underscores)
114 -- where nn is a serial number (2 for the second overloaded function,
115 -- 3 for the third, etc.). A suffix of __1 is always omitted (i.e. no
116 -- suffix implies the first instance).
118 -- These names are prefixed by the normal full qualification. So for
119 -- example, the third instance of the subprogram qrs in package yz
120 -- would have the name:
122 -- yz__qrs__3
124 -- A more subtle case arises with entities declared within overloaded
125 -- subprograms. If we have two overloaded subprograms, and both declare
126 -- an entity xyz, then the fully expanded name of the two xyz's is the
127 -- same. To distinguish these, we add the same __n suffix at the end of
128 -- the inner entity names.
130 -- In more complex cases, we can have multiple levels of overloading,
131 -- and we must make sure to distinguish which final declarative region
132 -- we are talking about. For this purpose, we use a more complex suffix
133 -- which has the form:
135 -- __nn_nn_nn ...
137 -- where the nn values are the homonym numbers as needed for any of the
138 -- qualifying entities, separated by a single underscore. If all the nn
139 -- values are 1, the suffix is omitted, Otherwise the suffix is present
140 -- (including any values of 1). The following example shows how this
141 -- suffixing works.
143 -- package body Yz is
144 -- procedure Qrs is -- Name is yz__qrs
145 -- procedure Tuv is ... end; -- Name is yz__qrs__tuv
146 -- begin ... end Qrs;
148 -- procedure Qrs (X: Int) is -- Name is yz__qrs__2
149 -- procedure Tuv is ... end; -- Name is yz__qrs__tuv__2_1
150 -- procedure Tuv (X: Int) is -- Name is yz__qrs__tuv__2_2
151 -- begin ... end Tuv;
153 -- procedure Tuv (X: Float) is -- Name is yz__qrs__tuv__2_3
154 -- type m is new float; -- Name is yz__qrs__tuv__m__2_3
155 -- begin ... end Tuv;
156 -- begin ... end Qrs;
157 -- end Yz;
159 --------------------
160 -- Operator Names --
161 --------------------
163 -- The above rules applied to operator names would result in names with
164 -- quotation marks, which are not typically allowed by assemblers and
165 -- linkers, and even if allowed would be odd and hard to deal with. To
166 -- avoid this problem, operator names are encoded as follows:
168 -- Oabs abs
169 -- Oand and
170 -- Omod mod
171 -- Onot not
172 -- Oor or
173 -- Orem rem
174 -- Oxor xor
175 -- Oeq =
176 -- One /=
177 -- Olt <
178 -- Ole <=
179 -- Ogt >
180 -- Oge >=
181 -- Oadd +
182 -- Osubtract -
183 -- Oconcat &
184 -- Omultiply *
185 -- Odivide /
186 -- Oexpon **
188 -- These names are prefixed by the normal full qualification, and
189 -- suffixed by the overloading identification. So for example, the
190 -- second operator "=" defined in package Extra.Messages would have
191 -- the name:
193 -- extra__messages__Oeq__2
195 ----------------------------------
196 -- Resolving Other Name Clashes --
197 ----------------------------------
199 -- It might be thought that the above scheme is complete, but in Ada 95,
200 -- full qualification is insufficient to uniquely identify an entity in
201 -- the program, even if it is not an overloaded subprogram. There are
202 -- two possible confusions:
204 -- a.b
206 -- interpretation 1: entity b in body of package a
207 -- interpretation 2: child procedure b of package a
209 -- a.b.c
211 -- interpretation 1: entity c in child package a.b
212 -- interpretation 2: entity c in nested package b in body of a
214 -- It is perfectly legal in both cases for both interpretations to be
215 -- valid within a single program. This is a bit of a surprise since
216 -- certainly in Ada 83, full qualification was sufficient, but not in
217 -- Ada 95. The result is that the above scheme can result in duplicate
218 -- names. This would not be so bad if the effect were just restricted
219 -- to debugging information, but in fact in both the above cases, it
220 -- is possible for both symbols to be external names, and so we have
221 -- a real problem of name clashes.
223 -- To deal with this situation, we provide two additional encoding
224 -- rules for names:
226 -- First: all library subprogram names are preceded by the string
227 -- _ada_ (which causes no duplications, since normal Ada names can
228 -- never start with an underscore. This not only solves the first
229 -- case of duplication, but also solves another pragmatic problem
230 -- which is that otherwise Ada procedures can generate names that
231 -- clash with existing system function names. Most notably, we can
232 -- have clashes in the case of procedure Main with the C main that
233 -- in some systems is always present.
235 -- Second, for the case where nested packages declared in package
236 -- bodies can cause trouble, we add a suffix which shows which
237 -- entities in the list are body-nested packages, i.e. packages
238 -- whose spec is within a package body. The rules are as follows,
239 -- given a list of names in a qualified name name1.name2....
241 -- If none are body-nested package entities, then there is no suffix
243 -- If at least one is a body-nested package entity, then the suffix
244 -- is X followed by a string of b's and n's (b = body-nested package
245 -- entity, n = not a body-nested package).
247 -- There is one element in this string for each entity in the encoded
248 -- expanded name except the first (the rules are such that the first
249 -- entity of the encoded expanded name can never be a body-nested'
250 -- package. Trailing n's are omitted, as is the last b (there must
251 -- be at least one b, or we would not be generating a suffix at all).
253 -- For example, suppose we have
255 -- package x is
256 -- pragma Elaborate_Body;
257 -- m1 : integer; -- #1
258 -- end x;
260 -- package body x is
261 -- package y is m2 : integer; end y; -- #2
262 -- package body y is
263 -- package z is r : integer; end z; -- #3
264 -- end;
265 -- m3 : integer; -- #4
266 -- end x;
268 -- package x.y is
269 -- pragma Elaborate_Body;
270 -- m2 : integer; -- #5
271 -- end x.y;
273 -- package body x.y is
274 -- m3 : integer; -- #6
275 -- procedure j is -- #7
276 -- package k is
277 -- z : integer; -- #8
278 -- end k;
279 -- begin
280 -- null;
281 -- end j;
282 -- end x.y;
284 -- procedure x.m3 is begin null; end; -- #9
286 -- Then the encodings would be:
288 -- #1. x__m1 (no BNPE's in sight)
289 -- #2. x__y__m2X (y is a BNPE)
290 -- #3. x__y__z__rXb (y is a BNPE, so is z)
291 -- #4. x__m3 (no BNPE's in sight)
292 -- #5. x__y__m2 (no BNPE's in sight)
293 -- #6. x__y__m3 (no BNPE's in signt)
294 -- #7. x__y__j (no BNPE's in sight)
295 -- #8. k__z (no BNPE's, only up to procedure)
296 -- #9 _ada_x__m3 (library-level subprogram)
298 -- Note that we have instances here of both kind of potential name
299 -- clashes, and the above examples show how the encodings avoid the
300 -- clash as follows:
302 -- Lines #4 and #9 both refer to the entity x.m3, but #9 is a library
303 -- level subprogram, so it is preceded by the string _ada_ which acts
304 -- to distinguish it from the package body entity.
306 -- Lines #2 and #5 both refer to the entity x.y.m2, but the first
307 -- instance is inside the body-nested package y, so there is an X
308 -- suffix to distinguish it from the child library entity.
310 -- Note that enumeration literals never need Xb type suffixes, since
311 -- they are never referenced using global external names.
313 ---------------------
314 -- Interface Names --
315 ---------------------
317 -- Note: if an interface name is present, then the external name is
318 -- taken from the specified interface name. Given current limitations of
319 -- the gcc backend, this means that the debugging name is also set to
320 -- the interface name, but conceptually, it would be possible (and
321 -- indeed desirable) to have the debugging information still use the Ada
322 -- name as qualified above, so we still fully qualify the name in the
323 -- front end.
325 -------------------------------------
326 -- Encodings Related to Task Types --
327 -------------------------------------
329 -- Each task object defined by a single task declaration is associated
330 -- with a prefix that is used to qualify procedures defined in that
331 -- task. Given
333 -- package body P is
334 -- task body TaskObj is
335 -- procedure F1 is ... end;
336 -- begin
337 -- B;
338 -- end TaskObj;
339 -- end P;
341 -- The name of subprogram TaskObj.F1 is encoded as p__taskobjTK__f1.
342 -- The body, B, is contained in a subprogram whose name is
343 -- p__taskobjTKB.
345 ------------------------------------------
346 -- Encodings Related to Protected Types --
347 ------------------------------------------
349 -- Each protected type has an associated record type, that describes
350 -- the actual layout of the private data. In addition to the private
351 -- components of the type, the Corresponding_Record_Type includes one
352 -- component of type Protection, which is the actual lock structure.
353 -- The run-time size of the protected type is the size of the corres-
354 -- ponding record.
356 -- For a protected type prot, the Corresponding_Record_Type is encoded
357 -- as protV.
359 -- The operations of a protected type are encoded as follows: each
360 -- operation results in two subprograms, a locking one that is called
361 -- from outside of the object, and a non-locking one that is used for
362 -- calls from other operations on the same object. The locking operation
363 -- simply acquires the lock, and then calls the non-locking version.
364 -- The names of all of these have a prefix constructed from the name of
365 -- the type, and a suffix which is P or N, depending on whether this is
366 -- the protected/non-locking version of the operation.
368 -- Operations generated for protected entries follow the same encoding.
369 -- Each entry results in two subprograms: a procedure that holds the
370 -- entry body, and a function that holds the evaluation of the barrier.
371 -- The names of these subprograms include the prefix '_E' or '_B' res-
372 -- pectively. The names also include a numeric suffix to render them
373 -- unique in the presence of overloaded entries.
375 -- Given the declaration:
377 -- protected type Lock is
378 -- function Get return Integer;
379 -- procedure Set (X: Integer);
380 -- entry Update (Val : Integer);
381 -- private
382 -- Value : Integer := 0;
383 -- end Lock;
385 -- the following operations are created:
387 -- lock_getN
388 -- lock_getP,
390 -- lock_setN
391 -- lock_setP
393 -- lock_update_E1s
394 -- lock_udpate_B2s
396 -- If the protected type implements at least one interface, the
397 -- following additional operations are created:
399 -- lock_get
401 -- lock_set
403 -- These operations are used to ensure overriding of interface level
404 -- subprograms and proper dispatching on interface class-wide objects.
405 -- The bodies of these operations contain calls to their respective
406 -- protected versions:
408 -- function lock_get return Integer is
409 -- begin
410 -- return lock_getP;
411 -- end lock_get;
413 -- procedure lock_set (X : Integer) is
414 -- begin
415 -- lock_setP (X);
416 -- end lock_set;
418 ----------------------------------------------------
419 -- Conversion between Entities and External Names --
420 ----------------------------------------------------
422 procedure Get_External_Name
423 (Entity : Entity_Id;
424 Has_Suffix : Boolean := False;
425 Suffix : String := "");
426 -- Set Name_Buffer and Name_Len to the external name of the entity. The
427 -- external name is the Interface_Name, if specified, unless the entity
428 -- has an address clause or Has_Suffix is true.
430 -- If the Interface is not present, or not used, the external name is the
431 -- concatenation of:
433 -- - the string "_ada_", if the entity is a library subprogram,
434 -- - the names of any enclosing scopes, each followed by "__",
435 -- or "X_" if the next entity is a subunit)
436 -- - the name of the entity
437 -- - the string "$" (or "__" if target does not allow "$"), followed
438 -- by homonym suffix, if the entity is an overloaded subprogram
439 -- or is defined within an overloaded subprogram.
440 -- - the string "___" followed by Suffix if Has_Suffix is true.
442 -- Note that a call to this procedure has no effect if we are not
443 -- generating code, since the necessary information for computing the
444 -- proper external name is not available in this case.
446 -- WARNING: There is a matching C declaration of this subprogram in fe.h
448 --------------------------------------------
449 -- Subprograms for Handling Qualification --
450 --------------------------------------------
452 procedure Qualify_Entity_Names (N : Node_Id);
453 -- Given a node N, that represents a block, subprogram body, or package
454 -- body or spec, or protected or task type, sets a fully qualified name
455 -- for the defining entity of given construct, and also sets fully
456 -- qualified names for all enclosed entities of the construct (using
457 -- First_Entity/Next_Entity). Note that the actual modifications of the
458 -- names is postponed till a subsequent call to Qualify_All_Entity_Names.
459 -- Note: this routine does not deal with prepending _ada_ to library
460 -- subprogram names. The reason for this is that we only prepend _ada_
461 -- to the library entity itself, and not to names built from this name.
463 procedure Qualify_All_Entity_Names;
464 -- When Qualify_Entity_Names is called, no actual name changes are made,
465 -- i.e. the actual calls to Qualify_Entity_Name are deferred until a call
466 -- is made to this procedure. The reason for this deferral is that when
467 -- names are changed semantic processing may be affected. By deferring
468 -- the changes till just before gigi is called, we avoid any concerns
469 -- about such effects. Gigi itself does not use the names except for
470 -- output of names for debugging purposes (which is why we are doing
471 -- the name changes in the first place).
473 -- Note: the routines Get_Unqualified_[Decoded]_Name_String in Namet are
474 -- useful to remove qualification from a name qualified by the call to
475 -- Qualify_All_Entity_Names.
477 --------------------------------
478 -- Handling of Numeric Values --
479 --------------------------------
481 -- All numeric values here are encoded as strings of decimal digits. Only
482 -- integer values need to be encoded. A negative value is encoded as the
483 -- corresponding positive value followed by a lower case m for minus to
484 -- indicate that the value is negative (e.g. 2m for -2).
486 ------------------------
487 -- Encapsulated Types --
488 ------------------------
490 -- In some cases, the compiler may encapsulate a type by wrapping it in a
491 -- record. For example, this is used when a size or alignment specification
492 -- requires a larger type. Consider:
494 -- type x is mod 2 ** 64;
495 -- for x'size use 256;
497 -- In this case, the compiler generates a record type x___PAD, which has
498 -- a single field whose name is F. This single field is 64-bit long and
499 -- contains the actual value. This kind of padding is used when the logical
500 -- value to be stored is shorter than the object in which it is allocated.
502 -- A similar encapsulation is done for some packed array types, in which
503 -- case the record type is x___JM and the field name is OBJECT. This is
504 -- used in the case of a packed array stored using modular representation
505 -- (see the section on representation of packed array objects). In this
506 -- case the wrapping is used to achieve correct positioning of the packed
507 -- array value (left/right justified in its field depending on endianness).
509 -- When the debugger sees an object of a type whose name has a suffix of
510 -- ___PAD or ___JM, the type will be a record containing a single field,
511 -- and the name of that field will be all upper case. In this case, it
512 -- should look inside to get the value of the inner field, and neither
513 -- the outer structure name, nor the field name should appear when the
514 -- value is printed.
516 -- Similarly, when the debugger sees a record named REP being the type of
517 -- a field inside another record type, it should treat the fields inside
518 -- REP as being part of the outer record (this REP field is only present
519 -- for code generation purposes). The REP record should not appear in the
520 -- values printed by the debugger.
522 --------------------
523 -- Implicit Types --
524 --------------------
526 -- The compiler creates implicit type names in many situations where a
527 -- type is present semantically, but no specific name is present. For
528 -- example:
530 -- S : Integer range M .. N;
532 -- Here the subtype of S is not integer, but rather an anonymous subtype
533 -- of Integer. Where possible, the compiler generates names for such
534 -- anonymous types that are related to the type from which the subtype
535 -- is obtained as follows:
537 -- T name suffix
539 -- where name is the name from which the subtype is obtained, using
540 -- lower case letters and underscores, and suffix starts with an upper
541 -- case letter. For example the name for the above declaration might be:
543 -- TintegerS4b
545 -- If the debugger is asked to give the type of an entity and the type
546 -- has the form T name suffix, it is probably appropriate to just use
547 -- "name" in the response since this is what is meaningful to the
548 -- programmer.
550 -------------------
551 -- Modular Types --
552 -------------------
554 -- A type declared
556 -- type x is mod N;
558 -- is encoded as a subrange of an unsigned base type with lower bound zero
559 -- and upper bound N - 1. Thus we give these types a somewhat nonstandard
560 -- interpretation: the standard interpretation would not, in general, imply
561 -- that arithmetic operations on type x are performed modulo N (especially
562 -- not when N is not a power of 2).
564 --------------------------------------
565 -- Tagged Types and Type Extensions --
566 --------------------------------------
568 -- A type D derived from a tagged type P has a field named "_parent" of
569 -- type P that contains its inherited fields. The type of this field is
570 -- usually P, but may be a more distant ancestor, if P is a null extension
571 -- of that type.
573 -- The type tag of a tagged type is a field named "_tag" of a pointer type.
574 -- If the type is derived from another tagged type, its _tag field is found
575 -- in its _parent field.
577 ------------------------------------
578 -- Type Name Encodings (OBSOLETE) --
579 ------------------------------------
581 -- In the following typ is the name of the type as normally encoded by the
582 -- debugger rules, i.e. a non-qualified name, all in lower case, with
583 -- standard encoding of upper half and wide characters.
585 -----------------------
586 -- Fixed-Point Types --
587 -----------------------
589 -- Fixed-point types are encoded using a suffix that indicates the
590 -- delta and small values. The actual type itself is a normal integer
591 -- type.
593 -- typ___XF_nn_dd
594 -- typ___XF_nn_dd_nn_dd
596 -- The first form is used when small = delta. The value of delta (and
597 -- small) is given by the rational nn/dd, where nn and dd are decimal
598 -- integers.
600 -- The second form is used if the small value is different from the
601 -- delta. In this case, the first nn/dd rational value is for delta,
602 -- and the second value is for small.
604 --------------------
605 -- Discrete Types --
606 --------------------
608 -- Discrete types are coded with a suffix indicating the range in the
609 -- case where one or both of the bounds are discriminants or variable.
611 -- Note: at the current time, we also encode compile time known bounds
612 -- if they do not match the natural machine type bounds, but this may
613 -- be removed in the future, since it is redundant for most debugging
614 -- formats. However, we do not ever need XD encoding for enumeration
615 -- base types, since here it is always clear what the bounds are from
616 -- the total number of enumeration literals.
618 -- typ___XD
619 -- typ___XDL_lowerbound
620 -- typ___XDU_upperbound
621 -- typ___XDLU_lowerbound__upperbound
623 -- If a discrete type is a natural machine type (i.e. its bounds
624 -- correspond in a natural manner to its size), then it is left
625 -- unencoded. The above encoding forms are used when there is a
626 -- constrained range that does not correspond to the size or that
627 -- has discriminant references or other compile time known bounds.
629 -- The first form is used if both bounds are dynamic, in which case two
630 -- constant objects are present whose names are typ___L and typ___U in
631 -- the same scope as typ, and the values of these constants indicate
632 -- the bounds. As far as the debugger is concerned, these are simply
633 -- variables that can be accessed like any other variables. In the
634 -- enumeration case, these values correspond to the Enum_Rep values for
635 -- the lower and upper bounds.
637 -- The second form is used if the upper bound is dynamic, but the lower
638 -- bound is either constant or depends on a discriminant of the record
639 -- with which the type is associated. The upper bound is stored in a
640 -- constant object of name typ___U as previously described, but the
641 -- lower bound is encoded directly into the name as either a decimal
642 -- integer, or as the discriminant name.
644 -- The third form is similarly used if the lower bound is dynamic, but
645 -- the upper bound is compile time known or a discriminant reference,
646 -- in which case the lower bound is stored in a constant object of name
647 -- typ___L, and the upper bound is encoded directly into the name as
648 -- either a decimal integer, or as the discriminant name.
650 -- The fourth form is used if both bounds are discriminant references
651 -- or compile time known values, with the encoding first for the lower
652 -- bound, then for the upper bound, as previously described.
654 ------------------
655 -- Biased Types --
656 ------------------
658 -- Only discrete types can be biased, and the fact that they are biased
659 -- is indicated by a suffix of the form:
661 -- typ___XB_lowerbound__upperbound
663 -- Here lowerbound and upperbound are decimal integers, with the usual
664 -- (postfix "m") encoding for negative numbers. Biased types are only
665 -- possible where the bounds are compile time known, and the values are
666 -- represented as unsigned offsets from the lower bound given. For
667 -- example:
669 -- type Q is range 10 .. 15;
670 -- for Q'size use 3;
672 -- The size clause will force values of type Q in memory to be stored
673 -- in biased form (e.g. 11 will be represented by the bit pattern 001).
675 ----------------------------------------------
676 -- Record Types with Variable-Length Fields --
677 ----------------------------------------------
679 -- The debugging formats do not fully support these types, and indeed
680 -- some formats simply generate no useful information at all for such
681 -- types. In order to provide information for the debugger, gigi creates
682 -- a parallel type in the same scope with one of the names
684 -- type___XVE
685 -- type___XVU
687 -- The former name is used for a record and the latter for the union
688 -- that is made for a variant record (see below) if that record or union
689 -- has a field of variable size or if the record or union itself has a
690 -- variable size. These encodings suffix any other encodings that that
691 -- might be suffixed to the type name.
693 -- The idea here is to provide all the needed information to interpret
694 -- objects of the original type in the form of a "fixed up" type, which
695 -- is representable using the normal debugging information.
697 -- There are three cases to be dealt with. First, some fields may have
698 -- variable positions because they appear after variable-length fields.
699 -- To deal with this, we encode *all* the field bit positions of the
700 -- special ___XV type in a non-standard manner.
702 -- The idea is to encode not the position, but rather information that
703 -- allows computing the position of a field from the position of the
704 -- previous field. The algorithm for computing the actual positions of
705 -- all fields and the length of the record is as follows. In this
706 -- description, let P represent the current bit position in the record.
708 -- 1. Initialize P to 0
710 -- 2. For each field in the record:
712 -- 2a. If an alignment is given (see below), then round P up, if
713 -- needed, to the next multiple of that alignment.
715 -- 2b. If a bit position is given, then increment P by that amount
716 -- (that is, treat it as an offset from the end of the preceding
717 -- record).
719 -- 2c. Assign P as the actual position of the field
721 -- 2d. Compute the length, L, of the represented field (see below)
722 -- and compute P'=P+L. Unless the field represents a variant part
723 -- (see below and also Variant Record Encoding), set P to P'.
725 -- The alignment, if present, is encoded in the field name of the
726 -- record, which has a suffix:
728 -- fieldname___XVAnn
730 -- where the nn after the XVA indicates the alignment value in storage
731 -- units. This encoding is present only if an alignment is present.
733 -- The size of the record described by an XVE-encoded type (in bits) is
734 -- generally the maximum value attained by P' in step 2d above, rounded
735 -- up according to the record's alignment.
737 -- Second, the variable-length fields themselves are represented by
738 -- replacing the type by a special access type. The designated type of
739 -- this access type is the original variable-length type, and the fact
740 -- that this field has been transformed in this way is signalled by
741 -- encoding the field name as:
743 -- field___XVL
745 -- where field is the original field name. If a field is both
746 -- variable-length and also needs an alignment encoding, then the
747 -- encodings are combined using:
749 -- field___XVLnn
751 -- Note: the reason that we change the type is so that the resulting
752 -- type has no variable-length fields. At least some of the formats used
753 -- for debugging information simply cannot tolerate variable- length
754 -- fields, so the encoded information would get lost.
756 -- Third, in the case of a variant record, the special union that
757 -- contains the variants is replaced by a normal C union. In this case,
758 -- the positions are all zero.
760 -- Discriminants appear before any variable-length fields that depend on
761 -- them, with one exception. In some cases, a discriminant governing the
762 -- choice of a variant clause may appear in the list of fields of an XVE
763 -- type after the entry for the variant clause itself (this can happen
764 -- in the presence of a representation clause for the record type in the
765 -- source program). However, when this happens, the discriminant's
766 -- position may be determined by first applying the rules described in
767 -- this section, ignoring the variant clause. As a result, discriminants
768 -- can always be located independently of the variable-length fields
769 -- that depend on them.
771 -- The size of the ___XVE or ___XVU record or union is set to the
772 -- alignment (in bytes) of the original object so that the debugger
773 -- can calculate the size of the original type.
775 -- As an example of this encoding, consider the declarations:
777 -- type Q is array (1 .. V1) of Float; -- alignment 4
778 -- type R is array (1 .. V2) of Long_Float; -- alignment 8
780 -- type X is record
781 -- A : Character;
782 -- B : Float;
783 -- C : String (1 .. V3);
784 -- D : Float;
785 -- E : Q;
786 -- F : R;
787 -- G : Float;
788 -- end record;
790 -- The encoded type looks like:
792 -- type anonymousQ is access Q;
793 -- type anonymousR is access R;
795 -- type X___XVE is record
796 -- A : Character; -- position contains 0
797 -- B : Float; -- position contains 24
798 -- C___XVL : access String (1 .. V3); -- position contains 0
799 -- D___XVA4 : Float; -- position contains 0
800 -- E___XVL4 : anonymousQ; -- position contains 0
801 -- F___XVL8 : anonymousR; -- position contains 0
802 -- G : Float; -- position contains 0
803 -- end record;
805 -- Any bit sizes recorded for fields other than dynamic fields and
806 -- variants are honored as for ordinary records.
808 -- Notes:
810 -- 1) The B field could also have been encoded by using a position of
811 -- zero and an alignment of 4, but in such a case the coding by position
812 -- is preferred (since it takes up less space). We have used the
813 -- (illegal) notation access xxx as field types in the example above.
815 -- 2) The E field does not actually need the alignment indication but
816 -- this may not be detected in this case by the conversion routines.
818 -- 3) Our conventions do not cover all XVE-encoded records in which
819 -- some, but not all, fields have representation clauses. Such records
820 -- may, therefore, be displayed incorrectly by debuggers. This situation
821 -- is not common.
823 -----------------------
824 -- Base Record Types --
825 -----------------------
827 -- Under certain circumstances, debuggers need two descriptions of a
828 -- record type, one that gives the actual details of the base type's
829 -- structure (as described elsewhere in these comments) and one that may
830 -- be used to obtain information about the particular subtype and the
831 -- size of the objects being typed. In such cases the compiler will
832 -- substitute type whose name is typically compiler-generated and
833 -- irrelevant except as a key for obtaining the actual type.
835 -- Specifically, if this name is x, then we produce a record type named
836 -- x___XVS consisting of one field. The name of this field is that of
837 -- the actual type being encoded, which we'll call y. The type of this
838 -- single field can be either an arbitrary non-reference type, e.g. an
839 -- integer type, or a reference type; in the latter case, the referenced
840 -- type is also the actual type being encoded y. Both x and y may have
841 -- corresponding ___XVE types.
843 -- The size of the objects typed as x should be obtained from the
844 -- structure of x (and x___XVE, if applicable) as for ordinary types
845 -- unless there is a variable named x___XVZ, which, if present, will
846 -- hold the size (in bytes) of x. In this latter case, the size of the
847 -- x___XVS type will not be a constant but a reference to x___XVZ.
849 -- The type x will either be a subtype of y (see also Subtypes of
850 -- Variant Records, below) or will contain a single field of type y,
851 -- or no fields at all. The layout, types, and positions of these
852 -- fields will be accurate, if present. (Currently, however, the GDB
853 -- debugger makes no use of x except to determine its size).
855 -- Among other uses, XVS types are used to encode unconstrained types.
856 -- For example, given:
858 -- subtype Int is INTEGER range 0..10;
859 -- type T1 (N: Int := 0) is record
860 -- F1: String (1 .. N);
861 -- end record;
862 -- type AT1 is array (INTEGER range <>) of T1;
864 -- the element type for AT1 might have a type defined as if it had
865 -- been written:
867 -- type at1___PAD is record F : T1; end record;
868 -- for at1___PAD'Size use 16 * 8;
870 -- and there would also be:
872 -- type at1___PAD___XVS is record t1: reft1; end record;
873 -- type t1 is ...
874 -- type reft1 is <reference to t1>
876 -- Had the subtype Int been dynamic:
878 -- subtype Int is INTEGER range 0 .. M; -- M a variable
880 -- Then the compiler would also generate a declaration whose effect
881 -- would be
883 -- at1___PAD___XVZ: constant Integer := 32 + M * 8 + padding term;
885 -- Not all unconstrained types are so encoded; the XVS convention may be
886 -- unnecessary for unconstrained types of fixed size. However, this
887 -- encoding is always necessary when a subcomponent type (array
888 -- element's type or record field's type) is an unconstrained record
889 -- type some of whose components depend on discriminant values.
891 -----------------
892 -- Array Types --
893 -----------------
895 -- Since there is no way for the debugger to obtain the index subtypes
896 -- for an array type, we produce a type that has the name of the array
897 -- type followed by "___XA" and is a record type whose field types are
898 -- the respective types for the bounds (and whose field names are the
899 -- names of these types).
901 -- To conserve space, we do not produce this type unless one of the
902 -- index types is either an enumeration type, has a variable lower or
903 -- upper bound or is a biased type.
905 -- Given the full encoding of these types (see above description for
906 -- the encoding of discrete types), this means that all necessary
907 -- information for addressing arrays is available. In some debugging
908 -- formats, some or all of the bounds information may be available
909 -- redundantly, particularly in the fixed-point case, but this
910 -- information can in any case be ignored by the debugger.
912 -------------------------------------------------
913 -- Subprograms for Handling Encoded Type Names --
914 -------------------------------------------------
916 procedure Get_Encoded_Name (E : Entity_Id);
917 -- If the entity is a typename, store the external name of the entity as in
918 -- Get_External_Name, followed by three underscores plus the type encoding
919 -- in Name_Buffer with the length in Name_Len, and an ASCII.NUL character
920 -- stored following the name. Otherwise set Name_Buffer and Name_Len to
921 -- hold the entity name. Note that a call to this procedure has no effect
922 -- if we are not generating code, since the necessary information for
923 -- computing the proper encoded name is not available in this case.
925 -- WARNING: There is a matching C declaration of this subprogram in fe.h
927 --------------
928 -- Renaming --
929 --------------
931 -- Debugging information is generated for exception, object, package, and
932 -- subprogram renaming (generic renamings are not significant, since
933 -- generic templates are not relevant at debugging time).
935 -- Consider a renaming declaration of the form
937 -- x : typ renames y;
939 -- There is one case in which no special debugging information is required,
940 -- namely the case of an object renaming where the back end allocates a
941 -- reference for the renamed variable, and the entity x is this reference.
942 -- The debugger can handle this case without any special processing or
943 -- encoding (it won't know it was a renaming, but that does not matter).
945 -- All other cases of renaming generate a dummy variable for an entity
946 -- whose name is of the form:
948 -- x___XR_... for an object renaming
949 -- x___XRE_... for an exception renaming
950 -- x___XRP_... for a package renaming
952 -- and where the "..." represents a suffix that describes the structure of
953 -- the object name given in the renaming (see details below).
955 -- The name is fully qualified in the usual manner, i.e. qualified in the
956 -- same manner as the entity x would be. In the case of a package renaming
957 -- where x is a child unit, the qualification includes the name of the
958 -- parent unit, to disambiguate child units with the same simple name and
959 -- (of necessity) different parents.
961 -- Note: subprogram renamings are not encoded at the present time
963 -- The suffix of the variable name describing the renamed object is defined
964 -- to use the following encoding:
966 -- For the simple entity case, where y is just an entity name, the suffix
967 -- is of the form:
969 -- y___XE
971 -- i.e. the suffix has a single field, the first part matching the
972 -- name y, followed by a "___" separator, ending with sequence XE.
973 -- The entity name portion is fully qualified in the usual manner.
974 -- This same naming scheme is followed for all forms of encoded
975 -- renamings that rename a simple entity.
977 -- For the object renaming case where y is a selected component or an
978 -- indexed component, the variable name is suffixed by additional fields
979 -- that give details of the components. The name starts as above with a
980 -- y___XE name indicating the outer level object entity. Then a series of
981 -- selections and indexing operations can be specified as follows:
983 -- Indexed component
985 -- A series of subscript values appear in sequence, the number
986 -- corresponds to the number of dimensions of the array. The
987 -- subscripts have one of the following two forms:
989 -- XSnnn
991 -- Here nnn is a constant value, encoded as a decimal integer
992 -- (pos value for enumeration type case). Negative values have
993 -- a trailing 'm' as usual.
995 -- XSe
997 -- Here e is the (unqualified) name of a constant entity in the
998 -- same scope as the renaming which contains the subscript value.
1000 -- Slice
1002 -- For the slice case, we have two entries. The first is for the
1003 -- lower bound of the slice, and has the form:
1005 -- XLnnn
1006 -- XLe
1008 -- Specifies the lower bound, using exactly the same encoding as
1009 -- for an XS subscript as described above.
1011 -- Then the upper bound appears in the usual XSnnn/XSe form
1013 -- Selected component
1015 -- For a selected component, we have a single entry
1017 -- XRf
1019 -- Here f is the field name for the selection
1021 -- For an explicit dereference (.all), we have a single entry
1023 -- XA
1025 -- As an example, consider the declarations:
1027 -- package p is
1028 -- type q is record
1029 -- m : string (2 .. 5);
1030 -- end record;
1032 -- type r is array (1 .. 10, 1 .. 20) of q;
1034 -- g : r;
1036 -- z : string renames g (1,5).m(2 ..3)
1037 -- end p;
1039 -- The generated variable entity would appear as
1041 -- p__z___XR_p__g___XEXS1XS5XRmXL2XS3 : _renaming_type;
1042 -- p__g___XE--------------------outer entity is g
1043 -- XS1-----------------first subscript for g
1044 -- XS5--------------second subscript for g
1045 -- XRm-----------select field m
1046 -- XL2--------lower bound of slice
1047 -- XS3-----upper bound of slice
1049 -- Note that the type of the variable is a special internal type named
1050 -- _renaming_type. This type is an arbitrary type of zero size created
1051 -- in package Standard (see cstand.adb) and is ignored by the debugger.
1053 function Debug_Renaming_Declaration (N : Node_Id) return Node_Id;
1054 -- The argument N is a renaming declaration. The result is a variable
1055 -- declaration as described in the above paragraphs. If N is not a special
1056 -- debug declaration, then Empty is returned. This function also takes care
1057 -- of setting Materialize_Entity on the renamed entity where required.
1059 -------------------------------------------
1060 -- Packed Array Representation in Memory --
1061 -------------------------------------------
1063 -- Packed arrays are represented in tightly packed form, with no extra bits
1064 -- between components. This is true even when the component size is not a
1065 -- factor of the storage unit size, so that as a result it is possible for
1066 -- components to cross storage unit boundaries.
1068 -- The layout in storage is identical, regardless of whether the
1069 -- implementation type is a modular type or an array-of-bytes type. See
1070 -- Exp_Pakd for details of how these implementation types are used, but for
1071 -- the purpose of the debugger, only the starting address of the object in
1072 -- memory is significant.
1074 -- The following example should show clearly how the packing works in
1075 -- the little-endian and big-endian cases:
1077 -- type B is range 0 .. 7;
1078 -- for B'Size use 3;
1080 -- type BA is array (0 .. 5) of B;
1081 -- pragma Pack (BA);
1083 -- BV : constant BA := (1,2,3,4,5,6);
1085 -- Little endian case
1087 -- BV'Address + 2 BV'Address + 1 BV'Address + 0
1088 -- +-----------------+-----------------+-----------------+
1089 -- | ? ? ? ? ? ? 1 1 | 0 1 0 1 1 0 0 0 | 1 1 0 1 0 0 0 1 |
1090 -- +-----------------+-----------------+-----------------+
1091 -- <---------> <-----> <---> <---> <-----> <---> <--->
1092 -- unused bits BV(5) BV(4) BV(3) BV(2) BV(1) BV(0)
1094 -- Big endian case
1096 -- BV'Address + 0 BV'Address + 1 BV'Address + 2
1097 -- +-----------------+-----------------+-----------------+
1098 -- | 0 0 1 0 1 0 0 1 | 1 1 0 0 1 0 1 1 | 1 0 ? ? ? ? ? ? |
1099 -- +-----------------+-----------------+-----------------+
1100 -- <---> <---> <-----> <---> <---> <-----> <--------->
1101 -- BV(0) BV(1) BV(2) BV(3) BV(4) BV(5) unused bits
1103 -- Note that if a modular type is used to represent the array, the
1104 -- allocation in memory is not the same as a normal modular type. The
1105 -- difference occurs when the allocated object is larger than the size of
1106 -- the array. For a normal modular type, we extend the value on the left
1107 -- with zeroes.
1109 -- For example, in the normal modular case, if we have a 6-bit modular
1110 -- type, declared as mod 2**6, and we allocate an 8-bit object for this
1111 -- type, then we extend the value with two bits on the most significant
1112 -- end, and in either the little-endian or big-endian case, the value 63
1113 -- is represented as 00111111 in binary in memory.
1115 -- For a modular type used to represent a packed array, the rule is
1116 -- different. In this case, if we have to extend the value, then we do it
1117 -- with undefined bits (which are not initialized and whose value is
1118 -- irrelevant to any generated code). Furthermore these bits are on the
1119 -- right (least significant bits) in the big-endian case, and on the left
1120 -- (most significant bits) in the little-endian case.
1122 -- For example, if we have a packed boolean array of 6 bits, all set to
1123 -- True, stored in an 8-bit object, then the value in memory in binary is
1124 -- ??111111 in the little-endian case, and 111111?? in the big-endian case.
1126 -- This is done so that the representation of packed arrays does not
1127 -- depend on whether we use a modular representation or array of bytes
1128 -- as previously described. This ensures that we can pass such values by
1129 -- reference in the case where a subprogram has to be able to handle values
1130 -- stored in either form.
1132 -- Note that when we extract the value of such a modular packed array, we
1133 -- expect to retrieve only the relevant bits, so in this same example, when
1134 -- we extract the value we get 111111 in both cases, and the code generated
1135 -- by the front end assumes this although it does not assume that any high
1136 -- order bits are defined.
1138 -- There are opportunities for optimization based on the knowledge that the
1139 -- unused bits are irrelevant for these type of packed arrays. For example
1140 -- if we have two such 6-bit-in-8-bit values and we do an assignment:
1142 -- a := b;
1144 -- Then logically, we extract the 6 bits and store only 6 bits in the
1145 -- result, but the back end is free to simply assign the entire 8-bits in
1146 -- this case, since we don't actually care about the undefined bits.
1147 -- However, in the equality case, it is important to ensure that the
1148 -- undefined bits do not participate in an equality test.
1150 -- If a modular packed array value is assigned to a register then logically
1151 -- it could always be held right justified, to avoid any need to shift,
1152 -- e.g. when doing comparisons. But probably this is a bad choice, as it
1153 -- would mean that an assignment such as a := above would require shifts
1154 -- when one value is in a register and the other value is in memory.
1156 -------------------------------------------
1157 -- Packed Array Name Encoding (OBSOLETE) --
1158 -------------------------------------------
1160 -- For every constrained packed array, two types are created, and both
1161 -- appear in the debugging output:
1163 -- The original declared array type is a perfectly normal array type, and
1164 -- its index bounds indicate the original bounds of the array.
1166 -- The corresponding packed array type, which may be a modular type, or
1167 -- may be an array of bytes type (see Exp_Pakd for full details). This is
1168 -- the type that is actually used in the generated code and for debugging
1169 -- information for all objects of the packed type.
1171 -- The name of the corresponding packed array type is:
1173 -- ttt___XPnnn
1175 -- where
1177 -- ttt is the name of the original declared array
1178 -- nnn is the component size in bits (1-31)
1180 -- Note that if the packed array is not bit-packed, the name will simply
1181 -- be tttP.
1183 -- When the debugger sees that an object is of a type that is encoded in
1184 -- this manner, it can use the original type to determine the bounds and
1185 -- the component type, and the component size to determine the packing
1186 -- details.
1188 -- For an unconstrained packed array, the corresponding packed array type
1189 -- is neither used in the generated code nor for debugging information,
1190 -- only the original type is used. In order to convey the packing in the
1191 -- debugging information, the compiler generates the associated fat- and
1192 -- thin-pointer types (see the Pointers to Unconstrained Array section
1193 -- below) using the name of the corresponding packed array type as the
1194 -- base name, i.e. ttt___XPnnn___XUP and ttt___XPnnn___XUT respectively.
1196 -- When the debugger sees that an object is of a type that is encoded in
1197 -- this manner, it can use the type of the fields to determine the bounds
1198 -- and the component type, and the component size to determine the packing
1199 -- details.
1201 ------------------------------------------------------
1202 -- Subprograms for Handling Packed Array Type Names --
1203 ------------------------------------------------------
1205 function Make_Packed_Array_Impl_Type_Name
1206 (Typ : Entity_Id;
1207 Csize : Uint) return Name_Id;
1208 -- This function is used in Exp_Pakd to create the name that is encoded as
1209 -- described above. The entity Typ provides the name ttt, and the value
1210 -- Csize is the component size that provides the nnn value.
1212 --------------------------------------
1213 -- Pointers to Unconstrained Arrays --
1214 --------------------------------------
1216 -- There are two kinds of pointer to unconstrained arrays. The debugger can
1217 -- tell which format is in use by the form of the type of the pointer.
1219 -- Fat Pointers
1221 -- Fat pointers are represented as a structure with two fields. This
1222 -- structure has two distinguished field names:
1224 -- P_ARRAY is a pointer to the array type. The name of this type is
1225 -- the unconstrained type followed by "___XUA". The bounds of this
1226 -- array will be obtained through dereferences of P_BOUNDS below.
1228 -- P_BOUNDS is a pointer to a structure. The name of this type is
1229 -- the unconstrained array name followed by "___XUB" and it has
1230 -- fields of the form:
1232 -- LBn (n a decimal integer) lower bound of n'th dimension
1233 -- UBn (n a decimal integer) upper bound of n'th dimension
1235 -- The bounds may be of any integral type. In the case of enumeration
1236 -- types, Enum_Rep values are used.
1238 -- For a given unconstrained array type, the compiler will generate a
1239 -- fat pointer type whose name is the name of the array type, and use
1240 -- it to represent the array type itself in the debugging information.
1242 -- This name was historically followed by "___XUP" (OBSOLETE).
1244 -- For each pointer to this unconstrained array type, the compiler will
1245 -- generate a typedef that points to the above fat pointer type. As a
1246 -- consequence, when it comes to fat pointer types:
1248 -- 1. The type name is given by the typedef, if any
1250 -- 2. If the debugger is asked to output the type, the appropriate
1251 -- form is "access arr" if there is the typedef, otherwise it is
1252 -- the array definition.
1254 -- Thin Pointers
1256 -- The value of a thin pointer is a pointer to the second field of a
1257 -- structure with two fields. The first field of the structure is of
1258 -- the type ___XUB described for fat pointer types above. The second
1259 -- field of the structure contains the actual array.
1261 -- Thin pointers are represented as a regular pointer to array in the
1262 -- debugging information. The bounds of this array will be the contents
1263 -- of the first field above obtained through (shifted) dereferences.
1265 -- Thin Pointers (OBSOLETE)
1267 -- The value of a thin pointer is a pointer to the second field of a
1268 -- structure with two fields. The name of this structure's type is
1269 -- "arr___XUT", where "arr" is the name of the unconstrained array
1270 -- type. Even though it points into the middle of this structure,
1271 -- the type in the debugging information is pointer to structure.
1273 -- The first field of the structure is named BOUNDS and is of the type
1274 -- ___XUB described for fat pointer types above.
1276 -- The second field of the structure is named ARRAY, and contains the
1277 -- actual array. Because this array has a dynamic size, determined by
1278 -- the BOUNDS field that precedes it, all of the information about
1279 -- arr___XUT is encoded in a parallel type named arr___XUT___XVE, with
1280 -- fields BOUNDS and ARRAY___XVL. As for previously described ___XVE
1281 -- types, ARRAY___XVL has a pointer-to-array type. However, the array
1282 -- type in this case is named arr___XUA and only its element type is
1283 -- meaningful, just as described for fat pointers.
1285 -----------------------------
1286 -- Variant Record Encoding --
1287 -----------------------------
1289 -- The variant part of a variant record is encoded as a single field in the
1290 -- enclosing record, whose name is:
1292 -- discrim___XVN
1294 -- where discrim is the unqualified name of the variant. This field name is
1295 -- built by gigi (not by code in this unit). For Unchecked_Union record,
1296 -- this discriminant will not appear in the record (see Unchecked Unions,
1297 -- below).
1299 -- The type corresponding to this field has a name that is obtained by
1300 -- concatenating the type name with the above string and is similar to a C
1301 -- union, in which each member of the union corresponds to one variant.
1302 -- However, unlike a C union, the size of the type may be variable even if
1303 -- each of the components are fixed size, since it includes a computation
1304 -- of which variant is present.
1306 -- The name of the union member is encoded to indicate the choices, and
1307 -- is a string given by the following grammar:
1309 -- member_name ::= {choice} | others_choice
1310 -- choice ::= simple_choice | range_choice
1311 -- simple_choice ::= S number
1312 -- range_choice ::= R number T number
1313 -- number ::= {decimal_digit} [m]
1314 -- others_choice ::= O (upper case letter O)
1316 -- The m in a number indicates a negative value. As an example of this
1317 -- encoding scheme, the choice 1 .. 4 | 7 | -10 would be represented by
1319 -- R1T4S7S10m
1321 -- In the case of enumeration values, the values used are the actual
1322 -- representation values in the case where an enumeration type has an
1323 -- enumeration representation spec (i.e. they are values that correspond
1324 -- to the use of the Enum_Rep attribute).
1326 -- The type of the inner record is given by the name of the union type (as
1327 -- above) concatenated with the above string.
1329 -- As an example, consider:
1331 -- type Var (Disc : Boolean := True) is record
1332 -- M : Integer;
1334 -- case Disc is
1335 -- when True =>
1336 -- R : Integer;
1337 -- S : Integer;
1339 -- when False =>
1340 -- T : Integer;
1341 -- end case;
1342 -- end record;
1344 -- V1 : Var;
1346 -- In this case, the type var is represented as a struct with three fields.
1347 -- The first two are "disc" and "m", representing the values of these
1348 -- record components. The third field is a union of two types, with field
1349 -- names S1 and O. S1 is a struct with fields "r" and "s", and O is a
1350 -- struct with field "t".
1352 ----------------------
1353 -- Unchecked Unions --
1354 ----------------------
1356 -- The encoding for variant records changes somewhat under the influence
1357 -- of a "pragma Unchecked_Union" clause:
1359 -- 1. The discriminant will not be present in the record, although its
1360 -- name is still used in the encodings.
1361 -- 2. Variants containing a single component named "x" of type "T" may
1362 -- be encoded, as in ordinary C unions, as a single field of the
1363 -- enclosing union type named "x" of type "T", dispensing with the
1364 -- enclosing struct. In this case, of course, the discriminant values
1365 -- corresponding to the variant are unavailable.
1367 -- For example, the type Var in the preceding section, if followed by
1368 -- "pragma Unchecked_Union (Var);" may be encoded as a struct with two
1369 -- fields. The first is "m". The second field is a union of two types,
1370 -- with field names S1 and "t". As before, S1 is a struct with fields
1371 -- "r" and "s". "t" is a field of type Integer.
1373 ------------------------------------------------
1374 -- Subprograms for Handling Variant Encodings --
1375 ------------------------------------------------
1377 procedure Get_Variant_Encoding (V : Node_Id);
1378 -- This procedure is called by Gigi with V being the variant node. The
1379 -- corresponding encoding string is returned in Name_Buffer with the length
1380 -- of the string in Name_Len, and an ASCII.NUL character stored following
1381 -- the name.
1383 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1385 ---------------------------------
1386 -- Subtypes of Variant Records --
1387 ---------------------------------
1389 -- A subtype of a variant record is represented by a type in which the
1390 -- union field from the base type is replaced by one of the possible
1391 -- values. For example, if we have:
1393 -- type Var (Disc : Boolean := True) is record
1394 -- M : Integer;
1396 -- case Disc is
1397 -- when True =>
1398 -- R : Integer;
1399 -- S : Integer;
1401 -- when False =>
1402 -- T : Integer;
1403 -- end case;
1405 -- end record;
1406 -- V1 : Var;
1407 -- V2 : Var (True);
1408 -- V3 : Var (False);
1410 -- Here V2, for example, is represented with a subtype whose name is
1411 -- something like TvarS3b, which is a struct with three fields. The first
1412 -- two fields are "disc" and "m" as for the base type, and the third field
1413 -- is S1, which contains the fields "r" and "s".
1415 -- The debugger should simply ignore structs with names of the form
1416 -- corresponding to variants, and consider the fields inside as belonging
1417 -- to the containing record.
1419 -----------------------------------------------
1420 -- Extra renamings for subprogram instances --
1421 -----------------------------------------------
1423 procedure Build_Subprogram_Instance_Renamings
1424 (N : Node_Id;
1425 Wrapper : Entity_Id);
1426 -- The debugger has difficulties in recovering the value of actuals of an
1427 -- elementary type, from within the body of a subprogram instantiation.
1428 -- This is because such actuals generate an object declaration that is
1429 -- placed within the wrapper package of the instance, and the entity in
1430 -- these declarations is encoded in a complex way that GDB does not handle
1431 -- well. These new renaming declarations appear within the body of the
1432 -- subprogram, and are redundant from a visibility point of view, but they
1433 -- should have no measurable performance impact, and require no special
1434 -- decoding in the debugger.
1436 -------------------------------------------
1437 -- Character literals in Character Types --
1438 -------------------------------------------
1440 -- Character types are enumeration types at least one of whose enumeration
1441 -- literals is a character literal. Enumeration literals are usually simply
1442 -- represented using their identifier names. If the enumeration literal is
1443 -- a character literal, the name is encoded as described in the following
1444 -- paragraph.
1446 -- The characters 'a'..'z' and '0'..'9' are represented as Qc, where 'c'
1447 -- stands for the character itself. A name QUhh, where each 'h' is a
1448 -- lower-case hexadecimal digit, stands for a character whose Unicode
1449 -- encoding is hh, and QWhhhh likewise stands for a wide character whose
1450 -- encoding is hhhh. The representation values are encoded as for ordinary
1451 -- enumeration literals (and have no necessary relationship to the values
1452 -- encoded in the names).
1454 -- For example, given the type declaration
1456 -- type x is (A, 'C', 'b');
1458 -- the second enumeration literal would be named QU43 and the value
1459 -- assigned to it would be 1, and the third enumeration literal would be
1460 -- named Qb and the value assigned to it would be 2.
1462 -----------------------------------------------
1463 -- Secondary Dispatch tables of tagged types --
1464 -----------------------------------------------
1466 procedure Get_Secondary_DT_External_Name
1467 (Typ : Entity_Id;
1468 Ancestor_Typ : Entity_Id;
1469 Suffix_Index : Int);
1470 -- Set Name_Buffer and Name_Len to the external name of one secondary
1471 -- dispatch table of Typ. If the interface has been inherited from some
1472 -- ancestor then Ancestor_Typ is such node (in this case the secondary DT
1473 -- is needed to handle overridden primitives); if there is no such ancestor
1474 -- then Ancestor_Typ is equal to Typ.
1476 -- Internal rule followed for the generation of the external name:
1478 -- Case 1. If the secondary dispatch has not been inherited from some
1479 -- ancestor of Typ then the external name is composed as
1480 -- follows:
1481 -- External_Name (Typ) + Suffix_Number + 'P'
1483 -- Case 2. if the secondary dispatch table has been inherited from some
1484 -- ancestor then the external name is composed as follows:
1485 -- External_Name (Typ) + '_' + External_Name (Ancestor_Typ)
1486 -- + Suffix_Number + 'P'
1488 -- Note: We have to use the external names (instead of simply their names)
1489 -- to protect the frontend against programs that give the same name to all
1490 -- the interfaces and use the expanded name to reference them. The
1491 -- Suffix_Number is used to differentiate all the secondary dispatch
1492 -- tables of a given type.
1494 -- Examples:
1496 -- package Pkg1 is | package Pkg2 is | package Pkg3 is
1497 -- type Typ is | type Typ is | type Typ is
1498 -- interface; | interface; | interface;
1499 -- end Pkg1; | end Pkg; | end Pkg3;
1501 -- with Pkg1, Pkg2, Pkg3;
1502 -- package Case_1 is
1503 -- type Typ is new Pkg1.Typ and Pkg2.Typ and Pkg3.Typ with ...
1504 -- end Case_1;
1506 -- with Case_1;
1507 -- package Case_2 is
1508 -- type Typ is new Case_1.Typ with ...
1509 -- end Case_2;
1511 -- These are the external names generated for Case_1.Typ (note that
1512 -- Pkg1.Typ is associated with the Primary Dispatch Table, because it
1513 -- is the parent of this type, and hence no external name is
1514 -- generated for it).
1515 -- case_1__typ0P (associated with Pkg2.Typ)
1516 -- case_1__typ1P (associated with Pkg3.Typ)
1518 -- These are the external names generated for Case_2.Typ:
1519 -- case_2__typ_case_1__typ0P
1520 -- case_2__typ_case_1__typ1P
1522 ----------------------------
1523 -- Effect of Optimization --
1524 ----------------------------
1526 -- If the program is compiled with optimization on (e.g. -O1 switch
1527 -- specified), then there may be variations in the output from the above
1528 -- specification. In particular, objects may disappear from the output.
1529 -- This includes not only constants and variables that the program declares
1530 -- at the source level, but also the x___L and x___U constants created to
1531 -- describe the lower and upper bounds of subtypes with dynamic bounds.
1532 -- This means for example, that array bounds may disappear if optimization
1533 -- is turned on. The debugger is expected to recognize that these constants
1534 -- are missing and deal as best as it can with the limited information
1535 -- available.
1537 -----------------------------------------
1538 -- GNAT Extensions to DWARF (OBSOLETE) --
1539 -----------------------------------------
1541 -- DW_AT_use_GNAT_descriptive_type, encoded with value 0x2301
1543 -- This extension has never been implemented in the compiler.
1545 -- DW_AT_GNAT_descriptive_type, encoded with value 0x2302
1547 -- Any debugging information entry representing a type may have a
1548 -- DW_AT_GNAT_descriptive_type attribute whose value is a reference,
1549 -- pointing to a debugging information entry representing another type
1550 -- associated to the type.
1552 end Exp_Dbug;