Daily bump.
[official-gcc.git] / gcc / ada / exp_dbug.ads
blob09921f0e42d0d911fa9a4370b9657a20a6ac90c1
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-2021, 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 -- Encoding for translation into C --
450 -------------------------------------
452 -- In Modify_Tree_For_C mode we must add encodings to dismabiguate cases
453 -- where Ada block structure cannot be directly translated. These cases
454 -- are as follows:
456 -- a) A loop variable may hide a homonym in an enclosing block
457 -- b) A block-local variable may hide a homonym in an enclosing block
459 -- In C these constructs are not scopes and we must distinguish the names
460 -- explicitly. In the first case we create a qualified name with the suffix
461 -- 'L', in the second case with a suffix 'B'.
463 --------------------------------------------
464 -- Subprograms for Handling Qualification --
465 --------------------------------------------
467 procedure Qualify_Entity_Names (N : Node_Id);
468 -- Given a node N, that represents a block, subprogram body, or package
469 -- body or spec, or protected or task type, sets a fully qualified name
470 -- for the defining entity of given construct, and also sets fully
471 -- qualified names for all enclosed entities of the construct (using
472 -- First_Entity/Next_Entity). Note that the actual modifications of the
473 -- names is postponed till a subsequent call to Qualify_All_Entity_Names.
474 -- Note: this routine does not deal with prepending _ada_ to library
475 -- subprogram names. The reason for this is that we only prepend _ada_
476 -- to the library entity itself, and not to names built from this name.
478 procedure Qualify_All_Entity_Names;
479 -- When Qualify_Entity_Names is called, no actual name changes are made,
480 -- i.e. the actual calls to Qualify_Entity_Name are deferred until a call
481 -- is made to this procedure. The reason for this deferral is that when
482 -- names are changed semantic processing may be affected. By deferring
483 -- the changes till just before gigi is called, we avoid any concerns
484 -- about such effects. Gigi itself does not use the names except for
485 -- output of names for debugging purposes (which is why we are doing
486 -- the name changes in the first place).
488 -- Note: the routines Get_Unqualified_[Decoded]_Name_String in Namet are
489 -- useful to remove qualification from a name qualified by the call to
490 -- Qualify_All_Entity_Names.
492 --------------------------------
493 -- Handling of Numeric Values --
494 --------------------------------
496 -- All numeric values here are encoded as strings of decimal digits. Only
497 -- integer values need to be encoded. A negative value is encoded as the
498 -- corresponding positive value followed by a lower case m for minus to
499 -- indicate that the value is negative (e.g. 2m for -2).
501 ------------------------
502 -- Encapsulated Types --
503 ------------------------
505 -- In some cases, the compiler may encapsulate a type by wrapping it in a
506 -- record. For example, this is used when a size or alignment specification
507 -- requires a larger type. Consider:
509 -- type x is mod 2 ** 64;
510 -- for x'size use 256;
512 -- In this case, the compiler generates a record type x___PAD, which has
513 -- a single field whose name is F. This single field is 64-bit long and
514 -- contains the actual value. This kind of padding is used when the logical
515 -- value to be stored is shorter than the object in which it is allocated.
517 -- A similar encapsulation is done for some packed array types, in which
518 -- case the record type is x___JM and the field name is OBJECT. This is
519 -- used in the case of a packed array stored using modular representation
520 -- (see the section on representation of packed array objects). In this
521 -- case the wrapping is used to achieve correct positioning of the packed
522 -- array value (left/right justified in its field depending on endianness).
524 -- When the debugger sees an object of a type whose name has a suffix of
525 -- ___PAD or ___JM, the type will be a record containing a single field,
526 -- and the name of that field will be all upper case. In this case, it
527 -- should look inside to get the value of the inner field, and neither
528 -- the outer structure name, nor the field name should appear when the
529 -- value is printed.
531 -- Similarly, when the debugger sees a record named REP being the type of
532 -- a field inside another record type, it should treat the fields inside
533 -- REP as being part of the outer record (this REP field is only present
534 -- for code generation purposes). The REP record should not appear in the
535 -- values printed by the debugger.
537 --------------------
538 -- Implicit Types --
539 --------------------
541 -- The compiler creates implicit type names in many situations where a
542 -- type is present semantically, but no specific name is present. For
543 -- example:
545 -- S : Integer range M .. N;
547 -- Here the subtype of S is not integer, but rather an anonymous subtype
548 -- of Integer. Where possible, the compiler generates names for such
549 -- anonymous types that are related to the type from which the subtype
550 -- is obtained as follows:
552 -- T name suffix
554 -- where name is the name from which the subtype is obtained, using
555 -- lower case letters and underscores, and suffix starts with an upper
556 -- case letter. For example the name for the above declaration might be:
558 -- TintegerS4b
560 -- If the debugger is asked to give the type of an entity and the type
561 -- has the form T name suffix, it is probably appropriate to just use
562 -- "name" in the response since this is what is meaningful to the
563 -- programmer.
565 -------------------
566 -- Modular Types --
567 -------------------
569 -- A type declared
571 -- type x is mod N;
573 -- is encoded as a subrange of an unsigned base type with lower bound zero
574 -- and upper bound N - 1. Thus we give these types a somewhat nonstandard
575 -- interpretation: the standard interpretation would not, in general, imply
576 -- that arithmetic operations on type x are performed modulo N (especially
577 -- not when N is not a power of 2).
579 --------------------------------------
580 -- Tagged Types and Type Extensions --
581 --------------------------------------
583 -- A type D derived from a tagged type P has a field named "_parent" of
584 -- type P that contains its inherited fields. The type of this field is
585 -- usually P, but may be a more distant ancestor, if P is a null extension
586 -- of that type.
588 -- The type tag of a tagged type is a field named "_tag" of a pointer type.
589 -- If the type is derived from another tagged type, its _tag field is found
590 -- in its _parent field.
592 ------------------------------------
593 -- Type Name Encodings (OBSOLETE) --
594 ------------------------------------
596 -- In the following typ is the name of the type as normally encoded by the
597 -- debugger rules, i.e. a non-qualified name, all in lower case, with
598 -- standard encoding of upper half and wide characters.
600 -----------------------
601 -- Fixed-Point Types --
602 -----------------------
604 -- Fixed-point types are encoded using a suffix that indicates the
605 -- delta and small values. The actual type itself is a normal integer
606 -- type.
608 -- typ___XF_nn_dd
609 -- typ___XF_nn_dd_nn_dd
611 -- The first form is used when small = delta. The value of delta (and
612 -- small) is given by the rational nn/dd, where nn and dd are decimal
613 -- integers.
615 -- The second form is used if the small value is different from the
616 -- delta. In this case, the first nn/dd rational value is for delta,
617 -- and the second value is for small.
619 --------------------
620 -- Discrete Types --
621 --------------------
623 -- Discrete types are coded with a suffix indicating the range in the
624 -- case where one or both of the bounds are discriminants or variable.
626 -- Note: at the current time, we also encode compile time known bounds
627 -- if they do not match the natural machine type bounds, but this may
628 -- be removed in the future, since it is redundant for most debugging
629 -- formats. However, we do not ever need XD encoding for enumeration
630 -- base types, since here it is always clear what the bounds are from
631 -- the total number of enumeration literals.
633 -- typ___XD
634 -- typ___XDL_lowerbound
635 -- typ___XDU_upperbound
636 -- typ___XDLU_lowerbound__upperbound
638 -- If a discrete type is a natural machine type (i.e. its bounds
639 -- correspond in a natural manner to its size), then it is left
640 -- unencoded. The above encoding forms are used when there is a
641 -- constrained range that does not correspond to the size or that
642 -- has discriminant references or other compile time known bounds.
644 -- The first form is used if both bounds are dynamic, in which case two
645 -- constant objects are present whose names are typ___L and typ___U in
646 -- the same scope as typ, and the values of these constants indicate
647 -- the bounds. As far as the debugger is concerned, these are simply
648 -- variables that can be accessed like any other variables. In the
649 -- enumeration case, these values correspond to the Enum_Rep values for
650 -- the lower and upper bounds.
652 -- The second form is used if the upper bound is dynamic, but the lower
653 -- bound is either constant or depends on a discriminant of the record
654 -- with which the type is associated. The upper bound is stored in a
655 -- constant object of name typ___U as previously described, but the
656 -- lower bound is encoded directly into the name as either a decimal
657 -- integer, or as the discriminant name.
659 -- The third form is similarly used if the lower bound is dynamic, but
660 -- the upper bound is compile time known or a discriminant reference,
661 -- in which case the lower bound is stored in a constant object of name
662 -- typ___L, and the upper bound is encoded directly into the name as
663 -- either a decimal integer, or as the discriminant name.
665 -- The fourth form is used if both bounds are discriminant references
666 -- or compile time known values, with the encoding first for the lower
667 -- bound, then for the upper bound, as previously described.
669 ------------------
670 -- Biased Types --
671 ------------------
673 -- Only discrete types can be biased, and the fact that they are biased
674 -- is indicated by a suffix of the form:
676 -- typ___XB_lowerbound__upperbound
678 -- Here lowerbound and upperbound are decimal integers, with the usual
679 -- (postfix "m") encoding for negative numbers. Biased types are only
680 -- possible where the bounds are compile time known, and the values are
681 -- represented as unsigned offsets from the lower bound given. For
682 -- example:
684 -- type Q is range 10 .. 15;
685 -- for Q'size use 3;
687 -- The size clause will force values of type Q in memory to be stored
688 -- in biased form (e.g. 11 will be represented by the bit pattern 001).
690 ----------------------------------------------
691 -- Record Types with Variable-Length Fields --
692 ----------------------------------------------
694 -- The debugging formats do not fully support these types, and indeed
695 -- some formats simply generate no useful information at all for such
696 -- types. In order to provide information for the debugger, gigi creates
697 -- a parallel type in the same scope with one of the names
699 -- type___XVE
700 -- type___XVU
702 -- The former name is used for a record and the latter for the union
703 -- that is made for a variant record (see below) if that record or union
704 -- has a field of variable size or if the record or union itself has a
705 -- variable size. These encodings suffix any other encodings that that
706 -- might be suffixed to the type name.
708 -- The idea here is to provide all the needed information to interpret
709 -- objects of the original type in the form of a "fixed up" type, which
710 -- is representable using the normal debugging information.
712 -- There are three cases to be dealt with. First, some fields may have
713 -- variable positions because they appear after variable-length fields.
714 -- To deal with this, we encode *all* the field bit positions of the
715 -- special ___XV type in a non-standard manner.
717 -- The idea is to encode not the position, but rather information that
718 -- allows computing the position of a field from the position of the
719 -- previous field. The algorithm for computing the actual positions of
720 -- all fields and the length of the record is as follows. In this
721 -- description, let P represent the current bit position in the record.
723 -- 1. Initialize P to 0
725 -- 2. For each field in the record:
727 -- 2a. If an alignment is given (see below), then round P up, if
728 -- needed, to the next multiple of that alignment.
730 -- 2b. If a bit position is given, then increment P by that amount
731 -- (that is, treat it as an offset from the end of the preceding
732 -- record).
734 -- 2c. Assign P as the actual position of the field
736 -- 2d. Compute the length, L, of the represented field (see below)
737 -- and compute P'=P+L. Unless the field represents a variant part
738 -- (see below and also Variant Record Encoding), set P to P'.
740 -- The alignment, if present, is encoded in the field name of the
741 -- record, which has a suffix:
743 -- fieldname___XVAnn
745 -- where the nn after the XVA indicates the alignment value in storage
746 -- units. This encoding is present only if an alignment is present.
748 -- The size of the record described by an XVE-encoded type (in bits) is
749 -- generally the maximum value attained by P' in step 2d above, rounded
750 -- up according to the record's alignment.
752 -- Second, the variable-length fields themselves are represented by
753 -- replacing the type by a special access type. The designated type of
754 -- this access type is the original variable-length type, and the fact
755 -- that this field has been transformed in this way is signalled by
756 -- encoding the field name as:
758 -- field___XVL
760 -- where field is the original field name. If a field is both
761 -- variable-length and also needs an alignment encoding, then the
762 -- encodings are combined using:
764 -- field___XVLnn
766 -- Note: the reason that we change the type is so that the resulting
767 -- type has no variable-length fields. At least some of the formats used
768 -- for debugging information simply cannot tolerate variable- length
769 -- fields, so the encoded information would get lost.
771 -- Third, in the case of a variant record, the special union that
772 -- contains the variants is replaced by a normal C union. In this case,
773 -- the positions are all zero.
775 -- Discriminants appear before any variable-length fields that depend on
776 -- them, with one exception. In some cases, a discriminant governing the
777 -- choice of a variant clause may appear in the list of fields of an XVE
778 -- type after the entry for the variant clause itself (this can happen
779 -- in the presence of a representation clause for the record type in the
780 -- source program). However, when this happens, the discriminant's
781 -- position may be determined by first applying the rules described in
782 -- this section, ignoring the variant clause. As a result, discriminants
783 -- can always be located independently of the variable-length fields
784 -- that depend on them.
786 -- The size of the ___XVE or ___XVU record or union is set to the
787 -- alignment (in bytes) of the original object so that the debugger
788 -- can calculate the size of the original type.
790 -- As an example of this encoding, consider the declarations:
792 -- type Q is array (1 .. V1) of Float; -- alignment 4
793 -- type R is array (1 .. V2) of Long_Float; -- alignment 8
795 -- type X is record
796 -- A : Character;
797 -- B : Float;
798 -- C : String (1 .. V3);
799 -- D : Float;
800 -- E : Q;
801 -- F : R;
802 -- G : Float;
803 -- end record;
805 -- The encoded type looks like:
807 -- type anonymousQ is access Q;
808 -- type anonymousR is access R;
810 -- type X___XVE is record
811 -- A : Character; -- position contains 0
812 -- B : Float; -- position contains 24
813 -- C___XVL : access String (1 .. V3); -- position contains 0
814 -- D___XVA4 : Float; -- position contains 0
815 -- E___XVL4 : anonymousQ; -- position contains 0
816 -- F___XVL8 : anonymousR; -- position contains 0
817 -- G : Float; -- position contains 0
818 -- end record;
820 -- Any bit sizes recorded for fields other than dynamic fields and
821 -- variants are honored as for ordinary records.
823 -- Notes:
825 -- 1) The B field could also have been encoded by using a position of
826 -- zero and an alignment of 4, but in such a case the coding by position
827 -- is preferred (since it takes up less space). We have used the
828 -- (illegal) notation access xxx as field types in the example above.
830 -- 2) The E field does not actually need the alignment indication but
831 -- this may not be detected in this case by the conversion routines.
833 -- 3) Our conventions do not cover all XVE-encoded records in which
834 -- some, but not all, fields have representation clauses. Such records
835 -- may, therefore, be displayed incorrectly by debuggers. This situation
836 -- is not common.
838 -----------------------
839 -- Base Record Types --
840 -----------------------
842 -- Under certain circumstances, debuggers need two descriptions of a
843 -- record type, one that gives the actual details of the base type's
844 -- structure (as described elsewhere in these comments) and one that may
845 -- be used to obtain information about the particular subtype and the
846 -- size of the objects being typed. In such cases the compiler will
847 -- substitute type whose name is typically compiler-generated and
848 -- irrelevant except as a key for obtaining the actual type.
850 -- Specifically, if this name is x, then we produce a record type named
851 -- x___XVS consisting of one field. The name of this field is that of
852 -- the actual type being encoded, which we'll call y. The type of this
853 -- single field can be either an arbitrary non-reference type, e.g. an
854 -- integer type, or a reference type; in the latter case, the referenced
855 -- type is also the actual type being encoded y. Both x and y may have
856 -- corresponding ___XVE types.
858 -- The size of the objects typed as x should be obtained from the
859 -- structure of x (and x___XVE, if applicable) as for ordinary types
860 -- unless there is a variable named x___XVZ, which, if present, will
861 -- hold the size (in bytes) of x. In this latter case, the size of the
862 -- x___XVS type will not be a constant but a reference to x___XVZ.
864 -- The type x will either be a subtype of y (see also Subtypes of
865 -- Variant Records, below) or will contain a single field of type y,
866 -- or no fields at all. The layout, types, and positions of these
867 -- fields will be accurate, if present. (Currently, however, the GDB
868 -- debugger makes no use of x except to determine its size).
870 -- Among other uses, XVS types are used to encode unconstrained types.
871 -- For example, given:
873 -- subtype Int is INTEGER range 0..10;
874 -- type T1 (N: Int := 0) is record
875 -- F1: String (1 .. N);
876 -- end record;
877 -- type AT1 is array (INTEGER range <>) of T1;
879 -- the element type for AT1 might have a type defined as if it had
880 -- been written:
882 -- type at1___PAD is record F : T1; end record;
883 -- for at1___PAD'Size use 16 * 8;
885 -- and there would also be:
887 -- type at1___PAD___XVS is record t1: reft1; end record;
888 -- type t1 is ...
889 -- type reft1 is <reference to t1>
891 -- Had the subtype Int been dynamic:
893 -- subtype Int is INTEGER range 0 .. M; -- M a variable
895 -- Then the compiler would also generate a declaration whose effect
896 -- would be
898 -- at1___PAD___XVZ: constant Integer := 32 + M * 8 + padding term;
900 -- Not all unconstrained types are so encoded; the XVS convention may be
901 -- unnecessary for unconstrained types of fixed size. However, this
902 -- encoding is always necessary when a subcomponent type (array
903 -- element's type or record field's type) is an unconstrained record
904 -- type some of whose components depend on discriminant values.
906 -----------------
907 -- Array Types --
908 -----------------
910 -- Since there is no way for the debugger to obtain the index subtypes
911 -- for an array type, we produce a type that has the name of the array
912 -- type followed by "___XA" and is a record type whose field types are
913 -- the respective types for the bounds (and whose field names are the
914 -- names of these types).
916 -- To conserve space, we do not produce this type unless one of the
917 -- index types is either an enumeration type, has a variable lower or
918 -- upper bound or is a biased type.
920 -- Given the full encoding of these types (see above description for
921 -- the encoding of discrete types), this means that all necessary
922 -- information for addressing arrays is available. In some debugging
923 -- formats, some or all of the bounds information may be available
924 -- redundantly, particularly in the fixed-point case, but this
925 -- information can in any case be ignored by the debugger.
927 -------------------------------------------------
928 -- Subprograms for Handling Encoded Type Names --
929 -------------------------------------------------
931 procedure Get_Encoded_Name (E : Entity_Id);
932 -- If the entity is a typename, store the external name of the entity as in
933 -- Get_External_Name, followed by three underscores plus the type encoding
934 -- in Name_Buffer with the length in Name_Len, and an ASCII.NUL character
935 -- stored following the name. Otherwise set Name_Buffer and Name_Len to
936 -- hold the entity name. Note that a call to this procedure has no effect
937 -- if we are not generating code, since the necessary information for
938 -- computing the proper encoded name is not available in this case.
940 -- WARNING: There is a matching C declaration of this subprogram in fe.h
942 --------------
943 -- Renaming --
944 --------------
946 -- Debugging information is generated for exception, object, package, and
947 -- subprogram renaming (generic renamings are not significant, since
948 -- generic templates are not relevant at debugging time).
950 -- Consider a renaming declaration of the form
952 -- x : typ renames y;
954 -- There is one case in which no special debugging information is required,
955 -- namely the case of an object renaming where the back end allocates a
956 -- reference for the renamed variable, and the entity x is this reference.
957 -- The debugger can handle this case without any special processing or
958 -- encoding (it won't know it was a renaming, but that does not matter).
960 -- All other cases of renaming generate a dummy variable for an entity
961 -- whose name is of the form:
963 -- x___XR_... for an object renaming
964 -- x___XRE_... for an exception renaming
965 -- x___XRP_... for a package renaming
967 -- and where the "..." represents a suffix that describes the structure of
968 -- the object name given in the renaming (see details below).
970 -- The name is fully qualified in the usual manner, i.e. qualified in the
971 -- same manner as the entity x would be. In the case of a package renaming
972 -- where x is a child unit, the qualification includes the name of the
973 -- parent unit, to disambiguate child units with the same simple name and
974 -- (of necessity) different parents.
976 -- Note: subprogram renamings are not encoded at the present time
978 -- The suffix of the variable name describing the renamed object is defined
979 -- to use the following encoding:
981 -- For the simple entity case, where y is just an entity name, the suffix
982 -- is of the form:
984 -- y___XE
986 -- i.e. the suffix has a single field, the first part matching the
987 -- name y, followed by a "___" separator, ending with sequence XE.
988 -- The entity name portion is fully qualified in the usual manner.
989 -- This same naming scheme is followed for all forms of encoded
990 -- renamings that rename a simple entity.
992 -- For the object renaming case where y is a selected component or an
993 -- indexed component, the variable name is suffixed by additional fields
994 -- that give details of the components. The name starts as above with a
995 -- y___XE name indicating the outer level object entity. Then a series of
996 -- selections and indexing operations can be specified as follows:
998 -- Indexed component
1000 -- A series of subscript values appear in sequence, the number
1001 -- corresponds to the number of dimensions of the array. The
1002 -- subscripts have one of the following two forms:
1004 -- XSnnn
1006 -- Here nnn is a constant value, encoded as a decimal integer
1007 -- (pos value for enumeration type case). Negative values have
1008 -- a trailing 'm' as usual.
1010 -- XSe
1012 -- Here e is the (unqualified) name of a constant entity in the
1013 -- same scope as the renaming which contains the subscript value.
1015 -- Slice
1017 -- For the slice case, we have two entries. The first is for the
1018 -- lower bound of the slice, and has the form:
1020 -- XLnnn
1021 -- XLe
1023 -- Specifies the lower bound, using exactly the same encoding as
1024 -- for an XS subscript as described above.
1026 -- Then the upper bound appears in the usual XSnnn/XSe form
1028 -- Selected component
1030 -- For a selected component, we have a single entry
1032 -- XRf
1034 -- Here f is the field name for the selection
1036 -- For an explicit dereference (.all), we have a single entry
1038 -- XA
1040 -- As an example, consider the declarations:
1042 -- package p is
1043 -- type q is record
1044 -- m : string (2 .. 5);
1045 -- end record;
1047 -- type r is array (1 .. 10, 1 .. 20) of q;
1049 -- g : r;
1051 -- z : string renames g (1,5).m(2 ..3)
1052 -- end p;
1054 -- The generated variable entity would appear as
1056 -- p__z___XR_p__g___XEXS1XS5XRmXL2XS3 : _renaming_type;
1057 -- p__g___XE--------------------outer entity is g
1058 -- XS1-----------------first subscript for g
1059 -- XS5--------------second subscript for g
1060 -- XRm-----------select field m
1061 -- XL2--------lower bound of slice
1062 -- XS3-----upper bound of slice
1064 -- Note that the type of the variable is a special internal type named
1065 -- _renaming_type. This type is an arbitrary type of zero size created
1066 -- in package Standard (see cstand.adb) and is ignored by the debugger.
1068 function Debug_Renaming_Declaration (N : Node_Id) return Node_Id;
1069 -- The argument N is a renaming declaration. The result is a variable
1070 -- declaration as described in the above paragraphs. If N is not a special
1071 -- debug declaration, then Empty is returned. This function also takes care
1072 -- of setting Materialize_Entity on the renamed entity where required.
1074 -------------------------------------------
1075 -- Packed Array Representation in Memory --
1076 -------------------------------------------
1078 -- Packed arrays are represented in tightly packed form, with no extra bits
1079 -- between components. This is true even when the component size is not a
1080 -- factor of the storage unit size, so that as a result it is possible for
1081 -- components to cross storage unit boundaries.
1083 -- The layout in storage is identical, regardless of whether the
1084 -- implementation type is a modular type or an array-of-bytes type. See
1085 -- Exp_Pakd for details of how these implementation types are used, but for
1086 -- the purpose of the debugger, only the starting address of the object in
1087 -- memory is significant.
1089 -- The following example should show clearly how the packing works in
1090 -- the little-endian and big-endian cases:
1092 -- type B is range 0 .. 7;
1093 -- for B'Size use 3;
1095 -- type BA is array (0 .. 5) of B;
1096 -- pragma Pack (BA);
1098 -- BV : constant BA := (1,2,3,4,5,6);
1100 -- Little endian case
1102 -- BV'Address + 2 BV'Address + 1 BV'Address + 0
1103 -- +-----------------+-----------------+-----------------+
1104 -- | ? ? ? ? ? ? 1 1 | 0 1 0 1 1 0 0 0 | 1 1 0 1 0 0 0 1 |
1105 -- +-----------------+-----------------+-----------------+
1106 -- <---------> <-----> <---> <---> <-----> <---> <--->
1107 -- unused bits BV(5) BV(4) BV(3) BV(2) BV(1) BV(0)
1109 -- Big endian case
1111 -- BV'Address + 0 BV'Address + 1 BV'Address + 2
1112 -- +-----------------+-----------------+-----------------+
1113 -- | 0 0 1 0 1 0 0 1 | 1 1 0 0 1 0 1 1 | 1 0 ? ? ? ? ? ? |
1114 -- +-----------------+-----------------+-----------------+
1115 -- <---> <---> <-----> <---> <---> <-----> <--------->
1116 -- BV(0) BV(1) BV(2) BV(3) BV(4) BV(5) unused bits
1118 -- Note that if a modular type is used to represent the array, the
1119 -- allocation in memory is not the same as a normal modular type. The
1120 -- difference occurs when the allocated object is larger than the size of
1121 -- the array. For a normal modular type, we extend the value on the left
1122 -- with zeroes.
1124 -- For example, in the normal modular case, if we have a 6-bit modular
1125 -- type, declared as mod 2**6, and we allocate an 8-bit object for this
1126 -- type, then we extend the value with two bits on the most significant
1127 -- end, and in either the little-endian or big-endian case, the value 63
1128 -- is represented as 00111111 in binary in memory.
1130 -- For a modular type used to represent a packed array, the rule is
1131 -- different. In this case, if we have to extend the value, then we do it
1132 -- with undefined bits (which are not initialized and whose value is
1133 -- irrelevant to any generated code). Furthermore these bits are on the
1134 -- right (least significant bits) in the big-endian case, and on the left
1135 -- (most significant bits) in the little-endian case.
1137 -- For example, if we have a packed boolean array of 6 bits, all set to
1138 -- True, stored in an 8-bit object, then the value in memory in binary is
1139 -- ??111111 in the little-endian case, and 111111?? in the big-endian case.
1141 -- This is done so that the representation of packed arrays does not
1142 -- depend on whether we use a modular representation or array of bytes
1143 -- as previously described. This ensures that we can pass such values by
1144 -- reference in the case where a subprogram has to be able to handle values
1145 -- stored in either form.
1147 -- Note that when we extract the value of such a modular packed array, we
1148 -- expect to retrieve only the relevant bits, so in this same example, when
1149 -- we extract the value we get 111111 in both cases, and the code generated
1150 -- by the front end assumes this although it does not assume that any high
1151 -- order bits are defined.
1153 -- There are opportunities for optimization based on the knowledge that the
1154 -- unused bits are irrelevant for these type of packed arrays. For example
1155 -- if we have two such 6-bit-in-8-bit values and we do an assignment:
1157 -- a := b;
1159 -- Then logically, we extract the 6 bits and store only 6 bits in the
1160 -- result, but the back end is free to simply assign the entire 8-bits in
1161 -- this case, since we don't actually care about the undefined bits.
1162 -- However, in the equality case, it is important to ensure that the
1163 -- undefined bits do not participate in an equality test.
1165 -- If a modular packed array value is assigned to a register then logically
1166 -- it could always be held right justified, to avoid any need to shift,
1167 -- e.g. when doing comparisons. But probably this is a bad choice, as it
1168 -- would mean that an assignment such as a := above would require shifts
1169 -- when one value is in a register and the other value is in memory.
1171 -------------------------------------------
1172 -- Packed Array Name Encoding (OBSOLETE) --
1173 -------------------------------------------
1175 -- For every constrained packed array, two types are created, and both
1176 -- appear in the debugging output:
1178 -- The original declared array type is a perfectly normal array type, and
1179 -- its index bounds indicate the original bounds of the array.
1181 -- The corresponding packed array type, which may be a modular type, or
1182 -- may be an array of bytes type (see Exp_Pakd for full details). This is
1183 -- the type that is actually used in the generated code and for debugging
1184 -- information for all objects of the packed type.
1186 -- The name of the corresponding packed array type is:
1188 -- ttt___XPnnn
1190 -- where
1192 -- ttt is the name of the original declared array
1193 -- nnn is the component size in bits (1-31)
1195 -- Note that if the packed array is not bit-packed, the name will simply
1196 -- be tttP.
1198 -- When the debugger sees that an object is of a type that is encoded in
1199 -- this manner, it can use the original type to determine the bounds and
1200 -- the component type, and the component size to determine the packing
1201 -- details.
1203 -- For an unconstrained packed array, the corresponding packed array type
1204 -- is neither used in the generated code nor for debugging information,
1205 -- only the original type is used. In order to convey the packing in the
1206 -- debugging information, the compiler generates the associated fat- and
1207 -- thin-pointer types (see the Pointers to Unconstrained Array section
1208 -- below) using the name of the corresponding packed array type as the
1209 -- base name, i.e. ttt___XPnnn___XUP and ttt___XPnnn___XUT respectively.
1211 -- When the debugger sees that an object is of a type that is encoded in
1212 -- this manner, it can use the type of the fields to determine the bounds
1213 -- and the component type, and the component size to determine the packing
1214 -- details.
1216 ------------------------------------------------------
1217 -- Subprograms for Handling Packed Array Type Names --
1218 ------------------------------------------------------
1220 function Make_Packed_Array_Impl_Type_Name
1221 (Typ : Entity_Id;
1222 Csize : Uint) return Name_Id;
1223 -- This function is used in Exp_Pakd to create the name that is encoded as
1224 -- described above. The entity Typ provides the name ttt, and the value
1225 -- Csize is the component size that provides the nnn value.
1227 --------------------------------------
1228 -- Pointers to Unconstrained Arrays --
1229 --------------------------------------
1231 -- There are two kinds of pointer to unconstrained arrays. The debugger can
1232 -- tell which format is in use by the form of the type of the pointer.
1234 -- Fat Pointers
1236 -- Fat pointers are represented as a structure with two fields. This
1237 -- structure has two distinguished field names:
1239 -- P_ARRAY is a pointer to the array type. The name of this type is
1240 -- the unconstrained type followed by "___XUA". The bounds of this
1241 -- array will be obtained through dereferences of P_BOUNDS below.
1243 -- P_BOUNDS is a pointer to a structure. The name of this type is
1244 -- the unconstrained array name followed by "___XUB" and it has
1245 -- fields of the form:
1247 -- LBn (n a decimal integer) lower bound of n'th dimension
1248 -- UBn (n a decimal integer) upper bound of n'th dimension
1250 -- The bounds may be of any integral type. In the case of enumeration
1251 -- types, Enum_Rep values are used.
1253 -- For a given unconstrained array type, the compiler will generate a
1254 -- fat pointer type whose name is the name of the array type, and use
1255 -- it to represent the array type itself in the debugging information.
1257 -- This name was historically followed by "___XUP" (OBSOLETE).
1259 -- For each pointer to this unconstrained array type, the compiler will
1260 -- generate a typedef that points to the above fat pointer type. As a
1261 -- consequence, when it comes to fat pointer types:
1263 -- 1. The type name is given by the typedef, if any
1265 -- 2. If the debugger is asked to output the type, the appropriate
1266 -- form is "access arr" if there is the typedef, otherwise it is
1267 -- the array definition.
1269 -- Thin Pointers
1271 -- The value of a thin pointer is a pointer to the second field of a
1272 -- structure with two fields. The first field of the structure is of
1273 -- the type ___XUB described for fat pointer types above. The second
1274 -- field of the structure contains the actual array.
1276 -- Thin pointers are represented as a regular pointer to array in the
1277 -- debugging information. The bounds of this array will be the contents
1278 -- of the first field above obtained through (shifted) dereferences.
1280 -- Thin Pointers (OBSOLETE)
1282 -- The value of a thin pointer is a pointer to the second field of a
1283 -- structure with two fields. The name of this structure's type is
1284 -- "arr___XUT", where "arr" is the name of the unconstrained array
1285 -- type. Even though it points into the middle of this structure,
1286 -- the type in the debugging information is pointer to structure.
1288 -- The first field of the structure is named BOUNDS and is of the type
1289 -- ___XUB described for fat pointer types above.
1291 -- The second field of the structure is named ARRAY, and contains the
1292 -- actual array. Because this array has a dynamic size, determined by
1293 -- the BOUNDS field that precedes it, all of the information about
1294 -- arr___XUT is encoded in a parallel type named arr___XUT___XVE, with
1295 -- fields BOUNDS and ARRAY___XVL. As for previously described ___XVE
1296 -- types, ARRAY___XVL has a pointer-to-array type. However, the array
1297 -- type in this case is named arr___XUA and only its element type is
1298 -- meaningful, just as described for fat pointers.
1300 -----------------------------
1301 -- Variant Record Encoding --
1302 -----------------------------
1304 -- The variant part of a variant record is encoded as a single field in the
1305 -- enclosing record, whose name is:
1307 -- discrim___XVN
1309 -- where discrim is the unqualified name of the variant. This field name is
1310 -- built by gigi (not by code in this unit). For Unchecked_Union record,
1311 -- this discriminant will not appear in the record (see Unchecked Unions,
1312 -- below).
1314 -- The type corresponding to this field has a name that is obtained by
1315 -- concatenating the type name with the above string and is similar to a C
1316 -- union, in which each member of the union corresponds to one variant.
1317 -- However, unlike a C union, the size of the type may be variable even if
1318 -- each of the components are fixed size, since it includes a computation
1319 -- of which variant is present.
1321 -- The name of the union member is encoded to indicate the choices, and
1322 -- is a string given by the following grammar:
1324 -- member_name ::= {choice} | others_choice
1325 -- choice ::= simple_choice | range_choice
1326 -- simple_choice ::= S number
1327 -- range_choice ::= R number T number
1328 -- number ::= {decimal_digit} [m]
1329 -- others_choice ::= O (upper case letter O)
1331 -- The m in a number indicates a negative value. As an example of this
1332 -- encoding scheme, the choice 1 .. 4 | 7 | -10 would be represented by
1334 -- R1T4S7S10m
1336 -- In the case of enumeration values, the values used are the actual
1337 -- representation values in the case where an enumeration type has an
1338 -- enumeration representation spec (i.e. they are values that correspond
1339 -- to the use of the Enum_Rep attribute).
1341 -- The type of the inner record is given by the name of the union type (as
1342 -- above) concatenated with the above string.
1344 -- As an example, consider:
1346 -- type Var (Disc : Boolean := True) is record
1347 -- M : Integer;
1349 -- case Disc is
1350 -- when True =>
1351 -- R : Integer;
1352 -- S : Integer;
1354 -- when False =>
1355 -- T : Integer;
1356 -- end case;
1357 -- end record;
1359 -- V1 : Var;
1361 -- In this case, the type var is represented as a struct with three fields.
1362 -- The first two are "disc" and "m", representing the values of these
1363 -- record components. The third field is a union of two types, with field
1364 -- names S1 and O. S1 is a struct with fields "r" and "s", and O is a
1365 -- struct with field "t".
1367 ----------------------
1368 -- Unchecked Unions --
1369 ----------------------
1371 -- The encoding for variant records changes somewhat under the influence
1372 -- of a "pragma Unchecked_Union" clause:
1374 -- 1. The discriminant will not be present in the record, although its
1375 -- name is still used in the encodings.
1376 -- 2. Variants containing a single component named "x" of type "T" may
1377 -- be encoded, as in ordinary C unions, as a single field of the
1378 -- enclosing union type named "x" of type "T", dispensing with the
1379 -- enclosing struct. In this case, of course, the discriminant values
1380 -- corresponding to the variant are unavailable.
1382 -- For example, the type Var in the preceding section, if followed by
1383 -- "pragma Unchecked_Union (Var);" may be encoded as a struct with two
1384 -- fields. The first is "m". The second field is a union of two types,
1385 -- with field names S1 and "t". As before, S1 is a struct with fields
1386 -- "r" and "s". "t" is a field of type Integer.
1388 ------------------------------------------------
1389 -- Subprograms for Handling Variant Encodings --
1390 ------------------------------------------------
1392 procedure Get_Variant_Encoding (V : Node_Id);
1393 -- This procedure is called by Gigi with V being the variant node. The
1394 -- corresponding encoding string is returned in Name_Buffer with the length
1395 -- of the string in Name_Len, and an ASCII.NUL character stored following
1396 -- the name.
1398 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1400 ---------------------------------
1401 -- Subtypes of Variant Records --
1402 ---------------------------------
1404 -- A subtype of a variant record is represented by a type in which the
1405 -- union field from the base type is replaced by one of the possible
1406 -- values. For example, if we have:
1408 -- type Var (Disc : Boolean := True) is record
1409 -- M : Integer;
1411 -- case Disc is
1412 -- when True =>
1413 -- R : Integer;
1414 -- S : Integer;
1416 -- when False =>
1417 -- T : Integer;
1418 -- end case;
1420 -- end record;
1421 -- V1 : Var;
1422 -- V2 : Var (True);
1423 -- V3 : Var (False);
1425 -- Here V2, for example, is represented with a subtype whose name is
1426 -- something like TvarS3b, which is a struct with three fields. The first
1427 -- two fields are "disc" and "m" as for the base type, and the third field
1428 -- is S1, which contains the fields "r" and "s".
1430 -- The debugger should simply ignore structs with names of the form
1431 -- corresponding to variants, and consider the fields inside as belonging
1432 -- to the containing record.
1434 -----------------------------------------------
1435 -- Extra renamings for subprogram instances --
1436 -----------------------------------------------
1438 procedure Build_Subprogram_Instance_Renamings
1439 (N : Node_Id;
1440 Wrapper : Entity_Id);
1441 -- The debugger has difficulties in recovering the value of actuals of an
1442 -- elementary type, from within the body of a subprogram instantiation.
1443 -- This is because such actuals generate an object declaration that is
1444 -- placed within the wrapper package of the instance, and the entity in
1445 -- these declarations is encoded in a complex way that GDB does not handle
1446 -- well. These new renaming declarations appear within the body of the
1447 -- subprogram, and are redundant from a visibility point of view, but They
1448 -- should have no measurable performance impact, and require no special
1449 -- decoding in the debugger.
1451 -------------------------------------------
1452 -- Character literals in Character Types --
1453 -------------------------------------------
1455 -- Character types are enumeration types at least one of whose enumeration
1456 -- literals is a character literal. Enumeration literals are usually simply
1457 -- represented using their identifier names. If the enumeration literal is
1458 -- a character literal, the name is encoded as described in the following
1459 -- paragraph.
1461 -- The characters 'a'..'z' and '0'..'9' are represented as Qc, where 'c'
1462 -- stands for the character itself. A name QUhh, where each 'h' is a
1463 -- lower-case hexadecimal digit, stands for a character whose Unicode
1464 -- encoding is hh, and QWhhhh likewise stands for a wide character whose
1465 -- encoding is hhhh. The representation values are encoded as for ordinary
1466 -- enumeration literals (and have no necessary relationship to the values
1467 -- encoded in the names).
1469 -- For example, given the type declaration
1471 -- type x is (A, 'C', 'b');
1473 -- the second enumeration literal would be named QU43 and the value
1474 -- assigned to it would be 1, and the third enumeration literal would be
1475 -- named Qb and the value assigned to it would be 2.
1477 -----------------------------------------------
1478 -- Secondary Dispatch tables of tagged types --
1479 -----------------------------------------------
1481 procedure Get_Secondary_DT_External_Name
1482 (Typ : Entity_Id;
1483 Ancestor_Typ : Entity_Id;
1484 Suffix_Index : Int);
1485 -- Set Name_Buffer and Name_Len to the external name of one secondary
1486 -- dispatch table of Typ. If the interface has been inherited from some
1487 -- ancestor then Ancestor_Typ is such node (in this case the secondary DT
1488 -- is needed to handle overridden primitives); if there is no such ancestor
1489 -- then Ancestor_Typ is equal to Typ.
1491 -- Internal rule followed for the generation of the external name:
1493 -- Case 1. If the secondary dispatch has not been inherited from some
1494 -- ancestor of Typ then the external name is composed as
1495 -- follows:
1496 -- External_Name (Typ) + Suffix_Number + 'P'
1498 -- Case 2. if the secondary dispatch table has been inherited from some
1499 -- ancestor then the external name is composed as follows:
1500 -- External_Name (Typ) + '_' + External_Name (Ancestor_Typ)
1501 -- + Suffix_Number + 'P'
1503 -- Note: We have to use the external names (instead of simply their names)
1504 -- to protect the frontend against programs that give the same name to all
1505 -- the interfaces and use the expanded name to reference them. The
1506 -- Suffix_Number is used to differentiate all the secondary dispatch
1507 -- tables of a given type.
1509 -- Examples:
1511 -- package Pkg1 is | package Pkg2 is | package Pkg3 is
1512 -- type Typ is | type Typ is | type Typ is
1513 -- interface; | interface; | interface;
1514 -- end Pkg1; | end Pkg; | end Pkg3;
1516 -- with Pkg1, Pkg2, Pkg3;
1517 -- package Case_1 is
1518 -- type Typ is new Pkg1.Typ and Pkg2.Typ and Pkg3.Typ with ...
1519 -- end Case_1;
1521 -- with Case_1;
1522 -- package Case_2 is
1523 -- type Typ is new Case_1.Typ with ...
1524 -- end Case_2;
1526 -- These are the external names generated for Case_1.Typ (note that
1527 -- Pkg1.Typ is associated with the Primary Dispatch Table, because it
1528 -- is the parent of this type, and hence no external name is
1529 -- generated for it).
1530 -- case_1__typ0P (associated with Pkg2.Typ)
1531 -- case_1__typ1P (associated with Pkg3.Typ)
1533 -- These are the external names generated for Case_2.Typ:
1534 -- case_2__typ_case_1__typ0P
1535 -- case_2__typ_case_1__typ1P
1537 ----------------------------
1538 -- Effect of Optimization --
1539 ----------------------------
1541 -- If the program is compiled with optimization on (e.g. -O1 switch
1542 -- specified), then there may be variations in the output from the above
1543 -- specification. In particular, objects may disappear from the output.
1544 -- This includes not only constants and variables that the program declares
1545 -- at the source level, but also the x___L and x___U constants created to
1546 -- describe the lower and upper bounds of subtypes with dynamic bounds.
1547 -- This means for example, that array bounds may disappear if optimization
1548 -- is turned on. The debugger is expected to recognize that these constants
1549 -- are missing and deal as best as it can with the limited information
1550 -- available.
1552 -----------------------------------------
1553 -- GNAT Extensions to DWARF (OBSOLETE) --
1554 -----------------------------------------
1556 -- DW_AT_use_GNAT_descriptive_type, encoded with value 0x2301
1558 -- This extension has never been implemented in the compiler.
1560 -- DW_AT_GNAT_descriptive_type, encoded with value 0x2302
1562 -- Any debugging information entry representing a type may have a
1563 -- DW_AT_GNAT_descriptive_type attribute whose value is a reference,
1564 -- pointing to a debugging information entry representing another type
1565 -- associated to the type.
1567 end Exp_Dbug;