OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [exp_dbug.ads] - Blame information for rev 753

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.