Patchwork [Ada] Fix missing debug info for concatenation

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 2, 2011, 2:39 p.m.
Message ID <20110802143932.GA5791@adacore.com>
Download mbox | patch
Permalink /patch/107934/
State New
Headers show

Comments

Arnaud Charlet - Aug. 2, 2011, 2:39 p.m.
The new concatenation circuitry installed some time ago, results in
missing debug information when a constant string is initialized with
the result of a concatenation. This is because the resulting generated
renaming did not generate required debug information. This patch fixes
the problem with concatenation, and is actually a little more general
than that, so may fix some other problems with missing debug info.

The following is a test program

     1. procedure debugconcat is
     2.    x : string := "hello";
     3.    y : string := "goodbye";
     4.    z : constant string := x & y;
     5. begin
     6.    null;
     7. end;

Before the patch, the debugger could not print the string z. With the
following script:

gnatmake debugconcat -g
cp gdbinit2 .gdbinit
gdb --quiet debugconcat.exe >log 2>&1
rm .gdbinit
grep " = " log

where gdbinit2 contains:
break debugconcat.adb:6
run
print z
quit
y

the output of the grep command should be:

$1 = "hellogoodbye"

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-02  Robert Dewar  <dewar@adacore.com>

	* einfo.ads (Materialize_Entity): Document this is only for renamings
	* exp_ch3.adb (Expand_N_Object_Declaration): Make sure we generate
	required debug information in the case where we transform the object
	declaration into a renaming declaration.
	* exp_ch4.adb (Expand_Concatenate): Generate debug info for result
	object
	* exp_dbug.ads (Debug_Renaming_Declaration): Document setting of
	Materialize_Entity.

Patch

Index: einfo.ads
===================================================================
--- einfo.ads	(revision 177161)
+++ einfo.ads	(working copy)
@@ -2943,11 +2943,10 @@ 
 --       used to reference tasks implementing such interface.
 
 --    Materialize_Entity (Flag168)
---       Present in all entities. Set only for constant or renamed entities
---       which should be materialized for debugging purposes. In the case of
---       a constant, a memory location should be allocated containing the
---       value. In the case of a renaming, a memory location containing the
---       renamed address should be allocated.
+--       Present in all entities. Set only for renamed obects which should be
+--       materialized for debugging purposes. This means that a memory location
+--       containing the renamed address should be allocated. This is needed so
+--       that the debugger can find the entity.
 
 --    Mechanism (Uint8) (returned as Mechanism_Type)
 --       Present in functions and non-generic formal parameters. Indicates
Index: exp_dbug.ads
===================================================================
--- exp_dbug.ads	(revision 176998)
+++ exp_dbug.ads	(working copy)
@@ -1082,7 +1082,8 @@ 
    function Debug_Renaming_Declaration (N : Node_Id) return Node_Id;
    --  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.
+   --  debug declaration, then Empty is returned. This function also takes care
+   --  of setting Materialize_Entity on the renamed entity where required.
 
    ---------------------------
    -- Packed Array Encoding --
Index: exp_ch4.adb
===================================================================
--- exp_ch4.adb	(revision 177156)
+++ exp_ch4.adb	(working copy)
@@ -2875,10 +2875,12 @@ 
 
       --  Now we construct an array object with appropriate bounds. We mark
       --  the target as internal to prevent useless initialization when
-      --  Initialize_Scalars is enabled.
+      --  Initialize_Scalars is enabled. Also since this is the actual result
+      --  entity, we make sure we have debug information for the result.
 
       Ent := Make_Temporary (Loc, 'S');
       Set_Is_Internal (Ent);
+      Set_Needs_Debug_Info (Ent);
 
       --  If the bound is statically known to be out of range, we do not want
       --  to abort, we want a warning and a runtime constraint error. Note that
Index: exp_ch3.adb
===================================================================
--- exp_ch3.adb	(revision 177161)
+++ exp_ch3.adb	(working copy)
@@ -34,6 +34,7 @@ 
 with Exp_Ch7;  use Exp_Ch7;
 with Exp_Ch9;  use Exp_Ch9;
 with Exp_Ch11; use Exp_Ch11;
+with Exp_Dbug; use Exp_Dbug;
 with Exp_Disp; use Exp_Disp;
 with Exp_Dist; use Exp_Dist;
 with Exp_Smem; use Exp_Smem;
@@ -5215,6 +5216,26 @@ 
 
             Set_Renamed_Object (Defining_Identifier (N), Expr_Q);
             Set_Analyzed (N);
+
+            --  We do need to deal with debug issues for this renaming
+
+            --  First, if entity comes from source, then mark it as needing
+            --  debug information, even though it is defined by a generated
+            --  renaming that does not come from source.
+
+            if Comes_From_Source (Defining_Identifier (N)) then
+               Set_Needs_Debug_Info (Defining_Identifier (N));
+            end if;
+
+            --  Now call the routine to generate debug info for the renaming
+
+            declare
+               Decl : constant Node_Id := Debug_Renaming_Declaration (N);
+            begin
+               if Present (Decl) then
+                  Insert_Action (N, Decl);
+               end if;
+            end;
          end if;
       end if;