[Ada] unqualified debug variable for library-level package renaming

Arnaud Charlet charlet@adacore.com
Thu Sep 6 09:56:00 GMT 2007


Tested on i686-linux, committed on trunk

The special variable created to encode the gdb name for a package renaming
did not include the embedded name of the renamed package in the case of a
library-level renaming. This qualification was being done for renamings
nested within a unit, but not for entities associated with the auxiliary
declarations of a compilation unit. This showed up as a problem when
linking with shared libraries on IVMS (link conflict between library-level
renamings of DEC.Text_IO and Ada.Text_IO packages). The fix is to enter
the debug variable's declaration in the list of entities that will later
be qualified by Qualify_All_Entity_Names at the point where the library-level
package renaming is expanded.

No simple test is available.

2007-08-31  Gary Dismukes  <dismukes@adacore.com>

	* exp_ch8.adb (Expand_N_Package_Renaming_Declaration): In the case of a
	library-level package renaming, pass the declaration associated with
	the renaming's special debug variable to Qualify_Entity_Names to ensure
	that its encoded name is properly qualified.

	* exp_dbug.adb (Qualify_All_Entity_Names): Check for a variable entity
	occurring in the list of entities to qualify, and do not attempt to
	traverse an entity list in that case. Variables associated with
`	library-level package renamings can now occur in the table.

	* exp_dbug.ads: Revise documentation of the encoding for renaming
	declarations.

-------------- next part --------------
Index: exp_ch8.adb
===================================================================
--- exp_ch8.adb	(revision 127923)
+++ exp_ch8.adb	(working copy)
@@ -319,6 +319,14 @@ package body Exp_Ch8 is
                end if;
 
                Analyze (Decl);
+
+               --  Enter the debug variable in the qualification list, which
+               --  must be done at this point because auxiliary declarations
+               --  occur at the library level and aren't associated with a
+               --  normal scope.
+
+               Qualify_Entity_Names (Decl);
+
                Pop_Scope;
             end;
 
Index: exp_dbug.adb
===================================================================
--- exp_dbug.adb	(revision 127923)
+++ exp_dbug.adb	(working copy)
@@ -1011,17 +1011,25 @@ package body Exp_Dbug is
          E := Defining_Entity (Name_Qualify_Units.Table (J));
          Qualify_Entity_Name (E);
 
-         Ent := First_Entity (E);
-         while Present (Ent) loop
-            Qualify_Entity_Name (Ent);
-            Next_Entity (Ent);
-
-            --  There are odd cases where Last_Entity (E) = E. This happens
-            --  in the case of renaming of packages. This test avoids getting
-            --  stuck in such cases.
+         --  Normally entities in the qualification list are scopes, but in the
+         --  case of a library-level package renaming there is an associated
+         --  variable that encodes the debugger name and that variable is
+         --  entered in the list since it occurs in the Aux_Decls list of the
+         --  compilation and doesn't have a normal scope.
+
+         if Ekind (E) /= E_Variable then
+            Ent := First_Entity (E);
+            while Present (Ent) loop
+               Qualify_Entity_Name (Ent);
+               Next_Entity (Ent);
+
+               --  There are odd cases where Last_Entity (E) = E. This happens
+               --  in the case of renaming of packages. This test avoids
+               --  getting stuck in such cases.
 
-            exit when Ent = E;
-         end loop;
+               exit when Ent = E;
+            end loop;
+         end if;
       end loop;
    end Qualify_All_Entity_Names;
 
Index: exp_dbug.ads
===================================================================
--- exp_dbug.ads	(revision 127923)
+++ exp_dbug.ads	(working copy)
@@ -603,8 +603,7 @@ package Exp_Dbug is
       --   for most debugging formats. However, we do not ever need XD
       --   encoding for enumeration base types, since here it is always
       --   clear what the bounds are from the total number of enumeration
-      --   literals, and of course we do not need to encode the dummy XR
-      --   types generated for renamings.
+      --   literals.
 
       --     typ___XD
       --     typ___XDL_lowerbound
@@ -969,20 +968,23 @@ package Exp_Dbug is
 
    --  Consider a renaming declaration of the form
 
-   --    x typ renames y;
+   --    x : typ renames y;
 
    --  There is one case in which no special debugging information is required,
-   --  namely the case of an object renaming where the backend allocates a
+   --  namely the case of an object renaming where the back end allocates a
    --  reference for the renamed variable, and the entity x is this reference.
    --  The debugger can handle this case without any special processing or
    --  encoding (it won't know it was a renaming, but that does not matter).
 
-   --  All other cases of renaming generate a dummy type definition for
-   --  an entity whose name is:
+   --  All other cases of renaming generate a dummy variable for an entity
+   --  whose name is of the form:
 
-   --    x___XR    for an object renaming
-   --    x___XRE   for an exception renaming
-   --    x___XRP   for a package renaming
+   --    x___XR_...    for an object renaming
+   --    x___XRE_...   for an exception renaming
+   --    x___XRP_...   for a package renaming
+
+   --  and where the "..." represents a suffix that describes the structure of
+   --  the object name given in the renaming (see details below).
 
    --  The name is fully qualified in the usual manner, i.e. qualified in the
    --  same manner as the entity x would be. In the case of a package renaming
@@ -992,24 +994,24 @@ package Exp_Dbug is
 
    --  Note: subprogram renamings are not encoded at the present time
 
-   --  The type is an enumeration type with a single enumeration literal
-   --  that is an identifier which describes the renamed variable.
+   --  The suffix of the variable name describing the renamed object is
+   --  defined to use the following encoding:
 
-   --    For the simple entity case, where y is an entity name,
-   --    the enumeration is of the form:
+   --    For the simple entity case, where y is just an entity name, the suffix
+   --    is of the form:
 
-   --       (y___XE)
+   --       y___XE
 
-   --          i.e. the enumeration type has a single field, whose name matches
-   --          the name y, with the XE suffix. The entity for this enumeration
-   --          literal is fully qualified in the usual manner. All subprogram,
-   --          exception, and package renamings fall into this category, as
-   --          well as simple object renamings.
+   --          i.e. the suffix has a single field, the first part matching the
+   --          name y, followed by a "___" separator, ending with sequence XE.
+   --          The entity name portion is fully qualified in the usual manner.
+   --          This same naming scheme is followed for all forms of encoded
+   --          renamings that rename a simple entity.
 
    --    For the object renaming case where y is a selected component or an
-   --    indexed component, the literal name is suffixed by additional fields
+   --    indexed component, the variable name is suffixed by additional fields
    --    that give details of the components. The name starts as above with a
-   --    y___XE entity indicating the outer level variable. Then a series of
+   --    y___XE name indicating the outer level object entity. Then a series of
    --    selections and indexing operations can be specified as follows:
 
    --      Indexed component
@@ -1020,20 +1022,19 @@ package Exp_Dbug is
 
    --          XSnnn
 
-   --            Here nnn is a constant value, encoded as a decimal
-   --            integer (pos value for enumeration type case). Negative
-   --            values have a trailing 'm' as usual.
+   --            Here nnn is a constant value, encoded as a decimal integer
+   --            (pos value for enumeration type case). Negative values have
+   --            a trailing 'm' as usual.
 
    --          XSe
 
-   --            Here e is the (unqualified) name of a constant entity in
-   --            the same scope as the renaming which contains the subscript
-   --            value.
+   --            Here e is the (unqualified) name of a constant entity in the
+   --            same scope as the renaming which contains the subscript value.
 
    --      Slice
 
    --        For the slice case, we have two entries. The first is for the
-   --        lower bound of the slice, and has the form
+   --        lower bound of the slice, and has the form:
 
    --          XLnnn
    --          XLe
@@ -1069,21 +1070,24 @@ package Exp_Dbug is
    --           z : string renames g (1,5).m(2 ..3)
    --        end p;
 
-   --     The generated type definition would appear as
+   --     The generated variable entity would appear as
 
-   --       type p__z___XR is
-   --         (p__g___XEXS1XS5XRmXL2XS3);
-   --          p__g___XE--------------------outer entity is g
-   --                   XS1-----------------first subscript for g
-   --                      XS5--------------second subscript for g
-   --                         XRm-----------select field m
-   --                            XL2--------lower bound of slice
-   --                               XS3-----upper bound of slice
+   --       p__z___XR_p__g___XEXS1XS5XRmXL2XS3 : _renaming_type;
+   --                 p__g___XE--------------------outer entity is g
+   --                          XS1-----------------first subscript for g
+   --                             XS5--------------second subscript for g
+   --                                XRm-----------select field m
+   --                                   XL2--------lower bound of slice
+   --                                      XS3-----upper bound of slice
+
+   --     Note that the type of the variable is a special internal type named
+   --     _renaming_type. This type is an arbitrary type of zero size created
+   --     in package Standard (see cstand.adb) and is ignored by the debugger.
 
    function Debug_Renaming_Declaration (N : Node_Id) return Node_Id;
-   --  The argument N is a renaming declaration. The result is a type
-   --  declaration as described in the above paragraphs. If not special
-   --  debug declaration, than Empty is returned.
+   --  The argument N is a renaming declaration. The result is a variable
+   --  declaration as described in the above paragraphs. If N is not a special
+   --  debug declaration, then Empty is returned.
 
    ---------------------------
    -- Packed Array Encoding --


More information about the Gcc-patches mailing list